formats the update timestamps in php, differently tracks which properties and informations where changed by the user

This commit is contained in:
Simon Gschnell
2024-01-04 16:06:47 +01:00
parent d412c1d00e
commit ee8051915e
7 changed files with 104 additions and 43 deletions
+9 -5
View File
@@ -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;
+8 -1
View File
@@ -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);
}
@@ -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;
}
}
+1 -3
View File
@@ -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);
}
}
+44 -15
View File
@@ -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+'<br/>'});
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:`
<div>
+38 -12
View File
@@ -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" }}
</template>
<template v-slot:default>
<!-- START OF THE ACCORDION
<pre>{{JSON.stringify(data)}}</pre>
<pre>{{JSON.stringify(result)}}</pre>-->
<!-- START OF THE ACCORDION
-->
<pre>{{JSON.stringify(changesData,null,2)}}</pre>
<div class="accordion accordion-flush" id="accordionFlushExample" >
<div class="accordion-item" v-for="(value,key) in editData ">
<h2 class="accordion-header" :id="'flush-headingOne'+key">
@@ -129,7 +156,7 @@ export default {
<div v-if="Array.isArray(value)" class="row gy-5">
<template v-for="(object,objectkey) in value" >
<template v-for="(object,objectKey) in value" >
<div class="col-12 ">
<div class="row gy-3">
<div v-for="(propertyValue,propertyKey) in object" class="col-6" >
@@ -139,8 +166,7 @@ export default {
<label :for="propertyKey+'input'" >{{propertyKey}}</label>
</div>
<div>
<input class="form-control" :id="propertyKey+'input'" v-model="editData[key][objectkey][propertyKey]" :placeholder="propertyValue">
<input class="form-control" :id="propertyKey+'input'" :value="editData[key][objectKey][propertyKey]" @input="updateData($event,key,objectKey,propertyKey)" :placeholder="propertyValue">
</div>
</div>
@@ -163,7 +189,7 @@ export default {
</div>
<div>
<input type="email" class="form-control" :id="propertyKey+'input'" v-model="editData[key][propertyKey]" :placeholder="propertyValue">
<input type="email" class="form-control" :id="propertyKey+'input'" :value="editData[key][propertyKey]" @input="updateData($event,key,propertyKey)" :placeholder="propertyValue">
</div>
</div>
</div>
@@ -188,7 +214,7 @@ export default {
</template>
<!-- optional footer -->
<template v-if="editTimestamp || isEditDataChanged" v-slot:footer>
<p v-if="editTimestamp" class="flex-fill">Letzte Anfrage: {{getFormatedDate}}</p>
<p v-if="editTimestamp" class="flex-fill">Letzte Anfrage: {{editTimestamp}}</p>
<button v-if="isEditDataChanged" @click="submitProfilChange" role="button" class="btn btn-primary">Senden</button>
</template>
@@ -126,13 +126,13 @@ export default {
methods: {
showModal() {
EditProfil.popup({
value:JSON.parse(JSON.stringify(this.data.editData)),
timestamp:this.data.editDataTimestamp
}).then((res) => {
if(res.timestamp && res.editData){
this.data.editDataTimestamp = new Date(res.timestamp);
this.data.editDataTimestamp = res.timestamp;
this.data.editData = res.editData;
}
@@ -260,14 +260,13 @@ export default {
created() {
if(!this.data.editData){
this.data.editData = {
Personen_Informationen : {...this.personData, vorname: this.data.vorname, nachname: this.data.nachname},
Mitarbeiter_Informatinen: this.specialData,
Mitarbeiter_Informationen: this.specialData,
Emails:this.data.emails,
Private_Kontakte: this.data.kontakte,
Private_Adressen:this.privateAdressen,