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

359 lines
11 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">
<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"
:filters="filters"
:id="pageId"
:pageUri="pageUri"
:name="pageName"
:defaultOption="defaultOption"
@onSubmitFilter="onSubmitFilter"
@onRemoveFilter="onRemoveFilter"
2020-12-11 19:36:41 +00:00
@onUpdatePage="onUpdatePage"
@onUpdateDataCase="onUpdateDataCase"
@onLastPage="onLastPage"
@onUpdateFilters="onUpdateFilters"
@cleanDefaultOption="cleanDefaultOption"
></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";
import MyCases from "./MyCases";
2020-12-02 21:28:16 +00:00
import MyDocuments from "./MyDocuments";
2021-07-08 15:00:07 +00:00
import Todo from "./Inbox/Todo.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";
2020-12-07 15:59:15 +00:00
import Unassigned from "./Unassigned";
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";
2020-12-07 18:52:12 +00:00
import AdvancedSearch from "./AdvancedSearch";
import LegacyFrame from "./LegacyFrame";
2020-12-02 19:46:17 +00:00
import api from "./../api/index";
2020-12-02 19:46:17 +00:00
export default {
name: "Home",
components: {
CustomSidebar,
MyCases,
AdvancedSearch,
MyDocuments,
BatchRouting,
TaskReassignments,
XCase,
Todo,
Draft,
Paused,
Unassigned,
CaseDetail,
LegacyFrame
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,
menuMap: {
CASES_MY_CASES: "MyCases",
CASES_SENT: "MyCases",
CASES_SEARCH: "advanced-search",
CASES_INBOX: "todo",
CASES_DRAFT: "draft",
CASES_PAUSED: "paused",
CASES_SELFSERVICE: "unassigned",
CONSOLIDATED_CASES: "batch-routing",
CASES_TO_REASSIGN: "task-reassignments",
CASES_FOLDERS: "my-documents"
},
defaultOption: window.config.defaultOption || ''
};
2020-12-04 13:33:23 +00:00
},
mounted() {
this.onResize();
this.getMenu();
2020-12-16 18:26:40 +00:00
this.listenerIframe();
window.setInterval(
this.setCounter,
parseInt(window.config.FORMATS.casesListRefreshTime) * 1000
);
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"){
2020-12-16 18:26:40 +00:00
that.page = "todo";
}
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.setCounter();
})
.catch((e) => {
console.error(e);
});
},
/**
* Set default cases menu option
*/
setDefaultCasesMenu(data) {
let 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";
}
this.lastPage = this.page;
},
/**
* Do a mapping of vue view for menus
* @returns array
*/
mappingMenu(data) {
var i,
j,
newData = data,
auxId;
for (i = 0; i < data.length; i += 1) {
auxId = data[i].id || "";
if (auxId !== "" && this.menuMap[auxId]) {
newData[i].id = this.menuMap[auxId];
} else if (newData[i].href) {
newData[i].id = "LegacyFrame";
}
}
return newData;
},
/**
* 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 = "";
},
OnClickSidebarItem(item) {
if (item.item.page && item.item.page === "/advanced-search") {
this.page = "advanced-search";
this.filters = item.item.filters;
this.pageId = item.item.id;
this.pageUri = item.item.href;
this.pageName = item.item.title;
} else {
this.filters = [];
this.pageId = null;
this.pageUri = item.item.href;
this.page = item.item.id || "MyCases";
if (this.page === this.lastPage
&& this.$refs["component"]
&& this.$refs["component"].updateView) {
2020-12-28 19:02:06 +00:00
this.$refs["component"].updateView();
}
this.lastPage = this.page;
}
},
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 === "advanced-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 === "advanced-search";
});
if (advSearch) {
const index = advSearch.child.findIndex(function(o) {
return o.id === id;
});
if (index !== -1) advSearch.child.splice(index, 1);
}
},
onUpdateFilters(filters) {
this.filters = filters;
}
}
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>