From 59b848c576df20a43c6164bf60ecfb6d43f9f373 Mon Sep 17 00:00:00 2001 From: Simon Gschnell Date: Thu, 28 Dec 2023 11:51:58 +0100 Subject: [PATCH] fetches profil update request if an entry with uid in table public.tbl_cis_profil_update exists --- application/controllers/Cis/Profil.php | 28 ++++++++- public/js/apps/Cis/Profil.js | 1 + public/js/apps/api/userdata.js | 25 +++----- .../Cis/Profil/MitarbeiterProfil.js | 59 +++++++++---------- .../Cis/Profil/MitarbeiterViewProfil.js | 2 +- 5 files changed, 63 insertions(+), 52 deletions(-) diff --git a/application/controllers/Cis/Profil.php b/application/controllers/Cis/Profil.php index a2de9497e..d46217fea 100644 --- a/application/controllers/Cis/Profil.php +++ b/application/controllers/Cis/Profil.php @@ -21,6 +21,7 @@ class Profil extends Auth_Controller 'foto_sperre_function' => ['student/anrechnung_beantragen:r', 'user:r'], 'getView' => ['student/anrechnung_beantragen:r', 'user:r'], 'editProfil' => ['student/anrechnung_beantragen:r', 'user:r'], + ]); $this->load->model('ressource/mitarbeiter_model', 'MitarbeiterModel'); @@ -90,6 +91,7 @@ class Profil extends Auth_Controller } + private function viewMitarbeiterProfil($uid) { @@ -179,6 +181,7 @@ class Profil extends Auth_Controller } } + $res = new stdClass(); $res->username = $uid; @@ -482,6 +485,15 @@ class Profil extends Auth_Controller } } + + //? querying if the user already has a pending profil information update request + $editData_res = $this->ProfilChangeModel->load([$this->uid]); + if(isError($editData_res)){ + //error handling + }else{ + $editData_res = hasData($editData_res) ? getData($editData_res)[0] : null; + } + $res = new stdClass(); $res->foto = $person_res->foto; $res->foto_sperre = $person_res->foto_sperre; @@ -520,6 +532,10 @@ class Profil extends Auth_Controller //telefon nummer von dem Standort $res->standort_telefon = $telefon_res; + + $res->editData = json_decode($editData_res->profil_changes); + $res->editDataTimestamp = $editData_res->change_timestamp; + return $res; } @@ -672,6 +688,15 @@ class Profil extends Auth_Controller } } + //? querying if the user already has a pending profil information update request + $editData_res = $this->ProfilChangeModel->load([$this->uid]); + if(isError($editData_res)){ + //error handling + }else{ + $editData_res = hasData($editData_res) ? getData($editData_res)[0] : null; + } + + $res = new stdClass(); @@ -708,7 +733,8 @@ class Profil extends Auth_Controller $res->mailverteiler = $mailverteiler_res; - + $res->editData = json_decode($editData_res->profil_changes); + $res->editDataTimestamp = $editData_res->change_timestamp; return $res; diff --git a/public/js/apps/Cis/Profil.js b/public/js/apps/Cis/Profil.js index 2547f9e48..2969d62f2 100644 --- a/public/js/apps/Cis/Profil.js +++ b/public/js/apps/Cis/Profil.js @@ -111,6 +111,7 @@ const app = Vue.createApp({ this.view = res.data?.view; this.data = res.data?.data; + }); }, template:` diff --git a/public/js/apps/api/userdata.js b/public/js/apps/api/userdata.js index d671cbd66..8e7ea9b47 100644 --- a/public/js/apps/api/userdata.js +++ b/public/js/apps/api/userdata.js @@ -5,6 +5,12 @@ export default { `/Cis/Profil/editProfil`; return axios.post(url,payload); }, + + getEditProfil: function() { + const url = FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router+ + `/Cis/Profil/getEditProfil`; + return axios.get(url); + }, isMitarbeiterOrStudent: function(uid) { const url = FHC_JS_DATA_STORAGE_OBJECT.app_root @@ -25,24 +31,7 @@ export default { }, - indexProfilInformaion: function(uid, view=false) { - const url = FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router+ - `/Cis/Profil/indexProfilInformaion/${uid}/${view}`; - - return axios.get(url); - }, - mitarbeiterProfil: function() { - const url = FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router+ - `/Cis/Profil/mitarbeiterProfil/`; - - return axios.get(url); - }, - studentProfil: function(uid, view=false) { - const url = FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router+ - `/Cis/Profil/studentProfil/${uid}/${view}`; - - return axios.get(url); - }, + diff --git a/public/js/components/Cis/Profil/MitarbeiterProfil.js b/public/js/components/Cis/Profil/MitarbeiterProfil.js index ad1fe4a9d..5630fa8ee 100644 --- a/public/js/components/Cis/Profil/MitarbeiterProfil.js +++ b/public/js/components/Cis/Profil/MitarbeiterProfil.js @@ -11,8 +11,7 @@ export default { data() { return { - //? this reactive object contains all the field the user is able to edit and keep track of which fields he has edited - editData:null, + funktionen_table_options: { height: 300, layout: "fitColumns", @@ -150,7 +149,7 @@ export default { submitProfilChange(){ if(this.isEditDataChanged){ //? inserts new row in public.tbl_cis_profil_update - Vue.$fhcapi.UserData.editProfil(this.editData); + Vue.$fhcapi.UserData.editProfil(this.data.editData); } }, @@ -182,7 +181,7 @@ export default { isEditDataChanged: function(){ - return JSON.stringify(this.editData) != this.originalEditData; + return JSON.stringify(this.data.editData) != this.originalEditData; }, get_mitarbeiter_standort_telefon(){ @@ -266,23 +265,22 @@ export default { created() { + if(this.data.editData){ + this.originalEditData = JSON.stringify(this.data.editData); + }else{ + //? storing an original version of the editData to check if the editData was changed by the user and is not in the original state + this.originalEditData = JSON.stringify( + { + Personen_Informationen : {...this.personData, vorname: this.data.vorname, nachname: this.data.nachname}, + Mitarbeiter_Informatinen: this.specialData, + Emails:this.data.emails, + Private_Kontakte: this.data.kontakte, + Private_Adressen:this.privateAdressen, + }); - - - //? storing an original version of the editData to check if the editData was changed by the user and is not in the original state - this.originalEditData = JSON.stringify( - { - Personen_Informationen : {...this.personData, vorname: this.data.vorname, nachname: this.data.nachname}, - Mitarbeiter_Informatinen: this.specialData, - Emails:this.data.emails, - Private_Kontakte: this.data.kontakte, - Private_Adressen:this.privateAdressen, - }); + this.data.editData = JSON.parse(this.originalEditData); - this.editData = JSON.parse(this.originalEditData); - - - + } }, mounted() { @@ -295,14 +293,11 @@ export default { }); - - - }, template: ` -
{{JSON.stringify(editData,null,2)}}
{{JSON.stringify(data.emails,null,2)}}
+
{{JSON.stringify(data.editData,null,2)}}
{{JSON.stringify(data.emails,null,2)}}
@@ -522,7 +517,7 @@ export default {
-
+