diff --git a/application/controllers/codex/Bismeldestichtag.php b/application/controllers/codex/Bismeldestichtag.php index 3c76486ca..98b76f5ae 100644 --- a/application/controllers/codex/Bismeldestichtag.php +++ b/application/controllers/codex/Bismeldestichtag.php @@ -14,19 +14,23 @@ class Bismeldestichtag extends Auth_Controller { parent::__construct( array( - 'index' => 'admin:r' + 'index' => 'admin:r', + 'addBismeldestichtag' => 'admin:rw', + 'getStudiensemester' => 'admin:r' ) ); // Loads WidgetLib $this->load->library('WidgetLib'); + // Load models + $this->load->model('codex/Bismeldestichtag_model', 'BismeldestichtagModel'); + $this->load->model('organisation/Studiensemester_model', 'StudiensemesterModel'); + // Loads phrases system $this->loadPhrases( array( - 'global', - 'ui', - 'filter' + 'bismeldestichtag' ) ); } @@ -41,4 +45,64 @@ class Bismeldestichtag extends Auth_Controller { $this->load->view('codex/bismeldestichtag.php'); } + + public function getStudiensemester() + { + // load semester list + $semList = array(); + $this->StudiensemesterModel->addSelect('studiensemester_kurzbz'); + $this->StudiensemesterModel->addOrder('start', 'DESC'); + $semRes = $this->StudiensemesterModel->load(); + + if (hasData($semRes)) + { + $semList = getData($semRes); + } + + // load current semester + $currSem = null; + $semRes = $this->StudiensemesterModel->getAkt(); + + if (hasData($semRes)) + { + $currSem = getData($semRes)[0]->studiensemester_kurzbz; + } + + // output data + $this->outputJsonSuccess( + array('semList' => $semList, 'currSem' => $currSem) + ); + } + + public function addBismeldestichtag() + { + // get request data + $request = $this->getPostJSON(); + + // check request data + if (!property_exists($request, 'meldestichtag') || isEmptyString($request->meldestichtag)) + $this->terminateWithJsonError('Error occured: Meldestichtag missing'); + if (!property_exists($request, 'studiensemester_kurzbz') || isEmptyString($request->studiensemester_kurzbz)) + $this->terminateWithJsonError('Error occured: Studiensemester missing'); + + $meldestichtag = $request->meldestichtag; + $studiensemester_kurzbz = $request->studiensemester_kurzbz; + + // check if Bismeldestichtag already exists + $this->BismeldestichtagModel->addSelect('1'); + $bismeldestichtagRes = $this->BismeldestichtagModel->loadWhere( + array('meldestichtag' => $meldestichtag, 'studiensemester_kurzbz' => $studiensemester_kurzbz) + ); + + // return success if already exists + if (hasData($bismeldestichtagRes)) + $this->outputJsonSuccess('Bismeldestichtag already exists'); + else + { + // insert new if Stichtag does not exist + $this->outputJson($this->BismeldestichtagModel->insert( + array('meldestichtag' => $request->meldestichtag, 'studiensemester_kurzbz' => $request->studiensemester_kurzbz) + )); + } + } } diff --git a/application/models/codex/Bismeldestichtag_model.php b/application/models/codex/Bismeldestichtag_model.php new file mode 100644 index 000000000..1a45f0fbd --- /dev/null +++ b/application/models/codex/Bismeldestichtag_model.php @@ -0,0 +1,14 @@ +dbTable = 'bis.tbl_bismeldestichtag'; + $this->pk = 'meldestichtag_id'; + } +} diff --git a/application/views/codex/bismeldestichtag.php b/application/views/codex/bismeldestichtag.php index cb4b1de7f..1953cf095 100644 --- a/application/views/codex/bismeldestichtag.php +++ b/application/views/codex/bismeldestichtag.php @@ -1,6 +1,6 @@ 'Logs Viewer', + 'title' => 'Bismeldestichtage', 'axios027' => true, 'bootstrap5' => true, 'fontawesome6' => true, @@ -8,34 +8,60 @@ 'filtercomponent' => true, 'navigationcomponent' => true, 'tabulator5' => true, - 'phrases' => array( - 'global' => array('mailAnXversandt'), - 'ui' => array('bitteEintragWaehlen') + 'customCSSs' => array( + 'public/css/components/verticalsplit.css' ), 'customJSModules' => array('public/js/apps/Bismeldestichtag/Bismeldestichtag.js') ); $this->load->view('templates/FHC-Header', $includesArray); ?> - +
+ + + +
- - - + + + +
load->view('templates/FHC-Footer', $includesArray); ?> - diff --git a/public/js/apps/Bismeldestichtag/API.js b/public/js/apps/Bismeldestichtag/API.js new file mode 100644 index 000000000..1644d6e49 --- /dev/null +++ b/public/js/apps/Bismeldestichtag/API.js @@ -0,0 +1,52 @@ +/** + * Copyright (C) 2022 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 . + */ + +import {CoreRESTClient} from '../../RESTClient.js'; + +// +const CORE_BISMELDESTICHTAG_CMPT_TIMEOUT = 2000; + +/** + * + */ +export const BismeldestichtagAPIs = { + /** + * + */ + getStudiensemester: function() { + return CoreRESTClient.get( + 'codex/Bismeldestichtag/getStudiensemester', + null, + { + timeout: CORE_BISMELDESTICHTAG_CMPT_TIMEOUT + } + ); + }, + addBismeldestichtag: function(wsParams) { + return CoreRESTClient.post( + 'codex/Bismeldestichtag/addBismeldestichtag', + { + meldestichtag: wsParams.meldestichtag, + studiensemester_kurzbz: wsParams.studiensemester_kurzbz + }, + { + timeout: CORE_BISMELDESTICHTAG_CMPT_TIMEOUT + } + ); + } +}; + diff --git a/public/js/apps/Bismeldestichtag/Bismeldestichtag.js b/public/js/apps/Bismeldestichtag/Bismeldestichtag.js index f2be375b9..1c2749dea 100644 --- a/public/js/apps/Bismeldestichtag/Bismeldestichtag.js +++ b/public/js/apps/Bismeldestichtag/Bismeldestichtag.js @@ -20,22 +20,108 @@ import {BismeldestichtagTabulatorEventHandlers} from './TabulatorSetup.js'; import {CoreFilterCmpt} from '../../components/filter/Filter.js'; import {CoreNavigationCmpt} from '../../components/navigation/Navigation.js'; +import {CoreRESTClient} from '../../RESTClient.js'; +import {CoreFetchCmpt} from '../../components/Fetch.js'; +import {BismeldestichtagAPIs} from './API.js'; +import verticalsplit from '../../components/verticalsplit/verticalsplit.js'; const bismeldestichtagApp = Vue.createApp({ data: function() { return { appSideMenuEntries: {}, bismeldestichtagTabulatorOptions: BismeldestichtagTabulatorOptions, - bismeldestichtagTabulatorEventHandlers: BismeldestichtagTabulatorEventHandlers + bismeldestichtagTabulatorEventHandlers: BismeldestichtagTabulatorEventHandlers, + meldestichtag: null, // date of Meldestichtag + semList: null, // all Studiensemester for dropdown + currSem: null, // selected Studiensemester + fetchCmptApiFunction: {}, // api function call + fetchCmptApiFunctionParams: null, // parameters for api function call + fetchCmptDataFetched: null, // function to execute after call + fetchCmptRefresh: true // for refreshing }; }, components: { CoreNavigationCmpt, - CoreFilterCmpt + CoreFilterCmpt, + BismeldestichtagAPIs, + CoreFetchCmpt, + verticalsplit + }, + created() { + this.handlerStudiensemester(); }, methods: { newSideMenuEntryHandler: function(payload) { this.appSideMenuEntries = payload; + }, + /** + * Define Studiensemester call and method to be executed after the call + */ + handlerStudiensemester: function() { + this.startFetchCmpt( + BismeldestichtagAPIs.getStudiensemester, + null, + this.fetchCmptDataFetchedStudiensemester + ); + }, + /** + * Define Bismeldestichtag call and method to be executed after the call + */ + handlerAddBismeldestichtag: function(event) { + this.startFetchCmpt( + BismeldestichtagAPIs.addBismeldestichtag, + { + meldestichtag: this.meldestichtag, + studiensemester_kurzbz: this.currSem + }, + this.fetchCmptDataFetchedAddBismeldestichtag + ); + }, + /** + * Called after Studiensemester response is received + */ + fetchCmptDataFetchedStudiensemester: function(data) { + if (CoreRESTClient.isError(data)) alert(CoreRESTClient.getError(data)); + if (CoreRESTClient.hasData(data)) + { + let semRes = CoreRESTClient.getData(data); + this.semList = semRes.semList; + this.currSem = semRes.currSem; + } + else + alert("No response data"); + }, + /** + * Called after Bismeldestichtag response is received + */ + fetchCmptDataFetchedAddBismeldestichtag: function(data) { + if (CoreRESTClient.isError(data)) + alert(CoreRESTClient.getError(data)); + else if (CoreRESTClient.hasData(data)) + { + window.location.reload(); + alert("Successfully added Bismeldestichtag"); + } + else + alert("No response data"); + }, + /** + * Used to start/refresh the FetchCmpt + */ + startFetchCmpt: function(apiFunction, apiFunctionParameters, dataFetchedCallback) { + // Assign the function api of the FetchCmpt binded property + this.fetchCmptApiFunction = apiFunction; + + // In case a null value is provided set the parameters as an empty object + if (apiFunctionParameters == null) apiFunctionParameters = {}; + + // Assign parameters to the FetchCmpt binded properties + this.fetchCmptApiFunctionParams = apiFunctionParameters; + // Assign data fetch callback to the FetchCmpt binded properties + this.fetchCmptDataFetched = dataFetchedCallback; + // Set the FetchCmpt binded property refresh to have the component to refresh + // NOTE: this should be the last one to be called because it triggers the FetchCmpt to start to refresh + this.fetchCmptRefresh === true ? this.fetchCmptRefresh = false : this.fetchCmptRefresh = true; } } }); diff --git a/public/js/apps/Bismeldestichtag/TabulatorSetup.js b/public/js/apps/Bismeldestichtag/TabulatorSetup.js index eb63b8eed..21690a794 100644 --- a/public/js/apps/Bismeldestichtag/TabulatorSetup.js +++ b/public/js/apps/Bismeldestichtag/TabulatorSetup.js @@ -23,13 +23,12 @@ export const BismeldestichtagTabulatorOptions = { layout: 'fitColumns', columns: [ {title: 'ID', field: 'Id', headerFilter: true}, - {title: 'Meldestichtag', field: 'Meldestichtag', headerFilter: true}, + {title: 'Meldestichtag',field: 'Meldestichtag', headerFilter: true, formatter: function(cell){ + return cell.getValue().replace(/(.*)-(.*)-(.*)/, '$3.$2.$1'); + } + }, {title: 'Studiensemester', field: 'Studiensemester', headerFilter: true} - ], - rowFormatter: function(row) { - - let data = row.getData(); // get data for this row - } + ] }; /** @@ -39,7 +38,8 @@ export const BismeldestichtagTabulatorEventHandlers = [ { event: "rowClick", handler: function(e, row) { - alert(row.getData().Data); + let data = row.getData(); + alert(data.Studiensemester + ': ' + data.Meldestichtag); } } ]; diff --git a/system/phrasesupdate.php b/system/phrasesupdate.php index 0bc748c80..93522b722 100644 --- a/system/phrasesupdate.php +++ b/system/phrasesupdate.php @@ -18123,6 +18123,46 @@ array( ) ) ), + array( + 'app' => 'core', + 'category' => 'bismeldestichtag', + 'phrase' => 'stichtagHinzufuegen', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => 'Meldestichtag hinzufügen', + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => 'Add report target date', + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), + array( + 'app' => 'core', + 'category' => 'bismeldestichtag', + 'phrase' => 'stichtageVerwalten', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => 'Bismeldestichtage verwalten', + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => 'Manage report target dates', + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), );