From 3362eb8e3141b4fdbb00df86c81cd7c76cddbbd0 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Tue, 30 Jan 2024 15:59:56 +0100 Subject: [PATCH] changing the text_input component to accept documents for the name or the title of a PersonUpdateRequest --- application/controllers/Cis/Profil.php | 32 +++++-- public/js/components/Cis/Profil/EditProfil.js | 41 +++++++- .../components/Cis/Profil/EditProfilSelect.js | 22 +++-- .../Cis/Profil/MitarbeiterProfil.js | 46 +++------ .../ProfilComponents/FetchProfilUpdates.js | 23 ++++- .../Cis/Profil/ProfilComponents/Status.js | 10 +- .../ProfilComponents/TextInputDokument.js | 93 +++++++++++++++++++ .../Cis/ProfilUpdate/AcceptDenyUpdate.js | 13 ++- 8 files changed, 214 insertions(+), 66 deletions(-) create mode 100644 public/js/components/Cis/Profil/ProfilComponents/TextInputDokument.js diff --git a/application/controllers/Cis/Profil.php b/application/controllers/Cis/Profil.php index b442a49c7..ee5d781b3 100755 --- a/application/controllers/Cis/Profil.php +++ b/application/controllers/Cis/Profil.php @@ -70,6 +70,15 @@ 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++; */ + + $res=[]; + $this->load->library('DmsLib'); $this->load->model('DmsVersion_model','DmsVersionModel'); $files = $_FILES['files']; @@ -81,19 +90,22 @@ class Profil extends Auth_Controller $_FILES['files']['tmp_name'] = $files['tmp_name'][$i]; $_FILES['files']['error'] = $files['error'][$i]; $_FILES['files']['size'] = $files['size'][$i]; - //! ID CHANGES EVERYTIME AND TMP_FILENAME IS A HASH THAT ALSO CHANGES EVERYTIME - $this->DmsVersionModel->addSelect(["version"]); - $fileVersion = $this->DmsVersionModel->loadWhere(["filename"=>$_FILES['files']['tmp_name']]); - $fileVersion = hasData($fileVersion) ? getData($fileVersion)[0]->version : 0; - if($fileVersion) $fileVersion++; - $res=$this->dmslib->upload(["kategorie_kurzbz"=>"dokumente","version"=>$fileVersion] , 'files'); - echo json_encode($res); - echo "\n\n"; + $dms = [ + "kategorie_kurzbz"=>"dokumente", + "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); } diff --git a/public/js/components/Cis/Profil/EditProfil.js b/public/js/components/Cis/Profil/EditProfil.js index 47ffd19fd..fda28d537 100755 --- a/public/js/components/Cis/Profil/EditProfil.js +++ b/public/js/components/Cis/Profil/EditProfil.js @@ -38,10 +38,22 @@ export default { }, methods: { - submitProfilChange(){ + async submitProfilChange(){ + //? when the update contains a file upload + //TODO: check if the updated value is different from the original value before submitting the request 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); + }; + } //? 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)=>{ @@ -53,13 +65,31 @@ export default { }else{ this.result= false; this.hide(); - console.log(res.data); Alert.popup("Ein Fehler ist aufgetreten: "+ JSON.stringify(res.data.retval)); - } - + } }); + + } }, + + //? uploads files to the dms table and returns an array with the ids of the created files + uploadFiles: async function(files){ + let formData = new FormData(); + for(let i = 0; i < files.length; i++){ + + formData.append("files[]",files[i]); + } + + return 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}}); + }).catch(err=>{ + console.log(err); + return null; + }) + }, }, computed: { }, @@ -100,7 +130,8 @@ export default { diff --git a/public/js/components/Cis/Profil/EditProfilSelect.js b/public/js/components/Cis/Profil/EditProfilSelect.js index c91ddd683..0d28d47f9 100755 --- a/public/js/components/Cis/Profil/EditProfilSelect.js +++ b/public/js/components/Cis/Profil/EditProfilSelect.js @@ -3,6 +3,7 @@ import EditKontakt from "./ProfilComponents/EditKontakt.js"; import Adresse from "./ProfilComponents/Adresse.js"; import EditAdresse from "./ProfilComponents/EditAdresse.js"; import Status from "./ProfilComponents/Status.js"; +import TextInputDokument from "./ProfilComponents/TextInputDokument.js"; export default { components: { @@ -11,10 +12,11 @@ export default { Adresse, EditAdresse, Status, + TextInputDokument, }, props: { - //! this should throw an error in the js console, have to check later + list:Object, //? Prop used to determine how many options the select should initially show @@ -48,6 +50,7 @@ export default { data:null, breadcrumbItems:[], topic:null, + properties:null, } }, @@ -100,13 +103,16 @@ export default { profilUpdateEmit: function(event){ //? passes the updated profil information to the parent component + this.$emit('update:profilUpdate',event); }, + + updateOptions: function(event, item){ - + this.properties = item; this.data=item.data; - this.view=item.view; - + this.view=item.view; + console.log("properties",this.properties); if(item.title){ //? emits the selected topic to the parent component this.topic= item.title; @@ -132,6 +138,8 @@ export default { }, created() { + //? JSON parse and stringify are used to deep clone the objects + this.properties = {...this.list}; this.data = JSON.parse(JSON.stringify(this.list.data)); this.view = JSON.parse(JSON.stringify(this.list.view)); @@ -142,6 +150,7 @@ export default { template: `