diff --git a/application/controllers/Cis/Profil.php b/application/controllers/Cis/Profil.php index 8e40c3f29..eae64452f 100755 --- a/application/controllers/Cis/Profil.php +++ b/application/controllers/Cis/Profil.php @@ -26,7 +26,8 @@ class Profil extends Auth_Controller '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'], + ]); $this->load->model('ressource/mitarbeiter_model', 'MitarbeiterModel'); $this->load->model('crm/Student_model', 'StudentModel'); @@ -38,6 +39,8 @@ class Profil extends Auth_Controller $this->load->model('ressource/Betriebsmittelperson_model', 'BetriebsmittelpersonModel'); $this->load->model('person/Kontakt_model', 'KontaktModel'); $this->load->model('person/Profil_change_model', 'ProfilChangeModel'); + $this->load->model('content/DmsVersion_model', 'DmsVersionModel'); + //? put the uid and pid inside the controller to reuse in controller $this->uid = getAuthUID(); @@ -114,6 +117,18 @@ class Profil extends Auth_Controller } + public function deleteOldVersionFiles(){ + //? table dms_version has a composite primary key with dms_id and dms_version + $file_array = json_decode($this->input->raw_input_stream); + $res =[]; + foreach($file_array as $value){ + + array_push($res, $this->DmsVersionModel->delete([$value,0])); + } + echo json_encode($res); + } + + public function selectProfilRequest(){ $_GET = json_decode($this->input->raw_input_stream, true); $uid = $this->input->get('uid'); diff --git a/application/controllers/Cis/ProfilUpdate.php b/application/controllers/Cis/ProfilUpdate.php index 24db74ddd..5e6d1df18 100755 --- a/application/controllers/Cis/ProfilUpdate.php +++ b/application/controllers/Cis/ProfilUpdate.php @@ -15,6 +15,7 @@ class ProfilUpdate extends Auth_Controller 'getAllRequests' => ['student/anrechnung_beantragen:r', 'user:r'], 'acceptProfilRequest'=>['user:r'], 'denyProfilRequest'=>['user:r'], + 'show'=>['user:r'], ]); @@ -31,6 +32,17 @@ class ProfilUpdate extends Auth_Controller $this->load->view('Cis/ProfilUpdate'); } + public function show($dms_id){ + $this->load->library('DmsLib'); + //? downloads the file using the dms_id + $file = $this->dmslib->download($dms_id); + $file = hasData($file) ? getData($file) : null; + //? returns the downloaded file to the user + $res = $this->outputFile($file); + + echo json_encode($res); + } + public function getAllRequests(){ $res = $this->ProfilChangeModel->getProfilUpdate(); $res = hasData($res)? getData($res) : null; @@ -87,7 +99,8 @@ class ProfilUpdate extends Auth_Controller case "titel": $topic ="titelpre"; break; case "postnomen": $topic = "titelpost"; break; } - $result = $this->PersonModel->update($personID,[$topic=>$requested_change]); + + $result = $this->PersonModel->update($personID,[$topic=>$requested_change["value"]]); if(isError($result)){ echo json_encode(error("was not able to update Person Information: " . $topic . " with value : " . $requested_change)); return; diff --git a/public/js/apps/api/userdata.js b/public/js/apps/api/userdata.js index c924d7b10..cc8fb5e58 100755 --- a/public/js/apps/api/userdata.js +++ b/public/js/apps/api/userdata.js @@ -12,6 +12,15 @@ export default { }); }, + 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 + diff --git a/public/js/components/Cis/Profil/EditProfil.js b/public/js/components/Cis/Profil/EditProfil.js index b8782f5ef..8f5a2d824 100755 --- a/public/js/components/Cis/Profil/EditProfil.js +++ b/public/js/components/Cis/Profil/EditProfil.js @@ -44,7 +44,7 @@ export default { if (this.topic && this.profilUpdate) { if (this.profilUpdate.files) { const fileIDs = await this.uploadFiles(this.profilUpdate.files); - + if (fileIDs) { this.profilUpdate.files = fileIDs; console.log("here is the update", this.profilUpdate); @@ -95,12 +95,26 @@ export default { ).then((res) => { return res.data; }); - updatedFiles = [...existingFiles.filter((file) => { - for(let j=0; j { + 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 + Vue.$fhcapi.UserData.deleteOldVersionFiles( + filesToDelete + ).then((res) => { + console.log(res); + }); + + + updatedFiles = [...filesToKeep]; } let formData = new FormData(); @@ -116,7 +130,8 @@ export default { updatedFiles = updatedFiles.concat( res.data?.map((file) => { - return { dms_id: file.dms_id, name: file.client_name }; + console.log("here are the files:",file); + return { dms_id: file.dms_id, name: file.client_name}; }) ); }) diff --git a/public/js/components/Cis/Profil/ProfilComponents/Status.js b/public/js/components/Cis/Profil/ProfilComponents/Status.js index 2eebbf8fa..3107ce8dc 100755 --- a/public/js/components/Cis/Profil/ProfilComponents/Status.js +++ b/public/js/components/Cis/Profil/ProfilComponents/Status.js @@ -9,6 +9,13 @@ export default { data() { return {}; }, + methods:{ + getDocumentLink: function(dms_id){ + return FHC_JS_DATA_STORAGE_OBJECT.app_root + + FHC_JS_DATA_STORAGE_OBJECT.ci_router + + `/Cis/ProfilUpdate/show/${dms_id}`; + } + }, computed: { getComponentView: function () { let title = this.topic.toLowerCase(); @@ -72,9 +79,9 @@ export default {
{{topic}}
{{data.value}} -
-

files:

-

{{file}}

+ diff --git a/public/js/components/Cis/ProfilUpdate/AcceptDenyUpdate.js b/public/js/components/Cis/ProfilUpdate/AcceptDenyUpdate.js index 3c808b913..ee0b48241 100755 --- a/public/js/components/Cis/ProfilUpdate/AcceptDenyUpdate.js +++ b/public/js/components/Cis/ProfilUpdate/AcceptDenyUpdate.js @@ -41,6 +41,11 @@ export default { }, methods: { + getDocumentLink: function(dms_id){ + return FHC_JS_DATA_STORAGE_OBJECT.app_root + + FHC_JS_DATA_STORAGE_OBJECT.ci_router + + `/Cis/ProfilUpdate/show/${dms_id}`; + }, acceptRequest: function () { Vue.$fhcapi.ProfilUpdate.acceptProfilRequest(this.data).then((res) => { console.log("res", res); @@ -183,9 +188,9 @@ export default { {{data.requested_change.value}}
-
-

files:

-

{{file}}

+