Files
luos/resources/assets/js/home/TaskMetrics/VueChartLvOne.vue

468 lines
11 KiB
Vue
Raw Normal View History

2021-07-30 20:18:11 +00:00
<template>
2021-08-12 19:05:50 +00:00
<div id="v-pm-charts" ref="v-pm-charts" class="v-pm-charts vp-inline-block">
<div class="p-1 v-flex">
2021-08-27 21:29:54 +00:00
<h6 class="v-search-title">
{{ $t("ID_DRILL_DOWN_NUMBER_TASKS_PROCESS") }}
</h6>
2021-08-12 19:05:50 +00:00
<div>
2021-08-16 18:54:43 +00:00
<BreadCrumb
:options="breadCrumbs.data"
2021-08-26 20:33:59 +00:00
:settings="settingsBreadcrumbs"
2021-08-16 18:54:43 +00:00
/>
2021-08-12 19:05:50 +00:00
<ProcessPopover
:options="optionsProcesses"
2021-09-13 20:00:12 +00:00
@onChange="onChangeSearchPopover"
2021-08-12 19:05:50 +00:00
target="pm-task-process"
ref="pm-task-process"
@onUpdateColumnSettings="onUpdateColumnSettings"
/>
<div class="vp-width-p40 vp-inline-block">
<multiselect
v-model="category"
:options="optionsCategory"
:searchable="false"
2021-08-26 20:33:59 +00:00
:close-on-select="true"
2021-08-12 19:05:50 +00:00
:show-labels="false"
track-by="id"
label="name"
@select="changeOption"
></multiselect>
</div>
2021-09-22 20:51:38 +00:00
<label class="vp-inline-block vp-padding-l20">{{ $t("ID_TOP10") }}</label>
2021-08-12 19:05:50 +00:00
<div class="vp-inline-block">
2021-08-16 18:54:43 +00:00
<b-form-checkbox
v-model="top"
name="check-button"
@change="changeOption"
switch
>
2021-08-12 19:05:50 +00:00
</b-form-checkbox>
</div>
2021-09-22 14:54:09 +00:00
<b-popover
ref="popover"
:target="popoverTarget"
variant="secondary"
placement="right"
>
<div class="vp-chart-minipopover">
<div class="vp-align-right vp-flex1">
<button
type="button"
class="btn btn-link btn-sm"
@click="onClickDrillDown"
>
<i class="fas fa-chart-line"></i>
{{ $t("ID_DRILL") }}
</button>
</div>
<div class="vp-flex1">
<button
type="button"
class="btn btn-link btn-sm"
@click="onClickData"
>
<i class="fas fa-th"></i>
{{ $t("ID_DATA") }}
</button>
</div>
</div>
</b-popover>
2021-08-12 19:05:50 +00:00
<div class="vp-inline-block vp-right vp-padding-r40">
<h4
class="v-search-title"
@click="showProcessesPopover"
id="pm-task-process"
>
<i class="fas fa-cog"></i>
</h4>
</div>
</div>
<apexchart
ref="LevelOneChart"
:width="width"
:options="optionsBar"
:series="seriesBar"
></apexchart>
</div>
</div>
2021-07-30 20:18:11 +00:00
</template>
<script>
import _ from "lodash";
2021-09-22 14:54:09 +00:00
import jquery from "jquery";
2021-07-30 20:18:11 +00:00
import Api from "../../api/index";
2021-08-12 19:05:50 +00:00
import BreadCrumb from "../../components/utils/BreadCrumb.vue";
import ProcessPopover from "./ProcessPopover.vue";
2021-08-04 16:25:56 +00:00
import Multiselect from "vue-multiselect";
2021-09-22 14:54:09 +00:00
import eventBus from "./../EventBus/eventBus";
2021-07-30 20:18:11 +00:00
2021-08-04 16:25:56 +00:00
export default {
2021-08-12 19:05:50 +00:00
name: "VueChartLvOne",
mixins: [],
components: {
Multiselect,
BreadCrumb,
ProcessPopover,
},
2021-08-16 18:54:43 +00:00
props: ["data", "breadCrumbs"],
2021-08-12 19:05:50 +00:00
data() {
let that = this;
return {
2021-09-22 14:54:09 +00:00
popoverTarget: "",
showPopover: false,
2021-08-12 19:05:50 +00:00
category: null,
dataProcesses: null, //Data API processes
2021-08-26 20:33:59 +00:00
settingsBreadcrumbs: [
{
class: "fas fa-info-circle",
tooltip: this.$t("ID_TASK_RISK_LEVEL1_INFO"),
onClick() {},
},
],
2021-08-12 19:05:50 +00:00
optionsCategory: [],
optionsProcesses: [],
selectedProcesses: [],
top: false,
width: 0,
totalCases: [],
currentSelection: null,
seriesBar: [
{
data: [],
},
],
optionsBar: {
chart: {
type: "bar",
id: "LevelOneChart",
toolbar: {
show: false,
},
events: {
2021-09-22 14:54:09 +00:00
click: function (event, chartContext, config) {
that.$refs.popover.$emit("close");
if (config.dataPointIndex != -1) {
that.currentSelection = that.totalCases[config.dataPointIndex];
that.onShowDrillDownOptions(
event.currentTarget,
config.dataPointIndex
);
}
2021-08-12 19:05:50 +00:00
},
},
},
plotOptions: {
bar: {
barHeight: "100%",
distributed: true,
horizontal: true,
},
},
colors: ["#33b2df", "#546E7A", "#d4526e", "#13d8aa"],
dataLabels: {
enabled: false,
},
xaxis: {
categories: [],
},
tooltip: {
x: {
show: false,
},
y: {
title: {
formatter: function () {
return "";
},
},
},
},
},
};
},
created() {},
mounted() {
this.getBodyHeight();
this.getCategories();
this.getProcesses();
},
watch: {},
computed: {},
updated() {},
beforeCreate() {},
methods: {
/**
* Return the height for Vue Card View body
*/
getBodyHeight() {
this.width = window.innerHeight;
},
/**
* Get Categories form API
*/
getCategories() {
let that = this;
Api.filters
.categories()
.then((response) => {
that.formatDataCategories(response.data);
})
.catch((e) => {
console.error(err);
});
},
/**
* Get Processes form API
2021-09-14 13:55:53 +00:00
* @param {string} query - Text value in search popover
2021-08-12 19:05:50 +00:00
*/
2021-09-13 20:00:12 +00:00
getProcesses(query) {
2021-08-12 19:05:50 +00:00
let that = this;
Api.filters
2021-09-13 20:00:12 +00:00
.processList(query || "")
2021-08-12 19:05:50 +00:00
.then((response) => {
that.formatDataProcesses(response.data);
that.changeOption({
2021-09-16 18:53:49 +00:00
id: "all",
2021-08-12 19:05:50 +00:00
});
})
.catch((e) => {
console.error(err);
});
},
/**
* Format categories for multiselect
2021-08-27 21:29:54 +00:00
* @param {*} data
2021-08-12 19:05:50 +00:00
*/
formatDataCategories(data) {
let array = [];
2021-09-16 18:53:49 +00:00
array.push({
name: this.$t("ID_ALL_CATEGORIES"),
id: "all",
});
2021-08-12 19:05:50 +00:00
array.push({
2021-08-26 21:10:56 +00:00
name: this.$t("ID_PROCESS_NONE_CATEGORY"),
2021-08-12 19:05:50 +00:00
id: "0",
});
_.each(data, (el) => {
array.push({ name: el["CATEGORY_NAME"], id: el["CATEGORY_ID"] });
});
this.optionsCategory = array;
this.category = array[0];
},
/**
* Format processes for popover
2021-08-27 21:29:54 +00:00
* @param {*} data
2021-08-12 19:05:50 +00:00
*/
formatDataProcesses(data) {
let sels = [],
labels = [],
array = [];
_.each(data, (el) => {
array.push({ value: el["PRO_TITLE"], key: el["PRO_ID"] });
sels.push(el["PRO_ID"]);
labels;
});
this.optionsProcesses = array;
this.selectedProcesses = sels;
//Update the labels
this.dataProcesses = data;
},
/**
* Change the options in TOTAL CASES BY PROCESS
2021-08-27 21:29:54 +00:00
* @param {*} option
2021-08-12 19:05:50 +00:00
*/
changeOption(option) {
let that = this,
dt = {};
if (this.data.length > 1) {
2021-08-12 19:05:50 +00:00
dt = {
category: option.id,
caseList: this.data[1].id.toLowerCase(),
2021-08-12 19:05:50 +00:00
processes: this.selectedProcesses,
2021-08-16 18:54:43 +00:00
top: this.top,
2021-08-12 19:05:50 +00:00
};
2021-09-22 14:54:09 +00:00
option.id == "all" ? delete dt.category : null;
2021-08-12 19:05:50 +00:00
Api.process
.totalCasesByProcess(dt)
.then((response) => {
that.totalCases = response.data;
that.formatTotalCases(response.data);
})
2021-08-12 19:05:50 +00:00
.catch((e) => {
console.error(err);
});
}
},
/**
* Show the processes popover
*/
showProcessesPopover() {
this.$root.$emit("bv::show::popover", "pm-task-process");
this.$refs["pm-task-process"].setOptions(this.optionsProcesses);
this.$refs["pm-task-process"].setSelectedOptions(this.selectedProcesses);
},
2021-08-26 21:10:56 +00:00
/**
* Format response form BE to chart
2021-08-27 21:29:54 +00:00
* @param {*} data
2021-08-26 21:10:56 +00:00
*/
2021-08-12 19:05:50 +00:00
formatTotalCases(data) {
let serie = [],
labels = [];
_.each(data, (el) => {
serie.push(el["TOTAL"]);
labels.push(el["PRO_TITLE"]);
});
2021-08-16 18:54:43 +00:00
2021-08-12 19:05:50 +00:00
this.$refs["LevelOneChart"].updateOptions({ labels: labels });
this.$apexcharts.exec("LevelOneChart", "updateSeries", [
{
data: serie,
},
]);
},
/**
* Update list processes in chart
2021-08-27 21:29:54 +00:00
* @param {*} data
2021-08-12 19:05:50 +00:00
*/
onUpdateColumnSettings(data) {
let res;
this.selectedProcesses = data;
res = _.intersectionBy(this.totalCases, data, (el) => {
if (_.isNumber(el)) {
return el;
}
if (_.isObject(el) && el["PRO_ID"]) {
return el["PRO_ID"];
}
});
this.formatTotalCases(res);
},
2021-08-26 21:10:56 +00:00
/**
* Update labels in chart
2021-08-27 21:29:54 +00:00
* @param {*} processes
2021-08-26 21:10:56 +00:00
*/
2021-08-12 19:05:50 +00:00
updateLabels(processes) {
let labels = [];
_.each(processes, (el) => {
labels.push(el["PRO_TITLE"]);
});
this.$refs["LevelOneChart"].updateOptions({ labels: labels });
},
2021-08-26 21:10:56 +00:00
/**
* UPdate serie in chart
2021-08-27 21:29:54 +00:00
* @param {*} processes
2021-08-26 21:10:56 +00:00
*/
2021-08-12 19:05:50 +00:00
updateSerie(processes) {
let labels = [];
_.each(processes, (el) => {
labels.push(el["TOTAL"]);
});
this.$refs["LevelOneChart"].updateOptions({ labels: labels });
},
2021-08-16 18:54:43 +00:00
/**
* Force update view when update level
*/
forceUpdateView() {
this.changeOption({
id: 0,
});
},
2021-09-13 20:00:12 +00:00
/**
* Event handler change input search popover
* @param {string} query - value in popover search input
*/
2021-09-22 14:54:09 +00:00
onChangeSearchPopover(query) {
2021-09-13 20:00:12 +00:00
this.getProcesses(query);
2021-09-22 14:54:09 +00:00
},
/**
* Show popover drill down options
* @param {objHtml} target
* @param {number} index
*/
onShowDrillDownOptions(target, index) {
let obj,
dt,
that = this;
if (index != -1) {
obj = jquery(target).find("path")[index];
dt = this.dataProcesses[index];
this.popoverTarget = obj.id;
setTimeout(() => {
that.$refs.popover.$emit("open");
}, 200);
}
},
/**
* Show popover drill down options
*/
onClickDrillDown() {
this.$emit("updateDataLevel", {
id: this.currentSelection["PRO_ID"],
name: this.currentSelection["PRO_TITLE"],
level: 2,
2021-09-22 14:54:09 +00:00
data: this.currentSelection,
});
},
/**
* Show popover data options
*/
onClickData() {
let taskList = this.data[1].id.toLowerCase(),
2021-09-22 14:54:09 +00:00
obj = {
autoshow: false,
fieldId: "processName",
filterVar: "process",
label: "",
options: {
label: this.currentSelection["PRO_TITLE"],
value: this.currentSelection["PRO_ID"],
},
value: this.currentSelection["PRO_ID"],
};
2021-09-22 16:37:52 +00:00
eventBus.$emit("home::update-settings", {
data: [obj],
key: "filters",
page: taskList,
type: "normal",
2021-09-22 14:54:09 +00:00
});
2021-09-22 16:37:52 +00:00
eventBus.$emit("home::sidebar::click-item", taskList);
2021-09-22 14:54:09 +00:00
},
2021-08-12 19:05:50 +00:00
},
2021-07-30 20:18:11 +00:00
};
</script>
<style>
2021-08-04 16:25:56 +00:00
.vp-task-metrics-label {
2021-08-12 19:05:50 +00:00
display: inline-block;
2021-08-04 16:25:56 +00:00
}
.vp-width-p40 {
2021-08-12 19:05:50 +00:00
width: 40%;
2021-07-30 20:18:11 +00:00
}
2021-08-04 16:25:56 +00:00
.vp-inline-block {
2021-08-12 19:05:50 +00:00
display: inline-block;
}
.vp-padding-l20 {
padding-left: 20px;
}
.vp-padding-r40 {
padding-right: 40px;
}
.vp-right {
float: right;
2021-07-30 20:18:11 +00:00
}
2021-09-22 14:54:09 +00:00
.vp-chart-minipopover {
display: flex;
}
.vp-flex1 {
flex: 1;
}
2021-08-04 16:25:56 +00:00
</style>
<style src="vue-multiselect/dist/vue-multiselect.min.css"></style>