makes it possible to display documents when reviewing profil update requests

This commit is contained in:
SimonGschnell
2024-02-01 14:08:55 +01:00
parent 1460e6ed80
commit d813f55a9b
6 changed files with 80 additions and 16 deletions
+16 -1
View File
@@ -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');
+14 -1
View File
@@ -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;
+9
View File
@@ -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 +
+23 -8
View File
@@ -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<files.length; j++) {
if (file.name === files[j].name)
return true;
}
})];
let filesToKeep = [];
let filesToDelete = [];
console.log(existingFiles);
console.log(files);
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
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};
})
);
})
@@ -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 {
<div class="form-underline-titel">{{topic}}</div>
<span class="form-underline-content">{{data.value}} </span>
</div>
<div class="ms-2">
<p>files:</p>
<p v-for="file in data.files">{{file}}</p>
<div v-if="data.files?.length" class="ms-2">
<a target="_blank" :href="getDocumentLink(file.dms_id)" v-for="file in data.files">{{file.name}}</a>
</div>
</template>
<component v-else :is="getComponentView" :data="data"></component>
@@ -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 {
<span class="form-underline-content" >{{data.requested_change.value}}</span>
</div>
<div class="ms-2">
<p>files:</p>
<p v-for="file in data.requested_change.files">{{file}}</p>
<div v-if="data.requested_change.files.length" class="ms-2">
<!--<p>files:</p>-->
<a v-for="file in data.requested_change.files" target="_blank" :href="getDocumentLink(file.dms_id)" >{{file.name}}</a>
</div>
</template>