mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-23 18:02:18 +00:00
changes how files are attached/replaced to a profil update
This commit is contained in:
@@ -20,13 +20,7 @@ class Profil extends Auth_Controller
|
||||
'foto_sperre_function' => ['student/anrechnung_beantragen:r', 'user:r'],
|
||||
'getView' => ['student/anrechnung_beantragen:r', 'user:r'],
|
||||
'View' => ['student/anrechnung_beantragen:r', 'user:r'],
|
||||
'insertProfilRequest' => ['student/anrechnung_beantragen:r', 'user:r'],
|
||||
'updateProfilRequest' => ['student/anrechnung_beantragen:r', 'user:r'],
|
||||
'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'],
|
||||
'deleteOldVersionFiles' => ['student/anrechnung_beantragen:r', 'user:r'],
|
||||
|
||||
|
||||
|
||||
]);
|
||||
@@ -44,11 +38,9 @@ class Profil extends Auth_Controller
|
||||
$this->load->model('person/Kontakt_model', 'KontaktModel');
|
||||
$this->load->model('person/Profil_update_model', 'ProfilUpdateModel');
|
||||
$this->load->model('content/DmsVersion_model', 'DmsVersionModel');
|
||||
$this->load->model('DmsVersion_model','DmsVersionModel');
|
||||
|
||||
$this->load->library('DmsLib');
|
||||
|
||||
//? put the uid and pid inside the controller to reuse in controller
|
||||
//? put the uid and pid inside the controller for reusability
|
||||
$this->uid = getAuthUID();
|
||||
$this->pid = getAuthPersonID();
|
||||
|
||||
@@ -79,178 +71,6 @@ class Profil extends Auth_Controller
|
||||
}
|
||||
|
||||
|
||||
public function insertFile(){
|
||||
|
||||
//? Version des Dokuments
|
||||
/*$this->DmsVersionModel->addSelect(["version"]);
|
||||
$fileVersion = $this->DmsVersionModel->loadWhere(["name"=>$_FILES['files']['name'], "mimetype"=>$_FILES['files']['type']]);
|
||||
$fileVersion = hasData($fileVersion) ? getData($fileVersion)[0]->version : 0;
|
||||
if($fileVersion) $fileVersion++; */
|
||||
if(!count($_FILES)){
|
||||
echo json_encode([]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$files = $_FILES['files'];
|
||||
$file_count = count($files['name']);
|
||||
|
||||
$res=[];
|
||||
|
||||
for ($i = 0; $i < $file_count; $i++) {
|
||||
$_FILES['files']['name'] = $files['name'][$i];
|
||||
$_FILES['files']['type'] = $files['type'][$i];
|
||||
$_FILES['files']['tmp_name'] = $files['tmp_name'][$i];
|
||||
$_FILES['files']['error'] = $files['error'][$i];
|
||||
$_FILES['files']['size'] = $files['size'][$i];
|
||||
|
||||
$dms = [
|
||||
"kategorie_kurzbz"=>"profil_aenderung",
|
||||
"version"=>0,
|
||||
"name"=>$_FILES['files']['name'],
|
||||
"mimetype"=>$_FILES['files']['type'],
|
||||
"beschreibung"=>$this->uid . " Profil Änderung",
|
||||
"insertvon"=>$this->uid,
|
||||
"insertamum"=>"NOW()",
|
||||
];
|
||||
$tmp_res=$this->dmslib->upload($dms , 'files');
|
||||
$tmp_res = hasData($tmp_res)? getData($tmp_res) : null;
|
||||
array_push($res,$tmp_res);
|
||||
}
|
||||
|
||||
echo json_encode($res);
|
||||
}
|
||||
|
||||
|
||||
public function deleteOldVersionFiles(){
|
||||
$file_array = json_decode($this->input->raw_input_stream);
|
||||
if(!isset($file_array) || !sizeof($file_array)){
|
||||
return;
|
||||
}
|
||||
|
||||
$res =[];
|
||||
foreach($file_array as $id){
|
||||
//? delete all the different versions of the dms_file
|
||||
|
||||
$zwischen_res = $this->DmsVersionModel->loadWhere(["dms_id"=>$id]);
|
||||
$zwischen_res = hasData($zwischen_res) ? getData($zwischen_res) : null;
|
||||
if(isset($zwischen_res)){
|
||||
$zwischen_res = array_map(function($item){ return $item->version;},$zwischen_res);
|
||||
foreach($zwischen_res as $version){
|
||||
array_push($res, $this->DmsVersionModel->delete([$id,$version]));
|
||||
}
|
||||
}else{
|
||||
echo json_encode(error("No version of the file has been found"));
|
||||
}
|
||||
}
|
||||
echo json_encode($res);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function selectProfilRequest(){
|
||||
$_GET = json_decode($this->input->raw_input_stream, true);
|
||||
$uid = $this->input->get('uid');
|
||||
$id = $this->input->get('id');
|
||||
$whereClause=['uid'=> $this->uid];
|
||||
|
||||
if(isset($uid)) $whereClause['uid'] = $uid;
|
||||
if(isset($id)) $whereClause['id'] = $id;
|
||||
|
||||
$res= $this->ProfilUpdateModel->getProfilUpdatesWhere($whereClause);
|
||||
|
||||
echo json_encode($res);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function getProfilRequestFiles(){
|
||||
$id = json_decode($this->input->raw_input_stream);
|
||||
echo json_encode($this->ProfilUpdateModel->getFilesFromChangeRequest($id));
|
||||
}
|
||||
|
||||
public function insertProfilRequest()
|
||||
{
|
||||
|
||||
$json = json_decode($this->input->raw_input_stream);
|
||||
$payload = $json->payload;
|
||||
|
||||
$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)){
|
||||
// error handling
|
||||
var_dump($name);
|
||||
return;
|
||||
}
|
||||
$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->ProfilUpdateModel->getProfilUpdatesWhere(["uid"=>$this->uid]);
|
||||
$res = hasData($res) ? getData($res) : null;
|
||||
|
||||
if($res){
|
||||
$pending_changes = array_filter($res, function($element) {
|
||||
return $element->status == 'pending';
|
||||
});
|
||||
foreach($pending_changes as $update_request){
|
||||
$existing_change = json_decode($update_request->requested_change);
|
||||
|
||||
//? the user can add as many new kontakt/adresse as he likes
|
||||
if( !isset($payload->add) && property_exists($existing_change,$identifier) && property_exists($payload,$identifier) && $existing_change->$identifier == $payload->$identifier){
|
||||
//? the kontakt_id / adresse_id of a change has to be unique
|
||||
echo json_encode(error("cannot change the same resource twice"));
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}}
|
||||
|
||||
$insertID = $this->ProfilUpdateModel->insert($data);
|
||||
|
||||
if(isError($insertID)){
|
||||
//catch error
|
||||
}else{
|
||||
$insertID = hasData($insertID)? getData($insertID): null;
|
||||
$editTimestamp = $this->ProfilUpdateModel->getTimestamp($insertID);
|
||||
|
||||
$date = success(date_create($editTimestamp)->format('d.m.Y'));
|
||||
echo json_encode($date);
|
||||
}
|
||||
}
|
||||
|
||||
public function updateProfilRequest()
|
||||
{
|
||||
|
||||
$json = json_decode($this->input->raw_input_stream);
|
||||
|
||||
|
||||
$updateID =$this->ProfilUpdateModel->update([$json->ID],["requested_change" => json_encode($json->payload), "updateamum" => "NOW()", "updatevon" => $this->uid]);
|
||||
if(isError($updateID)){
|
||||
//catch error
|
||||
}else{
|
||||
$updateID = hasData($updateID)? getData($updateID)[0]: null;
|
||||
$editTimestamp = $this->ProfilUpdateModel->getTimestamp($updateID,true);
|
||||
|
||||
$date = success(date_create($editTimestamp)->format('d.m.Y'));
|
||||
echo json_encode($date);
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteProfilRequest(){
|
||||
|
||||
$json = json_decode($this->input->raw_input_stream);
|
||||
$delete_res = $this->ProfilUpdateModel->delete([$json]);
|
||||
echo json_encode($delete_res);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -758,7 +578,7 @@ class Profil extends Auth_Controller
|
||||
|
||||
if (
|
||||
|
||||
isSuccess($adresse_res = $this->AdresseModel->addSelect(["adresse_id","strasse", "tbl_adressentyp.bezeichnung as adr_typ", "plz", "ort","zustelladresse"])) &&
|
||||
isSuccess($adresse_res = $this->AdresseModel->addSelect(["adresse_id","strasse", "tbl_adressentyp.bezeichnung as typ", "plz", "ort","zustelladresse"])) &&
|
||||
isSuccess($adresse_res = $this->AdresseModel->addOrder("zustelladresse", "DESC")) &&
|
||||
isSuccess($adresse_res = $this->AdresseModel->addJoin("tbl_adressentyp", "typ=adressentyp_kurzbz"))
|
||||
) {
|
||||
|
||||
@@ -16,8 +16,15 @@ class ProfilUpdate extends Auth_Controller
|
||||
'acceptProfilRequest'=>['student/stammdaten:rw','mitarbeiter/stammdaten:rw'],
|
||||
'denyProfilRequest'=>['student/stammdaten:rw','mitarbeiter/stammdaten:rw'],
|
||||
'show'=>['student/stammdaten:r','mitarbeiter/stammdaten:r'],
|
||||
|
||||
'insertProfilRequest' => ['student/anrechnung_beantragen:r', 'user:r'],
|
||||
'updateProfilRequest' => ['student/anrechnung_beantragen:r', 'user:r'],
|
||||
'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'],
|
||||
|
||||
|
||||
|
||||
]);
|
||||
|
||||
|
||||
@@ -26,6 +33,12 @@ class ProfilUpdate extends Auth_Controller
|
||||
$this->load->model('person/Adresse_model','AdresseModel');
|
||||
$this->load->model('person/Adressentyp_model', 'AdressenTypModel');
|
||||
$this->load->model('person/Person_model','PersonModel');
|
||||
|
||||
$this->load->library('DmsLib');
|
||||
|
||||
//? put the uid and pid inside the controller for reusability
|
||||
$this->uid = getAuthUID();
|
||||
$this->pid = getAuthPersonID();
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +58,221 @@ class ProfilUpdate extends Auth_Controller
|
||||
echo json_encode($res);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function insertFile($replace){
|
||||
$replace = json_decode($replace);
|
||||
|
||||
if(!count($_FILES)){
|
||||
echo json_encode([]);
|
||||
return;
|
||||
}
|
||||
|
||||
//? if replace is set it contains the profil_update_id in which the attachment_id has to be replaced
|
||||
if(isset($replace)){
|
||||
$this->ProfilUpdateModel->addSelect(["attachment_id"]);
|
||||
$attachmentID = $this->ProfilUpdateModel->load([$replace]);
|
||||
if(isError($attachmentID)){
|
||||
return json_encode(error("Error loading ProfilUpdate resource"));
|
||||
}
|
||||
//? get the attachmentID
|
||||
$dms_id = hasData($attachmentID) ? getData($attachmentID)[0]->attachment_id : null;
|
||||
|
||||
//? delete old dms_file of Profil Update
|
||||
$this->deleteOldVersionFile($dms_id);
|
||||
}
|
||||
|
||||
|
||||
$files = $_FILES['files'];
|
||||
$file_count = count($files['name']);
|
||||
|
||||
$res=[];
|
||||
|
||||
for ($i = 0; $i < $file_count; $i++) {
|
||||
$_FILES['files']['name'] = $files['name'][$i];
|
||||
$_FILES['files']['type'] = $files['type'][$i];
|
||||
$_FILES['files']['tmp_name'] = $files['tmp_name'][$i];
|
||||
$_FILES['files']['error'] = $files['error'][$i];
|
||||
$_FILES['files']['size'] = $files['size'][$i];
|
||||
|
||||
$dms = [
|
||||
"kategorie_kurzbz"=>"profil_aenderung",
|
||||
"version"=>0,
|
||||
"name"=>$_FILES['files']['name'],
|
||||
"mimetype"=>$_FILES['files']['type'],
|
||||
"beschreibung"=>$this->uid . " Profil Änderung",
|
||||
"insertvon"=>$this->uid,
|
||||
"insertamum"=>"NOW()",
|
||||
];
|
||||
|
||||
$tmp_res=$this->dmslib->upload($dms , 'files');
|
||||
$tmp_res = hasData($tmp_res)? getData($tmp_res) : null;
|
||||
array_push($res,$tmp_res);
|
||||
}
|
||||
|
||||
echo json_encode($res);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function deleteOldVersionFile($dms_id){
|
||||
if(!isset($dms_id)){
|
||||
return;
|
||||
}
|
||||
|
||||
//? collect all the results of the deleted versions in an array
|
||||
$res = array();
|
||||
|
||||
//? delete all the different versions of the dms_file
|
||||
$dmsVersions = $this->DmsVersionModel->loadWhere(["dms_id"=>$dms_id]);
|
||||
$dmsVersions = hasData($dmsVersions) ? getData($dmsVersions) : null;
|
||||
if(isset($dmsVersions)){
|
||||
$zwischen_res = array_map(function($item){ return $item->version;},$dmsVersions);
|
||||
foreach($zwischen_res as $version){
|
||||
array_push($res, $this->DmsVersionModel->delete([$dms_id,$version]));
|
||||
}
|
||||
}else{
|
||||
echo json_encode(error("No version of the file has been found"));
|
||||
}
|
||||
|
||||
//? returns a result for each deleted dms_file
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function selectProfilRequest(){
|
||||
$_GET = json_decode($this->input->raw_input_stream, true);
|
||||
$uid = $this->input->get('uid');
|
||||
$id = $this->input->get('id');
|
||||
$whereClause=['uid'=> $this->uid];
|
||||
|
||||
if(isset($uid)) $whereClause['uid'] = $uid;
|
||||
if(isset($id)) $whereClause['id'] = $id;
|
||||
|
||||
$res= $this->ProfilUpdateModel->getProfilUpdatesWhere($whereClause);
|
||||
|
||||
echo json_encode($res);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function getProfilRequestFiles(){
|
||||
$id = json_decode($this->input->raw_input_stream);
|
||||
|
||||
$this->ProfilUpdateModel->addSelect(["attachment_id"]);
|
||||
$attachmentID = $this->ProfilUpdateModel->load([$id]);
|
||||
if(isError($attachmentID)){
|
||||
return json_encode(error("Error loading ProfilUpdate resource"));
|
||||
}
|
||||
//? get the attachmentID
|
||||
$dms_id = hasData($attachmentID) ? getData($attachmentID)[0]->attachment_id : null;
|
||||
|
||||
//? get the name to the file
|
||||
$this->DmsVersionModel->addSelect(["name", "dms_id"]);
|
||||
$attachment = $this->DmsVersionModel->load([$dms_id,0]);
|
||||
if(isError($attachment)){
|
||||
return json_encode(error("Error loading DmsVersion resource"));
|
||||
}
|
||||
$attachment = hasData($attachment) ? getData($attachment) : null;
|
||||
|
||||
//? returns {name:..., dms_id:...}
|
||||
echo json_encode($attachment);
|
||||
}
|
||||
|
||||
public function insertProfilRequest()
|
||||
{
|
||||
|
||||
$json = json_decode($this->input->raw_input_stream);
|
||||
$payload = $json->payload;
|
||||
|
||||
$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)){
|
||||
// error handling
|
||||
var_dump($name);
|
||||
return;
|
||||
}
|
||||
$data = ["topic"=>$json->topic,"uid" => $this->uid, "name"=>getData($name), "requested_change" => json_encode($payload), "insertamum" => "NOW()", "insertvon"=>$this->uid,"status"=>"pending" ];
|
||||
//? insert fileID in the dataset if sent with post request
|
||||
if(isset($json->fileID)){
|
||||
$data['attachment_id'] = $json->fileID;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//? loops over all updateRequests from a user to validate if the new request is valid
|
||||
$res = $this->ProfilUpdateModel->getProfilUpdatesWhere(["uid"=>$this->uid]);
|
||||
$res = hasData($res) ? getData($res) : null;
|
||||
|
||||
if($res){
|
||||
$pending_changes = array_filter($res, function($element) {
|
||||
return $element->status == 'pending';
|
||||
});
|
||||
foreach($pending_changes as $update_request){
|
||||
$existing_change = json_decode($update_request->requested_change);
|
||||
|
||||
//? the user can add as many new kontakt/adresse as he likes
|
||||
if( !isset($payload->add) && property_exists($existing_change,$identifier) && property_exists($payload,$identifier) && $existing_change->$identifier == $payload->$identifier){
|
||||
//? the kontakt_id / adresse_id of a change has to be unique
|
||||
echo json_encode(error("cannot change the same resource twice"));
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}}
|
||||
|
||||
$insertID = $this->ProfilUpdateModel->insert($data);
|
||||
|
||||
if(isError($insertID)){
|
||||
//catch error
|
||||
}else{
|
||||
$insertID = hasData($insertID)? getData($insertID): null;
|
||||
$editTimestamp = $this->ProfilUpdateModel->getTimestamp($insertID);
|
||||
|
||||
$date = success(date_create($editTimestamp)->format('d.m.Y'));
|
||||
echo json_encode($date);
|
||||
}
|
||||
}
|
||||
|
||||
public function updateProfilRequest()
|
||||
{
|
||||
$json = json_decode($this->input->raw_input_stream);
|
||||
|
||||
$updateData = ["requested_change" => json_encode($json->payload), "updateamum" => "NOW()", "updatevon" => $this->uid];
|
||||
if(isset($json->fileID)){
|
||||
$updateData['attachment_id'] = json_decode($json->fileID);
|
||||
}
|
||||
$updateID =$this->ProfilUpdateModel->update([$json->ID],$updateData);
|
||||
//? insert fileID in the dataset if sent with post request
|
||||
|
||||
if(isError($updateID)){
|
||||
//catch error
|
||||
}else{
|
||||
$updateID = hasData($updateID)? getData($updateID)[0]: null;
|
||||
$editTimestamp = $this->ProfilUpdateModel->getTimestamp($updateID,true);
|
||||
|
||||
$date = success(date_create($editTimestamp)->format('d.m.Y'));
|
||||
echo json_encode($date);
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteProfilRequest(){
|
||||
|
||||
$json = json_decode($this->input->raw_input_stream);
|
||||
$delete_res = $this->ProfilUpdateModel->delete([$json]);
|
||||
echo json_encode($delete_res);
|
||||
}
|
||||
|
||||
|
||||
public function getProfilUpdateWithPermission($status=null){
|
||||
|
||||
|
||||
@@ -125,11 +353,11 @@ class ProfilUpdate extends Auth_Controller
|
||||
}
|
||||
|
||||
private function updateRequestedChange($id, $requested_change){
|
||||
return $this->ProfilUpdateModel->update([$id], ['requested_change'=>json_encode($requested_change)]);
|
||||
return $this->update([$id], ['requested_change'=>json_encode($requested_change)]);
|
||||
}
|
||||
|
||||
private function setStatusOnUpdateRequest($id, $status, $status_message ){
|
||||
return $this->ProfilUpdateModel->update([$id], ["status"=>$status,"status_timestamp"=>"NOW()","status_message"=>$status_message]);
|
||||
return $this->update([$id], ["status"=>$status,"status_timestamp"=>"NOW()","status_message"=>$status_message]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ class Profil_update_model extends DB_Model
|
||||
}
|
||||
|
||||
|
||||
//? queries the tbl_profil_updates without permissions of the user
|
||||
public function getProfilUpdatesWhere($whereClause){
|
||||
$res = $this->loadWhere($whereClause);
|
||||
if(isError($res)){
|
||||
|
||||
@@ -15,6 +15,82 @@ export default {
|
||||
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,payload);
|
||||
}
|
||||
},
|
||||
|
||||
replaceProfilUpdateAttachment: function (dms) {
|
||||
const url =
|
||||
FHC_JS_DATA_STORAGE_OBJECT.app_root +
|
||||
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
|
||||
`/Cis/ProfilUpdate/replaceProfilUpdateAttachment`;
|
||||
|
||||
return axios.post(url, dms, {
|
||||
headers: { "Content-Type": "multipart/form-data" },
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
//? new reuquests
|
||||
insertFile: function (dms,replace=null) {
|
||||
const url =
|
||||
FHC_JS_DATA_STORAGE_OBJECT.app_root +
|
||||
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
|
||||
`/Cis/ProfilUpdate/insertFile/${replace}`;
|
||||
|
||||
return axios.post(url, dms, {
|
||||
headers: { "Content-Type": "multipart/form-data" },
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
|
||||
getProfilRequestFiles: function (requestID) {
|
||||
const url =
|
||||
FHC_JS_DATA_STORAGE_OBJECT.app_root +
|
||||
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
|
||||
`/Cis/ProfilUpdate/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/ProfilUpdate/selectProfilRequest`;
|
||||
|
||||
return axios.get(url, { uid: uid, id: id });
|
||||
},
|
||||
|
||||
|
||||
|
||||
|
||||
insertProfilRequest: function (topic, payload, fileID=null) {
|
||||
const url =
|
||||
FHC_JS_DATA_STORAGE_OBJECT.app_root +
|
||||
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
|
||||
`/Cis/ProfilUpdate/insertProfilRequest`;
|
||||
|
||||
return axios.post(url, { topic, payload, ...(fileID?{fileID:fileID}:{}) });
|
||||
},
|
||||
|
||||
updateProfilRequest: function (topic, payload, ID, fileID=null) {
|
||||
const url =
|
||||
FHC_JS_DATA_STORAGE_OBJECT.app_root +
|
||||
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
|
||||
`/Cis/ProfilUpdate/updateProfilRequest`;
|
||||
|
||||
return axios.post(url, { topic, payload, ID, ...(fileID?{fileID:fileID}:{}) });
|
||||
},
|
||||
|
||||
deleteProfilRequest: function (requestID) {
|
||||
const url =
|
||||
FHC_JS_DATA_STORAGE_OBJECT.app_root +
|
||||
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
|
||||
`/Cis/ProfilUpdate/deleteProfilRequest`;
|
||||
|
||||
return axios.post(url, requestID);
|
||||
},
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,78 +1,7 @@
|
||||
export default {
|
||||
//! API Calls for Profil Views
|
||||
|
||||
insertFile: function (dms) {
|
||||
const url =
|
||||
FHC_JS_DATA_STORAGE_OBJECT.app_root +
|
||||
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
|
||||
`/Cis/Profil/insertFile`;
|
||||
|
||||
return axios.post(url, dms, {
|
||||
headers: { "Content-Type": "multipart/form-data" },
|
||||
});
|
||||
},
|
||||
|
||||
deleteOldVersionFiles: function (files) {
|
||||
const url =
|
||||
FHC_JS_DATA_STORAGE_OBJECT.app_root +
|
||||
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
|
||||
`/Cis/Profil/deleteOldVersionFiles`;
|
||||
|
||||
return axios.post(url, files);
|
||||
},
|
||||
|
||||
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`;
|
||||
|
||||
return axios.get(url, { uid: uid, id: id });
|
||||
},
|
||||
|
||||
insertProfilRequest: function (topic, payload) {
|
||||
const url =
|
||||
FHC_JS_DATA_STORAGE_OBJECT.app_root +
|
||||
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
|
||||
`/Cis/Profil/insertProfilRequest`;
|
||||
|
||||
return axios.post(url, { 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, ID });
|
||||
},
|
||||
|
||||
deleteProfilRequest: function (requestID) {
|
||||
const url =
|
||||
FHC_JS_DATA_STORAGE_OBJECT.app_root +
|
||||
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
|
||||
`/Cis/Profil/deleteProfilRequest`;
|
||||
|
||||
return axios.post(url, requestID);
|
||||
},
|
||||
|
||||
getEditProfil: function () {
|
||||
const url =
|
||||
FHC_JS_DATA_STORAGE_OBJECT.app_root +
|
||||
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
|
||||
`/Cis/Profil/getEditProfil`;
|
||||
return axios.get(url);
|
||||
},
|
||||
|
||||
isMitarbeiterOrStudent: function (uid) {
|
||||
const url =
|
||||
|
||||
@@ -24,16 +24,13 @@ export default {
|
||||
onShowBsModal: Function,
|
||||
onShownBsModal: Function,
|
||||
},
|
||||
/* provide(){
|
||||
return {
|
||||
topic: computed(()=> "test"),
|
||||
}
|
||||
}, */
|
||||
|
||||
data() {
|
||||
return {
|
||||
topic: null,
|
||||
profilUpdate: null,
|
||||
editData: this.value,
|
||||
fileID:null,
|
||||
breadcrumb: null,
|
||||
|
||||
result: false,
|
||||
@@ -41,17 +38,29 @@ export default {
|
||||
};
|
||||
},
|
||||
|
||||
provide(){
|
||||
return {
|
||||
updateFileID: this.updateFileIDFunction,
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
|
||||
updateFileIDFunction: function(newFileID){
|
||||
this.fileID = newFileID;
|
||||
},
|
||||
|
||||
async submitProfilChange() {
|
||||
//? check if data is valid before making a request
|
||||
if (this.topic && this.profilUpdate) {
|
||||
if (this.profilUpdate.files) {
|
||||
const fileIDs = await this.uploadFiles(this.profilUpdate.files);
|
||||
|
||||
if (fileIDs) {
|
||||
this.profilUpdate.files = fileIDs;
|
||||
}
|
||||
|
||||
//? if profil update contains any attachment
|
||||
if (this.fileID) {
|
||||
const fileData = await this.uploadFiles(this.fileID);
|
||||
|
||||
this.fileID = fileData? fileData : null;
|
||||
}
|
||||
|
||||
//? 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 modal
|
||||
const handleApiResponse = (res) => {
|
||||
@@ -71,16 +80,19 @@ export default {
|
||||
};
|
||||
|
||||
this.editData.updateID
|
||||
? Vue.$fhcapi.UserData.updateProfilRequest(
|
||||
? Vue.$fhcapi.ProfilUpdate.updateProfilRequest(
|
||||
this.topic,
|
||||
this.profilUpdate,
|
||||
this.editData.updateID
|
||||
this.editData.updateID,
|
||||
this.fileID[0]
|
||||
).then((res) => {
|
||||
handleApiResponse(res);
|
||||
})
|
||||
: Vue.$fhcapi.UserData.insertProfilRequest(
|
||||
: Vue.$fhcapi.ProfilUpdate.insertProfilRequest(
|
||||
this.topic,
|
||||
this.profilUpdate
|
||||
this.profilUpdate,
|
||||
this.fileID[0]
|
||||
|
||||
).then((res) => {
|
||||
handleApiResponse(res);
|
||||
});
|
||||
@@ -91,55 +103,31 @@ export default {
|
||||
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;
|
||||
});
|
||||
|
||||
let filesToKeep = [];
|
||||
let filesToDelete = [];
|
||||
existingFiles.forEach((file) => {
|
||||
Array.from(files).some((f) => f.name === file.name)
|
||||
? filesToKeep.push(file)
|
||||
: filesToDelete.push(file.dms_id);
|
||||
});
|
||||
|
||||
//? only keeps the newest version of the documents and deletes the old versions in the database
|
||||
if(filesToDelete.length > 0) {
|
||||
Vue.$fhcapi.UserData.deleteOldVersionFiles(
|
||||
filesToDelete
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
updatedFiles = [...filesToKeep];
|
||||
}
|
||||
|
||||
let formData = new FormData();
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
if (files[i].type !== "application/x.fhc-dms+json")
|
||||
formData.append("files[]", files[i]);
|
||||
}
|
||||
if(Array.from(formData).length > 0){
|
||||
await Vue.$fhcapi.UserData.insertFile(formData)
|
||||
.then((res) => {
|
||||
/* returns file information as
|
||||
[{"name":"example.png", "dms_id":282531}] */
|
||||
|
||||
updatedFiles = updatedFiles.concat(
|
||||
res.data?.map((file) => {
|
||||
return { dms_id: file.dms_id, name: file.client_name};
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
if (files[0].type !== "application/x.fhc-dms+json"){
|
||||
let formData = new FormData();
|
||||
formData.append("files[]", files[0]);
|
||||
const result = this.editData.updateID ?
|
||||
//? updating old attachment by replacing
|
||||
//* second parameter of api request insertFile checks if the file has to be replaced or not
|
||||
await Vue.$fhcapi.ProfilUpdate.insertFile(formData,this.editData.updateID).then(res => {
|
||||
return res.data?.map((file) => file.dms_id);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
:
|
||||
//? fresh insert of new attachment
|
||||
await Vue.$fhcapi.ProfilUpdate.insertFile(formData).then(res => {
|
||||
return res.data?.map((file) => file.dms_id);
|
||||
})
|
||||
return result;
|
||||
}else{
|
||||
//? attachment hasn't been replaced
|
||||
return false;
|
||||
}
|
||||
|
||||
return updatedFiles;
|
||||
},
|
||||
},
|
||||
computed: {},
|
||||
@@ -163,7 +151,6 @@ export default {
|
||||
</template>
|
||||
<template v-slot:default>
|
||||
|
||||
|
||||
<nav aria-label="breadcrumb" class="ps-2 ">
|
||||
<ol class="breadcrumb ">
|
||||
<li class="breadcrumb-item" v-for="element in breadcrumb">{{element}}</li>
|
||||
|
||||
@@ -146,7 +146,7 @@ export default {
|
||||
|
||||
|
||||
fetchProfilUpdates: function(){
|
||||
Vue.$fhcapi.UserData.selectProfilRequest().then((res)=>{
|
||||
Vue.$fhcapi.ProfilUpdate.selectProfilRequest().then((res)=>{
|
||||
|
||||
if(!res.error){
|
||||
this.data.profilUpdates = res.data.retval?.length ? res.data.retval.sort(this.sortProfilUpdates) : null ;
|
||||
@@ -161,7 +161,7 @@ export default {
|
||||
title:"Profil bearbeiten",
|
||||
}).then((popup_result) => {
|
||||
if(popup_result){
|
||||
Vue.$fhcapi.UserData.selectProfilRequest()
|
||||
Vue.$fhcapi.ProfilUpdate.selectProfilRequest()
|
||||
.then((res) =>{
|
||||
if(!res.error){
|
||||
this.data.profilUpdates = res.data.retval;
|
||||
@@ -223,12 +223,8 @@ export default {
|
||||
},
|
||||
|
||||
created() {
|
||||
|
||||
//? sorts the profil Updates: pending -> accepted -> rejected
|
||||
this.data.profilUpdates?.sort(this.sortProfilUpdates);
|
||||
|
||||
|
||||
|
||||
},
|
||||
mounted() {
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
deleteRequest: function (item) {
|
||||
Vue.$fhcapi.UserData.deleteProfilRequest(item.profil_update_id).then(
|
||||
Vue.$fhcapi.ProfilUpdate.deleteProfilRequest(item.profil_update_id).then(
|
||||
(res) => {
|
||||
if (res.data.error) {
|
||||
//? open alert
|
||||
@@ -50,7 +50,7 @@ export default {
|
||||
break;
|
||||
}
|
||||
},
|
||||
openModal(updateRequest) {
|
||||
async openModal(updateRequest) {
|
||||
let view = this.getView(updateRequest.topic, updateRequest.status);
|
||||
let data = null;
|
||||
let content = null;
|
||||
@@ -62,17 +62,15 @@ export default {
|
||||
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;
|
||||
|
||||
const filesFromDatabase = await Vue.$fhcapi.ProfilUpdate.getProfilRequestFiles(updateRequest.profil_update_id).then(res=>{
|
||||
return res.data;
|
||||
});
|
||||
|
||||
files= filesFromDatabase;
|
||||
if(files){
|
||||
withFiles = true;
|
||||
}
|
||||
withFiles = true;
|
||||
} else {
|
||||
data = updateRequest.requested_change;
|
||||
}
|
||||
|
||||
@@ -25,8 +25,10 @@ export default {
|
||||
type: Boolean,
|
||||
},
|
||||
},
|
||||
inject:["updateFileID"],
|
||||
computed: {
|
||||
didFilesChange: function () {
|
||||
this.updateFileID(this.dmsData);
|
||||
let res = false;
|
||||
//? case in which the profilRequest has already associated files
|
||||
if(this.files){
|
||||
@@ -48,7 +50,7 @@ export default {
|
||||
isChanged: function () {
|
||||
if (this.withFiles) {
|
||||
if(this.updateID){
|
||||
return this.didDataChange || this.didFilesChange;
|
||||
return (this.didDataChange || this.didFilesChange) && this.dmsData.length;
|
||||
}
|
||||
return this.didDataChange && this.didFilesChange;
|
||||
}
|
||||
@@ -63,13 +65,20 @@ export default {
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
stringifyFile(file) {
|
||||
return JSON.stringify({
|
||||
lastModified: file.lastModified,
|
||||
lastModifiedDate: file.lastModifiedDate,
|
||||
name: file.name,
|
||||
size: file.size,
|
||||
type: file.type
|
||||
});
|
||||
},
|
||||
emitChanges: function () {
|
||||
if (this.isChanged) {
|
||||
|
||||
this.$emit(
|
||||
"profilUpdate",
|
||||
this.withFiles
|
||||
? { value: this.data.value, files: this.dmsData }
|
||||
: { value: this.data.value }
|
||||
"profilUpdate", { value: this.data.value }
|
||||
);
|
||||
} else {
|
||||
this.$emit("profilUpdate", null);
|
||||
@@ -84,6 +93,7 @@ export default {
|
||||
}
|
||||
},
|
||||
template: `
|
||||
|
||||
<p style="opacity:0.8" class="ms-2" v-if="withFiles && !updateID">Please update your {{data.titel}} and upload the corresponding Document of proof</p>
|
||||
|
||||
<div class="form-underline">
|
||||
@@ -91,9 +101,14 @@ export default {
|
||||
|
||||
<input class="mb-2 form-control" @input="emitChanges" v-model="data.value" :placeholder="data.value">
|
||||
|
||||
|
||||
<dms ref="update" v-if="withFiles" id="files" :noList="false" :multiple="true" v-model="dmsData" @update:model-value="didFilesChange" ></dms>
|
||||
|
||||
<div class="row gx-2">
|
||||
<div class="col">
|
||||
<dms ref="update" v-if="withFiles" id="files" name="files" :multiple="false" v-model="dmsData" @update:model-value="didFilesChange" ></dms>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<button @click="dmsData=[]" class="btn btn-danger"><i style="color:white" class="fa fa-trash"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
};
|
||||
|
||||
@@ -84,7 +84,7 @@ export default {
|
||||
methods: {
|
||||
|
||||
fetchProfilUpdates: function(){
|
||||
Vue.$fhcapi.UserData.selectProfilRequest().then((res)=>{
|
||||
Vue.$fhcapi.ProfilUpdate.selectProfilRequest().then((res)=>{
|
||||
|
||||
if(!res.error){
|
||||
this.data.profilUpdates = res.data?.length ? res.data.sort(this.sortProfilUpdates) : null ;
|
||||
@@ -99,7 +99,7 @@ export default {
|
||||
title:"Profil bearbeiten",
|
||||
}).then((popup_result) => {
|
||||
if(popup_result){
|
||||
Vue.$fhcapi.UserData.selectProfilRequest()
|
||||
Vue.$fhcapi.ProfilUpdate.selectProfilRequest()
|
||||
.then((res) =>{
|
||||
if(!res.error){
|
||||
this.data.profilUpdates = res.data.sort(this.sortProfilUpdates);
|
||||
|
||||
Reference in New Issue
Block a user