Noten Tab: delete

This commit is contained in:
cgfhtw
2024-12-05 16:19:51 +01:00
parent 3969ebfa01
commit 6fdad1b664
5 changed files with 176 additions and 18 deletions
@@ -96,8 +96,9 @@ class Config extends FHCAPI_Controller
'component' => './Stv/Studentenverwaltung/Details/Noten.js',
'showOnlyWithUid' => true,
'config' => [
'usePoints' => defined('CIS_GESAMTNOTE_PUNKTE') && CIS_GESAMTNOTE_PUNKTE,
'edit' => 'both', // Possible values: both|header|inline
'usePoints' => defined('CIS_GESAMTNOTE_PUNKTE') && CIS_GESAMTNOTE_PUNKTE
'delete' => 'both', // Possible values: both|header|inline
]
];
@@ -33,6 +33,7 @@ class Grades extends FHCAPI_Controller
'getTeacherProposal' => 'student/noten:r',
'getRepeaterGrades' => 'student/noten:r',
'updateCertificate' => ['admin:w', 'assistenz:w'],
'deleteCertificate' => ['admin:w', 'assistenz:w'],
'copyTeacherProposalToCertificate' => 'student/noten:w',
'copyRepeaterGradeToCertificate' => 'student/noten:w',
'getGradeFromPoints' => 'student/noten:r'
@@ -153,15 +154,66 @@ class Grades extends FHCAPI_Controller
$this->load->model('education/Zeugnisnote_model', 'ZeugnisnoteModel');
$result = $this->ZeugnisnoteModel->update([
$result = $this->ZeugnisnoteModel->load([
'studiensemester_kurzbz' => $studiensemester_kurzbz,
'student_uid' => $student_uid,
'lehrveranstaltung_id' => $lehrveranstaltung_id
]);
$current = $this->getDataOrTerminateWithError($result);
if ($current) {
$result = $this->ZeugnisnoteModel->update([
'studiensemester_kurzbz' => $studiensemester_kurzbz,
'student_uid' => $student_uid,
'lehrveranstaltung_id' => $lehrveranstaltung_id
], [
'note' => $note,
'benotungsdatum' => $now,
'updateamum' => $now,
'updatevon' => $authUID
]);
} else {
$result = $this->ZeugnisnoteModel->insert([
'studiensemester_kurzbz' => $studiensemester_kurzbz,
'student_uid' => $student_uid,
'lehrveranstaltung_id' => $lehrveranstaltung_id,
'note' => $note,
'benotungsdatum' => $now,
'insertamum' => $now,
'insertvon' => $authUID
]);
}
$this->getDataOrTerminateWithError($result);
$this->terminateWithSuccess(true);
}
public function deleteCertificate()
{
$this->load->library('form_validation');
$this->form_validation->set_rules("lehrveranstaltung_id", $this->p->t('lehre', 'lehrveranstaltung'), "required|integer");
$this->form_validation->set_rules("student_uid", $this->p->t('person', 'student'), "required");
$this->form_validation->set_rules("studiensemester_kurzbz", $this->p->t('lehre', 'studiensemester'), "required");
if (!$this->form_validation->run())
$this->terminateWithValidationErrors($this->form_validation->error_array());
$studiensemester_kurzbz = $this->input->post('studiensemester_kurzbz');
$student_uid = $this->input->post('student_uid');
$lehrveranstaltung_id = $this->input->post('lehrveranstaltung_id');
// NOTE(chris): Stg Permissions
if (!$this->hasPermissionDelete($lehrveranstaltung_id, $student_uid))
return $this->_outputAuthError([$this->router->method => ['admin', 'assistenz']]);
$this->load->model('education/Zeugnisnote_model', 'ZeugnisnoteModel');
$result = $this->ZeugnisnoteModel->delete([
'studiensemester_kurzbz' => $studiensemester_kurzbz,
'student_uid' => $student_uid,
'lehrveranstaltung_id' => $lehrveranstaltung_id
], [
'note' => $note,
'benotungsdatum' => $now,
'updateamum' => $now,
'updatevon' => $authUID
]);
$this->getDataOrTerminateWithError($result);
@@ -467,6 +519,40 @@ class Grades extends FHCAPI_Controller
return false;
}
protected function hasPermissionDelete($lehrveranstaltung_id, $student_uid)
{
if ($lehrveranstaltung_id === null || $student_uid === null)
return true;
$this->load->model('crm/Student_model', 'StudentModel');
$result = $this->StudentModel->load([$student_uid]);
if (isError($result) || !hasData($result))
return false;
$student = current(getData($result));
if ($this->permissionlib->isBerechtigt('admin', 'suid', $student->studiengang_kz))
return true;
if ($this->permissionlib->isBerechtigt('assistenz', 'suid', $student->studiengang_kz))
return true;
$this->load->model('education/Lehrveranstaltung_model', 'LehrveranstaltungModel');
$result = $this->LehrveranstaltungModel->load($lehrveranstaltung_id);
if (isError($result) || !hasData($result))
return false;
$oe = current(getData($result));
if ($this->permissionlib->isBerechtigt('admin', 'suid', $oe->oe_kurzbz))
return true;
if ($this->permissionlib->isBerechtigt('assistenz', 'suid', $oe->oe_kurzbz))
return true;
return false;
}
protected function hasPermissionCopy($lehrveranstaltung_id, $student_uid)
{
if ($lehrveranstaltung_id === null || $student_uid === null)
+13
View File
@@ -28,6 +28,19 @@ export default {
}
);
},
deleteCertificate({lehrveranstaltung_id, student_uid, studiensemester_kurzbz, lehrveranstaltung_bezeichnung}) {
return this.$fhcApi.post(
'api/frontend/v1/stv/grades/deleteCertificate',
{
lehrveranstaltung_id,
student_uid,
studiensemester_kurzbz
},
{
errorHeader: lehrveranstaltung_bezeichnung
}
);
},
copyTeacherProposalToCertificate({lehrveranstaltung_id, student_uid, studiensemester_kurzbz, lehrveranstaltung_bezeichnung}) {
return this.$fhcApi.post(
'api/frontend/v1/stv/grades/copyTeacherProposalToCertificate',
@@ -66,6 +66,7 @@ export default {
.then(() => cell.getRow().reformat())
// cleanup
.then(cell.clearEdited)
.then(() => this.$fhcAlert.alertSuccess('updated')) // TODO(chris): phrase
.catch(err => {
cell.restoreOldValue();
cell.clearEdited();
@@ -124,6 +125,39 @@ export default {
{ field: 'lehrveranstaltung_bezeichnung_english', title: 'Englisch', visible: false }
];
const hasDownload = ['both', 'inline'].includes(this.config.download);
const hasDelete = ['both', 'inline'].includes(this.config.delete);
if (hasDownload || hasDelete) {
columns.push({
field: 'actions',
title: 'Actions',
headerSort: false,
formatter: cell => {
// get row data
const data = cell.getData();
data.student_uid = data.uid;
let container = document.createElement('div');
container.className = "d-flex gap-2 justify-content-end";
if (hasDelete) {
let deleteButton = document.createElement('button');
deleteButton.className = 'btn btn-outline-secondary';
deleteButton.innerHTML = '<i class="fa fa-trash"></i>';
deleteButton.addEventListener('click', evt => {
evt.stopPropagation();
this.deleteGrade(data);
});
container.append(deleteButton);
}
return container;
},
frozen: true
});
}
return {
ajaxURL: 'dummy',
ajaxRequestFunc: (url, config, params) => {
@@ -139,7 +173,6 @@ export default {
return response.data || [];
},
columns,
layout: 'fitDataStretch',
height: '100%',
selectable: 1,
selectableRangeMode: 'click',
@@ -156,11 +189,21 @@ export default {
}
},
methods: {
setGrades(selected) {
setGrade(data) {
this.$fhcApi.factory
.stv.grades.updateCertificate(selected.find(Boolean))
.stv.grades.updateCertificate(data)
.then(this.$refs.table.reloadTable)
.then(() => this.$fhcAlert.alertSuccess('updated')) // TODO(chris): phrase
.catch(this.$fhcAlert.handleFormValidation);
},
deleteGrade(data) {
return this.$fhcAlert
.confirmDelete()
.then(result => result ? data : Promise.reject({handled:true}))
.then(this.$fhcApi.factory.stv.grades.deleteCertificate)
.then(this.$refs.table.reloadTable)
.then(() => this.$fhcAlert.alertSuccess('deleted')) // TODO(chris): phrase
.catch(this.$fhcAlert.handleSystemError);
}
},
// TODO(chris): phrasen
@@ -176,8 +219,8 @@ export default {
:side-menu="false"
reload
>
<template v-if="['both', 'header'].includes(config.edit)" #actions="{selected}">
<zeugnis-actions :selected="selected" @set-grades="setGrades"></zeugnis-actions>
<template v-if="['both', 'header'].includes(config.edit) || ['both', 'header'].includes(config.delete)" #actions="{selected}">
<zeugnis-actions :selected="selected" @set-grade="setGrade" @delete-grade="deleteGrade"></zeugnis-actions>
</template>
</core-filter-cmpt>
</div>`
@@ -8,7 +8,8 @@ export default {
FormInput
},
emits: [
'setGrades'
'setGrade',
'deleteGrade'
],
inject: [
'config'
@@ -24,6 +25,12 @@ export default {
};
},
computed: {
selectedData() {
return this.selected.map(zeugnis => {
const { lehrveranstaltung_id, uid: student_uid, studiensemester_kurzbz } = zeugnis;
return { lehrveranstaltung_id, student_uid, studiensemester_kurzbz };
})
},
current: {
get() {
if (!this.selected.length)
@@ -39,10 +46,7 @@ export default {
return '';
},
set(note) {
this.$emit('setGrades', this.selected.map(zeugnis => {
const { lehrveranstaltung_id, uid: student_uid, studiensemester_kurzbz } = zeugnis;
return { lehrveranstaltung_id, student_uid, studiensemester_kurzbz, note };
}));
this.selectedData.forEach(data => this.$emit('setGrade', {...data, ...{note}}));
}
},
currentLabel() {
@@ -72,6 +76,9 @@ export default {
this.selected.forEach(grade => grade.note = note);
this.currentPoints = '';
this.current = note;
},
deleteGrades() {
this.selectedData.forEach(data => this.$emit('deleteGrade', data));
}
},
created() {
@@ -84,7 +91,7 @@ export default {
},
// TODO(chris): phrases
template: `
<div class="stv-details-noten-zeugnis-actions">
<div class="stv-details-noten-zeugnis-actions d-flex gap-2">
<template v-if="['both', 'header'].includes(config.edit)">
<core-form
v-if="config.usePoints"
@@ -110,5 +117,13 @@ export default {
<option v-for="grade in grades" :key="grade.note" :value="grade.note">{{ grade.bezeichnung }}</option>
</select>
</template>
<button
v-if="['both', 'header'].includes(config.delete)"
class="btn btn-outline-secondary"
:disabled="!selected.length"
@click="deleteGrades"
>
<i class="fa fa-trash"></i>
</button>
</div>`
};