From 6428fccc48f600f3aa3b75581e601e369e2f7223 Mon Sep 17 00:00:00 2001 From: chfhtw Date: Wed, 1 Jul 2026 15:45:09 +0200 Subject: [PATCH] Replace CoreRESTClient calls with $api calls in stv Studiensemester component and add logic to accept lowercase input (because it could come from the url) --- .../v1/organisation/Studiensemester.php | 39 +++++++++- .../components/stv/Studiensemester.php | 78 ------------------- public/js/api/factory/studiensemester.js | 15 ++++ .../Studentenverwaltung/Studiensemester.js | 61 +++++++++------ 4 files changed, 90 insertions(+), 103 deletions(-) delete mode 100644 application/controllers/components/stv/Studiensemester.php diff --git a/application/controllers/api/frontend/v1/organisation/Studiensemester.php b/application/controllers/api/frontend/v1/organisation/Studiensemester.php index 3c6b72d2f..eaafc6ac5 100644 --- a/application/controllers/api/frontend/v1/organisation/Studiensemester.php +++ b/application/controllers/api/frontend/v1/organisation/Studiensemester.php @@ -26,7 +26,9 @@ class Studiensemester extends FHCAPI_Controller 'getAll' => self::PERM_LOGGED, 'getAktNext' => self::PERM_LOGGED, 'getStudienjahrByStudiensemester' => self::PERM_LOGGED, - 'getAllStudiensemesterAndAktOrNext' => self::PERM_LOGGED + 'getAllStudiensemesterAndAktOrNext' => self::PERM_LOGGED, + 'current' => self::PERM_LOGGED, + 'set' => self::PERM_LOGGED ) ); // Load model StudiensemesterModel @@ -166,4 +168,39 @@ class Studiensemester extends FHCAPI_Controller $this->terminateWithSuccess(array($studiensemester, $aktuell)); } + + public function current() + { + $result = $this->StudiensemesterModel->getNearest(); + + $data = $this->getDataOrTerminateWithError($result); + + if (!$data) + $this->terminateWithError('Kein Studiensemester aktiv'); + if (count($data) > 1) + $this->terminateWithError('Mehrere Studiensemester aktiv'); + + $this->terminateWithSuccess(current($data)->studiensemester_kurzbz); + } + + public function set() + { + $this->load->library('AuthLib'); + $this->load->library('form_validation'); + + $this->form_validation->set_rules('studiensemester_kurzbz', 'Studiensemester', 'required'); + + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + + $stdsem = $this->input->post('studiensemester_kurzbz'); + + $this->load->model('system/Variable_model', 'VariableModel'); + + $result = $this->VariableModel->setVariable(getAuthUID(), 'semester_aktuell', $stdsem); + + $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess(true); + } } diff --git a/application/controllers/components/stv/Studiensemester.php b/application/controllers/components/stv/Studiensemester.php deleted file mode 100644 index c3db99686..000000000 --- a/application/controllers/components/stv/Studiensemester.php +++ /dev/null @@ -1,78 +0,0 @@ - self::PERM_LOGGED, - 'now' => self::PERM_LOGGED, - 'set' => self::PERM_LOGGED - ]); - } - - public function index() - { - $this->load->model('organisation/Studiensemester_model', 'StudiensemesterModel'); - - $this->StudiensemesterModel->addOrder('start'); - - $result = $this->StudiensemesterModel->load(); - - if (isError($result)) { - $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); - } - $this->outputJson($result); - } - - public function now() - { - $this->load->model('organisation/Studiensemester_model', 'StudiensemesterModel'); - - $result = $this->StudiensemesterModel->getNearest(); - - 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->outputJsonError(count($result) ? 'Mehrere Studiensemester aktiv' : 'Kein Studiensemester aktiv'); - } else { - $this->outputJsonSuccess(current($result)->studiensemester_kurzbz); - } - } - - public function set() - { - $this->load->library('AuthLib'); - $this->load->library('form_validation'); - - $_POST = json_decode(utf8_encode($this->input->raw_input_stream), true); - - $this->form_validation->set_rules('studiensemester', 'Studiensemester', 'required'); - - if ($this->form_validation->run() == false) { - $this->output->set_status_header(REST_Controller::HTTP_BAD_REQUEST); - return $this->outputJsonError($this->form_validation->error_array()); - } - - $stdsem = $this->input->post('studiensemester'); - - $this->load->model('system/Variable_model', 'VariableModel'); - - $result = $this->VariableModel->setVariable(getAuthUID(), 'semester_aktuell', $stdsem); - - if (isError($result)) { - $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); - return $this->outputJson($result); - } - - $this->outputJsonSuccess(true); - } -} diff --git a/public/js/api/factory/studiensemester.js b/public/js/api/factory/studiensemester.js index 7fe4a22d3..f57c10763 100644 --- a/public/js/api/factory/studiensemester.js +++ b/public/js/api/factory/studiensemester.js @@ -29,5 +29,20 @@ export default { url: 'api/frontend/v1/organisation/studiensemester/getAll', params: { order, start } }; + }, + current() { + return { + method: 'get', + url: 'api/frontend/v1/organisation/studiensemester/current' + }; + }, + set(studiensemester_kurzbz) { + return { + method: 'post', + url: 'api/frontend/v1/organisation/studiensemester/set', + params: { + studiensemester_kurzbz + } + }; } }; \ No newline at end of file diff --git a/public/js/components/Stv/Studentenverwaltung/Studiensemester.js b/public/js/components/Stv/Studentenverwaltung/Studiensemester.js index 32b0a831d..33230b54a 100644 --- a/public/js/components/Stv/Studentenverwaltung/Studiensemester.js +++ b/public/js/components/Stv/Studentenverwaltung/Studiensemester.js @@ -1,4 +1,4 @@ -import {CoreRESTClient} from '../../../RESTClient.js'; +import ApiStudiensemester from '../../../api/factory/studiensemester.js'; export default { emits: [ @@ -18,6 +18,11 @@ export default { today: -1 }; }, + computed: { + lowerCaseList() { + return this.list.map(i => i.toLowerCase()); + } + }, methods: { set(n) { this.loading = true; @@ -47,25 +52,18 @@ export default { } this.loading = true; - CoreRESTClient - .get('components/stv/studiensemester/now') - .then(result => CoreRESTClient.getData(result.data)) + this.$api + .call(ApiStudiensemester.current()) .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) - } + this.today = this.list.indexOf(result.data); + if (this.today >= 0 && this.today != this.current) + this.set(this.today); }) .catch(this.$fhcAlert.handleSystemError); }, save(fallback) { - CoreRESTClient - .post('components/stv/studiensemester/set', { - studiensemester: this.list[this.current] - }) + this.$api + .call(ApiStudiensemester.set(this.list[this.current])) .then(() => { this.loading = false; this.$emit('update:studiensemesterKurzbz', this.list[this.current]); @@ -73,27 +71,42 @@ export default { .catch(error => { this.current = fallback; this.loading = false; - this.$fhcAlert.handleFormValidation(error); + this.$fhcAlert.handleSystemError(error); }); + }, + index() { + let index = this.list.indexOf(this.studiensemesterKurzbz); + if (index >= 0) + return index; + + // check if input is lower cases (because it came from an url) + index = this.lowerCaseList.indexOf(this.studiensemesterKurzbz); + if (index >= 0) { + this.$emit('update:studiensemesterKurzbz', this.list[index]); + return index; + } + + this.$emit('update:studiensemesterKurzbz', null); + return -1; } }, watch: { - 'studiensemesterKurzbz': function () { - this.current = this.list.indexOf(this.studiensemesterKurzbz); + studiensemesterKurzbz() { + if (!this.loading) + this.current = this.index(this.studiensemesterKurzbz); } }, created() { - CoreRESTClient - .get('components/stv/studiensemester') - .then(result => CoreRESTClient.getData(result.data) || []) + this.$api + .call(ApiStudiensemester.getAll()) .then(result => { - this.list = result.map(el => el.studiensemester_kurzbz); + this.list = result.data.map(el => el.studiensemester_kurzbz); this.loading = false; - this.current = this.list.indexOf(this.studiensemesterKurzbz); + this.current = this.index(this.studiensemesterKurzbz); }) .catch(this.$fhcAlert.handleSystemError); }, - template: ` + template: /* html */`