From bb0656c480cb95763ca2f2aa1203da919b7bd1a2 Mon Sep 17 00:00:00 2001 From: Simon Gschnell Date: Fri, 29 Dec 2023 12:01:25 +0100 Subject: [PATCH] http response returns the timestamp of the change --- application/controllers/Cis/Profil.php | 15 ++++++- .../models/person/Profil_change_model.php | 20 +++------ public/js/apps/Cis/Profil.js | 10 ++++- public/js/components/Bootstrap/Confirm.js | 2 +- .../Cis/Profil/MitarbeiterProfil.js | 45 ++++++++++++------- 5 files changed, 58 insertions(+), 34 deletions(-) diff --git a/application/controllers/Cis/Profil.php b/application/controllers/Cis/Profil.php index 58b5e2280..323d6c3ea 100644 --- a/application/controllers/Cis/Profil.php +++ b/application/controllers/Cis/Profil.php @@ -80,9 +80,22 @@ class Profil extends Auth_Controller if (empty($res)) { $insert_res = $this->ProfilChangeModel->insert($data); - echo json_encode($insert_res); + if(isError($insert_res)){ + //catch error + }else{ + //? status code 201 CREATED + $insert_res->code = 201; + $insert_res->retval = $this->ProfilChangeModel->getTimestamp($this->uid)->change_timestamp; + echo json_encode($insert_res); + } + } else { $update_res = $this->ProfilChangeModel->update([$this->uid], $data); + if(isError($update_res)){ + //catch error + } + //? status code 200 OK + $update_res->code = 200; echo json_encode($update_res); } diff --git a/application/models/person/Profil_change_model.php b/application/models/person/Profil_change_model.php index eea42a5d0..946fe6d84 100644 --- a/application/models/person/Profil_change_model.php +++ b/application/models/person/Profil_change_model.php @@ -19,20 +19,10 @@ class Profil_change_model extends DB_Model /** * getLastStatuses */ - public function getData($uid){ - - $res = $this->load($uid); - $res = hasData($res) ? getData($res)[0] : null; - - return $res; - } - - public function insertData($data){ - - $res = $this->insert($data); - //$res = hasData($res) ? getData($res)[0] : null; - - return $res; - } + public function getTimestamp($uid){ + $this->addSelect(['change_timestamp']); + $res = $this->load([$uid]); + return hasData($res) ? getData($res)[0] : null; + } } diff --git a/public/js/apps/Cis/Profil.js b/public/js/apps/Cis/Profil.js index 4014d8e6e..c4d8aee3d 100644 --- a/public/js/apps/Cis/Profil.js +++ b/public/js/apps/Cis/Profil.js @@ -95,7 +95,15 @@ const app = Vue.createApp({ col.click(); }); } - } + }, + + getFormatedDate: function(date){ + return [ + date.getDate().toString().padStart(2,'0'), + (date.getMonth()+1).toString().padStart(2,'0'), + date.getFullYear(), + ].join('/'); + }, }, created(){ diff --git a/public/js/components/Bootstrap/Confirm.js b/public/js/components/Bootstrap/Confirm.js index 1c609d457..7a6f74b15 100644 --- a/public/js/components/Bootstrap/Confirm.js +++ b/public/js/components/Bootstrap/Confirm.js @@ -1,4 +1,4 @@ -import BsAlert from './Alert'; +import BsAlert from './Alert.js'; export default { mixins: [ diff --git a/public/js/components/Cis/Profil/MitarbeiterProfil.js b/public/js/components/Cis/Profil/MitarbeiterProfil.js index 0be210761..1234eeeff 100644 --- a/public/js/components/Cis/Profil/MitarbeiterProfil.js +++ b/public/js/components/Cis/Profil/MitarbeiterProfil.js @@ -1,6 +1,7 @@ import fhcapifactory from "../../../apps/api/fhcapifactory.js"; import { CoreFilterCmpt } from "../../../components/filter/Filter.js"; import BsModal from "../../Bootstrap/Modal.js"; +import Alert from "../../Bootstrap/Alert.js"; @@ -8,6 +9,7 @@ export default { components: { CoreFilterCmpt, BsModal, + Alert, }, data() { return { @@ -142,7 +144,6 @@ export default { }, hideModal() { - // You can call the hide method of the modal component if needed this.$refs.bsmodal.hide(); }, @@ -150,7 +151,22 @@ export default { submitProfilChange(){ if(this.isEditDataChanged){ //? inserts new row in public.tbl_cis_profil_update - Vue.$fhcapi.UserData.editProfil(this.data.editData); + Vue.$fhcapi.UserData.editProfil(this.data.editData).then((res)=>{ + this.hideModal(); + if(res.data.error == 0){ + + //? sets the requested changes as the current data state, so that computed property isEditDataChanged works properly + this.originalEditData = JSON.stringify(this.data.editData); + console.log(this.originalEditData != JSON.stringify(this.data.editData)); + + //* sets the returned timestamp from the response + this.data.editDataTimestamp = res.data.retval? new Date(res.data.retval) : null; + Alert.popup("Ihre Anfrage wurde erfolgreich gesendet. Bitte warten Sie, während sich das Team um Ihre Anfrage kümmert."); + }else{ + Alert.popup("Ein Fehler ist aufgetreten: "+ res.data.retval); + } + // + }); } }, @@ -167,13 +183,7 @@ export default { computed: { - editDataTimestampFormated: function(){ - return [ - this.data.editDataTimestamp.getDate().toString().padStart(2,'0'), - (this.data.editDataTimestamp.getMonth()+1).toString().padStart(2,'0'), - this.data.editDataTimestamp.getFullYear(), - ].join('/'); - }, + //? legacy mailto link to create an email with information that should be changed refreshMailTo() { @@ -190,8 +200,8 @@ export default { }, - isEditDataChanged: function(){ - return JSON.stringify(this.data.editData) != this.originalEditData; + isEditDataChanged(){ + return this.originalEditData != JSON.stringify(this.data.editData) }, get_mitarbeiter_standort_telefon(){ @@ -275,6 +285,9 @@ export default { created() { + + + if(this.data.editData){ this.originalEditData = JSON.stringify(this.data.editData); }else{ @@ -310,8 +323,8 @@ export default { template: ` -
{{JSON.stringify(data.editData,null,2)}}
{{JSON.stringify(data.emails,null,2)}}
- +
{{JSON.stringify(JSON.parse(originalEditData),null,2)}}
{{JSON.stringify(data.editData,null,2)}}
+

{{isEditDataChanged}}

@@ -600,10 +613,10 @@ export default { -