when user does not have permissions to accept/deny a profil update request it is notified via alert modal

This commit is contained in:
SimonGschnell
2024-02-07 14:21:25 +01:00
parent 286c7be83d
commit 9362aea0cf
5 changed files with 146 additions and 169 deletions
+2 -8
View File
@@ -46,15 +46,9 @@ class ProfilUpdate extends Auth_Controller
}
public function getProfilUpdates($status=null){
$this->load->library('PermissionLib');
$studentBerechtigung = $this->permissionlib->isBerechtigt('student/stammdaten','s');
$mitarbeiterBerechtigung = $this->permissionlib->isBerechtigt('mitarbeiter/stammdaten','s');
$options = ["mitarbeiterView"=>$mitarbeiterBerechtigung,"studentView"=>$studentBerechtigung];
if(isset($status)){
$options['status'] = $status;
}
$res = $this->ProfilChangeModel->getProfilUpdate($options);
$res = $this->ProfilChangeModel->getProfilUpdate(isset($status)?['status'=>$status]:null);
echo json_encode($res);
}
@@ -15,6 +15,8 @@ class Profil_change_model extends DB_Model
$this->load->model('crm/Student_model','StudentModel');
$this->load->model('ressource/Mitarbeiter_model','MitarbeiterModel');
$this->load->library('PermissionLib');
}
/**
@@ -53,8 +55,12 @@ class Profil_change_model extends DB_Model
* returns all profil updates if id is set to null
*/
public function getProfilUpdate($whereClause=null){
$studentBerechtigung = $this->permissionlib->isBerechtigt('student/stammdaten','s');
$mitarbeiterBerechtigung = $this->permissionlib->isBerechtigt('mitarbeiter/stammdaten','s');
$res =[];
if($whereClause["studentView"]) {
if($studentBerechtigung) {
$this->addJoin('tbl_student','tbl_student.student_uid=tbl_cis_profil_update.uid');
$studentRequests = $this->loadWhere(isset($whereClause['status']) && $whereClause['status']? ['status'=>$whereClause['status']]:[]);
if(isError($studentRequests)) return error("db error: ". getData($studentRequests));
@@ -63,7 +69,7 @@ class Profil_change_model extends DB_Model
array_push($res,$request);
}
}
if($whereClause["mitarbeiterView"]) {
if($mitarbeiterBerechtigung) {
$this->addJoin('tbl_mitarbeiter','tbl_mitarbeiter.mitarbeiter_uid=tbl_cis_profil_update.uid');
$mitarbeiterRequests = $this->loadWhere(isset($whereClause['status']) && $whereClause['status']? ['status'=>$whereClause['status']]:[]);
if(isError($mitarbeiterRequests)) return error("db error: ". getData($mitarbeiterRequests));
+128 -131
View File
@@ -1,26 +1,26 @@
import fhcapifactory from "../api/fhcapifactory.js";
import { CoreFilterCmpt } from "../../components/filter/Filter.js";
import AcceptDenyUpdate from "../../components/Cis/ProfilUpdate/AcceptDenyUpdate.js";
import Alert from "../../components/Bootstrap/Alert.js";
Vue.$fhcapi = fhcapifactory;
const sortProfilUpdates = (ele1,ele2)=>{
const sortProfilUpdates = (ele1, ele2) => {
let result = 0;
if(ele1.status === 'pending'){
result= -1;
}
else if(ele1.status === 'accepted'){
result= ele2.status ==='rejected'? -1 : 1;
}
else{
result= 1;
if (ele1.status === "pending") {
result = -1;
} else if (ele1.status === "accepted") {
result = ele2.status === "rejected" ? -1 : 1;
} else {
result = 1;
}
//? if they have the same status the insert date is used for ordering
if(ele1.status === ele2.status){
result= new Date(ele2.insertamum.split('.').reverse().join('-')) - new Date(ele1.insertamum.split('.').reverse().join('-'));
if (ele1.status === ele2.status) {
result =
new Date(ele2.insertamum.split(".").reverse().join("-")) -
new Date(ele1.insertamum.split(".").reverse().join("-"));
}
return result;
};
};
const app = Vue.createApp({
components: {
@@ -30,109 +30,110 @@ const app = Vue.createApp({
return {
showAll: false,
profil_updates_table_options: {
ajaxResponse:function(url, params, response){
//url - the URL of the request
//params - the parameters passed with the request
//response - the JSON object returned in the body of the response.
//? sorts the response data from the backend
if(response)
response.sort(sortProfilUpdates);
return response;
ajaxResponse: function (url, params, response) {
//url - the URL of the request
//params - the parameters passed with the request
//response - the JSON object returned in the body of the response.
//? sorts the response data from the backend
if (response) response.sort(sortProfilUpdates);
return response;
},
//? adds tooltip with the status message of a profil update request if its status is not pending
columnDefaults:{
tooltip:function(e, cell, onRendered){
//e - mouseover event
//cell - cell component
//onRendered - onRendered callback registration function
let statusMessage = cell.getData().status_message;
let statusDate = cell.getData().status_timestamp;
let status = cell.getData().status;
if(!statusMessage){
return null;
}
let el = document.createElement("div");
el.classList.add("border","border-dark");
let statusDateEl = document.createElement("p");
statusDateEl.innerHTML = "Request was "+ status + " on " + statusDate ;
let statusMessageEl = document.createElement("span");
statusMessageEl.innerHTML = "Status message: " + statusMessage ;
el.appendChild(statusDateEl);
el.appendChild(statusMessageEl);
return el;
},
},
rowContextMenu: (e, component)=>{
columnDefaults: {
tooltip: function (e, cell, onRendered) {
//e - mouseover event
//cell - cell component
//onRendered - onRendered callback registration function
let statusMessage = cell.getData().status_message;
let statusDate = cell.getData().status_timestamp;
let status = cell.getData().status;
if (!statusMessage) {
return null;
}
let el = document.createElement("div");
el.classList.add("border", "border-dark");
let menu =[];
if(component.getData().status === "pending"){
menu.push(
{
label:"<i class='fa fa-check'></i> Accept Request",
action:(e, column)=>{
Vue.$fhcapi.ProfilUpdate.acceptProfilRequest(column.getData()).then((res) => {
this.$refs.UpdatesTable.tabulator.setData();
});
}
},
{
separator:true,
},
{
label:" <i style='width:16px' class='text-center fa fa-xmark'></i> Deny Request",
action:(e, column)=>{
Vue.$fhcapi.ProfilUpdate.denyProfilRequest(column.getData()).then((res) => {
this.$refs.UpdatesTable.tabulator.setData();
});
}
},
{
separator:true,
},
{
label:"<i class='fa fa-eye'></i> Show Request",
action:(e, column)=>{
this.showModal(column.getData());
}
}
);
}else{
let statusDateEl = document.createElement("p");
statusDateEl.innerHTML =
"Request was " + status + " on " + statusDate;
let statusMessageEl = document.createElement("span");
statusMessageEl.innerHTML = "Status message: " + statusMessage;
el.appendChild(statusDateEl);
el.appendChild(statusMessageEl);
return el;
},
},
rowContextMenu: (e, component) => {
let menu = [];
if (component.getData().status === "pending") {
menu.push(
{
label:"<i class='fa fa-eye'></i> Show Request",
action:(e, column)=>{
label: "<i class='fa fa-check'></i> Accept Request",
action: (e, column) => {
Vue.$fhcapi.ProfilUpdate.acceptProfilRequest(column.getData())
.then((res) => {
console.log("here");
this.$refs.UpdatesTable.tabulator.setData();
})
.catch((e) => {
Alert.popup(Vue.h('div',{innerHTML:e.response.data}));
});
},
},
{
separator: true,
},
{
label:
" <i style='width:16px' class='text-center fa fa-xmark'></i> Deny Request",
action: (e, column) => {
Vue.$fhcapi.ProfilUpdate.denyProfilRequest(
column.getData()
).then((res) => {
this.$refs.UpdatesTable.tabulator.setData();
}).catch((e) => {
Alert.popup(Vue.h('div',{innerHTML:e.response.data}));
});
},
},
{
separator: true,
},
{
label: "<i class='fa fa-eye'></i> Show Request",
action: (e, column) => {
this.showModal(column.getData());
}
},
}
)
);
} else {
menu.push({
label: "<i class='fa fa-eye'></i> Show Request",
action: (e, column) => {
this.showModal(column.getData());
},
});
}
return menu;
},
ajaxURL:
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
`/Cis/ProfilUpdate/`,
} ,
ajaxURL:FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
`/Cis/ProfilUpdate/`,
ajaxURLGenerator: (url,config,params)=>{
ajaxURLGenerator: (url, config, params) => {
//? this function needs to be an array function in order to access the this properties of the Vue component
if(this.showAll){
return url +"getProfilUpdates";
}else{
return url +"getProfilUpdates/pending";
if (this.showAll) {
return url + "getProfilUpdates";
} else {
return url + "getProfilUpdates/pending";
}
},
height: 600,
layout: "fitColumns",
columns: [
{
title: "UID",
@@ -172,7 +173,6 @@ const app = Vue.createApp({
hozAlign: "center",
headerFilter: true,
formatter: function (cell, para) {
switch (cell.getValue()) {
case "pending":
return "<div class='row justify-content-center'><div class='col-2'><i class='fa fa-circle-info text-info fa-lg'></i></div> <div class='col-4'><span>pending</span></div></div>";
@@ -201,7 +201,6 @@ const app = Vue.createApp({
//! function that is called when clicking on a row in the table
let cellData = cell.getRow().getData();
this.showModal(cellData);
},
//responsive:0,
},
@@ -210,45 +209,43 @@ const app = Vue.createApp({
};
},
computed: {
getFetchUrl: function(){
let url = FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
`/Cis/ProfilUpdate/`;
if(this.showAll){
url+"getAllRequests";
}else{
url+"getPendingRequests";
getFetchUrl: function () {
let url =
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
`/Cis/ProfilUpdate/`;
if (this.showAll) {
url + "getAllRequests";
} else {
url + "getPendingRequests";
}
return url;
}
},
},
methods: {
showModal: function(value){
showModal: function (value) {
AcceptDenyUpdate.popup({ value: value })
.then((res) => {
console.log("res of the modal: ", res);
//? refetches the data, if any request was denied or accepted
//* setData will call the ajaxURL again to refresh the data
this.$refs.UpdatesTable.tabulator.setData();
})
.catch((e) => {
//? catches the rejected Promise if the result of the modal was falsy
console.log("catch of the modal: ", e);
});
.then((res) => {
console.log("res of the modal: ", res);
//? refetches the data, if any request was denied or accepted
//* setData will call the ajaxURL again to refresh the data
this.$refs.UpdatesTable.tabulator.setData();
})
.catch((e) => {
//? catches the rejected Promise if the result of the modal was falsy
console.log("catch of the modal: ", e);
});
},
updateData: function(event){
this.$refs.UpdatesTable.tabulator.setData();
updateData: function (event) {
this.$refs.UpdatesTable.tabulator.setData();
//? store the selected view in the session storage of the browser
sessionStorage.setItem("showAll",JSON.stringify(event.target.value));
}
sessionStorage.setItem("showAll", JSON.stringify(event.target.value));
},
},
mounted() {
if(!(sessionStorage.getItem("showAll")===null))
{
if (!(sessionStorage.getItem("showAll") === null)) {
this.showAll = JSON.parse(sessionStorage.getItem("showAll"));
}
},
template: `
<div>
@@ -87,7 +87,7 @@ export default {
Vue.$fhcapi.UserData.selectProfilRequest().then((res)=>{
if(!res.error){
this.data.profilUpdates = res.data.retval?.length ? res.data.retval.sort(this.sortProfilUpdates) : null ;
this.data.profilUpdates = res.data?.length ? res.data.sort(this.sortProfilUpdates) : null ;
}
});
},
@@ -102,9 +102,9 @@ export default {
Vue.$fhcapi.UserData.selectProfilRequest()
.then((res) =>{
if(!res.error){
this.data.profilUpdates = res.data.retval.sort(this.sortProfilUpdates);
this.data.profilUpdates = res.data.sort(this.sortProfilUpdates);
}else{
alert("Error when fetching profile updates: " +res.data.retval);
alert("Error when fetching profile updates: " +res.data);
}
})
.catch(err=>alert(err));
@@ -7,7 +7,6 @@ import Adresse from "../Profil/ProfilComponents/Adresse.js";
export default {
components: {
BsModal,
Alert,
Kontakt,
Adresse,
},
@@ -50,6 +49,8 @@ export default {
acceptRequest: function () {
Vue.$fhcapi.ProfilUpdate.acceptProfilRequest(this.data).then((res) => {
this.result = true;
}).catch((e) => {
Alert.popup(Vue.h('div',{innerHTML:e.response.data}));
});
this.hide();
},
@@ -58,34 +59,13 @@ export default {
Vue.$fhcapi.ProfilUpdate.denyProfilRequest(this.data).then((res) => {
this.result = true;
}).catch((e) => {
Alert.popup(Vue.h('div',{innerHTML:e.response.data}));
});
this.hide();
},
submitProfilChange() {
//TODO: check if the updated value is different from the original value before submitting the request
if (false) {
//? 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) => {
if (res.data.error == 0) {
this.result = true;
this.hide();
Alert.popup(
"Ihre Anfrage wurde erfolgreich gesendet. Bitte warten Sie, während sich das Team um Ihre Anfrage kümmert."
);
} else {
this.result = false;
this.hide();
Alert.popup(
"Ein Fehler ist aufgetreten: " + JSON.stringify(res.data.retval)
);
}
});
}
},
},
computed: {
getComponentView: function () {