diff --git a/application/controllers/Cis/Profil.php b/application/controllers/Cis/Profil.php
index ee5d781b3..76d225374 100755
--- a/application/controllers/Cis/Profil.php
+++ b/application/controllers/Cis/Profil.php
@@ -25,7 +25,8 @@ class Profil extends Auth_Controller
'deleteProfilRequest' => ['student/anrechnung_beantragen:r', 'user:r'],
'selectProfilRequest' => ['student/anrechnung_beantragen:r', 'user:r'],
'insertFile' => ['student/anrechnung_beantragen:r', 'user:r'],
-
+ 'getProfilRequestFiles' => ['student/anrechnung_beantragen:r', 'user:r'],
+
]);
$this->load->model('ressource/mitarbeiter_model', 'MitarbeiterModel');
$this->load->model('crm/Student_model', 'StudentModel');
@@ -130,6 +131,10 @@ class Profil extends Auth_Controller
}
+ public function getProfilRequestFiles(){
+ $id = json_decode($this->input->raw_input_stream);
+ echo json_encode($this->ProfilChangeModel->getFilesFromChangeRequest($id));
+ }
public function insertProfilRequest()
{
@@ -137,7 +142,7 @@ class Profil extends Auth_Controller
$json = json_decode($this->input->raw_input_stream);
$payload = $json->payload;
- $identifier = property_exists($json->payload,"kontakt_id")? "kontakt_id" : "adresse_id";
+ $identifier = property_exists($json->payload,"kontakt_id")? "kontakt_id" : (property_exists($json->payload,"adresse_id")? "adresse_id" : null);
$name = $this->PersonModel->getFullName($this->uid);
if(isError($name)){
@@ -145,7 +150,7 @@ class Profil extends Auth_Controller
var_dump($name);
return;
}
- $data = ["topic"=>$json->topic,"uid" => $this->uid, "name"=>getData($name), "requested_change" => json_encode($payload), "change_timestamp" => "NOW()","status"=>"pending" ];
+ $data = ["topic"=>$json->topic,"uid" => $this->uid, "name"=>getData($name), "requested_change" => json_encode($payload), "insertamum" => "NOW()", "insertvon"=>$this->uid,"status"=>"pending" ];
//? loops over all updateRequests from a user to validate if the new request is valid
$res = $this->ProfilChangeModel->loadWhere(["uid"=>$this->uid]);
@@ -165,22 +170,23 @@ class Profil extends Auth_Controller
return;
}
- elseif(!isset($payload->add) && !isset($payload->delete) && $update_request->topic == $json->topic ){
- //? if it is not a delete or add request than the topic in combination with the uid of the user have to be unique
+ elseif(!$identifier && $update_request->topic == $json->topic ){
+ //? if it is not a delete or add request than the topic has to be unique
echo json_encode(error("A request to change " . $json->topic . " is already open"));
return;
}
}}
- $insert_res = $this->ProfilChangeModel->insert($data);
+ $insertID = $this->ProfilChangeModel->insert($data);
- if(isError($insert_res)){
+ if(isError($insertID)){
//catch error
}else{
- $editTimestamp = $this->ProfilChangeModel->getTimestamp($insert_res->retval);
+ $insertID = hasData($insertID)? getData($insertID): null;
+ $editTimestamp = $this->ProfilChangeModel->getTimestamp($insertID);
- $insert_res->retval = date_create($editTimestamp)->format('d.m.Y');
- echo json_encode($insert_res);
+ $date = success(date_create($editTimestamp)->format('d.m.Y'));
+ echo json_encode($date);
}
}
@@ -189,24 +195,16 @@ class Profil extends Auth_Controller
$json = json_decode($this->input->raw_input_stream);
-
- $data = ["topic"=>$json->topic,"uid" => $this->uid, "requested_change" => json_encode($json->payload), "change_timestamp" => "NOW()","status"=>"pending" ];
-
- //? gets all the requested changes from a user
- if(isSuccess($this->ProfilChangeModel->addSelect(["profil_update_id"])) ){
- $requestID = $this->ProfilChangeModel->loadWhere(["uid"=>$this->uid,"topic"=>$json->topic]);
- $requestID = hasData($requestID) ? getData($requestID)[0]->profil_update_id : null;
- };
-
- $update_res =$this->ProfilChangeModel->update([$requestID],$data);
- if(isError($update_res)){
+ $updateID =$this->ProfilChangeModel->update([$json->ID],["requested_change" => json_encode($json->payload), "updateamum" => "NOW()", "updatevon" => $this->uid]);
+ if(isError($updateID)){
//catch error
}else{
- $editTimestamp = $this->ProfilChangeModel->getTimestamp($update_res->retval[0]);
+ $updateID = hasData($updateID)? getData($updateID)[0]: null;
+ $editTimestamp = $this->ProfilChangeModel->getTimestamp($updateID,true);
- $update_res->retval = date_create($editTimestamp)->format('d.m.Y');
- echo json_encode($update_res);
+ $date = success(date_create($editTimestamp)->format('d.m.Y'));
+ echo json_encode($date);
}
}
diff --git a/application/models/person/Profil_change_model.php b/application/models/person/Profil_change_model.php
index 9a229f308..ea272493c 100755
--- a/application/models/person/Profil_change_model.php
+++ b/application/models/person/Profil_change_model.php
@@ -17,11 +17,30 @@ class Profil_change_model extends DB_Model
/**
* getTimestamp
* returns insert or update timestamp of a certain profil update
+ *
+ * @param boolean $update: conditional whether to return insertamum or updateamum
*/
- public function getTimestamp($uid){
- $this->addSelect(['change_timestamp']);
- $res = $this->load([$uid]);
- return hasData($res) ? getData($res)[0]->change_timestamp : null;
+ public function getTimestamp($id, $update=false){
+ $selectStatement = $update? 'updateamum' : 'insertamum';
+ $this->addSelect([$selectStatement]);
+ $res = $this->load([$id]);
+ return hasData($res) ? getData($res)[0]->$selectStatement : null;
+ }
+
+ /**
+ * getFilesFromChangeRequest
+ *
+ * returns all files associated to a profil update request in the following format:
+ * {dms_id:123 , name:"test"}
+ *
+ * @param boolean $profil_update_id primary key of the profil update request
+ * @return Array
+ */
+ public function getFilesFromChangeRequest($profil_update_id){
+ $this->addSelect(["requested_change"]);
+ $res = $this->load([$profil_update_id]);
+ $res = hasData($res) ? getData($res)[0] : null;
+ return json_decode($res->requested_change)->files?:null;
}
/**
@@ -36,7 +55,6 @@ class Profil_change_model extends DB_Model
if(!is_null($uid)){
$whereClause['uid']=$uid;
}
- //?
if(!is_null($id)){
$whereClause['profil_update_id']=$id;
}
@@ -49,7 +67,7 @@ class Profil_change_model extends DB_Model
foreach($res->retval as $update){
$update->requested_change = json_decode($update->requested_change);
- $update->change_timestamp = !is_null($update->change_timestamp)?date_create($update->change_timestamp)->format('d.m.Y'):null;
+ $update->insertamum = !is_null($update->insertamum)?date_create($update->insertamum)->format('d.m.Y'):null;
$update->status_timestamp = !is_null($update->status_timestamp)?date_create($update->status_timestamp)->format('d.m.Y'):null;
}
diff --git a/public/js/apps/Cis/ProfilUpdateRequests.js b/public/js/apps/Cis/ProfilUpdateRequests.js
index 74f3e98c2..6f7fd773b 100755
--- a/public/js/apps/Cis/ProfilUpdateRequests.js
+++ b/public/js/apps/Cis/ProfilUpdateRequests.js
@@ -45,8 +45,8 @@ const app = Vue.createApp({
//responsive:0,
},
{
- title: "Date",
- field: "change_timestamp",
+ title: "Insert Date",
+ field: "insertamum",
resizable: true,
headerFilter: true,
minWidth: 200,
@@ -109,41 +109,11 @@ 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(){
- Vue.$fhcapi.ProfilUpdate.getProfilUpdateRequest().then((res)=>{
- console.log(res.data);
- })
},
diff --git a/public/js/apps/api/userdata.js b/public/js/apps/api/userdata.js
index 0fff20a31..956f78f90 100755
--- a/public/js/apps/api/userdata.js
+++ b/public/js/apps/api/userdata.js
@@ -12,6 +12,13 @@ export default {
});
},
+ getProfilRequestFiles: function(requestID) {
+ const url = FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router+
+ `/Cis/Profil/getProfilRequestFiles`;
+
+ return axios.post(url,requestID);
+ },
+
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`;
@@ -26,11 +33,11 @@ export default {
return axios.post(url,{topic, payload});
},
- updateProfilRequest: function(topic, payload) {
+ updateProfilRequest: function(topic, payload, ID) {
const url = FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router+
`/Cis/Profil/updateProfilRequest`;
- return axios.post(url,{topic, payload});
+ return axios.post(url,{topic, payload, ID});
},
deleteProfilRequest: function(requestID){
diff --git a/public/js/components/Cis/Profil/EditProfil.js b/public/js/components/Cis/Profil/EditProfil.js
index fda28d537..40a7caaf4 100755
--- a/public/js/components/Cis/Profil/EditProfil.js
+++ b/public/js/components/Cis/Profil/EditProfil.js
@@ -47,7 +47,7 @@ export default {
if(this.profilUpdate.files){
const fileIDs = await this.uploadFiles(this.profilUpdate.files);
-
+
if(fileIDs){
this.profilUpdate.files=fileIDs;
@@ -55,9 +55,8 @@ export default {
};
}
//? inserts new row in public.tbl_cis_profil_update
- //* calls the update api call if an update field is present in the data that was passed to the module
- Vue.$fhcapi.UserData[this.editData.update?'updateProfilRequest':'insertProfilRequest'](this.topic,this.profilUpdate).then((res)=>{
-
+ //* calls the update api call if an update field is present in the data that was passed to the modal
+ const handleApiResponse = (res)=>{
if(res.data.error == 0){
this.result= true;
this.hide();
@@ -67,7 +66,15 @@ export default {
this.hide();
Alert.popup("Ein Fehler ist aufgetreten: "+ JSON.stringify(res.data.retval));
}
- });
+ }
+
+ this.editData.updateID?
+ Vue.$fhcapi.UserData.updateProfilRequest(this.topic,this.profilUpdate,this.editData.updateID).then((res)=>{
+ handleApiResponse(res);
+ }):
+ Vue.$fhcapi.UserData.insertProfilRequest(this.topic,this.profilUpdate).then((res)=>{
+ handleApiResponse(res);
+ })
}
@@ -75,20 +82,29 @@ export default {
//? uploads files to the dms table and returns an array with the ids of the created files
uploadFiles: async function(files){
+ let updatedFiles = [];
+ if(this.editData.updateID){ //? if we are updating an already existing profilRequest
+ const existingFiles = await Vue.$fhcapi.UserData.getProfilRequestFiles(this.editData.updateID).then(res => {return res.data});
+ updatedFiles = [...existingFiles];
+ }
let formData = new FormData();
for(let i = 0; i < files.length; i++){
-
- formData.append("files[]",files[i]);
+ if(files[i].type!=='application/x.fhc-dms+json')
+ formData.append("files[]",files[i]);
}
- return await Vue.$fhcapi.UserData.insertFile(formData).then(res => {
+ await Vue.$fhcapi.UserData.insertFile(formData).then(res => {
/* returns file information as
[{"name":"example.png", "dms_id":282531}] */
- return res.data.map(file => { return {dms_id:file.dms_id, name:file.client_name}});
+ console.log(res)
+ updatedFiles = updatedFiles.concat(res.data?.map(file => { return {dms_id:file.dms_id, name:file.client_name}}));
}).catch(err=>{
console.log(err);
- return null;
+
})
+
+ return updatedFiles;
+
},
},
computed: {
diff --git a/public/js/components/Cis/Profil/ProfilComponents/FetchProfilUpdates.js b/public/js/components/Cis/Profil/ProfilComponents/FetchProfilUpdates.js
index ecc997c48..e32b96897 100755
--- a/public/js/components/Cis/Profil/ProfilComponents/FetchProfilUpdates.js
+++ b/public/js/components/Cis/Profil/ProfilComponents/FetchProfilUpdates.js
@@ -44,37 +44,41 @@ export default {
let view = this.getView(updateRequest.topic,updateRequest.status);
let data = null;
let content =null;
+ let files =null;
+ let withFiles = false;
if(view === "TextInputDokument"){
- // this should be the files : updateRequest.requested_change.files
+
data = {
titel:updateRequest.topic,
value: updateRequest.requested_change.value,
- };
-
-
-
+ };
+ if(updateRequest.requested_change.files.length){
+ const FILE = updateRequest.requested_change.files?.map(file=>{return new File(["files[]"], file.name);})
+ const FILELIST = new DataTransfer();
+ FILE.forEach(file => {
+ FILELIST.items.add(file);
+ })
+ files=updateRequest.requested_change.files;
+ }
+ withFiles = true;
}
else{
data = updateRequest.requested_change;
}
- const exampleFile = updateRequest.requested_change.files.map(file=>{return new File(["files[]"], file.name);})
- const exampleFileList = new DataTransfer();
- exampleFile.forEach(file => {
- exampleFileList.items.add(file);
- })
+
content={
+ updateID:updateRequest.profil_update_id,
view:view,
data:data,
- withFiles:view==="TextInputDokument" ? true:false,
- update:true,
+ withFiles:withFiles,
topic:updateRequest.topic,
- files: view==="TextInputDokument" ? exampleFileList.files:null,
+ files: files,
}
diff --git a/public/js/components/Cis/Profil/ProfilComponents/Status.js b/public/js/components/Cis/Profil/ProfilComponents/Status.js
index d9277145f..535252ec2 100755
--- a/public/js/components/Cis/Profil/ProfilComponents/Status.js
+++ b/public/js/components/Cis/Profil/ProfilComponents/Status.js
@@ -32,7 +32,7 @@ export default {
status:{type:String},
status_message:{type:String},
status_timestamp:{type:String},
- update:{type:Boolean},
+ updateID:{type:Number},
topic:{type:String},
},
created(){
diff --git a/public/js/components/Cis/Profil/ProfilComponents/TextInputDokument.js b/public/js/components/Cis/Profil/ProfilComponents/TextInputDokument.js
index 4312d9747..257c4c39f 100644
--- a/public/js/components/Cis/Profil/ProfilComponents/TextInputDokument.js
+++ b/public/js/components/Cis/Profil/ProfilComponents/TextInputDokument.js
@@ -24,23 +24,15 @@ export default {
files:{
type:FileList,
},
- update:{
+ updateID:{
type:Boolean,
}
},
computed: {
isChanged: function(){
- if(this.update ){
- if(this.originalFiles !== this.dmsData || this.originalValue !== JSON.stringify(this.data)){
- return true;
- }else{
- return false;
- }
- }else{
- //? controls whether the user is allowed to send the profil update or not
- if(this.withFiles && !this.dmsData.length) {return false;}
- return JSON.stringify(this.data) !== Vue.toRaw(this.originalValue);
- }
+ //? controls whether the user is allowed to send the profil update or not
+ if(this.withFiles && !this.dmsData.length) {return false;}
+ return JSON.stringify(this.data) !== Vue.toRaw(this.originalValue);
}
@@ -49,16 +41,14 @@ export default {
watch: {
//? watcher to trigger the event emit when a file was uploaded or removed
dmsData(value) {
- this.emitChanges();
- console.log("dmsData",this.dmsData);
- console.log("original files",Vue.toRaw(this.originalFiles));
- console.log("compare",this.dmsData == Vue.toRaw(this.originalFiles));
+ this.emitChanges();
+
}
},
methods:{
-
+
emitChanges: function(){
- if(this.isChanged){
+ if(this.updateID || this.isChanged){
this.$emit('profilUpdate', this.withFiles?{value:this.data.value, files:this.dmsData}:{value:this.data.value});
}else{
@@ -68,13 +58,19 @@ export default {
},
},
- created(){
+ mounted(){
this.originalValue = JSON.stringify(this.data);
- this.originalFiles = this.files;
+
if(this.files){
this.dmsData = this.files;
+
+ for(let i=0; i < this.dmsData.length; i++){
+ console.log("here",this.dmsData[i]);
+ }
+
+ this.originalFiles=null;
}
},
@@ -86,7 +82,7 @@ export default {
-
{{JSON.stringify(Array.from(modelValue).map(item => stringifyFile(item)),null,2)}}