From 65bf35fa3eb6d2ef026d029426c56ec99744d47d Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Mon, 16 Oct 2023 13:51:21 +0200 Subject: [PATCH] Studiensemester now --- .../components/stv/Studiensemester.php | 22 ++++++- .../Studentenverwaltung/Studiensemester.js | 60 ++++++++++++++----- 2 files changed, 67 insertions(+), 15 deletions(-) diff --git a/application/controllers/components/stv/Studiensemester.php b/application/controllers/components/stv/Studiensemester.php index 3c23a1534..88c95cd71 100644 --- a/application/controllers/components/stv/Studiensemester.php +++ b/application/controllers/components/stv/Studiensemester.php @@ -29,6 +29,26 @@ class Studiensemester extends FHC_Controller } } + public function now() + { + $this->load->model('organisation/Studiensemester_model', 'StudiensemesterModel'); + + $result = $this->StudiensemesterModel->getAkt(); + + if (isError($result)) { + $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); + $this->outputJson(getError($result)); + } + $result = getData($result) ?: []; + + if (count($result) != 1) { + $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); + $this->outputJson(count($result) ? 'Mehrere Studiensemester aktiv' : 'Kein Studiensemester aktiv'); + } else { + $this->outputJson(current($result)->studiensemester_kurzbz); + } + } + public function set() { $this->load->library('AuthLib'); @@ -39,7 +59,7 @@ class Studiensemester extends FHC_Controller $this->form_validation->set_rules('studiensemester', 'Studiensemester', 'required'); if ($this->form_validation->run() == false) { - $this->output->set_status_header(HTTP_BAD_REQUEST); + $this->output->set_status_header(REST_Controller::HTTP_BAD_REQUEST); return $this->outputJson($this->form_validation->error_array()); } diff --git a/public/js/components/Stv/Studentenverwaltung/Studiensemester.js b/public/js/components/Stv/Studentenverwaltung/Studiensemester.js index 09d0cb532..24a9e7206 100644 --- a/public/js/components/Stv/Studentenverwaltung/Studiensemester.js +++ b/public/js/components/Stv/Studentenverwaltung/Studiensemester.js @@ -14,7 +14,8 @@ export default { return { current: 0, loading: true, - list: [] + list: [], + today: -1 }; }, methods: { @@ -38,6 +39,31 @@ export default { this.current = 0; this.save(fallback); }, + setToToday() { + if (this.today > 0) { + if (this.today == this.current) + return; + return this.set(this.today); + } + + this.loading = true; + CoreRESTClient + .get('components/stv/studiensemester/now') + .then(result => result.data) + .then(result => { + this.today = this.list.indexOf(result); + if (this.today > 0) { + if (this.today != this.current) + this.set(this.today); + } else { + // TODO(chris): handle error (list might not be loaded yet) + } + }) + .catch(error => { + // TODO(chris): emit error + console.error(error); + }); + }, save(fallback) { CoreRESTClient .post('components/stv/studiensemester/set', { @@ -47,9 +73,10 @@ export default { this.loading = false; this.$emit('changed'); }) - .catch(() => { + .catch(error => { this.current = fallback; // TODO(chris): emit error + console.error(error); }); } }, @@ -68,18 +95,23 @@ export default { }, template: `
-
- - - - +
`