diff --git a/application/controllers/api/frontend/v1/stv/Filter.php b/application/controllers/api/frontend/v1/stv/Filter.php new file mode 100644 index 000000000..d5ee44d13 --- /dev/null +++ b/application/controllers/api/frontend/v1/stv/Filter.php @@ -0,0 +1,90 @@ +. + */ + +if (!defined('BASEPATH')) exit('No direct script access allowed'); + +/** + * This controller operates between (interface) the JS (GUI) and the back-end + * Provides data to the ajax get calls about the Studiengang filter + * Listens to ajax post calls to change the Studiengang filter data + * This controller works with JSON calls on the HTTP GET or POST and the output is always JSON + */ +class Filter extends FHCAPI_Controller +{ + /** + * Calls the parent's constructor and prepares libraries and phrases + */ + public function __construct() + { + // TODO(chris): permissions + parent::__construct([ + 'getStg' => 'student/stammdaten:r',#self::PERM_LOGGED, + 'setStg' => 'student/stammdaten:r'#self::PERM_LOGGED + ]); + + // Load models + $this->load->model('system/Variable_model', 'VariableModel'); + } + + //------------------------------------------------------------------------------------------------------------------ + // Public methods + + /** + * Get current setting + * + * @return void + */ + public function getStg() + { + $result = $this->VariableModel->getVariables(getAuthUID(), ['kontofilterstg']); + + #$data = $this->getDataOrTerminateWithError($result); + if (isError($result)) + $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + $data = $result->retval; + + $this->terminateWithSuccess($data['kontofilterstg'] == 'true'); + } + + /** + * Set current setting + * + * @return void + */ + public function setStg() + { + $this->load->library('form_validation'); + + $studiengang_kz = $this->input->post('studiengang_kz'); + + if ($studiengang_kz === null) { + $this->form_validation->set_rules('studiengang_kz', 'Studiengang', 'required'); + + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + } + + $result = $this->VariableModel->setVariable(getAuthUID(), 'kontofilterstg', $studiengang_kz ? 'true' : 'false'); + + #$this->getDataOrTerminateWithError($result); + if (isError($result)) + $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + + $this->terminateWithSuccess(true); + } +} diff --git a/public/js/api/stv.js b/public/js/api/stv.js index 2a84ab0b7..ab3e918a1 100644 --- a/public/js/api/stv.js +++ b/public/js/api/stv.js @@ -1,5 +1,7 @@ +import filter from './stv/filter.js'; import konto from './stv/konto.js'; export default { + filter, konto }; \ No newline at end of file diff --git a/public/js/api/stv/filter.js b/public/js/api/stv/filter.js new file mode 100644 index 000000000..13c7f55fd --- /dev/null +++ b/public/js/api/stv/filter.js @@ -0,0 +1,10 @@ +export default { + getStg() { + return this.$fhcApi.get('api/frontend/v1/stv/filter/getStg'); + }, + setStg(studiengang_kz) { + return this.$fhcApi.post('api/frontend/v1/stv/filter/setStg', { + studiengang_kz + }); + } +}; \ No newline at end of file diff --git a/public/js/components/Stv/Studentenverwaltung/Details/Konto.js b/public/js/components/Stv/Studentenverwaltung/Details/Konto.js index 1acfcd9dd..247a63d95 100644 --- a/public/js/components/Stv/Studentenverwaltung/Details/Konto.js +++ b/public/js/components/Stv/Studentenverwaltung/Details/Konto.js @@ -3,6 +3,7 @@ import FormInput from "../../../Form/Input.js"; import KontoNew from "./Konto/New.js"; import KontoEdit from "./Konto/Edit.js"; +const LOCAL_STORAGE_ID_FILTER = 'stv_details_konto_2024-01-11_filter'; export default { components: { @@ -165,11 +166,24 @@ export default { '_blank' ); } + }, + setFilter(type) { + if (type == 'open') + window.localStorage.setItem(LOCAL_STORAGE_ID_FILTER, this.filter ? 1 : 0); + else if (type == 'current_stg') + this.$fhcApi.factory + .stv.filter.setStg(this.studiengang_kz) + .catch(this.$fhcAlert.handleSystemError); + + this.$nextTick(this.$refs.table.reloadTable); } }, created() { - // TODO(chris): persist filter + studiengang_kz - // TODO(chris): studiengang_kz in variablelib + this.filter = window.localStorage.getItem(LOCAL_STORAGE_ID_FILTER) == 1; + this.$fhcApi.factory + .stv.filter.getStg() + .then(result => this.studiengang_kz = result.data) + .catch(this.$fhcAlert.handleSystemError); }, template: `
@@ -180,7 +194,7 @@ export default { type="checkbox" :label="$p.t('stv/konto_filter_open')" v-model="filter" - @update:model-value="() => $nextTick($refs.table.reloadTable)" + @update:model-value="setFilter('open')" >
@@ -191,7 +205,7 @@ export default { :label="$p.t('stv/konto_filter_current_stg')" v-model="studiengang_kz_intern" :disabled="!stg_kz" - @update:model-value="() => $nextTick($refs.table.reloadTable)" + @update:model-value="setFilter('current_stg')" >