From ceb8eb967171de00aa4544ee1962fa62b8d4d0e0 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Wed, 7 Aug 2024 11:52:50 +0200 Subject: [PATCH] corrects the way how to active ampeln check whether an ampel was bestaetigt or not and adds the Ampel_Benutzer_Bestaetigt_model --- .../controllers/api/frontend/v1/Ampeln.php | 8 +- application/core/DB_Model.php | 2 - .../Ampel_Benutzer_Bestaetigt_model.php | 14 + application/models/content/Ampel_model.php | 26 +- public/js/components/DashboardWidget/Ampel.js | 385 +++++++++--------- 5 files changed, 213 insertions(+), 222 deletions(-) create mode 100644 application/models/content/Ampel_Benutzer_Bestaetigt_model.php diff --git a/application/controllers/api/frontend/v1/Ampeln.php b/application/controllers/api/frontend/v1/Ampeln.php index 037996009..6bba658b7 100644 --- a/application/controllers/api/frontend/v1/Ampeln.php +++ b/application/controllers/api/frontend/v1/Ampeln.php @@ -56,7 +56,9 @@ class Ampeln extends FHCAPI_Controller $this->form_validation->set_rules('ampel_id', 'Ampel ID', 'required|integer'); if($this->form_validation->run() == FALSE) $this->terminateWithValidationErrors($this->form_validation->error_array()); - $insert_into_result = $this->AmpelModel->confirmAmpel($ampel_id,$this->uid); + // load Ampel_benutzer_bestaetigt_model to confirm the ampel + $this->load->model('content/Ampel_Benutzer_Bestaetigt_model', 'AmpelBenutzerBestaetigtModel'); + $insert_into_result = $this->AmpelBenutzerBestaetigtModel->insert(["ampel_id"=> $ampel_id, "uid"=> $this->uid]); $insert_into_result = $this->getDataOrTerminateWithError($insert_into_result); @@ -78,8 +80,8 @@ class Ampeln extends FHCAPI_Controller $activeAmpeln = $this->getDataOrTerminateWithError($activeAmpeln); foreach($activeAmpeln as $ampel){ - - // only include non confirmed active ampeln in the result + + // only include non confirmed active ampeln in the result if(!$ampel->bestaetigt){ // check if the user was assigned to the ampel diff --git a/application/core/DB_Model.php b/application/core/DB_Model.php index 86f8f57b2..901587893 100755 --- a/application/core/DB_Model.php +++ b/application/core/DB_Model.php @@ -94,8 +94,6 @@ class DB_Model extends CI_Model $this->load->library('UDFLib'); // Loads the logs library $this->load->library('LogLib'); - - } // ------------------------------------------------------------------------------------------ diff --git a/application/models/content/Ampel_Benutzer_Bestaetigt_model.php b/application/models/content/Ampel_Benutzer_Bestaetigt_model.php new file mode 100644 index 000000000..72373c2d8 --- /dev/null +++ b/application/models/content/Ampel_Benutzer_Bestaetigt_model.php @@ -0,0 +1,14 @@ +dbTable = 'public.tbl_ampel_benutzer_bestaetigt'; + $this->pk = 'ampel_benutzer_bestaetigt_id'; + } + +} diff --git a/application/models/content/Ampel_model.php b/application/models/content/Ampel_model.php index 9a8b211b8..f5404ecb2 100755 --- a/application/models/content/Ampel_model.php +++ b/application/models/content/Ampel_model.php @@ -23,12 +23,12 @@ class Ampel_model extends DB_Model $userLanguage = getUserLanguage(); $bestaetigt = ''; - if($uid != null){ + if($uid != null ){ $bestaetigt = ', COALESCE(( SELECT true FROM public.tbl_ampel_benutzer_bestaetigt a - WHERE a.ampel_id = ampel_id + WHERE a.ampel_id = ' . $this->dbTable . '.ampel_id AND uid = ' . $this->escape($uid) . ' LIMIT 1), false) as bestaetigt'; } @@ -111,28 +111,6 @@ class Ampel_model extends DB_Model return $result; //will contain the error-msg from execQuery } - - /** - * confirms Ampel by the user. - * @param int $ampel_id Ampel-ID - * @param string $uid UID - * @return stdClass insert into result - */ - public function confirmAmpel($ampel_id, $uid) - { - $this->load->library('form_validation'); - $this->form_validation->set_data(['ampel_id' => $ampel_id, 'uid' => $uid]); - $this->form_validation->set_rules('ampel_id', 'Ampel ID', 'required|integer'); - $this->form_validation->set_rules('uid', 'UID', 'required'); - - if ($this->form_validation->run() == FALSE) - $this->terminateWithValidationErrors($this->form_validation->error_array()); - - return $this->execQuery(' - INSERT INTO public.tbl_ampel_benutzer_bestaetigt (ampel_id, uid) - VALUES (?,?);', array($ampel_id, $uid)); - } - /** * checks if a user is assigned to an ampel * @param string $uid userID diff --git a/public/js/components/DashboardWidget/Ampel.js b/public/js/components/DashboardWidget/Ampel.js index 7257d70c1..a3a36eb94 100755 --- a/public/js/components/DashboardWidget/Ampel.js +++ b/public/js/components/DashboardWidget/Ampel.js @@ -2,209 +2,208 @@ import AbstractWidget from './Abstract'; import BaseOffcanvas from '../Base/Offcanvas'; export default { - name: 'WidgetsAmpel', - components: { BaseOffcanvas }, - data: () => ({ - WIDGET_AMPEL_MAX: 4, - filter: '', - source: '', - allAmpeln:null, - activeAmpeln:null, - }), - mixins: [ - AbstractWidget - ], - computed: { - - ampelnComputed(){ - - switch(this.source) - { - case 'offen': return this.applyFilter(this.activeAmpeln); - case 'alle': return this.applyFilter(this.allAmpeln); - default: return this.applyFilter(this.activeAmpeln); - } - - }, - ampelnOverview () { - return this.activeAmpeln?.slice(0, this.WIDGET_AMPEL_MAX); // show only newest 4 active ampeln - }, - count () { - let datasource = this.activeAmpeln; - if (this.source == 'offen') datasource = this.activeAmpeln; - if (this.source == 'alle') datasource = this.allAmpeln; + name: 'WidgetsAmpel', + components: { BaseOffcanvas }, + data: () => ({ + WIDGET_AMPEL_MAX: 4, + filter: '', + source: '', + allAmpeln:null, + activeAmpeln:null, + }), + mixins: [ + AbstractWidget + ], + computed: { + + ampelnComputed(){ + + switch(this.source) + { + case 'offen': return this.applyFilter(this.activeAmpeln); + case 'alle': return this.applyFilter(this.allAmpeln); + default: return this.applyFilter(this.activeAmpeln); + } + + }, + ampelnOverview () { + return this.activeAmpeln?.slice(0, this.WIDGET_AMPEL_MAX); // show only newest 4 active ampeln + }, + count () { + let datasource = this.activeAmpeln; + if (this.source == 'offen') datasource = this.activeAmpeln; + if (this.source == 'alle') datasource = this.allAmpeln; - return { - verpflichtend: datasource?.filter(item => item.verpflichtend).length, - ueberfaellig: datasource?.filter(item => (new Date() > new Date(item.deadline)) && !item.bestaetigt).length, - alle: datasource?.length - } - - } - }, - methods: { - applyFilter(data){ - switch(this.filter) - { - case 'verpflichtend': return data?.filter(item => item.verpflichtend); - case 'ueberfaellig': return data?.filter(item => (new Date() > new Date(item.deadline)) && !item.bestaetigt); - default: return data; - } - }, - toggleFilter(value){ - this.filter === value ? this.filter = '' : this.filter = value; - }, - closeOffcanvasAmpeln() - { - for (let i = 0; i < this.ampelnComputed.length; i++) - { - let ampelId = this.ampelnComputed[i].ampel_id; - if(this.$refs['ampelCollapse_' + ampelId]){ - this.$refs['ampelCollapse_' + ampelId][0].classList.remove('show'); - } - } - }, - openOffcanvasAmpel(ampelId){ - // Close earlier opened Ampeln - this.closeOffcanvasAmpeln(); + return { + verpflichtend: datasource?.filter(item => item.verpflichtend).length, + ueberfaellig: datasource?.filter(item => (new Date() > new Date(item.deadline)) && !item.bestaetigt).length, + alle: datasource?.length + } + + } + }, + methods: { + applyFilter(data){ + switch(this.filter) + { + case 'verpflichtend': return data?.filter(item => item.verpflichtend); + case 'ueberfaellig': return data?.filter(item => (new Date() > new Date(item.deadline)) && !item.bestaetigt); + default: return data; + } + }, + toggleFilter(value){ + this.filter === value ? this.filter = '' : this.filter = value; + }, + closeOffcanvasAmpeln() + { + for (let i = 0; i < this.ampelnComputed.length; i++) + { + let ampelId = this.ampelnComputed[i].ampel_id; + if(this.$refs['ampelCollapse_' + ampelId]){ + this.$refs['ampelCollapse_' + ampelId][0].classList.remove('show'); + } + } + }, + openOffcanvasAmpel(ampelId){ + // Close earlier opened Ampeln + this.closeOffcanvasAmpeln(); - // Show given Ampel - this.$refs['ampelCollapse_' + ampelId][0].classList.add('show'); - }, - closeOffcanvas(){ - this.closeOffcanvasAmpeln(); - this.filter = ''; - // maybe we also want to reset the source (open/alle) of the displayed ampeln - }, - async fetchNonConfirmedActiveAmpeln(){ - await this.$fhcApi.factory.ampeln.open().then(res=>{ - this.activeAmpeln = res.data.sort((a,b) => new Date(b.deadline) - new Date(a.deadline)); - }); - }, - async fetchAllActiveAmpeln(){ - await this.$fhcApi.factory.ampeln.all().then(res=>{ - this.allAmpeln = res.data.sort((a,b) => new Date(b.deadline) - new Date(a.deadline)); - }); - }, - async confirm(ampelId){ - this.$fhcApi.factory.ampeln.confirm(ampelId) - .then(res => res.data) - .then(result => { - this.$fhcAlert.alertSuccess(this.$p.t('ampeln','ampelBestaetigt')); - }) - .catch(this.$fhcAlert.handleSystemError); + // Show given Ampel + this.$refs['ampelCollapse_' + ampelId][0].classList.add('show'); + }, + closeOffcanvas(){ + this.closeOffcanvasAmpeln(); + this.filter = ''; + // maybe we also want to reset the source (open/alle) of the displayed ampeln + }, + async fetchNonConfirmedActiveAmpeln(){ + await this.$fhcApi.factory.ampeln.open().then(res=>{ + this.activeAmpeln = res.data.sort((a,b) => new Date(b.deadline) - new Date(a.deadline)); + }); + }, + async fetchAllActiveAmpeln(){ + await this.$fhcApi.factory.ampeln.all().then(res=>{ + this.allAmpeln = res.data.sort((a,b) => new Date(b.deadline) - new Date(a.deadline)); + }); + }, + async confirm(ampelId){ + this.$fhcApi.factory.ampeln.confirm(ampelId) + .then(() => { + this.$fhcAlert.alertSuccess(this.$p.t('ampeln','ampelBestaetigt')); + }) + .catch(this.$fhcAlert.handleSystemError); - // update the ampeln by refetching them - this.fetchNonConfirmedActiveAmpeln(); - this.fetchAllActiveAmpeln(); - }, - validateBtnTxt(buttontext){ + // update the ampeln by refetching them + this.fetchNonConfirmedActiveAmpeln(); + this.fetchAllActiveAmpeln(); + }, + validateBtnTxt(buttontext){ - if(buttontext instanceof Array && !buttontext.length) return this.$p.t('ui','bestaetigen'); + if(buttontext instanceof Array && !buttontext.length) return this.$p.t('ui','bestaetigen'); - if(!buttontext) return this.$p.t('ui','bestaetigen'); + if(!buttontext) return this.$p.t('ui','bestaetigen'); - return buttontext; - } - }, - created() { - this.$emit('setConfig', false); - }, - async mounted() { - await this.fetchNonConfirmedActiveAmpeln(); - await this.fetchAllActiveAmpeln(); - }, - template: /*html*/` -
-
-
-
{{$p.t('ampeln','newestAmpeln')}}
- -
- -
-
-
-
-
-
{{$p.t('ampeln','deadline')}}: {{ getDate(ampel.deadline) }}
-
-
-
-
-
- {{ ampel.kurzbz }}
-
-
-
+ return buttontext; + } + }, + created() { + this.$emit('setConfig', false); + }, + async mounted() { + await this.fetchNonConfirmedActiveAmpeln(); + await this.fetchAllActiveAmpeln(); + }, + template: /*html*/` +
+
+
+
{{$p.t('ampeln','newestAmpeln')}}
+ +
+ +
+
+
+
+
+
{{$p.t('ampeln','deadline')}}: {{ getDate(ampel.deadline) }}
+
+
+
+
+
+ {{ ampel.kurzbz }}
+
+
+
-
- - {{$p.t('ampeln','super')}}
- {{$p.t('ampeln','noOpenAmpeln')}} -
-
-
-
{{$p.t('ampeln','newestAmpeln')}}
- -
+
-
+
- - - - - ` + + + + + ` }