Files
luos/resources/assets/js/home/Home.vue

664 lines
22 KiB
Vue
Raw Normal View History

2020-12-02 19:46:17 +00:00
<template>
<div
id="home"
:class="[{ collapsed: collapsed }, { onmobile: isOnMobile }]"
>
<div class="demo">
<b-alert
:show="dataAlert.dismissCountDown"
dismissible
:variant="dataAlert.variant"
@dismissed="dataAlert.dismissCountDown = 0"
@dismiss-count-down="countDownChanged"
>
{{ dataAlert.message }}
</b-alert>
<div class="container">
<router-view />
</div>
<CustomSidebar
:menu="menu"
@OnClickSidebarItem="OnClickSidebarItem"
@onToggleCollapse="onToggleCollapse"
/>
<div
v-if="isOnMobile && !collapsed"
class="sidebar-overlay"
@click="collapsed = true"
/>
<component
v-bind:is="page"
ref="component"
:id="pageId"
:pageUri="pageUri"
:name="pageName"
:defaultOption="defaultOption"
:settings="settings"
2021-07-29 20:48:58 +00:00
:filters="filters"
2021-08-27 14:37:31 +00:00
:data="pageData"
2021-08-20 03:40:20 +00:00
@onSubmitFilter="onSubmitFilter"
@onRemoveFilter="onRemoveFilter"
2020-12-11 19:36:41 +00:00
@onUpdatePage="onUpdatePage"
@onUpdateDataCase="onUpdateDataCase"
@onLastPage="onLastPage"
@onUpdateFilters="onUpdateFilters"
@cleanDefaultOption="cleanDefaultOption"
@updateSettings="updateSettings"
2021-08-20 03:40:20 +00:00
></component>
</div>
2020-12-02 19:46:17 +00:00
</div>
</template>
2020-12-02 19:46:17 +00:00
<script>
import CustomSidebar from "./../components/menu/CustomSidebar";
2021-08-17 21:48:08 +00:00
import CustomSidebarMenuItem from "./../components/menu/CustomSidebarMenuItem";
2021-07-22 19:33:43 +00:00
import MyCases from "./MyCases/MyCases.vue";
2020-12-02 21:28:16 +00:00
import MyDocuments from "./MyDocuments";
2021-08-20 04:08:57 +00:00
import Inbox from "./Inbox/Inbox.vue";
2021-07-14 20:50:12 +00:00
import Paused from "./Paused/Paused.vue";
2021-07-14 16:50:06 +00:00
import Draft from "./Draft/Draft.vue";
2021-07-15 19:34:33 +00:00
import Unassigned from "./Unassigned/Unassigned.vue";
2021-07-30 20:18:11 +00:00
import TaskMetrics from "./TaskMetrics/TaskMetrics.vue";
2020-12-03 12:39:57 +00:00
import BatchRouting from "./BatchRouting";
2020-12-07 18:52:12 +00:00
import CaseDetail from "./CaseDetail";
2020-12-04 13:33:23 +00:00
import XCase from "./XCase";
2020-12-03 15:23:23 +00:00
import TaskReassignments from "./TaskReassignments";
2021-07-22 19:33:43 +00:00
import AdvancedSearch from "./AdvancedSearch/AdvancedSearch.vue";
import LegacyFrame from "./LegacyFrame";
2021-08-27 14:37:31 +00:00
import CustomCaseList from "./CustomCaseList/CustomCaseList.vue"
import utils from "../utils/utils"
import api from "./../api/index";
2021-08-20 03:40:20 +00:00
import eventBus from './EventBus/eventBus'
2021-09-10 22:58:21 +00:00
import _ from "lodash";
2020-12-02 19:46:17 +00:00
export default {
name: "Home",
components: {
CustomSidebar,
MyCases,
AdvancedSearch,
MyDocuments,
BatchRouting,
TaskReassignments,
XCase,
2021-08-20 04:08:57 +00:00
Inbox,
Draft,
Paused,
Unassigned,
CaseDetail,
2021-08-27 14:37:31 +00:00
LegacyFrame,
2021-08-30 14:17:43 +00:00
TaskMetrics,
CustomCaseList
2020-12-02 19:46:17 +00:00
},
data() {
return {
2020-12-11 19:36:41 +00:00
lastPage: "MyCases",
page: null,
menu: [],
dataCase: {},
hideToggle: true,
collapsed: false,
selectedTheme: "",
isOnMobile: false,
sidebarWidth: "260px",
pageId: null,
pageName: null,
pageUri: null,
filters: null,
2021-07-29 20:48:58 +00:00
config: {
id: window.config.userId || "1",
2021-08-20 03:40:20 +00:00
name: "userConfig",
2021-07-29 20:48:58 +00:00
setting: {}
},
menuMap: {
CASES_MY_CASES: "MyCases",
CASES_SENT: "MyCases",
CASES_SEARCH: "advanced-search",
2021-08-20 04:08:57 +00:00
CASES_INBOX: "inbox",
CASES_DRAFT: "draft",
CASES_PAUSED: "paused",
CASES_SELFSERVICE: "unassigned",
CONSOLIDATED_CASES: "batch-routing",
CASES_TO_REASSIGN: "task-reassignments",
2021-09-17 23:14:57 +00:00
CASES_FOLDERS: "my-documents",
TASK_METRICS:"task-metrics"
},
2021-08-27 14:37:31 +00:00
defaultOption: window.config.defaultOption || '',
pageData: {},
settings: {},
dataAlert: {
dismissSecs: 5,
dismissCountDown: 0,
message: "",
variant: "info"
},
};
2020-12-04 13:33:23 +00:00
},
mounted() {
2021-08-20 03:40:20 +00:00
let that = this;
this.onResize();
this.getUserSettings();
2020-12-16 18:26:40 +00:00
this.listenerIframe();
window.setInterval(
this.getHighlight,
parseInt(window.config.FORMATS.casesListRefreshTime) * 1000
);
2021-08-20 03:40:20 +00:00
// adding eventBus listener
eventBus.$on('sort-menu', (data) => {
let page;
let newData = [];
data.forEach(item => {
newData.push({id: item.id});
if (!page) {
page = item.page;
}
});
2021-08-30 23:44:29 +00:00
that.updateSettings({
data: newData,
key: "customCaseListOrder",
page: page,
2021-08-30 23:44:29 +00:00
type: "normal",
id: this.id
});
2021-08-20 03:40:20 +00:00
});
2021-08-26 20:33:59 +00:00
eventBus.$on('home-update-page', (data) => {
that.onUpdatePage(data);
});
2021-09-22 16:37:52 +00:00
eventBus.$on('home::sidebar::click-item', (data) => {
that.OnClickSidebarItem(that.getItemMenuByValue("page",data));
});
eventBus.$on('home::update-settings', (data) => {
that.updateSettings(data);
});
2021-08-26 20:33:59 +00:00
eventBus.$on('home-update-datacase', (data) => {
that.onUpdateDataCase(data);
});
2020-12-02 19:46:17 +00:00
},
methods: {
2020-12-16 18:26:40 +00:00
/**
* Listener for iframes childs
*/
listenerIframe() {
2020-12-16 18:26:40 +00:00
let that = this,
eventMethod = window.addEventListener
? "addEventListener"
: "attachEvent",
eventer = window[eventMethod],
messageEvent =
eventMethod === "attachEvent" ? "onmessage" : "message";
2020-12-16 18:26:40 +00:00
eventer(messageEvent, function(e) {
2021-01-28 19:05:33 +00:00
if ( e.data === "redirect=todo" || e.message === "redirect=todo"){
2021-09-10 23:00:00 +00:00
that.OnClickSidebarItem(that.getItemMenuByValue("page","inbox"));
2020-12-16 18:26:40 +00:00
}
2021-01-28 19:05:33 +00:00
if ( e.data === "update=debugger" || e.message === "update=debugger"){
if(that.$refs["component"].updateView){
that.$refs["component"].updateView();
}
}
2020-12-16 18:26:40 +00:00
});
},
/**
* Gets the menu from the server
*/
getMenu() {
api.menu
.get()
.then((response) => {
this.setDefaultCasesMenu(response.data);
this.menu = this.mappingMenu(this.setDefaultIcon(response.data));
this.getHighlight();
})
.catch((e) => {
console.error(e);
});
},
/**
* Gets the user config
*/
getUserSettings() {
api.config
2021-07-29 20:48:58 +00:00
.get({
id: this.config.id,
name: this.config.name
})
.then((response) => {
2021-08-20 03:40:20 +00:00
if(response.data && response.data.status === 404) {
this.createUserSettings();
2021-08-20 03:40:20 +00:00
} else if (response.data) {
this.config = response.data;
2021-08-20 16:09:30 +00:00
this.getMenu();
}
})
.catch((e) => {
console.error(e);
});
},
/**
* Creates the user config service
*/
createUserSettings() {
api.config
2021-08-20 03:40:20 +00:00
.post(this.config)
.then((response) => {
if (response.data) {
this.config = response.data;
2021-08-31 00:09:51 +00:00
this.getMenu();
}
})
.catch((e) => {
console.error(e);
});
},
/**
* Update the user config service
* @param {object} params
*/
updateSettings (params){
if (params.type === "custom") {
if (!this.config.setting[params.page]) {
this.config.setting[params.page] = {};
}
if (!this.config.setting[params.page]["customCaseList"]) {
this.config.setting[params.page]["customCaseList"] = {};
}
if (!this.config.setting[params.page].customCaseList[params.id]) {
this.config.setting[params.page].customCaseList[params.id] = {}
}
this.config.setting[params.page].customCaseList[params.id][params.key] = params.data;
} else {
if (!this.config.setting[params.page]) {
this.config.setting[params.page] = {};
}
this.config.setting[params.page][params.key] = params.data;
}
api.config
.put(this.config)
.then((response) => {
if (response.data) {
//TODO success response
}
})
.catch((e) => {
console.error(e);
});
},
/**
* Set default cases menu option
*/
setDefaultCasesMenu(data) {
let params,
menuItem = _.find(data, function(o) {
return o.id === window.config._nodeId;
});
if (menuItem && menuItem.href) {
this.page = this.menuMap[window.config._nodeId] || "MyCases";
this.$router.push(menuItem.href);
} else {
this.page = "MyCases";
}
params = utils.getAllUrlParams(this.defaultOption);
if (params.action === 'mycases' && params.filter === '') {
this.showAlert(this.$i18n.t("ID_NO_PERMISSION_NO_PARTICIPATED_CASES"));
}
this.settings = this.config.setting[this.page];
this.lastPage = this.page;
2021-08-30 23:32:23 +00:00
},
/**
* Do a mapping of vue view for menus
* @returns array
*/
mappingMenu(data) {
var i,
j,
2021-08-26 20:33:59 +00:00
that = this,
newData = data,
auxId;
for (i = 0; i < data.length; i += 1) {
2021-08-27 14:37:31 +00:00
auxId = data[i].page || "";
if (auxId !== "" && this.menuMap[auxId]) {
2021-08-27 14:37:31 +00:00
newData[i].page = this.menuMap[auxId];
} else if (newData[i].href) {
2021-08-27 14:37:31 +00:00
newData[i].page = "LegacyFrame";
}
2021-08-17 21:48:08 +00:00
// Tasks group need pie chart icon
if (data[i].header && data[i].id === "FOLDERS") {
data[i] = {
component: CustomSidebarMenuItem,
props: {
isCollapsed: this.collapsed? true: false,
item: {
2021-09-17 23:14:57 +00:00
href: "/task-metrics/" + data[i].id,
icon: "fas fa-chart-pie",
id: "TASK_METRICS",
page: "task-metrics",
2021-08-17 21:48:08 +00:00
title: data[i].title,
2021-09-28 20:32:06 +00:00
header: data[i] && !data[i].permission? true : null,
specialType: data[i] && data[i].permission? "header" : null
2021-08-17 21:48:08 +00:00
}
}
2021-09-17 23:14:57 +00:00
};
2021-09-28 20:32:06 +00:00
2021-08-17 21:48:08 +00:00
}
2021-08-27 14:37:31 +00:00
if (data[i].customCasesList) {
2021-08-20 16:09:30 +00:00
data[i]["child"] = this.sortCustomCasesList(
data[i].customCasesList,
this.config.setting[data[i]["page"]] &&
this.config.setting[data[i]["page"]].customCaseListOrder
? this.config.setting[data[i]["page"]].customCaseListOrder
2021-08-20 16:09:30 +00:00
: []
);
2021-08-17 21:48:08 +00:00
data[i]["sortable"] = data[i].customCasesList.length > 1;
data[i]["sortIcon"] = "gear-fill";
data[i]['highlight'] = false;
2021-08-17 21:48:08 +00:00
data[i] = {
2021-08-20 03:40:20 +00:00
component: CustomSidebarMenuItem,
2021-08-17 21:48:08 +00:00
props: {
isCollapsed: this.collapsed? true: false,
item: data[i],
showOneChild: true
2021-08-17 21:48:08 +00:00
}
};
}
}
return newData;
},
2021-08-20 04:16:37 +00:00
/**
* Sort the custom case list menu items
* @param {array} list
* @param {array} ref
* @returns {array}
*/
2021-08-20 03:40:20 +00:00
sortCustomCasesList(list, ref) {
let item,
newList = [],
temp = [];
if (ref && ref.length) {
ref.forEach(function (menu) {
item = list.find(x => x.id === menu.id);
if (item) {
newList.push(item);
}
})
} else {
return list;
}
temp = list.filter(this.comparerById(newList));
return [...newList, ...temp];
},
2021-08-20 04:16:37 +00:00
/**
2021-08-20 04:18:00 +00:00
* Util to compare an array by id
2021-08-20 04:16:37 +00:00
* @param {array} otherArray
* @returns {object}
*/
2021-08-20 03:40:20 +00:00
comparerById(otherArray){
return function(current){
return otherArray.filter(function(other){
return other.id == current.id
}).length == 0;
}
},
/**
* Set a default icon if the item doesn't have one
*/
setDefaultIcon(data){
var i,
auxData = data;
for (i = 0; i < auxData.length; i += 1) {
if (auxData[i].icon !== undefined && auxData[i].icon === "") {
auxData[i].icon = "fas fa-bars";
}
}
return auxData;
},
/**
* Clean the default option property
*/
cleanDefaultOption() {
this.defaultOption = "";
},
/**
* Page view factory
* @param {object} item
*/
pageFactory(item){
this.filters = [];
2021-09-22 16:37:52 +00:00
this.lastPage = this.page;
this.page = item.item.page;
this.filters = item.item.filters;
this.pageId = item.item.id;
this.pageUri = item.item.href;
this.pageName = item.item.title;
this.settings = this.config.setting[this.page];
this.pageData = {
pageUri: item.item.pageUri,
pageParent: item.item.page,
pageName: item.item.title,
pageIcon: item.item.icon,
customListId: item.item.id,
color: item.item.colorScreen,
settings: this.settings
}
//Custom Cases List
2021-09-15 16:16:21 +00:00
if (!this.menuMap[item.item.id] && item.item.page !== "LegacyFrame" && item.item.page !== "advanced-search" ) {
this.page = "custom-case-list";
if (this.config.setting[item.item.page] && this.config.setting[item.item.page]["customCaseList"]) {
this.pageData.settings = this.config.setting[item.item.page]["customCaseList"][item.item.id];
2021-09-23 18:09:33 +00:00
this.settings = this.pageData.settings;
} else {
this.pageData.settings = {};
2020-12-28 19:02:06 +00:00
}
}
if (this.page === this.lastPage
&& this.$refs["component"]
&& this.$refs["component"].updateView) {
this.$refs["component"].updateView(this.pageData);
}
},
/**
* Click sidebar menu item handler
* @param {object} item
*/
OnClickSidebarItem(item) {
this.pageFactory(item);
},
setCounter() {
let that = this,
counters = [];
if (that.menu.length > 0) {
api.menu
.getCounters()
.then((response) => {
var i,
j,
data = response.data;
that.counters = data;
for (i = 0; i < that.menu.length; i += 1) {
if (that.menu[i].id && data[that.menu[i].id]) {
that.menu[i].badge.text = data[that.menu[i].id];
}
}
})
.catch((e) => {
console.error(e);
});
}
},
onResize() {
if (window.innerWidth <= 767) {
this.isOnMobile = true;
this.collapsed = true;
} else {
this.isOnMobile = false;
this.collapsed = false;
}
},
/**
* Toggle sidebar handler
* @param {Boolean} collapsed - if sidebar is collapsed true|false
*
*/
onToggleCollapse(collapsed) {
this.collapsed = collapsed;
},
/**
* Handle if filter was submited
*/
onSubmitFilter(data) {
this.addMenuSearchChild(data);
},
/**
* Add a child submenu to search menu
* @param {object} data - cnotains theinfo to generate a menu
*/
addMenuSearchChild(data) {
let newMenu = this.menu;
let advSearch = _.find(newMenu, function(o) {
return o.id === "CASES_SEARCH";
});
if (advSearch) {
const index = advSearch.child.findIndex(function(o) {
return o.id === data.id;
});
if (index !== -1) {
advSearch.child[index].filters = data.filters;
} else {
if (!advSearch.hasOwnProperty("child")) {
advSearch["child"] = [];
}
advSearch.child.push({
filters: data.filters,
href: "/advanced-search/" + data.id,
title: data.name,
icon: "fas fa-circle",
id: data.id,
page: "advanced-search",
});
}
}
},
onRemoveFilter(id) {
this.removeMenuSearchChild(id);
this.resetSettings();
},
resetSettings() {
this.page = "advanced-search";
this.pageId = null;
this.pageName = null;
this.filters = [];
},
2020-12-11 19:36:41 +00:00
onUpdatePage(page) {
this.lastPage = this.page;
this.page = page;
2020-12-28 19:02:06 +00:00
if (this.$refs["component"] && this.$refs["component"].updateView) {
this.$refs["component"].updateView();
}
2020-12-11 19:36:41 +00:00
},
onUpdateDataCase(data) {
this.dataCase = data;
},
onLastPage() {
2020-12-11 19:36:41 +00:00
this.page = this.lastPage;
this.lastPage = "MyCases";
2020-12-11 19:36:41 +00:00
},
removeMenuSearchChild(id) {
let newMenu = this.menu;
let advSearch = _.find(newMenu, function(o) {
return o.id === "CASES_SEARCH";
});
if (advSearch) {
const index = advSearch.child.findIndex(function(o) {
return o.id === id;
});
if (index !== -1) advSearch.child.splice(index, 1);
}
},
2021-09-06 20:07:48 +00:00
/**
* Update filters handler
*/
onUpdateFilters(filters) {
this.filters = filters;
},
2021-09-06 20:07:48 +00:00
/**
* Service to get Highlight
*/
getHighlight() {
let that = this;
if (that.menu.length > 0) {
api.menu
.getHighlight()
.then((response) => {
var i,
dataHighlight = [];
for (i = 0; i < response.data.length; i += 1) {
if (response.data[i].highlight) {
dataHighlight.push({
id: that.menuMap[response.data[i].item],
highlight: response.data[i].highlight
});
}
}
eventBus.$emit('highlight', dataHighlight);
})
.catch((e) => {
console.error(e);
});
}
2021-09-10 22:58:21 +00:00
},
/**
* Search in menu Items by value, return the item
* @param {string} key - Key for search in object
* @param {string} value - value for search in key
*/
getItemMenuByValue(key, value) {
let obj = _.find(this.menu, function(o) {
if(o.component){
return o.props.item[key] == value;
}
return o[key] == value;
});
if(obj.component){
return obj.props;
}
return obj;
},
/**
* Show the alert message
* @param {string} message - message to be displayen in the body
* @param {string} type - alert type
*/
showAlert(message, type) {
this.dataAlert.message = message;
this.dataAlert.variant = type || "info";
this.dataAlert.dismissCountDown = this.dataAlert.dismissSecs;
},
/**
* Updates the alert dismiss value to update
* dismissCountDown and decrease
* @param {mumber}
*/
countDownChanged(dismissCountDown) {
this.dataAlert.dismissCountDown = dismissCountDown;
},
}
2020-12-02 19:46:17 +00:00
};
</script>
<style lang="scss">
#home {
padding-left: 260px;
transition: 0.3s;
2020-12-02 19:46:17 +00:00
}
#home.collapsed {
padding-left: 50px;
2020-12-02 19:46:17 +00:00
}
#home.onmobile {
padding-left: 50px;
2020-12-02 19:46:17 +00:00
}
.container {
max-width: 1500px;
2020-12-02 19:46:17 +00:00
}
</style>