diff --git a/application/controllers/Cis/Profil.php b/application/controllers/Cis/Profil.php index da601b890..f606484ea 100644 --- a/application/controllers/Cis/Profil.php +++ b/application/controllers/Cis/Profil.php @@ -70,17 +70,28 @@ class Profil extends Auth_Controller public function editProfil() { - $json = $this->input->raw_input_stream; + $json = json_decode($this->input->raw_input_stream); - $data = ["uid" => $this->uid, "requested_change" => $json, "change_timestamp" => "NOW()"]; + $data = ["uid" => $this->uid, "requested_change" => json_encode($json->payload), "change_timestamp" => "NOW()", "topic"=>$json->topic]; //? gets all the requested changes from a user $res = $this->ProfilChangeModel->loadWhere(["uid"=>$this->uid]); $res = hasData($res) ? getData($res) : null; + + //? checks if the user already made a request to change a topic + //! which is an constraint added to the public.tbl_cis_profil_update table + foreach($res as $update_request){ + if($update_request->topic == $json->topic && $update_request->uid == $this->uid){ + + echo json_encode(error("uid and topic combination exists already")); + return; + } + } $insert_res = $this->ProfilChangeModel->insert($data); + if(isError($insert_res)){ //catch error @@ -504,13 +515,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)){ + //? querying if the user has profil update requests + $profilUpdates = $this->ProfilChangeModel->loadWhere(["uid"=>$this->uid]); + if(isError($profilUpdates)){ //error handling }else{ - $editData_res = hasData($editData_res) ? getData($editData_res)[0] : null; - } */ + //? array containing all the requested profil information changes from the current user + $profilUpdates = hasData($profilUpdates) ? getData($profilUpdates) : null; + + } $res = new stdClass(); $res->foto = $person_res->foto; @@ -551,9 +564,8 @@ class Profil extends Auth_Controller //telefon nummer von dem Standort $res->standort_telefon = $telefon_res; - /* $res->editData = $editData_res? json_decode($editData_res->profil_data): null; - $res->editDataTimestamp = $editData_res? date_create($editData_res->change_timestamp)->format('d/m/Y') : null; - */ + $res->profilUpdates = $profilUpdates?: null; + return $res; } @@ -707,13 +719,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)){ + //? querying if the user has profil update requests + $profilUpdates = $this->ProfilChangeModel->loadWhere(["uid"=>$this->uid]); + if(isError($profilUpdates)){ //error handling }else{ - $editData_res = hasData($editData_res) ? getData($editData_res)[0] : null; - } */ + //? array containing all the requested profil information changes from the current user + $profilUpdates = hasData($profilUpdates) ? getData($profilUpdates) : null; + + } $res = new stdClass(); @@ -752,9 +766,8 @@ class Profil extends Auth_Controller $res->mailverteiler = $mailverteiler_res; - /* $res->editData = $editData_res? json_decode($editData_res->profil_data): null; - $res->editDataTimestamp = $editData_res? date_create($editData_res->change_timestamp)->format('d/m/Y'): null; - */ + $res->profilUpdates = $profilUpdates?: null; + return $res; diff --git a/public/js/apps/api/userdata.js b/public/js/apps/api/userdata.js index bb0309423..fb3a68a42 100644 --- a/public/js/apps/api/userdata.js +++ b/public/js/apps/api/userdata.js @@ -3,10 +3,11 @@ export default { //! API Calls for Profil Views - editProfil: function(payload) { + editProfil: function(topic, payload) { const url = FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router+ `/Cis/Profil/editProfil`; - return axios.post(url,payload); + + return axios.post(url,{topic, payload}); }, getEditProfil: function() { diff --git a/public/js/components/Cis/Profil/EditProfil.js b/public/js/components/Cis/Profil/EditProfil.js index b6363077b..02cdbfbca 100644 --- a/public/js/components/Cis/Profil/EditProfil.js +++ b/public/js/components/Cis/Profil/EditProfil.js @@ -1,6 +1,6 @@ import BsModal from "../../Bootstrap/Modal.js"; import Alert from "../../Bootstrap/Alert.js"; -const infos = {}; + export default { components: { @@ -27,93 +27,50 @@ export default { }, data() { return { - selection: null, - propertySelection:true, - selectedProperty:null, - inputField:null, - detailSelection:false, - editData: this.value, - //? tracks what specific profil data was changed - changesData: {}, - editTimestamp: this.timestamp, - selectionOrder: {firstSelect: true, secondSelect:false}, + topic:null, + firstSelectedOption:null, + secondSelectedOption: null, + secondSelectedOptionIndex: null, - result: true, - info: null, - } - + + inputField:null, + + editData: this.value, + //? tracks what specific profil data was changed + changesData: {}, + editTimestamp: this.timestamp, + + result: true, + info: null, + } }, methods: { + - formSelection: function(selection){ - - if(Array.isArray(selection)){ - return ['a','b']; - }else if(typeof(selection) === 'object'){ - console.log(selection); - return Object.keys(selection); - - }else{ - // it is not an array or and object - return null; - } + createDeepCopy: function(object){ + //? using Vue.toRaw because deep clones with structuredClone can not be done on proxies + return structuredClone(Vue.toRaw(object)); }, - - updateData: function(event,key,ArrayKey,ObjectKey=null){ - const cleanUpObjectProperties= () => { - Object.entries(this.changesData).forEach( ([property, value]) => { if(!Object.keys(value).length) delete this.changesData[property]; }) - } - - let newValue = event.target.value; - if(!this.changesData[key]){ - Array.isArray(this.editData[key])? this.changesData[key] = [] : this.changesData[key] = {}; - } - - if(Array.isArray(this.editData[key])){ - if(newValue.length > 0) this.editData[key][ArrayKey][ObjectKey]= newValue; - - else this.editData[key][ArrayKey][ObjectKey]= null; + changeInput: function(event, inputField,index){ + let newValue = event.target.value? event.target.value: null; + inputField[index] = newValue; - let Obj = {key:ArrayKey, new: this.editData[key][ArrayKey], old: JSON.parse(this.originalEditData)[key][ArrayKey]}; - - - if(JSON.stringify(this.editData[key][ArrayKey]) === JSON.stringify(JSON.parse(this.originalEditData)[key][ArrayKey]) ){ - this.changesData[key] = this.changesData[key].filter( arrayElement => arrayElement.key !== ArrayKey ); - cleanUpObjectProperties(); - }else{ - if(!this.changesData[key].filter( arrayElement => arrayElement.key === ArrayKey ).length){ - this.changesData[key].push(Obj); - } - - } - }else{ - if(newValue.length > 0) this.editData[key][ArrayKey]= newValue; - - else this.editData[key][ArrayKey]= null; - - let Obj = { new: this.editData[key][ArrayKey], old: JSON.parse(this.originalEditData)[key][ArrayKey]}; - - - if(JSON.stringify(this.editData[key][ArrayKey]) === JSON.stringify(JSON.parse(this.originalEditData)[key][ArrayKey])){ - delete this.changesData[key][ArrayKey]; - cleanUpObjectProperties(); - }else{ - this.changesData[key][ArrayKey]= Obj; - } - - } - - }, + + + + submitProfilChange(){ + //* only inserts new row if the inputField value is different from the original value + if(this.isInputFieldChanged && this.topic){ + //? inserts new row in public.tbl_cis_profil_update - - - Vue.$fhcapi.UserData.editProfil(this.inputField).then((res)=>{ + + Vue.$fhcapi.UserData.editProfil(this.topic,this.inputField).then((res)=>{ this.result = { editData: this.editData, timestamp: res.data.retval, @@ -129,54 +86,34 @@ export default { // }); - + } }, }, computed: { + isInputFieldChanged: function(){ + if(this.inputField){ + return JSON.stringify(this.inputField) !== JSON.stringify(this.secondSelectedOption); + } + return false; + }, + firstSelection(){ return Object.keys(this.value); }, secondSelection(){ - switch(this.selectedProperty){ - case "Personen_Informationen": return Object.keys(this.editData[this.selectedProperty]); - case "Private_Kontakte": return this.editData[this.selectedProperty]; - case "Private_Adressen": return this.editData[this.selectedProperty]; + switch(this.firstSelectedOption){ + case "Personen_Informationen": return Object.keys(this.editData[this.firstSelectedOption]); + case "Private_Kontakte": return this.editData[this.firstSelectedOption]; + case "Private_Adressen": return this.editData[this.firstSelectedOption]; default: return []; } }, - - - - - isEditDataChanged(){ - return this.originalEditData != JSON.stringify(this.editData) - }, }, created() { - this.originalEditData = JSON.stringify(this.editData); - - /* - if (infos[this.lehrveranstaltung_id]) { - this.info = infos[this.lehrveranstaltung_id]; - } else { - axios - .get( - FHC_JS_DATA_STORAGE_OBJECT.app_root + - FHC_JS_DATA_STORAGE_OBJECT.ci_router + - "/components/Cis/Mylv/Info/" + - this.studien_semester + - "/" + - this.lehrveranstaltung_id - ) - .then((res) => { - this.info = infos[this.lehrveranstaltung_id] = res.data.retval || []; - }) - .catch(() => (this.info = {})); - } */ }, mounted() { this.modal = this.$refs.modalContainer.modal; @@ -192,19 +129,35 @@ export default { `, diff --git a/public/js/components/Cis/Profil/MitarbeiterProfil.js b/public/js/components/Cis/Profil/MitarbeiterProfil.js index 279b3bd76..fbec823b1 100644 --- a/public/js/components/Cis/Profil/MitarbeiterProfil.js +++ b/public/js/components/Cis/Profil/MitarbeiterProfil.js @@ -303,7 +303,7 @@ export default {
-
+

@@ -328,8 +328,25 @@ export default {
+ +
+
+
+
+ Profil Informations Änderungen Anfragen
+
+

{{update.requested_change}}

- +
+ +
+
+ + + +
+ + @@ -771,8 +788,27 @@ export default { -
-
+
+
+ +
+
+ Something else +
+
+ +

{{JSON.stringify(update)}}

+
+
+ + + + +
+
+
+ +
diff --git a/public/js/components/Cis/Profil/oldAccordion.txt b/public/js/components/Cis/Profil/oldAccordion.txt index 733ecafd2..9581f5846 100644 --- a/public/js/components/Cis/Profil/oldAccordion.txt +++ b/public/js/components/Cis/Profil/oldAccordion.txt @@ -1,3 +1,60 @@ + +// Legacy function that constructed a result object where the old and the new versions of the changed data was stored +updateData: function(event,key,ArrayKey,ObjectKey=null){ + + const cleanUpObjectProperties= () => { + Object.entries(this.changesData).forEach( ([property, value]) => { if(!Object.keys(value).length) delete this.changesData[property]; }) + } + + let newValue = event.target.value; + if(!this.changesData[key]){ + Array.isArray(this.editData[key])? this.changesData[key] = [] : this.changesData[key] = {}; + } + + if(Array.isArray(this.editData[key])){ + if(newValue.length > 0) this.editData[key][ArrayKey][ObjectKey]= newValue; + + else this.editData[key][ArrayKey][ObjectKey]= null; + + let Obj = {key:ArrayKey, new: this.editData[key][ArrayKey], old: JSON.parse(this.originalEditData)[key][ArrayKey]}; + + + if(JSON.stringify(this.editData[key][ArrayKey]) === JSON.stringify(JSON.parse(this.originalEditData)[key][ArrayKey]) ){ + this.changesData[key] = this.changesData[key].filter( arrayElement => arrayElement.key !== ArrayKey ); + cleanUpObjectProperties(); + }else{ + if(!this.changesData[key].filter( arrayElement => arrayElement.key === ArrayKey ).length){ + this.changesData[key].push(Obj); + } + + } + }else{ + if(newValue.length > 0) this.editData[key][ArrayKey]= newValue; + + else this.editData[key][ArrayKey]= null; + + let Obj = { new: this.editData[key][ArrayKey], old: JSON.parse(this.originalEditData)[key][ArrayKey]}; + + + if(JSON.stringify(this.editData[key][ArrayKey]) === JSON.stringify(JSON.parse(this.originalEditData)[key][ArrayKey])){ + delete this.changesData[key][ArrayKey]; + cleanUpObjectProperties(); + }else{ + this.changesData[key][ArrayKey]= Obj; + } + + } + + + }, + + + + + + + +