Konto: save filter settings

This commit is contained in:
cgfhtw
2024-04-25 14:17:08 +02:00
parent 4f4df8a8b7
commit 7944ce091e
4 changed files with 120 additions and 4 deletions
@@ -0,0 +1,90 @@
<?php
/**
* Copyright (C) 2024 fhcomplete.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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);
}
}
+2
View File
@@ -1,5 +1,7 @@
import filter from './stv/filter.js';
import konto from './stv/konto.js';
export default {
filter,
konto
};
+10
View File
@@ -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
});
}
};
@@ -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: `
<div class="stv-details-konto h-100 d-flex flex-column">
@@ -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')"
>
</form-input>
</div>
@@ -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')"
>
</form-input>
</div>