From 1211d63ccfa845c985b412c94d6d21a1e95fb650 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Tue, 23 Jul 2024 13:59:04 +0200 Subject: [PATCH] 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
+ + +
+