From 6fdad1b664bb64f3720b338793f6707b8414c085 Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Thu, 5 Dec 2024 16:19:51 +0100 Subject: [PATCH] Noten Tab: delete --- .../api/frontend/v1/stv/Config.php | 3 +- .../api/frontend/v1/stv/Grades.php | 98 +++++++++++++++++-- public/js/api/stv/grades.js | 13 +++ .../Details/Noten/Zeugnis.js | 53 +++++++++- .../Details/Noten/Zeugnis/Actions.js | 27 +++-- 5 files changed, 176 insertions(+), 18 deletions(-) diff --git a/application/controllers/api/frontend/v1/stv/Config.php b/application/controllers/api/frontend/v1/stv/Config.php index 111087d21..0f12f5fa3 100644 --- a/application/controllers/api/frontend/v1/stv/Config.php +++ b/application/controllers/api/frontend/v1/stv/Config.php @@ -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 ] ]; diff --git a/application/controllers/api/frontend/v1/stv/Grades.php b/application/controllers/api/frontend/v1/stv/Grades.php index ecb452b5a..c0628399a 100644 --- a/application/controllers/api/frontend/v1/stv/Grades.php +++ b/application/controllers/api/frontend/v1/stv/Grades.php @@ -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) diff --git a/public/js/api/stv/grades.js b/public/js/api/stv/grades.js index c4532863b..135cd836c 100644 --- a/public/js/api/stv/grades.js +++ b/public/js/api/stv/grades.js @@ -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', diff --git a/public/js/components/Stv/Studentenverwaltung/Details/Noten/Zeugnis.js b/public/js/components/Stv/Studentenverwaltung/Details/Noten/Zeugnis.js index b52c1eb1b..e1d926d3d 100644 --- a/public/js/components/Stv/Studentenverwaltung/Details/Noten/Zeugnis.js +++ b/public/js/components/Stv/Studentenverwaltung/Details/Noten/Zeugnis.js @@ -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 = ''; + 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 > -