From 1e3146d33f7d21e72d8faf2bff18fd0b58fedb48 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Wed, 24 Jul 2024 13:31:00 +0200 Subject: [PATCH] dashboardAmpeln --- .../controllers/api/frontend/v1/Ampeln.php | 56 ++++---- application/models/content/Ampel_model.php | 14 ++ public/js/api/ampeln.js | 6 +- public/js/components/DashboardWidget/Ampel.js | 124 +++++++++++++----- .../components/DashboardWidget/Stundenplan.js | 4 +- 5 files changed, 134 insertions(+), 70 deletions(-) diff --git a/application/controllers/api/frontend/v1/Ampeln.php b/application/controllers/api/frontend/v1/Ampeln.php index b29d6934e..62f061e82 100644 --- a/application/controllers/api/frontend/v1/Ampeln.php +++ b/application/controllers/api/frontend/v1/Ampeln.php @@ -30,6 +30,7 @@ class Ampeln extends FHCAPI_Controller 'getNonConfirmedActiveAmpeln' => self::PERM_LOGGED, 'getAllActiveAmpeln' => self::PERM_LOGGED, 'getConfirmedActiveAmpeln' => self::PERM_LOGGED, + 'confirmAmpel' => self::PERM_LOGGED, ]); @@ -46,6 +47,27 @@ class Ampeln extends FHCAPI_Controller //------------------------------------------------------------------------------------------------------------------ // Public methods + /** + * function that queries all the ampeln that are addressed to the user uid + * @access public + * + */ + public function confirmAmpel($ampel_id) + { + if(!isset($ampel_id)){ + $this->terminateWithError("missing parameter"); + } + + $insert_into_result = $this->AmpelModel->confirmAmpel($ampel_id,$this->uid); + + if(isError($insert_into_result)){ + $this->terminateWithError(getError($insert_into_result)); + } + + $insert_into_result = $this->getDataOrTerminateWithError($insert_into_result); + + $this->terminateWithSuccess($insert_into_result); + } /** * function that queries all the ampeln that are addressed to the user uid @@ -59,10 +81,10 @@ class Ampeln extends FHCAPI_Controller $ampel_result = $this->getDataOrTerminateWithError($ampel_result); - $is_confirmed_array = array(); foreach($ampel_result as $ampel){ $confirmedByUser = $this->AmpelModel->isConfirmed($ampel->ampel_id,$this->uid); + $ampel->bestaetigt = $confirmedByUser; if(!$confirmedByUser){ $userUID_array = $this->AmpelModel->execBenutzerSelect($ampel->benutzer_select); $userUID_array = $this->getDataOrTerminateWithError($userUID_array); @@ -90,6 +112,8 @@ class Ampeln extends FHCAPI_Controller foreach($ampel_result as $ampel){ + $confirmedByUser = $this->AmpelModel->isConfirmed($ampel->ampel_id,$this->uid); + $ampel->bestaetigt = $confirmedByUser; $userUID_array = $this->AmpelModel->execBenutzerSelect($ampel->benutzer_select); $userUID_array = $this->getDataOrTerminateWithError($userUID_array); foreach($userUID_array as $user_obj){ @@ -104,35 +128,7 @@ class Ampeln extends FHCAPI_Controller $this->terminateWithSuccess($userAmpeln); } - - public function getConfirmedActiveAmpeln() - { - $userAmpeln = array(); - $ampel_result = $this->AmpelModel->active(); - - $ampel_result = $this->getDataOrTerminateWithError($ampel_result); - - $is_confirmed_array = array(); - foreach($ampel_result as $ampel){ - - $confirmedByUser = $this->AmpelModel->isConfirmed($ampel->ampel_id,$this->uid); - if($confirmedByUser){ - $userUID_array = $this->AmpelModel->execBenutzerSelect($ampel->benutzer_select); - $userUID_array = $this->getDataOrTerminateWithError($userUID_array); - foreach($userUID_array as $user_obj){ - - $user_uid = property_exists($user_obj,"uid") ? $user_obj->uid : $user_obj->mitarbeiter_uid; - if($user_uid === $this->uid){ - $userAmpeln[] = $ampel; - } - } - - } - - } - - $this->terminateWithSuccess($userAmpeln); - } + } diff --git a/application/models/content/Ampel_model.php b/application/models/content/Ampel_model.php index c50025a12..c4e32e21b 100755 --- a/application/models/content/Ampel_model.php +++ b/application/models/content/Ampel_model.php @@ -90,4 +90,18 @@ class Ampel_model extends DB_Model else return $result; //will contain the error-msg from execQuery } + + + public function confirmAmpel($ampel_id, $uid) + { + if(isset($ampel_id) && isset($uid)){ + return $this->execQuery(' + INSERT INTO public.tbl_ampel_benutzer_bestaetigt (ampel_id, uid) + VALUES (?,?);', array($ampel_id, $uid)); + }else{ + + return error("parameter were missing to execute the insert into"); + } + + } } diff --git a/public/js/api/ampeln.js b/public/js/api/ampeln.js index 7e0aef247..85cd08df2 100644 --- a/public/js/api/ampeln.js +++ b/public/js/api/ampeln.js @@ -14,11 +14,13 @@ export default { `/api/frontend/v1/Ampeln/getAllActiveAmpeln`,{}); }, - getConfirmedActiveAmpeln: function () { + + + confirmAmpel: function (ampel_id) { return this.$fhcApi.get( FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + - `/api/frontend/v1/Ampeln/getConfirmedActiveAmpeln`,{}); + `/api/frontend/v1/Ampeln/confirmAmpel/${ampel_id}`,{}); }, } \ No newline at end of file diff --git a/public/js/components/DashboardWidget/Ampel.js b/public/js/components/DashboardWidget/Ampel.js index 6cb61ee47..855eb15b6 100755 --- a/public/js/components/DashboardWidget/Ampel.js +++ b/public/js/components/DashboardWidget/Ampel.js @@ -7,33 +7,76 @@ export default { data: () => ({ filter: '', source: '', - ampeln: [], + ampeln: null, + allAmpeln:null, + activeAmpeln:null, }), mixins: [ AbstractWidget ], computed: { + filteredAmpeln(){ + + if (this.source == 'offen') + { + switch(this.filter) + { + case 'verpflichtend': return this.activeAmpeln?.filter(item => item.verpflichtend); + case 'ueberfaellig': return this.activeAmpeln?.filter(item => (new Date() > new Date(item.deadline)) && !item.bestaetigt); + default: return this.activeAmpeln; + } + } + if (this.source == 'alle') + { + switch(this.filter) + { + case 'verpflichtend': return this.allActiveAmpeln?.filter(item => item.verpflichtend); + case 'ueberfaellig': return this.allActiveAmpeln?.filter(item => (new Date() > new Date(item.deadline)) && !item.bestaetigt); + default: return this.allActiveAmpeln; + } + + } + return this.activeAmpeln; + }, + openAmpeln () { + return this.ampeln.filter(ampel=>{ + if(!ampel.bestaetigt){ + return true; + } + return false; + }) + }, widgetAmpeln () { - return this.ampeln.slice(0, 4); // show only newest 4 ampeln + return this.activeAmpeln?.slice(0, 4); // show only newest 4 ampeln }, offcanvasAmpeln () { switch(this.filter) { - case 'verpflichtend': return this.ampeln.filter(item => item.verpflichtend); - case 'ueberfaellig': return this.ampeln.filter(item => (new Date() > new Date(item.deadline)) && !item.bestaetigt); - default: return this.ampeln; + case 'verpflichtend': return this.activeAmpeln?.filter(item => item.verpflichtend); + case 'ueberfaellig': return this.activeAmpeln?.filter(item => (new Date() > new Date(item.deadline)) && !item.bestaetigt); + default: return this.activeAmpeln; } }, count () { + let datasource = this.activeAmpeln; + if (this.source == 'offen') datasource = this.activeAmpeln; + if (this.source == 'alle') datasource = this.allActiveAmpeln; + return { - verpflichtend: this.ampeln.filter(item => item.verpflichtend).length, - ueberfaellig: this.ampeln.filter(item => (new Date() > new Date(item.deadline)) && !item.bestaetigt).length, - alle: this.ampeln.length + verpflichtend: datasource?.filter(item => item.verpflichtend).length, + ueberfaellig: datasource?.filter(item => (new Date() > new Date(item.deadline)) && !item.bestaetigt).length, + alle: datasource?.length } + } }, methods: { + + toggleFilter(value){ + this.filter === value ? this.filter = '' : this.filter = value; + }, + closeOffcanvasAmpeln() { for (let i = 0; i < this.offcanvasAmpeln.length; i++) @@ -52,20 +95,38 @@ export default { closeOffcanvas(){ this.filter = ''; }, - confirm(ampelId){ - let indexToRemove = this.ampeln.findIndex((obj => obj.ampel_id === ampelId)); - this.ampeln.splice(indexToRemove, 1); + async fetchActiveAmpeln(){ + + await this.$fhcApi.factory.ampeln.getNonConfirmedActiveAmpeln().then(res=>{ + this.activeAmpeln = res.data; + }); + }, + async fetchAllAmpeln(){ + + await this.$fhcApi.factory.ampeln.getAllActiveAmpeln().then(res=>{ + this.allActiveAmpeln = res.data; + }); + }, + async confirm(ampelId){ + this.$fhcApi.factory.ampeln.confirmAmpel(ampelId).then(res =>{ + console.log(res,"result of the insert into") + }); + + // fetch all the ampeln after an ampel has been confirmed + await this.fetchActiveAmpeln(); + await this.fetchAllAmpeln(); + }, changeDisplay(){ this.filter = ''; if (this.source == 'offen') { - this.ampeln = TEST_OFFENE_AMPELN; + //this.ampeln = openAmpeln; } if (this.source == 'alle') { - this.ampeln = TEST_ALLE_AMPELN; + //this.ampeln = TEST_ALLE_AMPELN; // axios // .get(this.apiurl + '/dashboard/Api/getAmpeln') // .then(res => { this.ampeln = res.data }) @@ -78,31 +139,22 @@ export default { }, async created() { - let temporary_ampeln=null; - let temporary_confirmedAmpeln=null; + await this.fetchActiveAmpeln(); + await this.fetchAllAmpeln(); - await this.$fhcApi.factory.ampeln.getAllActiveAmpeln().then(res=>{ - temporary_ampeln = res.data; - }); - - await this.$fhcApi.factory.ampeln.getConfirmedActiveAmpeln().then(res=>{ - temporary_confirmedAmpeln = res.data; - }); - - - /* this.ampeln = temporary_ampeln.filter((ampel)=>{ - if(temporary_confirmedAmpeln.some((confirmedAmpel)=> confirmedAmpel.ampel_id === ampel.ampel_id)){ - return false; - } - return true; - }); - */ + // add the first element of the active ampeln again just for testing purposes + /* let duplicate = {...this.allActiveAmpeln[0]}; + duplicate.verpflichtend= false; + this.allActiveAmpeln.push(duplicate); + console.log(this.activeAmpeln,"this are the active ampeln") + console.log(this.allActiveAmpeln,"this are all the ampeln") + */ this.$emit('setConfig', false); }, template: /*html*/`
-
+
Neueste Ampeln
@@ -126,7 +178,7 @@ export default {
-
+
Super!
Keine offenen Ampeln. @@ -165,10 +217,10 @@ export default {
-
-
+
+
-
+
  • diff --git a/public/js/components/DashboardWidget/Stundenplan.js b/public/js/components/DashboardWidget/Stundenplan.js index b74095b32..0b0840d73 100755 --- a/public/js/components/DashboardWidget/Stundenplan.js +++ b/public/js/components/DashboardWidget/Stundenplan.js @@ -36,7 +36,7 @@ export default { }, created() { this.$emit('setConfig', false); - axios + /* axios .get(this.apiurl + '/components/Cis/Stundenplan/Stunden').then(res => { res.data.retval.forEach(std => { this.stunden[std.stunde] = std; // TODO(chris): geht besser @@ -57,7 +57,7 @@ export default { }) .catch(err => { console.log(err);console.error('ERROR: ', err.response.data) }); }) - .catch(err => { console.error('ERROR: ', err.response.data) }); + .catch(err => { console.error('ERROR: ', err.response.data) }); */ }, template: `