fixes bug when getting all the profil update requests and makes it possible to add a message when dening or accepting a profil update

This commit is contained in:
SimonGschnell
2024-01-23 11:00:43 +01:00
parent 7abe04a69f
commit df74bade9b
12 changed files with 133 additions and 64 deletions
+9 -6
View File
@@ -69,8 +69,11 @@ class Profil extends Auth_Controller
public function selectProfilRequest(){
$uid =json_decode($this->input->get("uid"));
$id =json_decode($this->input->get("id"));
$_GET = json_decode($this->input->raw_input_stream, true);
$uid = $this->input->get('uid');
$id = $this->input->get('id');
echo $uid;
echo $id;
if($uid && $id){
$res= $this->ProfilChangeModel->getProfilUpdate($uid, $id);
@@ -93,7 +96,8 @@ class Profil extends Auth_Controller
$json = json_decode($this->input->raw_input_stream);
$payload = $json->payload;
$type = isset($json->payload->kontakt_id)? "kontakt_id" : "adresse_id";
$type = property_exists($json->payload,"kontakt_id")? "kontakt_id" : "adresse_id";
$data = ["topic"=>$json->topic,"uid" => $this->uid, "requested_change" => json_encode($payload), "change_timestamp" => "NOW()","status"=>"pending" ];
@@ -104,10 +108,9 @@ class Profil extends Auth_Controller
if($res){
foreach($res as $update_request){
$existing_change = json_decode($update_request->requested_change);
echo json_encode($existing_change);
echo property_exists($existing_change,$type);
if(property_exists($existing_change,$type) && $existing_change->$type == $payload->$type){
if(property_exists($existing_change,$type) && property_exists($payload,$type) && $existing_change->$type == $payload->$type){
//? the kontakt_id / adresse_id of a change has to be unique
echo json_encode(error("cannot change the same resource twice"));
+8 -12
View File
@@ -37,28 +37,24 @@ class ProfilUpdate extends Auth_Controller
public function acceptProfilRequest(){
$_POST = json_decode($this->input->raw_input_stream,true);
$id = $this->input->post('requestID',true);
$id = $this->input->post('profil_update_id',true);
$status_message = $this->input->post('status_message',true);
if(isset($id)){
$res =$this->ProfilChangeModel->update([$id], ["status"=>"accepted","status_timestamp"=>"NOW()"]);
$res =$this->ProfilChangeModel->update([$id], ["status"=>"accepted","status_timestamp"=>"NOW()","status_message"=>$status_message]);
echo json_encode($res);
}
}
}
public function denyProfilRequest(){
$_POST = json_decode($this->input->raw_input_stream,true);
$id = $this->input->post('requestID',true);
$id = $this->input->post('profil_update_id',true);
$status_message = $this->input->post('status_message',true);
if(isset($id)){
var_dump($id);
//! instead of deleting the rejected profil update, the status of the db entry is set to rejected
//$res = $this->ProfilChangeModel->delete([$id]);
$res = $this->ProfilChangeModel->update([$id],["status"=>"rejected","status_timestamp"=>"NOW()"]);
$res = $this->ProfilChangeModel->update([$id],["status"=>"rejected","status_timestamp"=>"NOW()","status_mesage"=>$status_message]);
echo json_encode($res);
}
@@ -49,6 +49,7 @@ class Profil_change_model extends DB_Model
foreach($res->retval as $update){
$update->requested_change = json_decode($update->requested_change);
$update->change_timestamp = date_create($update->change_timestamp)->format('d.m.Y');
$update->status_timestamp = date_create($update->status_timestamp)->format('d.m.Y');
}
}
}
@@ -73,6 +73,7 @@ const app = Vue.createApp({
//! function that is called when clicking on a row in the table
let cellData = cell.getRow().getData();
AcceptDenyUpdate.popup({value:cellData}).then(res=>{
console.log("res of the modal: ",res);
//? refetches the data, if any request was denied or accepted
@@ -82,6 +83,7 @@ const app = Vue.createApp({
//? catches the rejected Promise if the result of the modal was falsy
console.log("catch of the modal: ",e);
});
},
//responsive:0,
+4 -4
View File
@@ -7,14 +7,14 @@ export default {
return axios.get(url);
},
acceptProfilRequest: function(requestID){
acceptProfilRequest: function(payload){
const url = FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + '/Cis/ProfilUpdate/acceptProfilRequest';
return axios.post(url,{requestID: requestID});
return axios.post(url,payload);
},
denyProfilRequest: function(requestID){
denyProfilRequest: function(payload){
const url = FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + '/Cis/ProfilUpdate/denyProfilRequest';
return axios.post(url,{requestID: requestID});
return axios.post(url,payload);
}
}
+2 -2
View File
@@ -5,9 +5,9 @@ export default {
selectProfilRequest: function(uid=null,id=null) {
const url = FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router+
`/Cis/Profil/selectProfilRequest?uid=${uid}&id=${id}`;
`/Cis/Profil/selectProfilRequest`;
return axios.get(url);
return axios.get(url,{uid:uid, id:id});
},
insertProfilRequest: function(topic, payload) {
@@ -55,6 +55,7 @@ export default {
addItem: function(){
this.view= this.topic == "Private Kontakte"?"EditKontakt":"EditAdresse" ;
//? updates the topic when a Kontakt or an Address should be added
@@ -63,7 +64,6 @@ export default {
this.breadcrumbItems.push(this.topic);
this.$emit('update:breadcrumb',this.breadcrumbItems);
this.data= this.view=="EditAdresse"?
{
added:true,
@@ -72,8 +72,7 @@ export default {
adr_typ: null,
plz: null,
ort: null
}:
{
}: {
added:true,
kontakt_id: null,
kontakttyp: null,
@@ -81,7 +80,8 @@ export default {
anmerkung: null,
zustellung: false
}
},
deleteItem: function(item){
@@ -138,8 +138,6 @@ export default {
},
template: `
<template v-if="!view">
<div class="list-group">
<template v-for="item in data">
@@ -175,7 +173,8 @@ export default {
<!-- if it not a normal text input field then reder the custom edit input component -->
<!-- custom component is required to emit an profilUpdate event to register the new entered value -->
<template v-else>
<component @profilUpdate="profilUpdateEmit" :is="view" :data="data" v-bind="list"></component>
<!-- both v-bind="list" and :data="data" pass a data prop, in this case the last one is the one that gets taken -->
<component @profilUpdate="profilUpdateEmit" :is="view" v-bind="list" :data="data"></component>
</template>
`,
};
@@ -249,14 +249,7 @@ export default {
title:"Personen Informationen",
view:null,
data:{
username:{
title:"username",
view:"text_input",
data:{
titel:"username",
value:this.data.username,
}
},
vorname: {
title:"vorname",
view:"text_input",
@@ -271,7 +264,23 @@ export default {
titel:"nachname",
value:this.data.nachname,
}
}
},
titel:{
title:"titel",
view:"text_input",
data:{
titel:"titel",
value:this.data.titel,
}
},
postnomen:{
title:"postnomen",
view:"text_input",
data:{
titel:"postnomen",
value:this.data.titel,
}
},
}
},
Private_Kontakte: {
@@ -26,7 +26,7 @@ export default {
},
template:`
<pre>{{isChanged}}</pre>
<div class="gy-3 row justify-content-center align-items-center">
<!-- column 1 in the address row -->
@@ -46,6 +46,7 @@ export default {
<!-- column 2 in the address row -->
<div class=" order-2 order-sm-4 order-xl-3 order-xxl-4 col-12 col-sm-5 col-xl-8 col-xxl-5 ">
<!-- OLD INPUT FIELD FOR ADDRESS TYPE
<template v-if="data.adresse_id">
<div class="form-underline ">
<div class="form-underline-titel">Typ</div>
@@ -54,6 +55,7 @@ export default {
</div>
</template>
<template v-else>
-->
@@ -10,6 +10,7 @@ export default {
},
methods:{
updateValue: function(event,bind){
if(bind === 'zustellung'){
this.data[bind] = event.target.checked;
}else{
@@ -38,7 +39,6 @@ export default {
},
template:
`
<div class="gy-3 row align-items-center justify-content-center">
<div v-if="!data.kontakt_id" class="col-12">
@@ -30,13 +30,13 @@ export default {
},
getView: function(topic,status){
switch(topic){
case "Private Kontakte" : return "EditKontakt"; break;
case "Private Adressen" : return "EditAdresse"; break;
case "Add Adressen" : return "EditAdresse"; break;
case "Add Kontakte" : return "EditKontakt"; break;
case "Private Kontakte" : return status ==='pending'? "EditKontakt": "Status"; break;
case "Private Adressen" : return status ==='pending'? "EditAdresse": "Status"; break;
case "Add Adressen" : return status ==='pending'? "EditAdresse": "Status"; break;
case "Add Kontakte" : return status ==='pending'? "EditKontakt": "Status"; break;
case "Delete Adressen" : return status ==='pending'? "Adresse": "Status" ; break;
case "Delete Kontakte" : return status ==='pending'? "Kontakt": "Status"; break;
default: return "text_input"; break;
default: return status ==='pending'? "text_input": "Status"; break;
}
},
openModal(updateRequest) {
@@ -45,15 +45,19 @@ export default {
let view = this.getView(updateRequest.topic,updateRequest.status);
let data = null;
let content =null;
if(view === 'text_input'){
//TODO: change data handling for text_input component to accept the data in the same way as the other components
if(view === "text_input"){
data = {
titel:updateRequest.topic,
value:updateRequest.requested_change,
};
}else{
titel:updateRequest.topic,
value: updateRequest.requested_change,
};
}
else{
data = updateRequest.requested_change;
}
content={
view:view,
@@ -130,7 +134,7 @@ export default {
<template v-if="item.status === 'pending'">
<td>
<template v-if="item.topic.toLowerCase().includes('delete')">
<!-- old edit view for delete requests <div class="align-middle text-center" >{{item.requested_change.adr_typ?item.requested_change.adr_typ:item.requested_change.kontakt}}</div>-->
<div class="align-middle text-center"><i style="color:gray" role="button" @click="openModal(item)" class="fa fa-eye"></i></div>
</template>
<template v-else >
@@ -45,7 +45,7 @@ export default {
methods: {
acceptRequest: function(){
console.log(this.data.profil_update_id);
Vue.$fhcapi.ProfilUpdate.acceptProfilRequest(this.data.profil_update_id).then(res =>{
Vue.$fhcapi.ProfilUpdate.acceptProfilRequest(this.data).then(res =>{
console.log("res",res);
console.log("res.data",res.data);
this.result = true;
@@ -55,7 +55,7 @@ export default {
denyRequest: function(){
console.log(this.data.profil_update_id);
Vue.$fhcapi.ProfilUpdate.denyProfilRequest(this.data.profil_update_id).then(res =>{
Vue.$fhcapi.ProfilUpdate.denyProfilRequest(this.data).then(res =>{
console.log("res",res);
console.log("res.data",res.data);
this.result = true;
@@ -116,44 +116,97 @@ export default {
<template v-slot:default>
<pre>{{JSON.stringify(data.profil_update_id,null,2)}}</pre>
<!-- debugging prints
<pre>{{JSON.stringify(data.profil_update_id,null,2)}}</pre>
<pre>view {{getComponentView}}</pre>
<pre>topic {{JSON.stringify(data.topic,null,2)}}</pre>
<pre>data {{JSON.stringify(data.requested_change,null,2)}}</pre>
-->
<div class="row">
<div class="form-underline mb-2 col">
<div class="form-underline-titel">Status: </div>
<div class="form-underline mb-2">
<span class="form-underline-content" >{{data.status}}</span>
</div>
<div class="form-underline mb-2 col">
<div class="form-underline-titel">Date of Status: </div>
<span class="form-underline-content" >{{data.status_timestamp}}</span>
</div>
<div class="form-underline mb-2 col">
<div class="form-underline-titel">Status message: </div>
<span class="form-underline-content" >{{data.status_message? data.status_message : '-'}}</span>
</div>
<div class="form-underline mb-2 col">
<div class="form-underline-titel">UserID: </div>
<span class="form-underline-content" >{{data.uid}}</span>
</div>
<div class="form-underline mb-2">
<div class="form-underline mb-2 col">
<div class="form-underline-titel">Topic of Request: </div>
<span class="form-underline-content" >{{data.topic}}</span>
</div>
<div class="form-underline mb-2">
<div class="form-underline mb-2 col">
<div class="form-underline-titel">Date of Request:</div>
<span class="form-underline-content" >{{data.change_timestamp}}</span>
</div>
</div>
<div class="row my-4">
<div class="col ">
<div class="card">
<div class="card-header">update</div>
<div class="card-body">
<div v-if="getComponentView==='text_input'" class="form-underline mb-2">
<div class="form-underline-titel">{{data.topic}}</div>
<span class="form-underline-content" >{{data.requested_change}}</span>
</div>
<component v-else :is="getComponentView" :data="data.requested_change"></component>
</div>
</div>
</div>
</div>
</template>
<template v-slot:footer>
<button @click="acceptRequest" class="btn btn-primary">Accept <i class="fa fa-check"></i></button>
<button @click="denyRequest" class="btn btn-danger">Deny <i class="fa fa-xmark"></i></button>
<template v-if="data.status === 'pending'" v-slot:footer>
<div class="form-underline flex-fill">
<div class="form-underline-titel">Message</div>
<div class="d-flex flex-row gap-2">
<input class="form-control " v-model="data.status_message" >
<button @click="acceptRequest" class="text-nowrap btn btn-primary">Accept <i class="fa fa-check"></i></button>
<button @click="denyRequest" class="text-nowrap btn btn-danger">Deny <i class="fa fa-xmark"></i></button>
</div>
</div>
</template>
</bs-modal>`,