import { CoreFilterCmpt } from "../../filter/Filter.js"; import AcceptDenyUpdate from "./AcceptDenyUpdate.js"; import Alert from "../../../components/Bootstrap/Alert.js"; import Loading from "../../../components/Loader.js"; import ApiProfilUpdate from '../../../api/factory/profilUpdate.js'; const sortProfilUpdates = (ele1, ele2, thisPointer) => { let result = 0; if (ele1.status === thisPointer.profilUpdateStates["Pending"]) { result = -1; } else if (ele1.status === thisPointer.profilUpdateStates["Accepted"]) { result = ele2.status === thisPointer.profilUpdateStates["Rejected"] ? -1 : 1; } else { result = 1; } if (ele1.status === ele2.status) { //? if they have the same status , insert_date gets compared for order result = new Date(ele2.insertamum.split(".").reverse().join("-")) - new Date(ele1.insertamum.split(".").reverse().join("-")); } return result; }; export default { components: { CoreFilterCmpt, Loading, AcceptDenyUpdate, }, inject: ["profilUpdateTopic", "profilUpdateStates"], props: { id: { type: Number, }, }, data() { return { categoryLoaded: false, showModal: false, modalData: null, loading: false, filter: "Pending", events: [], profil_update_id: Number(this.id), }; }, computed:{ profilUpdateOptions: function(){ return { ajaxURL: FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + `/Cis/ProfilUpdate/`, ajaxURLGenerator: (url, config, params) => { //? this function needs to be an array function in order to access the this properties of the Vue component switch (this.filter) { case this.profilUpdateStates["Pending"]: return ( url + `getProfilUpdateWithPermission/${this.profilUpdateStates["Pending"]}` ); case this.profilUpdateStates["Accepted"]: return ( url + `getProfilUpdateWithPermission/${this.profilUpdateStates["Accepted"]}` ); case this.profilUpdateStates["Rejected"]: return ( url + `getProfilUpdateWithPermission/${this.profilUpdateStates["Rejected"]}` ); default: return url + `getProfilUpdateWithPermission`; } }, ajaxResponse: (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((ele1, ele2) => sortProfilUpdates(ele1, ele2, this)); return response; }, //? adds tooltip with the status message of a profil update request if its status is not pending columnDefaults: { tooltip: (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("span"); statusDateEl.classList.add("d-block", "mb-1"); 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 === this.profilUpdateStates["Pending"] ) { menu.push( { label: ` ${this.$p.t( "profilUpdate", "acceptUpdate" )}`, action: (e, column) => { this.$api .call(ApiProfilUpdate.acceptProfilRequest(column.getData())) .then((res) => { this.$refs.UpdatesTable.tabulator.setData(); }) .catch((e) => this.$fhcAlert.handleSystemError); }, }, { separator: true, }, { label: ` ${this.$p.t( "profilUpdate", "denyUpdate" )}`, action: (e, column) => { this.$api .call(ApiProfilUpdate.denyProfilRequest(column.getData())) .then((res) => { this.$refs.UpdatesTable.tabulator.setData(); }) .catch((e) => this.$fhcAlert.handleSystemError); }, }, { separator: true, }, { label: ` ${this.$p.t( "profilUpdate", "showRequest" )}`, action: (e, column) => { this.showAcceptDenyModal(column.getData()); }, } ); } else { menu.push({ label: ` ${this.$p.t( "profilUpdate", "showRequest" )}`, action: (e, column) => { this.showAcceptDenyModal(column.getData()); }, }); } return menu; }, height: 600, layout: "fitColumns", columns: [ { title: this.$p.t("profilUpdate", "UID"), field: "uid", minWidth: 200, resizable: true, headerFilter: true, //responsive:0, }, { title: this.$p.t("profilUpdate", "Name"), field: "name", minWidth: 200, resizable: true, headerFilter: true, //responsive:0, }, { title: this.$p.t("profilUpdate", "Topic"), field: "topic", resizable: true, minWidth: 200, headerFilter: true, //responsive:0, }, { title: this.$p.t("profilUpdate", "insertamum"), field: "insertamum", resizable: true, headerFilter: true, minWidth: 200, //responsive:0, }, { title: this.$p.t("profilUpdate", "Status"), field: "status_translated", hozAlign: "center", headerFilter: true, formatter: (cell, para) => { let iconClasses = ""; let status = cell.getRow().getData().status; switch (status) { case this.profilUpdateStates["Pending"]: iconClasses += "fa fa-lg fa-circle-info text-info "; break; case this.profilUpdateStates["Accepted"]: iconClasses += "fa fa-lg fa-circle-check text-success "; break; case this.profilUpdateStates["Rejected"]: iconClasses += "fa fa-lg fa-circle-xmark text-danger "; break; } return `