From ee8051915ece438fb305f43a4928f3ce3d02a440 Mon Sep 17 00:00:00 2001 From: Simon Gschnell Date: Thu, 4 Jan 2024 16:06:47 +0100 Subject: [PATCH] formats the update timestamps in php, differently tracks which properties and informations where changed by the user --- application/controllers/Cis/Profil.php | 14 +++-- application/controllers/Cis/ProfilUpdate.php | 9 ++- .../models/person/Profil_change_model.php | 4 +- public/js/apps/Cis/Profil.js | 4 +- public/js/apps/Cis/ProfilUpdateRequests.js | 59 ++++++++++++++----- public/js/components/Cis/Profil/EditProfil.js | 50 ++++++++++++---- .../Cis/Profil/MitarbeiterProfil.js | 7 +-- 7 files changed, 104 insertions(+), 43 deletions(-) diff --git a/application/controllers/Cis/Profil.php b/application/controllers/Cis/Profil.php index 9f692b0a9..272474d22 100644 --- a/application/controllers/Cis/Profil.php +++ b/application/controllers/Cis/Profil.php @@ -76,15 +76,16 @@ class Profil extends Auth_Controller $res = $this->ProfilChangeModel->load([$this->uid]); $res = hasData($res) ? getData($res) : null; - + if (empty($res)) { $insert_res = $this->ProfilChangeModel->insert($data); if(isError($insert_res)){ //catch error }else{ + $editTimestamp = $this->ProfilChangeModel->getTimestamp($this->uid); //? status code 201 CREATED $insert_res->code = 201; - $insert_res->retval = $this->ProfilChangeModel->getTimestamp($this->uid)->change_timestamp; + $insert_res->retval = date_create($editTimestamp)->format('d/m/Y'); echo json_encode($insert_res); } @@ -93,9 +94,10 @@ class Profil extends Auth_Controller if(isError($update_res)){ //catch error } + $editTimestamp = $this->ProfilChangeModel->getTimestamp($this->uid); //? status code 200 OK $update_res->code = 200; - $update_res->retval = $this->ProfilChangeModel->getTimestamp($this->uid)->change_timestamp; + $update_res->retval = date_create($editTimestamp)->format('d/m/Y');; echo json_encode($update_res); } @@ -547,7 +549,8 @@ class Profil extends Auth_Controller $res->standort_telefon = $telefon_res; $res->editData = $editData_res? json_decode($editData_res->profil_changes): null; - $res->editDataTimestamp = $editData_res? $editData_res->change_timestamp: null; + $res->editDataTimestamp = $editData_res? date_create($editData_res->change_timestamp)->format('d/m/Y') : null; + return $res; } @@ -747,7 +750,8 @@ class Profil extends Auth_Controller $res->mailverteiler = $mailverteiler_res; $res->editData = $editData_res? json_decode($editData_res->profil_changes): null; - $res->editDataTimestamp = $editData_res? $editData_res->change_timestamp: null; + $res->editDataTimestamp = $editData_res? date_create($editData_res->change_timestamp)->format('d/m/Y'): null; + return $res; diff --git a/application/controllers/Cis/ProfilUpdate.php b/application/controllers/Cis/ProfilUpdate.php index 5e410bace..2ee7368be 100644 --- a/application/controllers/Cis/ProfilUpdate.php +++ b/application/controllers/Cis/ProfilUpdate.php @@ -35,7 +35,14 @@ class ProfilUpdate extends Auth_Controller echo $res->retval->data; return; }else{ - $res = hasData($res)? getData($res) : null; + if(hasData($res)){ + $res = getData($res); + foreach($res as $element){ + $element->change_timestamp = date_create($element->change_timestamp)->format('d/m/Y H:i'); + } + }else{ + $res = null; + } } echo json_encode($res); } diff --git a/application/models/person/Profil_change_model.php b/application/models/person/Profil_change_model.php index 946fe6d84..f7e514847 100644 --- a/application/models/person/Profil_change_model.php +++ b/application/models/person/Profil_change_model.php @@ -12,8 +12,6 @@ class Profil_change_model extends DB_Model $this->pk = ['uid']; $this->hasSequence = false; - //? loading other models to query them - $this->load->model('crm/prestudentstatus_model', 'PrestudentstatusModel'); } /** @@ -22,7 +20,7 @@ class Profil_change_model extends DB_Model public function getTimestamp($uid){ $this->addSelect(['change_timestamp']); $res = $this->load([$uid]); - return hasData($res) ? getData($res)[0] : null; + return hasData($res) ? getData($res)[0]->change_timestamp : null; } } diff --git a/public/js/apps/Cis/Profil.js b/public/js/apps/Cis/Profil.js index ba4443b69..a490eddc5 100644 --- a/public/js/apps/Cis/Profil.js +++ b/public/js/apps/Cis/Profil.js @@ -114,9 +114,7 @@ const app = Vue.createApp({ this.data = res.data?.data; - if(this.data.editDataTimestamp){ - this.data.editDataTimestamp= new Date(this.data.editDataTimestamp); - } + } diff --git a/public/js/apps/Cis/ProfilUpdateRequests.js b/public/js/apps/Cis/ProfilUpdateRequests.js index 4a518796c..65b996f3c 100644 --- a/public/js/apps/Cis/ProfilUpdateRequests.js +++ b/public/js/apps/Cis/ProfilUpdateRequests.js @@ -1,6 +1,14 @@ import fhcapifactory from "../api/fhcapifactory.js"; import {CoreFilterCmpt} from '../../components/filter/Filter.js' Vue.$fhcapi = fhcapifactory; +/* +data: [ + { + uid: "", + profil_changes: "", + change_timestamp: "", + }, +], */ const app = Vue.createApp({ components:{ @@ -9,32 +17,32 @@ const app = Vue.createApp({ data(){ return{ profil_updates_table_options:{ + ajaxURL:FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + '/Cis/ProfilUpdate/getAllRequests', height:300, layout:'fitColumns', responsiveLayout: "collapse", - data: [ - { - uid: "", - profil_changes: "", - change_timestamp: "", - }, - ], + responsiveLayoutCollapseUseFormatters:false, + responsiveLayoutCollapseFormatter:this.collapseFormatter, + columns: [ { title: "Uid", field: "uid", minWidth: 200, + responsive:0, }, { title: "Update", field: "profil_changes", - minWidth: 200, + minWidth: 10000, + responsive:3, }, { title: "Date", field: "change_timestamp", resizable: true, minWidth: 200, + responsive:0, }, ], @@ -44,7 +52,33 @@ const app = Vue.createApp({ methods:{ sideMenuFunction: function(){ console.log("test from the side menu"); - } + }, + collapseFormatter: function(data){ + //data - an array of objects containing the column title and value for each cell + var container = document.createElement("div"); + container.classList.add("tabulator-collapsed-row"); + container.classList.add("text-break"); + + var list = document.createElement("div"); + list.classList.add("row"); + + + container.appendChild(list); + + data.forEach(function(col){ + let item = document.createElement("div"); + item.classList.add("col-12"); + + + item.innerHTML = Object.keys(JSON.parse(col.value)).map(key => {return key+'
'}); + + + list.appendChild(item); + + }); + + return Object.keys(data).length ? container : ""; + }, }, created(){ @@ -54,12 +88,7 @@ const app = Vue.createApp({ }, mounted(){ - this.$refs.UpdatesTable.tabulator.on('tableBuilt',()=>{ - Vue.$fhcapi.UserData.getProfilUpdateRequest().then((data)=>{ - this.$refs.UpdatesTable.tabulator.setData(data.data); - }).catch(()=>{}); - - }); + }, template:`
diff --git a/public/js/components/Cis/Profil/EditProfil.js b/public/js/components/Cis/Profil/EditProfil.js index b29c1c345..cfd3b2a2f 100644 --- a/public/js/components/Cis/Profil/EditProfil.js +++ b/public/js/components/Cis/Profil/EditProfil.js @@ -28,20 +28,46 @@ export default { data() { return { editData: this.value, + //? tracks what specific profil data was changed + changesData: {Emails: [],Private_Adressen:[],Private_Kontakte:[],Personen_Informationen:{},Mitarbeiter_Informationen:{} }, editTimestamp: this.timestamp, result: true, info: null, } }, + methods: { - test(){ - console.log("test"); + + updateData: function(event,key,ArrayKey,ObjectKey=null){ + if(Array.isArray(this.editData[key])){ + this.editData[key][ArrayKey][ObjectKey]= event.target.value; + if(event.target.value === JSON.parse(this.originalEditData)[key][ArrayKey][ObjectKey]){ + this.changesData[key].splice(ArrayKey,1); + }else{ + if(!this.changesData[key].includes(this.editData[key][ArrayKey])){ + this.changesData[key].push(this.editData[key][ArrayKey]); + } + + } + }else{ + console.log(key); + this.editData[key][ArrayKey]= event.target.value; + if(event.target.value === JSON.parse(this.originalEditData)[key][ArrayKey]){ + delete this.changesData[key][ArrayKey]; + }else{ + this.changesData[key][ArrayKey]= this.editData[key][ArrayKey]; + } + } + + }, submitProfilChange(){ if(this.isEditDataChanged){ //? inserts new row in public.tbl_cis_profil_update + + Vue.$fhcapi.UserData.editProfil(this.editData).then((res)=>{ this.result = { editData: this.editData, @@ -62,6 +88,7 @@ export default { }, }, computed: { + getFormatedDate: function(){ return [ this.editTimestamp.getDate().toString().padStart(2,'0'), @@ -109,13 +136,13 @@ export default { {{"Profil bearbeiten" }}