mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-19 16:02:15 +00:00
fixes a lot of bugs and adds the inseramum/insertvon/updateamum/updatevon fields to the cis_profil_update db table
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
@@ -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+'<br/>'});
|
||||
|
||||
|
||||
list.appendChild(item);
|
||||
|
||||
});
|
||||
|
||||
return Object.keys(data).length ? container : "";
|
||||
},
|
||||
|
||||
|
||||
},
|
||||
created(){
|
||||
|
||||
Vue.$fhcapi.ProfilUpdate.getProfilUpdateRequest().then((res)=>{
|
||||
console.log(res.data);
|
||||
})
|
||||
|
||||
|
||||
},
|
||||
|
||||
@@ -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){
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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,
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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(){
|
||||
|
||||
@@ -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 {
|
||||
<input class="form-control" @input="emitChanges" v-model="data.value" :placeholder="data.value">
|
||||
|
||||
|
||||
<dms v-if="withFiles" id="files" :noList="false" :multiple="true" v-model="dmsData" ></dms>
|
||||
<dms ref="update" v-if="withFiles" id="files" :noList="false" :multiple="true" v-model="dmsData" ></dms>
|
||||
|
||||
</div>
|
||||
`,
|
||||
|
||||
@@ -171,7 +171,7 @@ export default {
|
||||
<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>
|
||||
<span class="form-underline-content" >{{data.insertamum}}</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -52,8 +52,7 @@ export default {
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
modelValue:{
|
||||
handler(n) {
|
||||
modelValue(n) {
|
||||
if (n instanceof FileList)
|
||||
return this.$refs.upload.files = n;
|
||||
|
||||
@@ -71,12 +70,10 @@ export default {
|
||||
}
|
||||
this.$emit('update:modelValue', dt.files);
|
||||
},
|
||||
immediate:true
|
||||
}
|
||||
},
|
||||
template: `
|
||||
<div class="form-upload-dms">
|
||||
|
||||
<pre>{{JSON.stringify(Array.from(modelValue).map(item => stringifyFile(item)),null,2)}}</pre>
|
||||
<input ref="upload" class="form-control" :class="inputClass" :id="id" :name="name" :multiple="multiple" type="file" @change="addFiles">
|
||||
<ul v-if="modelValue.length && multiple && !noList" class="list-unstyled m-0">
|
||||
<li v-for="(file, index) in modelValue" :key="index" class="d-flex mx-1 mt-1 align-items-center">
|
||||
|
||||
@@ -223,7 +223,7 @@ $tabellen=array(
|
||||
"public.tbl_benutzerfunktion" => array("benutzerfunktion_id","fachbereich_kurzbz","uid","oe_kurzbz","funktion_kurzbz","semester", "datum_von","datum_bis", "updateamum","updatevon","insertamum","insertvon","ext_id","bezeichnung","wochenstunden"),
|
||||
"public.tbl_benutzergruppe" => array("uid","gruppe_kurzbz","studiensemester_kurzbz","updateamum","updatevon","insertamum","insertvon","ext_id"),
|
||||
"public.tbl_bewerbungstermine" => array("bewerbungstermin_id","studiengang_kz","studiensemester_kurzbz","beginn","ende","nachfrist","nachfrist_ende","anmerkung", "insertamum", "insertvon", "updateamum", "updatevon","studienplan_id","nationengruppe_kurzbz"),
|
||||
"public.tbl_cis_profil_update" => array("profil_update_id","topic","uid","requested_change","change_timestamp"),
|
||||
"public.tbl_cis_profil_update" => array("profil_update_id","uid","name","topic","requested_change", "updateamum", "updatevon", "insertamum", "insertvon", "status", "status_timestamp", "status_message"),
|
||||
"public.tbl_buchungstyp" => array("buchungstyp_kurzbz","beschreibung","standardbetrag","standardtext","aktiv","credit_points"),
|
||||
"public.tbl_dokument" => array("dokument_kurzbz","bezeichnung","ext_id","bezeichnung_mehrsprachig","dokumentbeschreibung_mehrsprachig","ausstellungsdetails"),
|
||||
"public.tbl_dokumentprestudent" => array("dokument_kurzbz","prestudent_id","mitarbeiter_uid","datum","updateamum","updatevon","insertamum","insertvon","ext_id"),
|
||||
|
||||
@@ -8,7 +8,10 @@
|
||||
name TEXT NOT NULL,
|
||||
topic VARCHAR(32) NOT NULL,
|
||||
requested_change jsonb NOT NULL,
|
||||
change_timestamp TIMESTAMP NOT NULL,
|
||||
updateamum TIMESTAMP NULL,
|
||||
updatevon VARCHAR(32) NULL,
|
||||
insertamum TIMESTAMP NOT NULL,
|
||||
insertvon VARCHAR(32) NOT NULL,
|
||||
status VARCHAR(32) NOT NULL,
|
||||
status_timestamp TIMESTAMP NULL,
|
||||
status_message TEXT NULL,
|
||||
|
||||
Reference in New Issue
Block a user