From cda13ac7053ba8d57aceb89f084e051592eafe1c Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Thu, 8 Feb 2024 13:47:03 +0100 Subject: [PATCH] makes the send button in the profil update popup disabled instead of not showing it --- application/controllers/Cis/Profil.php | 21 +++-------- application/controllers/Cis/ProfilUpdate.php | 6 ++-- .../models/person/Profil_update_model.php | 36 ++++++++++++++----- public/js/apps/Cis/ProfilUpdateRequests.js | 5 ++- public/js/components/Cis/Profil/EditProfil.js | 3 +- .../js/components/Cis/Profil/StudentProfil.js | 3 ++ 6 files changed, 42 insertions(+), 32 deletions(-) diff --git a/application/controllers/Cis/Profil.php b/application/controllers/Cis/Profil.php index ab7a60e80..06c829763 100755 --- a/application/controllers/Cis/Profil.php +++ b/application/controllers/Cis/Profil.php @@ -27,7 +27,7 @@ class Profil extends Auth_Controller 'insertFile' => ['student/anrechnung_beantragen:r', 'user:r'], 'getProfilRequestFiles' => ['student/anrechnung_beantragen:r', 'user:r'], 'deleteOldVersionFiles' => ['student/anrechnung_beantragen:r', 'user:r'], - 'test' => ['student/anrechnung_beantragen:r', 'user:r'], + ]); @@ -63,17 +63,6 @@ class Profil extends Auth_Controller * @return void */ - public function test(){ - - // Loads permission lib - $this->load->library('PermissionLib'); - $mit_daten =$this->permissionlib->isBerechtigt('mitarbeiter/stammdaten','suid'); - var_dump($mit_daten); - $stud_daten = $this->permissionlib->isBerechtigt('student/stammdaten','suid'); - var_dump($stud_daten); - } - - public function index() { $this->load->view('Cis/Profil'); @@ -172,7 +161,7 @@ class Profil extends Auth_Controller if(isset($uid)) $whereClause['uid'] = $uid; if(isset($id)) $whereClause['id'] = $id; - $res= $this->ProfilUpdateModel->getProfilUpdate($whereClause); + $res= $this->ProfilUpdateModel->getProfilUpdatesWhere($whereClause); echo json_encode($res); @@ -201,7 +190,7 @@ class Profil extends Auth_Controller $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->loadWhere(["uid"=>$this->uid]); + $res = $this->ProfilUpdateModel->getProfilUpdatesWhere(["uid"=>$this->uid]); $res = hasData($res) ? getData($res) : null; if($res){ @@ -659,7 +648,7 @@ class Profil extends Auth_Controller //? querying if the user has profil update requests - $profilUpdates = $this->ProfilUpdateModel->getProfilUpdate(['uid'=>$this->uid]); + $profilUpdates = $this->ProfilUpdateModel->getProfilUpdatesWhere(['uid'=>$this->uid]); if(isError($profilUpdates)){ //error handling }else{ @@ -865,7 +854,7 @@ class Profil extends Auth_Controller } //? querying if the user has profil update requests - $profilUpdates = $this->ProfilUpdateModel->getProfilUpdate(['uid'=>$this->uid]); + $profilUpdates = $this->ProfilUpdateModel->getProfilUpdatesWhere(['uid'=>$this->uid]); if(isError($profilUpdates)){ //error handling }else{ diff --git a/application/controllers/Cis/ProfilUpdate.php b/application/controllers/Cis/ProfilUpdate.php index c35b808bd..7e39d6310 100755 --- a/application/controllers/Cis/ProfilUpdate.php +++ b/application/controllers/Cis/ProfilUpdate.php @@ -12,7 +12,7 @@ class ProfilUpdate extends Auth_Controller public function __construct(){ parent::__construct([ 'index' => ['student/stammdaten:r','mitarbeiter/stammdaten:r'], - 'getProfilUpdates' => ['student/stammdaten:r','mitarbeiter/stammdaten:r'], + 'getProfilUpdateWithPermission' => ['student/stammdaten:r','mitarbeiter/stammdaten:r'], 'acceptProfilRequest'=>['student/stammdaten:rw','mitarbeiter/stammdaten:rw'], 'denyProfilRequest'=>['student/stammdaten:rw','mitarbeiter/stammdaten:rw'], 'show'=>['student/stammdaten:r','mitarbeiter/stammdaten:r'], @@ -45,10 +45,10 @@ class ProfilUpdate extends Auth_Controller echo json_encode($res); } - public function getProfilUpdates($status=null){ + public function getProfilUpdateWithPermission($status=null){ - $res = $this->ProfilUpdateModel->getProfilUpdate(isset($status)?['status'=>$status]:null); + $res = $this->ProfilUpdateModel->getProfilUpdateWithPermission(isset($status)?['status'=>$status]:null); echo json_encode($res); } diff --git a/application/models/person/Profil_update_model.php b/application/models/person/Profil_update_model.php index 2fbecb27c..d316feab0 100755 --- a/application/models/person/Profil_update_model.php +++ b/application/models/person/Profil_update_model.php @@ -48,13 +48,30 @@ class Profil_update_model extends DB_Model return json_decode($res->requested_change)->files?:[]; } + + public function getProfilUpdatesWhere($whereClause){ + $res = $this->loadWhere($whereClause); + if(isError($res)){ + return error("Could not load public.tbl_profil_update with whereClause"); + } + $res = hasData($res) ? getData($res) : []; + if($res){ + foreach($res as $request){ + $this->formatProfilRequest($request); + } + } + return $res; + + } + + /** * * getProfilUpdate * returns a profil update with id * returns all profil updates if id is set to null */ - public function getProfilUpdate($whereClause=null){ + public function getProfilUpdateWithPermission($whereClause=null){ $studentBerechtigung = $this->permissionlib->isBerechtigt('student/stammdaten','s'); $mitarbeiterBerechtigung = $this->permissionlib->isBerechtigt('mitarbeiter/stammdaten','s'); @@ -103,14 +120,8 @@ class Profil_update_model extends DB_Model if($res){ - foreach($res as $update){ - - - $update->requested_change = json_decode($update->requested_change); - $update->insertamum = !is_null($update->insertamum)?date_create($update->insertamum)->format('d.m.Y'):null; - $update->updateamum = !is_null($update->updateamum)?date_create($update->updateamum)->format('d.m.Y'):null; - $update->status_timestamp = !is_null($update->status_timestamp)?date_create($update->status_timestamp)->format('d.m.Y'):null; - + foreach($res as $request){ + $this->formatProfilRequest($request); } } @@ -118,4 +129,11 @@ class Profil_update_model extends DB_Model } + private function formatProfilRequest($request){ + $request->requested_change = json_decode($request->requested_change); + $request->insertamum = !is_null($request->insertamum)?date_create($request->insertamum)->format('d.m.Y'):null; + $request->updateamum = !is_null($request->updateamum)?date_create($request->updateamum)->format('d.m.Y'):null; + $request->status_timestamp = !is_null($request->status_timestamp)?date_create($request->status_timestamp)->format('d.m.Y'):null; + } + } diff --git a/public/js/apps/Cis/ProfilUpdateRequests.js b/public/js/apps/Cis/ProfilUpdateRequests.js index 188406e84..7982c8519 100755 --- a/public/js/apps/Cis/ProfilUpdateRequests.js +++ b/public/js/apps/Cis/ProfilUpdateRequests.js @@ -38,11 +38,10 @@ const app = Vue.createApp({ ajaxURLGenerator: (url, config, params) => { //? this function needs to be an array function in order to access the this properties of the Vue component - console.log("showAll printed here:", this.showAll); if (this.showAll) { - return url + "getProfilUpdates"; + return url + "getProfilUpdateWithPermission"; } else { - return url + "getProfilUpdates/pending"; + return url + "getProfilUpdateWithPermission/pending"; } }, ajaxResponse: function (url, params, response) { diff --git a/public/js/components/Cis/Profil/EditProfil.js b/public/js/components/Cis/Profil/EditProfil.js index 07e62cd30..6ca410214 100755 --- a/public/js/components/Cis/Profil/EditProfil.js +++ b/public/js/components/Cis/Profil/EditProfil.js @@ -43,6 +43,7 @@ export default { methods: { 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); @@ -179,7 +180,7 @@ export default { `, diff --git a/public/js/components/Cis/Profil/StudentProfil.js b/public/js/components/Cis/Profil/StudentProfil.js index 4fc8bedf9..c1c647a96 100755 --- a/public/js/components/Cis/Profil/StudentProfil.js +++ b/public/js/components/Cis/Profil/StudentProfil.js @@ -158,6 +158,9 @@ export default { }, created(){ + + //? sorts the profil Updates: pending -> accepted -> rejected + this.data.profilUpdates?.sort(this.sortProfilUpdates); }, mounted() {