From 7e983292ea842aa4a69d9acca6733a1e5a8b71ff Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Tue, 23 Jul 2024 11:26:52 +0200 Subject: [PATCH 01/24] adds the endpoint that fetches all ampeln of a user that are not confirmed by the user yet and also removes some unnecessary comments from other enpoints --- .../controllers/api/frontend/v1/Ampeln.php | 84 +++++++++++++++++++ .../controllers/api/frontend/v1/Profil.php | 5 -- .../api/frontend/v1/ProfilUpdate.php | 5 -- public/js/api/ampeln.js | 10 +++ public/js/api/fhcapifactory.js | 2 + public/js/apps/Dashboard/Fhc.js | 2 + 6 files changed, 98 insertions(+), 10 deletions(-) create mode 100644 application/controllers/api/frontend/v1/Ampeln.php create mode 100644 public/js/api/ampeln.js diff --git a/application/controllers/api/frontend/v1/Ampeln.php b/application/controllers/api/frontend/v1/Ampeln.php new file mode 100644 index 000000000..e4029f841 --- /dev/null +++ b/application/controllers/api/frontend/v1/Ampeln.php @@ -0,0 +1,84 @@ +. + */ + +if (! defined('BASEPATH')) exit('No direct script access allowed'); + +class Ampeln extends FHCAPI_Controller +{ + + /** + * Object initialization + */ + public function __construct() + { + parent::__construct([ + 'getAmpeln' => self::PERM_LOGGED, + + ]); + + + $this->load->model('content/Ampel_model', 'AmpelModel'); + + + //? put the uid and pid inside the controller for reusability + $this->uid = getAuthUID(); + $this->pid = getAuthPersonID(); + + } + + //------------------------------------------------------------------------------------------------------------------ + // Public methods + + + /** + * function that queries all the ampeln that are addressed to the user uid + * @access public + * + */ + public function getAmpeln() + { + $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/controllers/api/frontend/v1/Profil.php b/application/controllers/api/frontend/v1/Profil.php index ffb7449f8..63e86d1b2 100644 --- a/application/controllers/api/frontend/v1/Profil.php +++ b/application/controllers/api/frontend/v1/Profil.php @@ -18,11 +18,6 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); -/** - * This controller operates between (interface) the JS (GUI) and the SearchBarLib (back-end) - * Provides data to the ajax get calls about the searchbar component - * This controller works with JSON calls on the HTTP GET and the output is always JSON - */ class Profil extends FHCAPI_Controller { diff --git a/application/controllers/api/frontend/v1/ProfilUpdate.php b/application/controllers/api/frontend/v1/ProfilUpdate.php index 4b9dedb48..7a528b2de 100644 --- a/application/controllers/api/frontend/v1/ProfilUpdate.php +++ b/application/controllers/api/frontend/v1/ProfilUpdate.php @@ -18,11 +18,6 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); -/** - * This controller operates between (interface) the JS (GUI) and the SearchBarLib (back-end) - * Provides data to the ajax get calls about the searchbar component - * This controller works with JSON calls on the HTTP GET and the output is always JSON - */ class ProfilUpdate extends FHCAPI_Controller { diff --git a/public/js/api/ampeln.js b/public/js/api/ampeln.js new file mode 100644 index 000000000..8173d8511 --- /dev/null +++ b/public/js/api/ampeln.js @@ -0,0 +1,10 @@ +export default { + + getAmpeln: function () { + return this.$fhcApi.get( + FHC_JS_DATA_STORAGE_OBJECT.app_root + + FHC_JS_DATA_STORAGE_OBJECT.ci_router + + `/api/frontend/v1/Ampeln/getAmpeln`,{}); + }, + +} \ No newline at end of file diff --git a/public/js/api/fhcapifactory.js b/public/js/api/fhcapifactory.js index 73ce0dd7f..6df1d7467 100644 --- a/public/js/api/fhcapifactory.js +++ b/public/js/api/fhcapifactory.js @@ -22,6 +22,7 @@ import filter from "./filter.js"; import studstatus from "./studstatus.js"; import profil from "./profil.js"; import profilUpdate from "./profilUpdate.js"; +import ampeln from "./ampeln.js"; export default { search, @@ -31,4 +32,5 @@ export default { studstatus, profil, profilUpdate, + ampeln, }; diff --git a/public/js/apps/Dashboard/Fhc.js b/public/js/apps/Dashboard/Fhc.js index ebcbb4b78..98f06f329 100755 --- a/public/js/apps/Dashboard/Fhc.js +++ b/public/js/apps/Dashboard/Fhc.js @@ -1,4 +1,5 @@ import FhcDashboard from '../../components/Dashboard/Dashboard.js'; +import Phrasen from "../../plugin/Phrasen.js" const app = Vue.createApp({ data: () => ({ @@ -9,4 +10,5 @@ const app = Vue.createApp({ } }); app.config.unwrapInjectedRef = true; +app.use(Phrasen); app.mount('#content'); From 1211d63ccfa845c985b412c94d6d21a1e95fb650 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Tue, 23 Jul 2024 13:59:04 +0200 Subject: [PATCH 02/24] adds placeholders for the ampeln and adds new endpoints that fetch activeAmpeln and confirmedActiveAmpeln of the user --- .../controllers/api/frontend/v1/Ampeln.php | 59 ++++++++++++++++++- public/js/api/ampeln.js | 18 +++++- public/js/components/DashboardWidget/Ampel.js | 46 +++++++++++++-- 3 files changed, 114 insertions(+), 9 deletions(-) diff --git a/application/controllers/api/frontend/v1/Ampeln.php b/application/controllers/api/frontend/v1/Ampeln.php index e4029f841..b29d6934e 100644 --- a/application/controllers/api/frontend/v1/Ampeln.php +++ b/application/controllers/api/frontend/v1/Ampeln.php @@ -27,7 +27,9 @@ class Ampeln extends FHCAPI_Controller public function __construct() { parent::__construct([ - 'getAmpeln' => self::PERM_LOGGED, + 'getNonConfirmedActiveAmpeln' => self::PERM_LOGGED, + 'getAllActiveAmpeln' => self::PERM_LOGGED, + 'getConfirmedActiveAmpeln' => self::PERM_LOGGED, ]); @@ -50,7 +52,7 @@ class Ampeln extends FHCAPI_Controller * @access public * */ - public function getAmpeln() + public function getNonConfirmedActiveAmpeln() { $userAmpeln = array(); $ampel_result = $this->AmpelModel->active(); @@ -79,6 +81,59 @@ class Ampeln extends FHCAPI_Controller $this->terminateWithSuccess($userAmpeln); } + public function getAllActiveAmpeln() + { + $userAmpeln = array(); + $ampel_result = $this->AmpelModel->active(); + + $ampel_result = $this->getDataOrTerminateWithError($ampel_result); + + foreach($ampel_result as $ampel){ + + $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); + } + + 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/public/js/api/ampeln.js b/public/js/api/ampeln.js index 8173d8511..7e0aef247 100644 --- a/public/js/api/ampeln.js +++ b/public/js/api/ampeln.js @@ -1,10 +1,24 @@ export default { - getAmpeln: function () { + getNonConfirmedActiveAmpeln: function () { return this.$fhcApi.get( FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + - `/api/frontend/v1/Ampeln/getAmpeln`,{}); + `/api/frontend/v1/Ampeln/getNonConfirmedActiveAmpeln`,{}); + }, + + getAllActiveAmpeln: function () { + return this.$fhcApi.get( + FHC_JS_DATA_STORAGE_OBJECT.app_root + + FHC_JS_DATA_STORAGE_OBJECT.ci_router + + `/api/frontend/v1/Ampeln/getAllActiveAmpeln`,{}); + }, + + getConfirmedActiveAmpeln: function () { + return this.$fhcApi.get( + FHC_JS_DATA_STORAGE_OBJECT.app_root + + FHC_JS_DATA_STORAGE_OBJECT.ci_router + + `/api/frontend/v1/Ampeln/getConfirmedActiveAmpeln`,{}); }, } \ No newline at end of file diff --git a/public/js/components/DashboardWidget/Ampel.js b/public/js/components/DashboardWidget/Ampel.js index 9f0918aa7..6cb61ee47 100755 --- a/public/js/components/DashboardWidget/Ampel.js +++ b/public/js/components/DashboardWidget/Ampel.js @@ -7,7 +7,7 @@ export default { data: () => ({ filter: '', source: '', - ampeln: [] + ampeln: [], }), mixins: [ AbstractWidget @@ -76,13 +76,33 @@ export default { return buttontext == null ? 'Bestätigen' : buttontext; } }, - created() { + async created() { + + let temporary_ampeln=null; + let temporary_confirmedAmpeln=null; + + 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; + }); + */ this.$emit('setConfig', false); - this.ampeln = TEST_OFFENE_AMPELN; + }, - template: ` + template: /*html*/`
-
+
Neueste Ampeln
@@ -105,12 +125,28 @@ export default {
+
Super!
Keine offenen Ampeln.
+
+
Neueste Ampeln
+ + +
+ From 1e3146d33f7d21e72d8faf2bff18fd0b58fedb48 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Wed, 24 Jul 2024 13:31:00 +0200 Subject: [PATCH 03/24] 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: `
    From ca6e3a84630e113878338559b997c5b1e5d39755 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Thu, 25 Jul 2024 15:16:01 +0200 Subject: [PATCH 04/24] adds endpoint to query all user ampeln that were assigned after the start_working_date with the appropriate beschreibungs translations --- .../controllers/api/frontend/v1/Ampeln.php | 13 ++++ application/models/content/Ampel_model.php | 61 +++++++++++++++++++ public/js/api/ampeln.js | 7 +++ 3 files changed, 81 insertions(+) diff --git a/application/controllers/api/frontend/v1/Ampeln.php b/application/controllers/api/frontend/v1/Ampeln.php index 62f061e82..23aa239a4 100644 --- a/application/controllers/api/frontend/v1/Ampeln.php +++ b/application/controllers/api/frontend/v1/Ampeln.php @@ -31,6 +31,7 @@ class Ampeln extends FHCAPI_Controller 'getAllActiveAmpeln' => self::PERM_LOGGED, 'getConfirmedActiveAmpeln' => self::PERM_LOGGED, 'confirmAmpel' => self::PERM_LOGGED, + 'alleAmpeln' => self::PERM_LOGGED, ]); @@ -128,6 +129,18 @@ class Ampeln extends FHCAPI_Controller $this->terminateWithSuccess($userAmpeln); } + + public function alleAmpeln(){ + + $alle_ampeln = $this->AmpelModel->alleAmpeln($this->uid); + + if(isError($alle_ampeln)) $this->terminateWithError(getError($alle_ampeln)); + + $alle_ampeln = $this->getDataOrTerminateWithError($alle_ampeln); + + $this->terminateWithSuccess($alle_ampeln); + + } diff --git a/application/models/content/Ampel_model.php b/application/models/content/Ampel_model.php index c4e32e21b..0bb500c55 100755 --- a/application/models/content/Ampel_model.php +++ b/application/models/content/Ampel_model.php @@ -104,4 +104,65 @@ class Ampel_model extends DB_Model } } + + + function alleAmpeln($uid){ + + $datum = new datum(); + $now = $datum->mktime_fromdate(date('Y-m-d')); + + // start date of user + $benutzerStartDate = $this->execReadOnlyQuery(" + SELECT insertamum FROM public.tbl_benutzer WHERE uid = ?", [$uid]); + $benutzerStartDate = $datum->mktime_fromdate(date(current(getData($benutzerStartDate))->insertamum)); + + // user language + $userLanguage = getUserLanguage(); + $this->load->model('system/Sprache_model','SpracheModel'); + $this->SpracheModel->addSelect(["index"]); + $userLanguage = $this->SpracheModel->loadWhere(["sprache" => $userLanguage]); + //checking for error + if(isError($userLanguage)) return error(getError($userLanguage)); + $userLanguage = getData($userLanguage)[0]->index - 1; // why does the index start at 1? + + $zugeteile_ampeln = []; + + $allAmpeln = $this->execReadOnlyQuery(" + SELECT * FROM + public.tbl_ampel"); + + if(isError($allAmpeln)) return error(getError($allAmpeln)); + + $allAmpeln = getData($allAmpeln); + + foreach($allAmpeln as $ampel){ + $zugeteilt = $this->execReadOnlyQuery(" + SELECT + CASE WHEN ? IN (?) + THEN true + ELSE false + END as zugeteilt + ", [$uid, $ampel->benutzer_select]); + + if(isError($zugeteilt)) return error(getError($zugeteilt)); + + if($zugeteilt + // datum der Ampel liegt nicht vor der Vorlaufzeit + && (isset($ampel->vorlaufzeit) && !($now < strtotime('-' . $ampel->vorlaufzeit . ' day', $datum->mktime_fromdate($ampel->deadline)) )) + // verfallszeit nicht vor dem start Datum des Benutzers abgelaufen + && isset($ampel->verfallszeit) && $benutzerStartDate < strtotime('+' . $ampel->verfallszeit . ' day', $datum->mktime_fromdate($ampel->deadline)) + + // verfallszeit ist abgelaufen + //&& $now > strtotime('+' . $ampel->verfallszeit . ' day', $ampel->deadline) + + ){ + $ampel->beschreibung = $ampel->beschreibung[$userLanguage]; + $ampel->buttontext = $ampel->buttontext[$userLanguage]; + $zugeteile_ampeln[] = $ampel; + } + } + + return success($zugeteile_ampeln); + } + } diff --git a/public/js/api/ampeln.js b/public/js/api/ampeln.js index 85cd08df2..248903415 100644 --- a/public/js/api/ampeln.js +++ b/public/js/api/ampeln.js @@ -23,4 +23,11 @@ export default { `/api/frontend/v1/Ampeln/confirmAmpel/${ampel_id}`,{}); }, + alleAmpeln: function () { + return this.$fhcApi.get( + FHC_JS_DATA_STORAGE_OBJECT.app_root + + FHC_JS_DATA_STORAGE_OBJECT.ci_router + + `/api/frontend/v1/Ampeln/alleAmpeln`,{}); + }, + } \ No newline at end of file From fb30a8e009599a73e8970ff7440510ec027bd0c4 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Fri, 26 Jul 2024 14:07:56 +0200 Subject: [PATCH 05/24] translates the ampel queries in separate private function --- .../controllers/api/frontend/v1/Ampeln.php | 71 +++++++++++++++---- application/models/content/Ampel_model.php | 15 +--- 2 files changed, 61 insertions(+), 25 deletions(-) diff --git a/application/controllers/api/frontend/v1/Ampeln.php b/application/controllers/api/frontend/v1/Ampeln.php index 23aa239a4..21fa83c4d 100644 --- a/application/controllers/api/frontend/v1/Ampeln.php +++ b/application/controllers/api/frontend/v1/Ampeln.php @@ -37,6 +37,7 @@ class Ampeln extends FHCAPI_Controller $this->load->model('content/Ampel_model', 'AmpelModel'); + $this->load->model('system/Sprache_model','SpracheModel'); //? put the uid and pid inside the controller for reusability @@ -49,7 +50,7 @@ class Ampeln extends FHCAPI_Controller // Public methods /** - * function that queries all the ampeln that are addressed to the user uid + * confirms ampel and inserts ampelID in public.tbl_ampel_benutzer_bestaetigt * @access public * */ @@ -71,32 +72,40 @@ class Ampeln extends FHCAPI_Controller } /** - * function that queries all the ampeln that are addressed to the user uid + * queries active and not confirmed ampeln by the user * @access public * */ public function getNonConfirmedActiveAmpeln() { + $userAmpeln = array(); - $ampel_result = $this->AmpelModel->active(); - $ampel_result = $this->getDataOrTerminateWithError($ampel_result); + // fetch active ampeln + $activeAmpeln = $this->AmpelModel->active(); - foreach($ampel_result as $ampel){ + $activeAmpeln = $this->getDataOrTerminateWithError($activeAmpeln); + + foreach($activeAmpeln as $ampel){ + // check if ampel is confirmed by user $confirmedByUser = $this->AmpelModel->isConfirmed($ampel->ampel_id,$this->uid); $ampel->bestaetigt = $confirmedByUser; + + // only include non confirmed active ampeln in the result if(!$confirmedByUser){ $userUID_array = $this->AmpelModel->execBenutzerSelect($ampel->benutzer_select); $userUID_array = $this->getDataOrTerminateWithError($userUID_array); + + // check if user is assigned to the ampel foreach($userUID_array as $user_obj){ - + // property is called uid for students and mitarbeiter_uid for employees $user_uid = property_exists($user_obj,"uid") ? $user_obj->uid : $user_obj->mitarbeiter_uid; - if($user_uid === $this->uid){ - $userAmpeln[] = $ampel; - } - } + if($user_uid === $this->uid){ + $userAmpeln[] = $this->translateAmpel($ampel); + } + } } } @@ -104,6 +113,11 @@ class Ampeln extends FHCAPI_Controller $this->terminateWithSuccess($userAmpeln); } + /** + * queries active ampeln by the user + * @access public + * + */ public function getAllActiveAmpeln() { $userAmpeln = array(); @@ -121,27 +135,60 @@ class Ampeln extends FHCAPI_Controller $user_uid = property_exists($user_obj,"uid") ? $user_obj->uid : $user_obj->mitarbeiter_uid; if($user_uid === $this->uid){ - $userAmpeln[] = $ampel; + $userAmpeln[] = $this->translateAmpel($ampel); } } - } $this->terminateWithSuccess($userAmpeln); } + /** + * queries all ampeln that were assigned to the user until start of first work day + * @access public + * + */ public function alleAmpeln(){ + //fetch all ampeln $alle_ampeln = $this->AmpelModel->alleAmpeln($this->uid); if(isError($alle_ampeln)) $this->terminateWithError(getError($alle_ampeln)); $alle_ampeln = $this->getDataOrTerminateWithError($alle_ampeln); + // translate ampeln + array_map(function($ampel){ return $this->translateAmpel($ampel);}, $alle_ampeln); + $this->terminateWithSuccess($alle_ampeln); } + + //------------------------------------------------------------------------------------------------------------------ + // Private methods + /** + * translate ampel description and button text + * @access private + * + */ + public function translateAmpel($ampel){ + + // fetch user language + $userLanguage = getUserLanguage(); + + $userLanguage = $this->SpracheModel->loadWhere(["sprache" => $userLanguage]); + + if(isError($userLanguage)) $this->terminateWithError(getError($userLanguage)); + $userLanguage = $this->getDataOrTerminateWithError($userLanguage)[0]->index - 1; // why does the index start at 1? + + // translate the ampel description and button text + $ampel->beschreibung = $ampel->beschreibung[$userLanguage]; + $ampel->buttontext = $ampel->buttontext[$userLanguage]; + + return $ampel; + + } } diff --git a/application/models/content/Ampel_model.php b/application/models/content/Ampel_model.php index 0bb500c55..136d4b38d 100755 --- a/application/models/content/Ampel_model.php +++ b/application/models/content/Ampel_model.php @@ -108,6 +108,8 @@ class Ampel_model extends DB_Model function alleAmpeln($uid){ + $zugeteile_ampeln = []; + $datum = new datum(); $now = $datum->mktime_fromdate(date('Y-m-d')); @@ -116,17 +118,6 @@ class Ampel_model extends DB_Model SELECT insertamum FROM public.tbl_benutzer WHERE uid = ?", [$uid]); $benutzerStartDate = $datum->mktime_fromdate(date(current(getData($benutzerStartDate))->insertamum)); - // user language - $userLanguage = getUserLanguage(); - $this->load->model('system/Sprache_model','SpracheModel'); - $this->SpracheModel->addSelect(["index"]); - $userLanguage = $this->SpracheModel->loadWhere(["sprache" => $userLanguage]); - //checking for error - if(isError($userLanguage)) return error(getError($userLanguage)); - $userLanguage = getData($userLanguage)[0]->index - 1; // why does the index start at 1? - - $zugeteile_ampeln = []; - $allAmpeln = $this->execReadOnlyQuery(" SELECT * FROM public.tbl_ampel"); @@ -156,8 +147,6 @@ class Ampel_model extends DB_Model //&& $now > strtotime('+' . $ampel->verfallszeit . ' day', $ampel->deadline) ){ - $ampel->beschreibung = $ampel->beschreibung[$userLanguage]; - $ampel->buttontext = $ampel->buttontext[$userLanguage]; $zugeteile_ampeln[] = $ampel; } } From 65b71191a0bb9a5875057e1d805f26126dd803ac Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Fri, 26 Jul 2024 15:41:21 +0200 Subject: [PATCH 06/24] adds +1 to month in getMonth() function because the month index of a javascript date starts with 0, additional cleanup in Ampel.js Widgett --- .../js/components/DashboardWidget/Abstract.js | 4 +- public/js/components/DashboardWidget/Ampel.js | 329 ++++-------------- 2 files changed, 61 insertions(+), 272 deletions(-) diff --git a/public/js/components/DashboardWidget/Abstract.js b/public/js/components/DashboardWidget/Abstract.js index a21c9834f..c121dba9a 100755 --- a/public/js/components/DashboardWidget/Abstract.js +++ b/public/js/components/DashboardWidget/Abstract.js @@ -19,12 +19,12 @@ export default { methods: { formatDateTime: function(dateTime) { const dt = new Date(dateTime); - return dt.getDate() + '.' + dt.getMonth() + '.' + dt.getFullYear() + ' | ' + return dt.getDate() + '.' + (dt.getMonth()+1) + '.' + dt.getFullYear() + ' | ' + dt.getHours() + ':' + dt.getMinutes(); }, getDate: function(dateTime){ const dt = new Date(dateTime); - return dt.getDate() + '.' + dt.getMonth() + '.' + dt.getFullYear(); + return dt.getDate() + '.' + (dt.getMonth()+1) + '.' + dt.getFullYear(); } } } diff --git a/public/js/components/DashboardWidget/Ampel.js b/public/js/components/DashboardWidget/Ampel.js index 855eb15b6..271aa2326 100755 --- a/public/js/components/DashboardWidget/Ampel.js +++ b/public/js/components/DashboardWidget/Ampel.js @@ -1,6 +1,8 @@ import AbstractWidget from './Abstract'; import BaseOffcanvas from '../Base/Offcanvas'; +const widgetAmpelMAX = 4; + export default { name: 'WidgetsAmpel', components: { BaseOffcanvas }, @@ -15,53 +17,23 @@ export default { AbstractWidget ], computed: { - filteredAmpeln(){ + ampelnComputed(){ - if (this.source == 'offen') + switch(this.source) { - 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; - } + case 'offen': return this.applyFilter(this.activeAmpeln); + case 'alle': return this.applyFilter(this.allAmpeln); + 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.activeAmpeln?.slice(0, 4); // show only newest 4 ampeln - }, - offcanvasAmpeln () - { - 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; - } + ampelnOverview () { + return this.activeAmpeln?.slice(0, widgetAmpelMAX); // show only newest 4 active ampeln }, count () { let datasource = this.activeAmpeln; if (this.source == 'offen') datasource = this.activeAmpeln; - if (this.source == 'alle') datasource = this.allActiveAmpeln; + if (this.source == 'alle') datasource = this.allAmpeln; return { verpflichtend: datasource?.filter(item => item.verpflichtend).length, @@ -72,6 +44,26 @@ export default { } }, 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; + } + }, + isExpiredAmpel(ampel){ + + let deadline = new Date(ampel.deadline); + if(ampel.verfallszeit instanceof Number) deadline.setDate(deadline.getDate() + ampel.verfallszeit); + deadline.setHours(0, 0, 0, 0); + + let today = new Date(); + today.setHours(0, 0, 0, 0); + + return deadline < today ? true : false; + + }, toggleFilter(value){ this.filter === value ? this.filter = '' : this.filter = value; @@ -79,9 +71,9 @@ export default { closeOffcanvasAmpeln() { - for (let i = 0; i < this.offcanvasAmpeln.length; i++) + for (let i = 0; i < this.ampelnComputed.length; i++) { - let ampelId = this.offcanvasAmpeln[i].ampel_id; + let ampelId = this.ampelnComputed[i].ampel_id; this.$refs['ampelCollapse_' + ampelId][0].classList.remove('show'); } }, @@ -98,18 +90,18 @@ export default { async fetchActiveAmpeln(){ await this.$fhcApi.factory.ampeln.getNonConfirmedActiveAmpeln().then(res=>{ - this.activeAmpeln = res.data; + this.activeAmpeln = res.data.sort((a,b) => new Date(b.deadline) - new Date(a.deadline)); }); }, async fetchAllAmpeln(){ - await this.$fhcApi.factory.ampeln.getAllActiveAmpeln().then(res=>{ - this.allActiveAmpeln = res.data; + await this.$fhcApi.factory.ampeln.alleAmpeln().then(res=>{ + this.allAmpeln = res.data.sort((a,b) => new Date(b.deadline) - new Date(a.deadline)); }); }, async confirm(ampelId){ - this.$fhcApi.factory.ampeln.confirmAmpel(ampelId).then(res =>{ - console.log(res,"result of the insert into") + await this.$fhcApi.factory.ampeln.confirmAmpel(ampelId).then(res =>{ + res.data ? this.$toast.success('Ampel bestätigt') : this.$toast.error('Fehler beim Bestätigen der Ampel'); }); // fetch all the ampeln after an ampel has been confirmed @@ -117,40 +109,23 @@ export default { await this.fetchAllAmpeln(); }, - changeDisplay(){ - this.filter = ''; - if (this.source == 'offen') - { - //this.ampeln = openAmpeln; - } - - if (this.source == 'alle') - { - //this.ampeln = TEST_ALLE_AMPELN; - // axios - // .get(this.apiurl + '/dashboard/Api/getAmpeln') - // .then(res => { this.ampeln = res.data }) - // .catch(err => { console.error('ERROR: ', err.response.data) }); - } - }, validateBtnTxt(buttontext){ - return buttontext == null ? 'Bestätigen' : buttontext; + + if(buttontext instanceof Array && !buttontext.length) return 'Bestätigen'; + + if(!buttontext) return 'Bestätigen'; + + return buttontext; } }, - async created() { + created() { + + this.$emit('setConfig', false); + }, + async mounted() { await this.fetchActiveAmpeln(); await this.fetchAllAmpeln(); - - // 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*/`
    @@ -162,7 +137,7 @@ export default { -
    +
    @@ -186,7 +161,7 @@ export default {
    Neueste Ampeln
    -