feat(feat(init): serviceOfMachines):
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import {scandApiRequest} from '@helpers/apiHelpers.js'
|
||||
import {Adapter} from '1-toolkits-helpers'
|
||||
|
||||
const {convertList} = Adapter
|
||||
|
||||
const machinesConfig = {
|
||||
zav_nomer: 'zavNomer',
|
||||
type: 'type',
|
||||
railway_name: 'railwayName',
|
||||
org_name: 'orgName',
|
||||
nomer_zn8: 'nomerZn8',
|
||||
machine_type: 'machineType',
|
||||
machine_id: 'machineId',
|
||||
imei: 'imei',
|
||||
device_number: 'deviceNumber',
|
||||
device_id: 'deviceId'
|
||||
}
|
||||
|
||||
class AdapterOfMachines {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {String} url
|
||||
*/
|
||||
constructor(url) {
|
||||
this.url = url
|
||||
}
|
||||
|
||||
async getModalMachines() {
|
||||
let result = await scandApiRequest('ScandApi.LiveMonitor.Machines', 'select_machines', [])
|
||||
result = convertList(result, {
|
||||
config: machinesConfig
|
||||
})
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
export default AdapterOfMachines
|
||||
@@ -57,11 +57,11 @@ export default {
|
||||
const urlParams = path.value === '/' && query?.value?.mode ? query.value.mode : ''
|
||||
const externalParams = {historyData: updatedData, urlParams: urlParams}
|
||||
|
||||
store.commit('machines/setHistoryData', updatedData)
|
||||
store.dispatch('machines/uploadData', externalParams)
|
||||
store.commit('layoutMachines/setHistoryData', updatedData)
|
||||
store.dispatch('layoutMachines/uploadData', externalParams)
|
||||
},
|
||||
computed: {
|
||||
...mapGetters('machines', ['searchModes', 'searchValue', 'selectedSearchMode', 'leftTopButtons', 'rightTopButtons', 'selectedMode', 'toggleFilter', 'activeFilterBtn', 'mapData', 'machinesData']),
|
||||
...mapGetters('layoutMachines', ['searchModes', 'searchValue', 'selectedSearchMode', 'leftTopButtons', 'rightTopButtons', 'selectedMode', 'toggleFilter', 'activeFilterBtn', 'mapData', 'machinesData']),
|
||||
...mapGetters('layout', ['isOpenMenu']),
|
||||
},
|
||||
mounted () {
|
||||
@@ -81,7 +81,7 @@ export default {
|
||||
},
|
||||
unmounted() {
|
||||
const store = useStore();
|
||||
store.dispatch('machines/resetStore')
|
||||
store.dispatch('layoutMachines/resetStore')
|
||||
},
|
||||
watch: {
|
||||
isSuccessSearch: {
|
||||
@@ -92,8 +92,8 @@ export default {
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
...mapMutations('machines', ['setSearchMode', 'setSelectedMode', 'setToggleFilter', 'setActiveFilterBtn']),
|
||||
...mapActions('machines', ['updateSearch', 'clearFilters']),
|
||||
...mapMutations('layoutMachines', ['setSearchMode', 'setSelectedMode', 'setToggleFilter', 'setActiveFilterBtn']),
|
||||
...mapActions('layoutMachines', ['updateSearch', 'clearFilters']),
|
||||
updateSearchMode: function(selectedSearchMode) {
|
||||
this.setSearchMode(selectedSearchMode)
|
||||
},
|
||||
|
||||
@@ -69,9 +69,6 @@ export default {
|
||||
|
||||
<template>
|
||||
<div class="col-span-12">
|
||||
<div class="hidden" id="ignore:21QxOfq">
|
||||
{{ console.log('selectedPage', selectedPage) }}
|
||||
</div>
|
||||
<div class="p-2 sm:px-5 pt-1 bg-light rounded-t-xl">
|
||||
<div class="relative">
|
||||
<div class="flex gap-3 sm:gap-7 w-full lg:w-[50%]">
|
||||
|
||||
54
live_monitor_vue/src/helpers/apiHelpers.js
Normal file
54
live_monitor_vue/src/helpers/apiHelpers.js
Normal file
@@ -0,0 +1,54 @@
|
||||
import axios from "axios";
|
||||
|
||||
const post = async (path, data, onError) => {
|
||||
return axios.post(`${path}`, data)
|
||||
.then(r => r.data)
|
||||
.catch(error => {
|
||||
onError && onError(error)
|
||||
console.error('Error post request:', error)
|
||||
})
|
||||
}
|
||||
|
||||
const get = async (path) => {
|
||||
return axios.get(`${path}`)
|
||||
.then(r => r.data)
|
||||
.catch(error => {
|
||||
console.error('Error post request:', error)
|
||||
})
|
||||
}
|
||||
|
||||
const put = async (path, data, onError) => {
|
||||
return axios.put(`${path}`, data)
|
||||
.then(r => r.data)
|
||||
.catch(error => {
|
||||
onError && onError(error)
|
||||
console.error('Error put request:', error)
|
||||
})
|
||||
}
|
||||
|
||||
const remove = async (path, onError) => {
|
||||
return axios.delete(`${path}`)
|
||||
.then(r => r.data)
|
||||
.catch(error => {
|
||||
onError && onError(error)
|
||||
console.error('Error delete request:', error)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for request to scand api
|
||||
* @param {String} module
|
||||
* @param {String} functionName
|
||||
* @param {Array} params
|
||||
* @param {String | undefined} onError
|
||||
* @returns {Promise<Promise<unknown | void | Array | Object> | *>}
|
||||
*/
|
||||
const scandApiRequest = async (module, functionName, params, onError= undefined) => {
|
||||
return post('http://0.0.0.0:9999/scand/api/get_data', {
|
||||
module,
|
||||
function: functionName,
|
||||
params
|
||||
}, onError)
|
||||
}
|
||||
|
||||
export {get, post, put, remove, scandApiRequest}
|
||||
@@ -9,7 +9,7 @@ import "./helpers/dropdown.js"
|
||||
|
||||
|
||||
createApp(App)
|
||||
.use(Router)
|
||||
.use(ramdaVue)
|
||||
.use(store)
|
||||
.mount('#app')
|
||||
.use(Router)
|
||||
.use(ramdaVue)
|
||||
.use(store)
|
||||
.mount('#app')
|
||||
|
||||
24
live_monitor_vue/src/services/ServiceOfMachines.js
Normal file
24
live_monitor_vue/src/services/ServiceOfMachines.js
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
class ServiceOfMachines {
|
||||
constructor(adapter, store) {
|
||||
this.adapter = adapter
|
||||
this.store = store
|
||||
}
|
||||
|
||||
async fetchModalMachines() {
|
||||
return await this.adapter.getModalMachines()
|
||||
}
|
||||
|
||||
async putModalMachines(machines) {
|
||||
const result = await this.store.dispatch('machines/saveModalMachines', machines)
|
||||
return result
|
||||
}
|
||||
|
||||
async makeFetchAndPutModalMachines() {
|
||||
const machines = await this.fetchModalMachines()
|
||||
await this.putModalMachines(machines)
|
||||
return machines
|
||||
}
|
||||
}
|
||||
|
||||
export default ServiceOfMachines
|
||||
@@ -1,6 +1,7 @@
|
||||
import { createStore, createLogger } from 'vuex';
|
||||
import { store as main } from '@/store/modules/main';
|
||||
import { store as machines } from '@/store/modules/machines';
|
||||
import { store as layoutMachines } from '@/store/modules/machines';
|
||||
import { store as finder_packs } from '@/store/modules/finder_packs';
|
||||
import { store as add_users } from '@/store/modules/add_users';
|
||||
import { store as layout } from '@/store/modules/layout';
|
||||
@@ -21,6 +22,7 @@ export const store = createStore({
|
||||
plugins,
|
||||
modules: {
|
||||
main,
|
||||
layoutMachines,
|
||||
machines,
|
||||
finder_packs,
|
||||
add_users,
|
||||
@@ -35,5 +37,5 @@ export const store = createStore({
|
||||
});
|
||||
|
||||
export function useStore() {
|
||||
return store;
|
||||
return store;
|
||||
}
|
||||
|
||||
2854
live_monitor_vue/src/store/modules/layoutMachines/StaticData.js
Normal file
2854
live_monitor_vue/src/store/modules/layoutMachines/StaticData.js
Normal file
File diff suppressed because it is too large
Load Diff
120
live_monitor_vue/src/store/modules/layoutMachines/helpers.js
Normal file
120
live_monitor_vue/src/store/modules/layoutMachines/helpers.js
Normal file
@@ -0,0 +1,120 @@
|
||||
import {isEmpty, uniq} from 'ramda'
|
||||
import {pagination, searchModes} from './StaticData'
|
||||
|
||||
const prepareSelects = (selects, selectors) => {
|
||||
const updatedSelects = selects.reduce((acc, el) => {
|
||||
if (selectors[el.key]) {
|
||||
const newEl = {...el, data: selectors[el.key]}
|
||||
acc = [...acc, newEl]
|
||||
} else {
|
||||
acc
|
||||
}
|
||||
return acc
|
||||
}, [])
|
||||
// console.log('updSelects', updatedSelects)
|
||||
|
||||
const filteredSelects = updatedSelects.map((el) => ({...el, data: el.data.reduce((acc, select) => {
|
||||
if (select) {
|
||||
const newSelect = {name: select}
|
||||
acc = [...acc, newSelect]
|
||||
} else {
|
||||
acc
|
||||
}
|
||||
return acc
|
||||
}, [])
|
||||
})).sort((a, b) => a.order - b.order)
|
||||
// console.log('filteredSelects', filteredSelects)
|
||||
return filteredSelects
|
||||
}
|
||||
|
||||
const mergedMachines = (machinesData, historyData) => {
|
||||
const orderHistoryData = historyData.map((el, idx) => ({...el, order: idx}))
|
||||
const historyMachinesIds = orderHistoryData.filter((el, idx, arr) => arr.findIndex((item) => item.machine_id === el.machine_id) === idx).map((el) => el.machine_id)
|
||||
const historyMachines = Array.from(machinesData).filter((el) => historyMachinesIds.find((id) => id === el.machine_id)).sort((a, b) => a.order - b.order)
|
||||
const countHistoryNachines = historyMachines.length > 0 ? historyMachines.slice(0, 20).length : 0
|
||||
const currentMachines = machinesData.slice(0, 20 - countHistoryNachines)
|
||||
return [...historyMachines.slice(0, 20), ...currentMachines]
|
||||
}
|
||||
|
||||
const colorSelection = (key, value) => {
|
||||
if(key) {
|
||||
const machinesContainer = document.querySelector('#listMachines')
|
||||
const allSearchField = machinesContainer ? machinesContainer.querySelectorAll('[search-mode]') : null
|
||||
if (allSearchField) {
|
||||
allSearchField.forEach((el) => {
|
||||
el.style = ''
|
||||
})
|
||||
}
|
||||
if (value) {
|
||||
const searchField = machinesContainer ? machinesContainer.querySelectorAll(`[search-mode=${key}]`) : null
|
||||
if (searchField) {
|
||||
searchField.forEach((el) => {
|
||||
el.style.width = "fit-content"
|
||||
el.style.padding = "2px"
|
||||
// el.style.color = "#FFF"
|
||||
el.style.borderRadius = "3px"
|
||||
el.style.backgroundColor = "rgb(1 97 253 / 30%)"
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const findMachine = (machine, filters) => {
|
||||
const isArr = filters && Array.isArray(filters)
|
||||
if (isArr) {
|
||||
const filteredMachine = filters.filter((filter) => {
|
||||
if (machine === filter) {
|
||||
return machine
|
||||
}
|
||||
})
|
||||
return filteredMachine.length > 0 ? true : false
|
||||
}
|
||||
if (!isArr) {
|
||||
if (`${machine}`.includes(filters)) { // Для поиска неточное совпадение
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
const setUpdatedDataMachines = (machines, params) => {
|
||||
const filters = params.filter
|
||||
if(!isEmpty(filters)) {
|
||||
const searchModeKeys = searchModes.map((el) => el.key)
|
||||
const searchData = filters.find((filter) => (searchModeKeys.includes(Object.entries(filter)[0][0])))
|
||||
const currentFilters = searchData ? [searchData] : filters
|
||||
const filteredMachines = machines.filter((machine) => {
|
||||
return currentFilters.find((filter) => {
|
||||
const entries = Object.entries(filter)
|
||||
if (!isEmpty(entries) && machine[entries[0][0]] && findMachine(machine[entries[0][0]], entries[0][1])) {
|
||||
return machine
|
||||
}
|
||||
})
|
||||
})
|
||||
// console.log('filteredMachines', filteredMachines)
|
||||
return filteredMachines
|
||||
}
|
||||
return machines
|
||||
}
|
||||
|
||||
const loadingPagination = (machines, pagination) => {
|
||||
pagination.paginationOptions.total = machines.length
|
||||
pagination.paginationOptions.total_pages = Math.ceil(pagination.paginationOptions.total / pagination.paginationOptions.page_size)
|
||||
return machines.slice(0, pagination.paginationOptions.page_size)
|
||||
}
|
||||
|
||||
const setPagination = (machines, pagination, updatedData) => {
|
||||
const pageNumber = Number(updatedData.pageNumber)
|
||||
const pageSize = Number(updatedData.pageSize)
|
||||
pagination.paginationOptions.total_pages = Math.ceil(pagination.paginationOptions.total / pageSize)
|
||||
const updatedPaginationOptions = {...pagination.paginationOptions, page_number: pageNumber, page_size: pageSize}
|
||||
const updatedPagination = {...pagination, paginationOptions: updatedPaginationOptions}
|
||||
const beginPageDataIdx = pageSize === 1 ? 0 : (pageNumber - 1) * pageSize
|
||||
const endPageDataIdx = beginPageDataIdx + pageSize
|
||||
const isEndPageDataIdxMore = endPageDataIdx > machines.length
|
||||
const currentTableData = isEndPageDataIdxMore ? machines.slice(beginPageDataIdx) : machines.slice(beginPageDataIdx, endPageDataIdx)
|
||||
return {currentTableData, updatedPagination}
|
||||
}
|
||||
|
||||
export { prepareSelects, mergedMachines, colorSelection, setUpdatedDataMachines, loadingPagination, setPagination }
|
||||
@@ -0,0 +1,431 @@
|
||||
import { chartsFilterParams, chartsGroupByParams, chartsGroupByParams2, chartsFilterKeysMl, chartsMountParams, chartsBarTypesParams, chartsBarTypesGroupByParams, chartsBarTypesWithoutLayoutParams } from "./StaticData"
|
||||
import {cond, uniq, has, T} from 'ramda'
|
||||
|
||||
const setPeriodCharts = (filterKeys) => {
|
||||
if (typeof filterKeys === 'array') return {period: 'dayly', title: '24 часа'}
|
||||
switch(filterKeys) {
|
||||
case 'commun': return {period: 'yearly', title: "год"}
|
||||
case 'rors': return {period: 'dayly', title: "на данный момент"}
|
||||
case 'routes': return {period: 'weekly', title: "две недели"}
|
||||
default: return {period: 'dayly', title: "на данный момент"}
|
||||
}
|
||||
}
|
||||
|
||||
const setNamesMl = (filterKey) => {
|
||||
if (!filterKey) return null
|
||||
switch(filterKey) {
|
||||
case 'routes_common': return 'Обычные'
|
||||
case 'routes_emergency': return 'Аварийные'
|
||||
case 'routes_other': return 'Прочие'
|
||||
case 'routes_repair': return 'Ремонтные'
|
||||
case 'routes_without_leaving': return 'Без выезда'
|
||||
case 'routes_without_ml': return 'СПС без МЛ'
|
||||
default: return ''
|
||||
}
|
||||
}
|
||||
|
||||
const setMachinesClass = (typeId) => {
|
||||
if (typeId) {
|
||||
switch(typeId) {
|
||||
case 'mpt_types': return 'МРТ'
|
||||
case 'gdsm_types': return 'ЖДСМ'
|
||||
case 'sm_pss_types': return 'СМ'
|
||||
default: return ''
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const setFilterValues = (machineValue, filterParams) => {
|
||||
if(filterParams.values.includes(machineValue.toLowerCase())) {
|
||||
return {name: machineValue}
|
||||
}
|
||||
}
|
||||
|
||||
const setCountMachinesMl = (arr, counter = 0) => {
|
||||
return arr.reduce((acc, item) => {
|
||||
if (item && item.length > 0) {
|
||||
return setCountMachinesMl(item, acc)
|
||||
} else {
|
||||
if (item.charts?.value) {
|
||||
acc = acc + item.charts?.value
|
||||
} else {
|
||||
acc
|
||||
}
|
||||
}
|
||||
return acc
|
||||
}, counter)
|
||||
}
|
||||
|
||||
/* Charts updated data */
|
||||
|
||||
const chartsPie = (data, filterParams) => {
|
||||
// {list, _resp} = Agents.MachineList.get_machines(set_period_loading_charts(filterKey).period, params) apiHelpers
|
||||
|
||||
const countMachines = data?.length
|
||||
const machines = data.reduce((acc, machine) => {
|
||||
if (machine[filterParams.filterKey]) {
|
||||
acc.push(setFilterValues(machine[filterParams.filterKey], filterParams))
|
||||
} else {
|
||||
acc
|
||||
}
|
||||
return acc
|
||||
}, [])
|
||||
|
||||
// const isFilteredMachine = machines.find((el) => filterParams.values.includes(el.name.toLowerCase()))
|
||||
const groupByfiltered = machines.reduce((acc, machine) => {
|
||||
if (filterParams.values.includes(machine.name.toLowerCase())) {
|
||||
const count = machines.filter((el) => el.name === machine.name).length
|
||||
const filteredMachines = {name: machine.name, value: count}
|
||||
acc = uniq([...acc, filteredMachines])
|
||||
} else {
|
||||
acc
|
||||
}
|
||||
return acc
|
||||
}, [])
|
||||
return {countMachines: countMachines, period: setPeriodCharts(filterParams.filterKey).title, machines: groupByfiltered}
|
||||
}
|
||||
|
||||
const chartsPieGroupedBy = (data, groupByParams, filterParams) => {
|
||||
|
||||
const filteredGroupByParams = data.filter((machine) => machine[groupByParams.groupByKey] && machine[groupByParams.groupByKey].toLowerCase() === groupByParams.value)
|
||||
const countMachines = filteredGroupByParams?.length
|
||||
|
||||
const machines = filteredGroupByParams.reduce((acc, machine) => {
|
||||
|
||||
if (machine[filterParams.filterKey]) {
|
||||
acc.push(setFilterValues(machine[filterParams.filterKey], filterParams))
|
||||
} else {
|
||||
acc
|
||||
}
|
||||
return acc
|
||||
}, [])
|
||||
|
||||
const filteredMachines = machines.reduce((acc, machine) => {
|
||||
if (filterParams.values.includes(machine.name.toLowerCase())) {
|
||||
const count = machines.filter((el) => el.name === machine.name).length
|
||||
const filteredMachines = {name: machine.name, value: count}
|
||||
acc = uniq([...acc, filteredMachines])
|
||||
} else {
|
||||
acc
|
||||
}
|
||||
return acc
|
||||
}, [])
|
||||
return {countMachines: countMachines, period: setPeriodCharts(filterParams.filterKey).title, machines: filteredMachines}
|
||||
}
|
||||
|
||||
const chartsBarGroupedByMl = (data, filterKeysMl) => {
|
||||
|
||||
const machinesWithMl = filterKeysMl.map((filterKey) => {
|
||||
const filteredWithMl = data.reduce((acc, machine) => {
|
||||
if (machine[filterKey] === 0 || machine[filterKey]) {
|
||||
acc = [...acc, {[filterKey]: machine[filterKey]}]
|
||||
} else {
|
||||
acc
|
||||
}
|
||||
return acc
|
||||
}, [])
|
||||
const count = filteredWithMl.reduce((acc, machine) => {
|
||||
acc = acc + parseFloat(machine[filterKey])
|
||||
return acc
|
||||
}, 0)
|
||||
|
||||
return {key: filterKey, name: setNamesMl(filterKey), machinesCount: filteredWithMl.length, value: count}
|
||||
})
|
||||
|
||||
// console.log('machinesWithMl', machinesWithMl)
|
||||
|
||||
const countMachinesWithMl = Math.floor((machinesWithMl.reduce((acc, machine) => {
|
||||
return acc + machine.machinesCount
|
||||
}, 0)) / filterKeysMl.length)
|
||||
|
||||
const machinesWithoutMl = filterKeysMl.map((filterKey) => {
|
||||
const countNull = data.reduce((acc, machine) => {
|
||||
if (machine[filterKey] === null) {
|
||||
acc = acc + 1
|
||||
} else {
|
||||
acc
|
||||
}
|
||||
return acc
|
||||
}, 0)
|
||||
return {key: filterKey, value: countNull}
|
||||
})
|
||||
|
||||
// console.log('machinesWithoutMl', machinesWithoutMl)
|
||||
|
||||
const countMachinesWithoutMl = Math.floor((machinesWithoutMl.reduce((acc, machine) => {
|
||||
return acc + machine.value
|
||||
}, 0)) / filterKeysMl.length // Либо только машины, если без деления тогда все null МЛ суммируются
|
||||
)
|
||||
|
||||
machinesWithMl.push({key: 'routes_without_ml', name: setNamesMl('routes_without_ml'), value: countMachinesWithoutMl})
|
||||
|
||||
return {countMachinesWithMl: countMachinesWithMl, period: setPeriodCharts(filterKeysMl).title, machines: machinesWithMl}
|
||||
}
|
||||
|
||||
const chartsBarMount = (data, groupByKey, filterKey, countKey) => {
|
||||
|
||||
const groupByData = Object.groupBy(data, (el) => el[groupByKey])
|
||||
|
||||
const yAxisData = Object.entries(groupByData).map(([key, val]) => ({key: key, val: val.reduce((acc, val) => acc + val[countKey], 0)}))
|
||||
const xAxisData = Object.entries(groupByData).map(([key, groupArr]) => {
|
||||
const groupByFilterData = Object.groupBy(groupArr, (el) => el[filterKey])
|
||||
const newArr = Object.entries(groupByFilterData).map(([key, val]) => ({name: key, value: val.reduce((acc, val) => acc + val[countKey], 0)}))
|
||||
return {yAxisData: key, totalCount: groupArr.length, charts: newArr}
|
||||
})
|
||||
|
||||
const countMounts = yAxisData.reduce((acc, year) => (acc + year.val), 0)
|
||||
|
||||
return {yAxisData: yAxisData, xAxisData: xAxisData, countMounts: countMounts, filterKey: filterKey}
|
||||
}
|
||||
|
||||
const chartsBarTypes = (data, groupByKey, filterKey, prevGroupByData, prevGroupByFilters) => {
|
||||
|
||||
const countMachines = data.length
|
||||
const groupByData = Object.groupBy(data, (el) => el[groupByKey])
|
||||
|
||||
const yAxisData = Object.entries(groupByData).map(([key, val]) => ({key: key, val: val.length}))
|
||||
const xAxisData = Object.entries(groupByData).map(([key, groupArr]) => {
|
||||
const groupByFilterData = Object.groupBy(groupArr, (el) => el[filterKey])
|
||||
const newArr = Object.entries(groupByFilterData).map(([key, val]) => ({name: key, value: val.length, linkData: groupByKey === 'machine_type' ? val.map((el) => ({machine_type: el.machine_type, device_number: el.device_number})) : ''}))
|
||||
return {yAxisData: key, totalCount: groupArr.length, charts: newArr}
|
||||
})
|
||||
|
||||
return {yAxisData: yAxisData, xAxisData: xAxisData, countMachines: countMachines, period: setPeriodCharts(filterKey).title, filterKey: filterKey, groupByKey: groupByKey, prevGroupByData: prevGroupByData, prevGroupByFilters: prevGroupByFilters}
|
||||
}
|
||||
|
||||
const chartsBarTypesGroupedBy = (data, groupByKey, filterKey, prevGroupByData, prevGroupByFilters, typeId) => {
|
||||
|
||||
const machineClass = setMachinesClass(typeId)
|
||||
const machinesFilteredClass = data.filter(({machine_class}) => machine_class === machineClass)
|
||||
|
||||
const groupByData = Object.groupBy(machinesFilteredClass, (el) => el[groupByKey])
|
||||
|
||||
const yAxisData = Object.entries(groupByData).map(([key, val]) => ({key: key, val: val.length}))
|
||||
const xAxisData = Object.entries(groupByData).map(([key, groupArr]) => {
|
||||
const groupByFilterData = Object.groupBy(groupArr, (el) => el[filterKey])
|
||||
const newArr = Object.entries(groupByFilterData).map(([key, val]) => ({name: key, value: val.length, linkData: groupByKey === 'machine_type' ? val.map((el) => ({machine_type: el.machine_type, device_number: el.device_number})) : ''}))
|
||||
return {yAxisData: key, totalCount: groupArr.length, charts: newArr}
|
||||
})
|
||||
|
||||
const countMachines = yAxisData.reduce((acc, type) => acc + type.val, 0)
|
||||
|
||||
return {yAxisData: yAxisData, xAxisData: xAxisData, countMachines: countMachines, period: setPeriodCharts(filterKey).title, filterKey: filterKey, groupByKey: groupByKey, prevGroupByData: prevGroupByData, prevGroupByFilters: prevGroupByFilters, typeId: typeId}
|
||||
}
|
||||
|
||||
const chartsBarTypesWithoutFirstLayout = (data, groupByKey, filterKey, prevGroupByData, prevGroupByFilters, groupByValue) => {
|
||||
|
||||
const groupByData = Object.groupBy(data, (el) => el['org_type_name'])
|
||||
const filteredGroupByData = Object.entries(groupByData).filter(([key, val]) => key === groupByValue)
|
||||
|
||||
if (filteredGroupByData.length === 0) return {yAxisData: [], xAxisData: [], countMachines: 0, period: setPeriodCharts(filterKey).title, filterKey: filterKey, groupByKey: groupByKey, prevGroupByData: prevGroupByData, prevGroupByFilters: prevGroupByFilters, groupByValue: groupByValue}
|
||||
|
||||
const [groupedByGroupByKeyY] = filteredGroupByData.map(([key, groupArr]) => Object.groupBy(groupArr, (el) => el[groupByKey]))
|
||||
const yAxisData = Object.entries(groupedByGroupByKeyY).map(([key, val]) => ({key: key, val: val.length}))
|
||||
|
||||
const [groupedByGroupByKeyX] = filteredGroupByData.map(([key, groupArr]) => Object.groupBy(groupArr, (el) => el[groupByKey]))
|
||||
const xAxisData = Object.entries(groupedByGroupByKeyX).map(([key, groupArr]) => {
|
||||
const groupByFilterData = Object.groupBy(groupArr, (el) => el[filterKey])
|
||||
const newArr = Object.entries(groupByFilterData).map(([key, val]) => ({name: key, value: val.length, linkData: groupByKey === 'machine_type' ? val.map((el) => ({machine_type: el.machine_type, device_number: el.device_number})) : ''}))
|
||||
return {yAxisData: key, totalCount: groupArr.length, charts: newArr}
|
||||
})
|
||||
|
||||
const countMachines = yAxisData.reduce((acc, type) => acc + type.val, 0)
|
||||
|
||||
return {yAxisData: yAxisData, xAxisData: xAxisData, countMachines: countMachines, period: setPeriodCharts(filterKey).title, filterKey: filterKey, groupByKey: groupByKey, prevGroupByData: prevGroupByData, prevGroupByFilters: prevGroupByFilters, groupByValue: groupByValue}
|
||||
}
|
||||
|
||||
const chartsBarTypesGroupedByMl = (data, groupByKey, filterKeys, prevGroupByData, prevGroupByFilters) => {
|
||||
|
||||
const groupByData = Object.groupBy(data, (el) => el[groupByKey])
|
||||
const yAxisData = Object.entries(groupByData).map(([key, val]) => {
|
||||
const allValuesArr = filterKeys.map((filterKey) => {
|
||||
const machinesWithMl = val.reduce((acc, el) => {
|
||||
if (el[filterKey] || el[filterKey] === 0) {
|
||||
acc = acc + el[filterKey]
|
||||
} else {
|
||||
acc
|
||||
}
|
||||
return acc
|
||||
}, 0)
|
||||
const machinesWithoutMl = val.filter((el) => el[filterKey] === null).length
|
||||
return {machinesWithMl: machinesWithMl, machinesWithoutMl: machinesWithoutMl}
|
||||
})
|
||||
// console.log('allValuesArr', allValuesArr)
|
||||
const countMachinesWithMl = allValuesArr.reduce((acc, count) => (acc + count.machinesWithMl), 0)
|
||||
const countMachinesWithoutMl = allValuesArr.reduce((acc, count) => (acc + count.machinesWithoutMl), 0) / filterKeys.length // Для исключения дублирования делим н а длину filterKeys
|
||||
|
||||
return {key: key, val: countMachinesWithMl + countMachinesWithoutMl}
|
||||
})
|
||||
|
||||
const xAxisData = Object.entries(groupByData).map(([key, groupArr]) => {
|
||||
return filterKeys.map((filterKey) => {
|
||||
const groupByFilterData = Object.groupBy(groupArr, (el) => el[filterKey])
|
||||
const newArr = Object.entries(groupByFilterData).map(([key, val]) => ({key: filterKey, name: key, value: val.reduce((acc, el) => el[filterKey] ? acc + el[filterKey] : acc, 0), linkData: groupByKey === 'machine_type' ? val.map((el) => ({machine_type: el.machine_type, device_number: el.device_number})) : ''}
|
||||
))
|
||||
const machinesWithMl = newArr.reduce((acc, type) => {
|
||||
if (type.key === filterKey) {
|
||||
acc = {filterKey: filterKey, name: setNamesMl(filterKey), value: acc?.value + type.value, linkData: type.linkData}
|
||||
} else {
|
||||
acc = {filterKey: filterKey, name: setNamesMl(filterKey), value: acc?.value, linkData: type.linkData}
|
||||
}
|
||||
return acc
|
||||
}, {value: 0})
|
||||
// console.log('machinesWithMl', machinesWithMl)
|
||||
return {yAxisData: key, charts: machinesWithMl}
|
||||
})
|
||||
})
|
||||
|
||||
const machinesWithoutMl = Object.entries(groupByData).map(([key, val]) => {
|
||||
const countWithoutMl = val.filter((el) => filterKeys.find((filterKey) => el[filterKey] === null)).length
|
||||
return {yAxisData: key, charts: {filterKey: 'routes_without_ml', name: setNamesMl('routes_without_ml'), value: countWithoutMl, linkData: groupByKey === 'machine_type' ? val.map((el) => ({machine_type: el.machine_type, device_number: el.device_number})) : ''}}
|
||||
})
|
||||
|
||||
const countMachinesWithMl = setCountMachinesMl(xAxisData)
|
||||
const countMachinesWithoutMl = Math.floor(setCountMachinesMl(machinesWithoutMl)) / filterKeys.length
|
||||
|
||||
const updatedXAxisData = xAxisData.reduce((acc, group) => {
|
||||
const isFindGroup = machinesWithoutMl.find((machine) => machine.yAxisData === group[0].yAxisData)
|
||||
if (isFindGroup) {
|
||||
const updatedGroup = [...group, isFindGroup]
|
||||
acc.push(updatedGroup)
|
||||
} else {
|
||||
acc
|
||||
}
|
||||
return acc
|
||||
}, [])
|
||||
|
||||
// console.log('updatedXAxisData', updatedXAxisData)
|
||||
|
||||
return {yAxisData: yAxisData, xAxisData: updatedXAxisData, countMachinesWithMl: countMachinesWithMl, countMachinesWithoutMl: countMachinesWithoutMl, period: setPeriodCharts(filterKeys).title, groupByKey: groupByKey, prevGroupByData: prevGroupByData, prevGroupByFilters: prevGroupByFilters}
|
||||
}
|
||||
|
||||
/* Charts updated data end */
|
||||
|
||||
|
||||
const loadingChartsData = ({chartsSetup, data, dataMount, prevGroupByData, prevGroupByFilters}) => {
|
||||
|
||||
// console.log('dataPie', chartsPie(data, chartsFilterParams[0]))
|
||||
// console.log('dataPieValue', chartsPieGroupByValue(data, chartsGroupByParams[0], chartsFilterParams[0]))
|
||||
// console.log('dataPieTypes', chartsPieGroupedBy(data, chartsGroupByParams2[0], chartsFilterParams[0]))
|
||||
// console.log('dataBarMl', chartsBarGroupedByMl(data, chartsFilterKeysMl))
|
||||
// console.log('dataBarMount', chartsBarMount(dataMount, 'year', 'client_type', 'device_count'))
|
||||
// console.log('chartsBarTypesGroupedByMl', chartsBarTypesGroupedByMl(data, 'org_type_name', chartsFilterKeysMl, {}, {}))
|
||||
|
||||
const filteredPie = chartsFilterParams.reduce((acc, param) => {
|
||||
const idChart = `${param.filterKey}_pie`
|
||||
return {...acc, [idChart]: chartsPie(data, param)}}, {}) // Далее объединение всех типов графиков
|
||||
|
||||
const filteredPieGroupByValue = chartsGroupByParams.reduce((acc, param) => {
|
||||
const idChart = `${chartsFilterParams[0].filterKey}_pie_${param.valueId}`
|
||||
return {...acc, [idChart]: chartsPieGroupedBy(data, param, chartsFilterParams[0])}}, {})
|
||||
|
||||
const filteredPieGroupByTypes = chartsGroupByParams2.reduce((acc, param) => {
|
||||
const idChart = `${chartsFilterParams[0].filterKey}_pie_${param.valueId}`
|
||||
return {...acc, [idChart]: chartsPieGroupedBy(data, param, chartsFilterParams[0])}}, {})
|
||||
|
||||
const filteredBarGroupByMl = {[`${chartsFilterParams[1].filterKey}_bar`]: chartsBarGroupedByMl(data, chartsFilterKeysMl)}
|
||||
|
||||
const filteredBarMount = chartsMountParams.reduce((acc, param) => {
|
||||
const idChart = `mount_${param.filterKey}_bar`
|
||||
return {...acc, [idChart]: chartsBarMount(dataMount, param.groupByKey, param.filterKey, param.countKey)}}, {})
|
||||
|
||||
const filteredBarTypes = chartsBarTypesParams.reduce((acc, param) => {
|
||||
const idChart = `${param.filterKey}_${param.valueId}_bar`
|
||||
return {...acc, [idChart]: chartsBarTypes(data, param.groupByKey, param.filterKey, prevGroupByData, prevGroupByFilters)}}, {})
|
||||
|
||||
const filteredBarGroupByTypes = chartsBarTypesGroupByParams.reduce((acc, param) => {
|
||||
const idChart = `${param.filterKey}_${param.valueId}_bar_${param.typeId}`
|
||||
return {...acc, [idChart]: chartsBarTypesGroupedBy(data, param.groupByKey, param.filterKey, prevGroupByData, prevGroupByFilters, param.typeId)}}, {})
|
||||
|
||||
const filteredBarWithoutLayoutTypes = chartsBarTypesWithoutLayoutParams.reduce((acc, param) => {
|
||||
const idChart = `${param.filterKey}_types_bar_${param.valueId}`
|
||||
return {...acc, [idChart]: chartsBarTypesWithoutFirstLayout(data, param.groupByKey, param.filterKey, prevGroupByData, prevGroupByFilters, param.groupByValue)}}, {})
|
||||
|
||||
const filteredBarGroupByMlTypes = {[`${chartsFilterParams[1].filterKey}_types_bar_ml`]: chartsBarTypesGroupedByMl(data, 'org_type_name', chartsFilterKeysMl, prevGroupByData, prevGroupByFilters)}
|
||||
|
||||
const allCharts = {...filteredPie, ...filteredPieGroupByValue, ...filteredPieGroupByTypes, ...filteredBarGroupByMl, ...filteredBarMount, ...filteredBarTypes, ...filteredBarGroupByTypes, ...filteredBarWithoutLayoutTypes, ...filteredBarGroupByMlTypes}
|
||||
|
||||
console.log('allCharts', allCharts)
|
||||
|
||||
// console.log('this.charts', data)
|
||||
const main = chartsSetup.main.reduce((acc, chart) => {
|
||||
if (allCharts[chart.id]) {
|
||||
const newChart = {...chart, data: allCharts[chart.id]}
|
||||
acc = [...acc, newChart]
|
||||
} else {
|
||||
acc
|
||||
}
|
||||
return acc
|
||||
|
||||
}, [])
|
||||
const types = chartsSetup.types.reduce((acc, chart) => {
|
||||
if (allCharts[chart.id]) {
|
||||
const newChart = {...chart, data: allCharts[chart.id]}
|
||||
acc = [...acc, newChart]
|
||||
} else {
|
||||
acc
|
||||
}
|
||||
return acc
|
||||
|
||||
}, [])
|
||||
return {...chartsSetup, main: main, types: types}
|
||||
}
|
||||
|
||||
const setBarTypesChart = (activeChartParams, prevGroupByData, prevGroupByFilters, defaultData, currentData) => {
|
||||
switch (activeChartParams.type) {
|
||||
case 'default':
|
||||
const dataDefault = chartsBarTypes(defaultData, activeChartParams.groupByKey, activeChartParams.filterKey, prevGroupByData, prevGroupByFilters)
|
||||
// const updatedData = currentData.types.reduce((acc, chart) => {
|
||||
// if (chart.id === activeChartParams.id) {
|
||||
// const newChart = {...chart, data: data}
|
||||
// acc = [...acc, newChart]
|
||||
// } else {
|
||||
// acc = [...acc, chart]
|
||||
// }
|
||||
// return acc
|
||||
// }, [])
|
||||
// return {main: currentData.main, types: updatedData}
|
||||
return dataDefault
|
||||
case 'without_first_layout':
|
||||
const dataWithoutFirstLayout = chartsBarTypesWithoutFirstLayout(defaultData, activeChartParams.groupByKey, activeChartParams.filterKey, prevGroupByData, prevGroupByFilters, activeChartParams.groupByValue)
|
||||
return dataWithoutFirstLayout
|
||||
case 'types':
|
||||
const dataGroupBy = chartsBarTypesGroupedBy(defaultData, activeChartParams.groupByKey, activeChartParams.filterKey, prevGroupByData, prevGroupByFilters, activeChartParams.groupByValue)
|
||||
return dataGroupBy
|
||||
case 'ml':
|
||||
const dataMl = chartsBarTypesGroupedByMl(defaultData, activeChartParams.groupByKey, chartsFilterKeysMl, prevGroupByData, prevGroupByFilters)
|
||||
return dataMl
|
||||
}
|
||||
}
|
||||
|
||||
const setNextLayoutGroupByKey = (groupByKey, prevGroupByValue) => {
|
||||
if (prevGroupByValue === 'без типа') return null
|
||||
switch (groupByKey) {
|
||||
case 'org_type_name': return 'railway_name'
|
||||
case 'railway_name': return 'org_name'
|
||||
case 'org_name': return 'type'
|
||||
case 'type': return 'machine_type'
|
||||
case 'zav_nomer': return 'machine_type'
|
||||
default: return null
|
||||
}
|
||||
}
|
||||
|
||||
const setBeforeLayoutGroupByData = (prevGroupByData, prevGroupByFilters, type) => {
|
||||
return cond([
|
||||
[has('type'), () => ({org_name: prevGroupByFilters['org_name']})],
|
||||
[has('org_name'), () => ({railway_name: prevGroupByFilters['railway_name']})],
|
||||
[has('railway_name'), () => (type === 'without_first_layout' ? {} : {org_type_name: prevGroupByFilters['org_type_name']})],
|
||||
[T, () => {}],
|
||||
])(prevGroupByData)
|
||||
}
|
||||
|
||||
const typesCharts = (type) => {
|
||||
switch (type) {
|
||||
case 'pie': return true
|
||||
case 'mount': return true
|
||||
case 'mainMl': return true
|
||||
default: return false
|
||||
}
|
||||
}
|
||||
|
||||
export { loadingChartsData, setBarTypesChart, setNextLayoutGroupByKey, setBeforeLayoutGroupByData, typesCharts }
|
||||
459
live_monitor_vue/src/store/modules/layoutMachines/index.js
Normal file
459
live_monitor_vue/src/store/modules/layoutMachines/index.js
Normal file
@@ -0,0 +1,459 @@
|
||||
import {toRaw} from 'vue'
|
||||
import {searchModes, leftTopButtons, rightTopButtons, selects, selectors, charts, dataMachines, dataMount, pagination, machineInfo, reportPacks, report, packStructure, multiReport, multiPackStructure} from './StaticData'
|
||||
import { chartsSetup } from '@/store/hooks/Echarts/staticData.js';
|
||||
import { prepareSelects, mergedMachines, setUpdatedDataMachines, colorSelection, loadingPagination, setPagination } from './helpers';
|
||||
import { loadingChartsData, setBarTypesChart, setNextLayoutGroupByKey, setBeforeLayoutGroupByData, typesCharts } from './helpersCharts';
|
||||
import { fetchColumn, prepareSetPackColumns } from '@organisms/PackColumns';
|
||||
import { get } from '../apiHelpers';
|
||||
import {equals, isEmpty, uniq} from 'ramda'
|
||||
|
||||
const initState = {
|
||||
leftTopButtons: leftTopButtons,
|
||||
rightTopButtons: rightTopButtons,
|
||||
searchModes: searchModes,
|
||||
pagination: pagination,
|
||||
toggleFilter: false,
|
||||
openMenuChart: false,
|
||||
initHistory: false,
|
||||
|
||||
selectedSearchMode: searchModes[0],
|
||||
selectedMode: leftTopButtons[0].key,
|
||||
selectedSelects: {},
|
||||
activeFilterBtn: null,
|
||||
activeChartData: null,
|
||||
activeMenuChartData: {openMenuChart: false},
|
||||
selectedPackStruct: null,
|
||||
selectedPackMode: 'askr_logs',
|
||||
|
||||
searchValue: '',
|
||||
selectedData: [],
|
||||
selectsData: [],
|
||||
machinesDataDefault: [],
|
||||
machinesData: [],
|
||||
tableData: [],
|
||||
chartsData: [],
|
||||
chartsMountData: [],
|
||||
mapData: null,
|
||||
machineInfo: null,
|
||||
reportPacks: [],
|
||||
structPackDefault: [],
|
||||
selectPackStructs: [],
|
||||
packData: {},
|
||||
|
||||
historyData: [],
|
||||
historyMachines: [],
|
||||
legendFiltersParams: [],
|
||||
};
|
||||
|
||||
const state = {
|
||||
...initState
|
||||
};
|
||||
|
||||
const getters = {
|
||||
pages: (state) => state.pages,
|
||||
searchModes: (state) => state.searchModes,
|
||||
leftTopButtons: (state) => state.leftTopButtons,
|
||||
rightTopButtons: (state) => state.rightTopButtons,
|
||||
toggleFilter: (state) => state.toggleFilter,
|
||||
openMenuChart: (state) => state.openMenuChart,
|
||||
initHistory: (state) => state.initHistory,
|
||||
|
||||
selectedPage: (state) => state.selectedPage,
|
||||
selectedSearchMode: (state) => state.selectedSearchMode,
|
||||
selectedMode: (state) => state.selectedMode,
|
||||
selectedSelects: (state) => state.selectedSelects,
|
||||
activeFilterBtn: (state) => state.activeFilterBtn,
|
||||
activeChartData: (state) => state.activeChartData,
|
||||
activeMenuChartData: (state) => state.activeMenuChartData,
|
||||
selectedPackStruct: (state) => state.selectedPackStruct,
|
||||
selectedPackMode: (state) => state.selectedPackMode,
|
||||
|
||||
searchValue: (state) => state.searchValue,
|
||||
selectedData: (state) => state.selectedData,
|
||||
selectsData: (state) => state.selectsData,
|
||||
machinesDataDefault: (state) => state.machinesDataDefault,
|
||||
machinesData: (state) => state.machinesData,
|
||||
tableData: (state) => state.tableData,
|
||||
chartsData: (state) => state.chartsData,
|
||||
chartsMountData: (state) => state.chartsMountData,
|
||||
historyData: (state) => state.historyData,
|
||||
historyMachines: (state) => state.historyMachines,
|
||||
legendFiltersParams: (state) => state.legendFiltersParams,
|
||||
pagination: (state) => state.pagination,
|
||||
mapData: (state) => state.mapData,
|
||||
machineInfo: (state) => state.machineInfo,
|
||||
reportPacks: (state) => state.reportPacks,
|
||||
selectPackStructs: (state) => state.selectPackStructs,
|
||||
packData: (state) => state.packData,
|
||||
};
|
||||
|
||||
const mutations = {
|
||||
setPage: (state, updval) => state.selectedPage = updval,
|
||||
setToggleFilter: (state) => state.toggleFilter = !state.toggleFilter,
|
||||
setOpenMenuChart: (state, updval) => state.openMenuChart = updval,
|
||||
setInitHistory: (state, updval) => state.initHistory = updval,
|
||||
|
||||
setSearchMode: (state, updval) => state.selectedSearchMode = updval,
|
||||
setSelectedMode: (state, updval) => state.selectedMode = updval,
|
||||
setSelectedSelects: (state, updval) => state.selectedSelects = updval,
|
||||
setSelectedMachines: (state, updval) => state.selectedMachines = updval,
|
||||
setActiveFilterBtn: (state, updval) => state.activeFilterBtn = updval,
|
||||
setActiveChartData: (state, updval) => state.activeChartData = updval,
|
||||
setActiveMenuChartData: (state, updval) => state.activeMenuChartData = updval,
|
||||
setSelectedPackStruct: (state, updval) => state.selectedPackStruct = updval,
|
||||
setSelectedPackMode: (state, updval) => state.selectedPackMode = updval,
|
||||
|
||||
setSelectsData: (state, updval) => state.selectsData = updval,
|
||||
setSearchValue: (state, updval) => state.searchValue = updval,
|
||||
setSelectedData: (state, updval) => state.selectedData = updval,
|
||||
setMachinesDataDefault: (state, updval) => state.machinesDataDefault = updval,
|
||||
setMachinesData: (state, updval) => state.machinesData = updval,
|
||||
setTableData: (state, updval) => state.tableData = updval,
|
||||
setChartsData: (state, updval) => state.chartsData = updval,
|
||||
setChartsDataMount: (state, updval) => state.chartsMountData = updval,
|
||||
setHistoryData: (state, updval) => state.historyData = updval,
|
||||
setHistoryMachines: (state, updval) => state.historyMachines = updval,
|
||||
setLegendFiltersParams: (state, updval) => state.legendFiltersParams = updval,
|
||||
setPagination: (state, updval) => state.pagination = updval,
|
||||
setMapData: (state, updval) => state.mapData = updval,
|
||||
setMachineInfo: (state, updval) => state.machineInfo = updval,
|
||||
setReportPacks: (state, updval) => state.reportPacks = updval,
|
||||
setStructPackDefault: (state, updval) => state.structPackDefault = updval,
|
||||
setSelectPackStructs: (state, updval) => state.selectPackStructs = updval,
|
||||
setPackData: (state, updval) => state.packData = updval,
|
||||
resetStore: (state) => {
|
||||
Object.entries(initState).forEach(([k,v]) => {
|
||||
state[k] = v
|
||||
})
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
const actions = {
|
||||
uploadData: async ({commit, getters, state}, externalParams) => {
|
||||
try{
|
||||
// const machinesData = toRaw(getters.machinesData)
|
||||
// const machinesDataDefault = toRaw(state.machinesDataDefault)
|
||||
const pagination = toRaw(getters.pagination)
|
||||
// const chartsData = toRaw(state.chartsData)
|
||||
const historyData = externalParams.historyData ? externalParams.historyData : toRaw(state.historyData)
|
||||
const chartsData = !isEmpty(dataMachines) ? dataMachines.filter((machine) => machine.machine_id !== null) : []
|
||||
const chartsMountData = !isEmpty(dataMount) ? dataMount.filter((el) => el.client_type !== null) : []
|
||||
|
||||
const updatedData = loadingChartsData({chartsSetup: chartsSetup, data: chartsData, dataMount: chartsMountData, prevGroupByData: {}, prevGroupByFilters: {}})
|
||||
const filteredSelects = prepareSelects(selects, selectors)
|
||||
const mergedData = mergedMachines(dataMachines, historyData)
|
||||
const currentTableData = loadingPagination(dataMachines, pagination)
|
||||
const currentSelectedMode = externalParams.urlParams ? externalParams.urlParams : 'cards'
|
||||
// console.log('updatedData', updatedData)
|
||||
|
||||
commit('setSelectedMode', currentSelectedMode)
|
||||
commit('setTableData', currentTableData)
|
||||
commit('setPagination', pagination)
|
||||
commit('setSelectsData', filteredSelects)
|
||||
commit('setChartsData', updatedData)
|
||||
commit('setChartsDataMount', chartsMountData)
|
||||
commit('setMachinesDataDefault', dataMachines)
|
||||
commit('setMachinesData', mergedData)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
},
|
||||
updateSearch: async ({commit, getters, state}, updatedSearchValue) => {
|
||||
try {
|
||||
const selectedSearchMode = toRaw(getters.selectedSearchMode)
|
||||
const selectedData = toRaw(getters.selectedData)
|
||||
const machinesDataDefault = toRaw(state.machinesDataDefault)
|
||||
// const machinesData = toRaw(state.machinesData)
|
||||
const isEmptyParams = isEmpty(selectedData)
|
||||
let updatedFilters = []
|
||||
if (updatedSearchValue) {
|
||||
console.log('isEmptyParams', isEmptyParams)
|
||||
console.log('selectedData', selectedData)
|
||||
// updatedFilters = isEmptyParams ? [{[selectedSearchMode.key]: updatedSearchValue}] : [...selectedData.filter, {[selectedSearchMode.key]: updatedSearchValue}]
|
||||
updatedFilters = [{[selectedSearchMode.key]: updatedSearchValue}]
|
||||
}
|
||||
if (!updatedSearchValue) {
|
||||
updatedFilters = !isEmptyParams ? selectedData.filter.filter((el) => !el[selectedSearchMode.key]) : selectedData
|
||||
}
|
||||
const updatedFiltersForSend = {filter: updatedFilters}
|
||||
// const currentData = !isEmptyParams && updatedSearchValue && !isEmpty(machinesData) ? machinesData : machinesDataDefault
|
||||
const updatedData = setUpdatedDataMachines(machinesDataDefault, updatedFiltersForSend)
|
||||
const updatedDataCharts = loadingChartsData({chartsSetup: chartsSetup, data: updatedData, dataMount: dataMount, prevGroupByData: {}, prevGroupByFilters: {}})
|
||||
commit('setSelectedData', updatedFiltersForSend)
|
||||
commit('setSelectedSelects', {})
|
||||
commit('setSearchValue', updatedSearchValue)
|
||||
commit('setMachinesData', updatedData)
|
||||
commit('setChartsData', updatedDataCharts)
|
||||
colorSelection(selectedSearchMode.key, updatedSearchValue)
|
||||
// console.log('updatedFilters', updatedFilters)
|
||||
// console.log('updatedData', updatedData)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
},
|
||||
updateSelects: async ({dispatch, commit, getters, state}, updatedSelect) => {
|
||||
try {
|
||||
const allSelects = toRaw(getters.selectsData)
|
||||
const selectedSelects = toRaw(getters.selectedSelects)
|
||||
const machinesDataDefault = toRaw(state.machinesDataDefault)
|
||||
dispatch('updateSearch', '')
|
||||
const curUpdatedSelectName = updatedSelect.key === 'set' ? updatedSelect.value[0].name : updatedSelect.value.name
|
||||
let updatedSelects = {}
|
||||
for (let i = 0; i < allSelects.length; i++) {
|
||||
const curSelect = allSelects[i]
|
||||
const newSelected = curSelect.data.find((el) => el.name === curUpdatedSelectName)
|
||||
if (!newSelected && (selectedSelects[curSelect.key] && selectedSelects[curSelect.key].length > 0)) {
|
||||
updatedSelects[curSelect.key] = selectedSelects[curSelect.key]
|
||||
}
|
||||
if (updatedSelect.key === 'removed' && newSelected && (selectedSelects[curSelect.key] && selectedSelects[curSelect.key].length === 0)) {
|
||||
break
|
||||
}
|
||||
if (updatedSelect.key === 'removed' && newSelected && (selectedSelects[curSelect.key] && selectedSelects[curSelect.key].length > 0)) {
|
||||
updatedSelects[curSelect.key] = selectedSelects[curSelect.key].filter((el) => el.name !== newSelected.name)
|
||||
break
|
||||
}
|
||||
if (updatedSelect.key === 'set' && newSelected && (selectedSelects[curSelect.key] && selectedSelects[curSelect.key].length > 0)) {
|
||||
updatedSelects[curSelect.key] = selectedSelects[curSelect.key]
|
||||
break
|
||||
}
|
||||
}
|
||||
const updatedFilters = Object.entries(updatedSelects).map(([key, value]) => ({[key]: value.map((el) => el.name)}))
|
||||
// const mergedFilters = searchValue ? [...updatedFilters, {[selectedSearchMode.key]: searchValue}] : updatedFilters
|
||||
// console.log('mergedFilters', mergedFilters)
|
||||
// const currentData = !isEmptyParams ? machinesData : machinesDataDefault
|
||||
const updatedFiltersForSend = {filter: updatedFilters}
|
||||
const updatedData = setUpdatedDataMachines(machinesDataDefault, updatedFiltersForSend)
|
||||
const updatedDataCharts = loadingChartsData({chartsSetup: chartsSetup, data: updatedData, dataMount: dataMount, prevGroupByData: {}, prevGroupByFilters: {}})
|
||||
// console.log('updatedData', updatedData)
|
||||
// console.log('updatedFilters', updatedFilters)
|
||||
commit('setMachinesData', updatedData)
|
||||
commit('setChartsData', updatedDataCharts)
|
||||
commit('setSelectedSelects', updatedSelects)
|
||||
commit('setSelectedData', updatedFiltersForSend)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
},
|
||||
updateCharts: async ({commit, getters, state}, updatedData) => {
|
||||
try {
|
||||
switch(updatedData.action) {
|
||||
case 'nextLayoutChart':
|
||||
// console.log('updatedDataNext', updatedData)
|
||||
const prevGroupByFiltersNext = updatedData.prevGroupByFilters
|
||||
const updatedFiltersNext = {...prevGroupByFiltersNext, ...updatedData.prevGroupByData}
|
||||
const prevGroupByValue = updatedData.prevGroupByData.type ? updatedData.prevGroupByData.type : null
|
||||
const groupByKeyNext = setNextLayoutGroupByKey(updatedData.groupByKey, prevGroupByValue)
|
||||
if (groupByKeyNext) {
|
||||
const activeChartData = {id: updatedData.id, data: updatedData.data, groupByKey: groupByKeyNext, filterKey: updatedData.filterKey, type: updatedData.type, groupByValue: updatedData.groupByValue}
|
||||
const newData = setBarTypesChart(activeChartData, updatedData.prevGroupByData, updatedFiltersNext, state.machinesDataDefault, toRaw(state.chartsData))
|
||||
return commit('setActiveChartData', {...activeChartData, data: newData})
|
||||
}
|
||||
break
|
||||
case 'beforeLayoutChart':
|
||||
// console.log('updatedDataBefore', updatedData)
|
||||
const prevGroupByData = updatedData.groupByInfo.prevGroupByData
|
||||
const prevGroupByFiltersBefore = updatedData.groupByInfo.prevGroupByFilters
|
||||
const groupByKeyBefore = Object.keys(prevGroupByData)[0] // Получаем уже предыдущее значение ключа
|
||||
delete prevGroupByFiltersBefore[groupByKeyBefore] // Удаляем значение после вычисления prevGroupByData, так как подымаемся на уровень выше, сохраняя актуальное значение для фильтрации
|
||||
const isOnlyFiltersParams = equals(prevGroupByData, prevGroupByFiltersBefore)
|
||||
const updatedPrevGroupByDataBefore = isOnlyFiltersParams ? {} : setBeforeLayoutGroupByData(prevGroupByData, prevGroupByFiltersBefore, updatedData.groupByInfo.type)
|
||||
if (groupByKeyBefore) {
|
||||
const activeChartData = {id: updatedData.id, data: updatedData.data, groupByKey: groupByKeyBefore, filterKey: updatedData.filterKey, type: updatedData.groupByInfo.type, groupByValue: updatedData.groupByInfo.groupByValue}
|
||||
const newData = setBarTypesChart(activeChartData, updatedPrevGroupByDataBefore, prevGroupByFiltersBefore, state.machinesDataDefault, toRaw(state.chartsData))
|
||||
return commit('setActiveChartData', {...activeChartData, data: newData})
|
||||
}
|
||||
break
|
||||
case 'openMenuChart':
|
||||
// console.log('updatedDataOpen', updatedData)
|
||||
const openMenuChart = toRaw(state.activeMenuChartData.openMenuChart)
|
||||
updatedData.groupByInfo.data[0].type = updatedData.groupByInfo.type
|
||||
const activeChartDataMenu = {chartId: updatedData.groupByInfo.chartId, data: updatedData.groupByInfo.data, groupByKey: updatedData.groupByInfo.groupByKey, filterKey: updatedData.groupByInfo.filterKey, type: updatedData.groupByInfo.type, groupByValue: updatedData.groupByInfo.groupByValue}
|
||||
const newDataMenu = setBarTypesChart(activeChartDataMenu, updatedData.groupByInfo.prevGroupByData, updatedData.groupByInfo.prevGroupByFilters, state.machinesDataDefault, toRaw(state.chartsData))
|
||||
const isNotTypesChartsMenu = typesCharts(updatedData.groupByInfo.type)
|
||||
const toggleActiveMenuChartData = {openMenuChart: !openMenuChart, groupByInfo: {...activeChartDataMenu, data: isNotTypesChartsMenu ? updatedData.groupByInfo.data[0] : newDataMenu}}
|
||||
commit('setActiveMenuChartData', toggleActiveMenuChartData)
|
||||
break
|
||||
case 'downloadChart':
|
||||
// console.log('updatedDataDownload', updatedData)
|
||||
const activeChartDataDownload = {chartId: updatedData.groupByInfo.chartId, isDownloadChart: updatedData.groupByInfo.isDownloadChart, data: updatedData.groupByInfo.data, groupByKey: updatedData.groupByInfo.groupByKey, prevGroupByData: updatedData.groupByInfo.prevGroupByData, prevGroupByFilters: updatedData.groupByInfo.prevGroupByFilters, filterKey: updatedData.groupByInfo.filterKey, type: updatedData.groupByInfo.type, groupByValue: updatedData.groupByInfo.groupByValue}
|
||||
const newDataDownload = setBarTypesChart(activeChartDataDownload, updatedData.groupByInfo.prevGroupByData, updatedData.groupByInfo.prevGroupByFilters, state.machinesDataDefault, toRaw(state.chartsData))
|
||||
const isNotTypesChartsDownload = typesCharts(updatedData.groupByInfo.type)
|
||||
const downloadActiveMenuChartData = {openMenuChart: false, groupByInfo: {...updatedData.groupByInfo, data: isNotTypesChartsDownload ? updatedData.groupByInfo.data[0] : newDataDownload}}
|
||||
commit('setActiveMenuChartData', downloadActiveMenuChartData)
|
||||
break
|
||||
case 'legendFiltersParams':
|
||||
commit('setLegendFiltersParams', updatedData.data)
|
||||
default: return false
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
},
|
||||
updatePagination: async ({commit, getters, state}, updatedData) => {
|
||||
try {
|
||||
const pagination = toRaw(getters.pagination)
|
||||
const machinesDataDefault = toRaw(state.machinesDataDefault)
|
||||
const newData = setPagination(machinesDataDefault, pagination, updatedData)
|
||||
console.log('currentTableData', newData.currentTableData)
|
||||
commit('setTableData', newData.currentTableData)
|
||||
commit('setPagination', newData.updatedPagination)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
},
|
||||
openMapModal: async ({commit, state}, machine) => {
|
||||
try {
|
||||
// Добавить запрос на получение координат
|
||||
/*
|
||||
machine_id = machine["machine_id"]
|
||||
last_loc = Communicator.PackFetcher.last_locations([machine_id])
|
||||
|
||||
*/
|
||||
const coords = [44.510345, 48.771025]
|
||||
const params = {machine: machine, coords: coords}
|
||||
commit('setMapData', params)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
},
|
||||
openDataModal: async ({commit, state}, machine) => {
|
||||
try {
|
||||
|
||||
// Добавить запрос на получение пакетов и информации о машине
|
||||
/*
|
||||
curr_machine_info = Communicator.Devices.askr_devices(where: "imei = #{imei}")
|
||||
|
||||
[{_, machine_name} | machine_info] =
|
||||
Analyzer.reparse_machine_info(curr_machine_info, :imei)
|
||||
|> Enum.reduce([], fn
|
||||
{"Текущая машина", _} = cur, acc -> [cur] ++ acc
|
||||
cur, acc -> acc ++ [cur]
|
||||
end)
|
||||
|
||||
report_packs =
|
||||
Enum.reduce(curr_machine_info, [], fn
|
||||
%{imei: imei}, acc ->
|
||||
acc ++
|
||||
PacksFuncs.get_pack_nums(
|
||||
imei,
|
||||
Timex.now() |> Timex.beginning_of_day(),
|
||||
Timex.now() |> Timex.end_of_day()
|
||||
)
|
||||
|
||||
_, acc ->
|
||||
acc
|
||||
end)
|
||||
|> DynamicStructDestroyer.destroy()
|
||||
|> Enum.sort_by(& &1.packNumber)
|
||||
|
||||
*/
|
||||
|
||||
commit('setMachineInfo', machineInfo)
|
||||
commit('setReportPacks', reportPacks)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
},
|
||||
loadPack: async ({commit, state}, packNumber) => {
|
||||
try {
|
||||
|
||||
/* Получение данных о пакете
|
||||
report =
|
||||
Enum.reduce(curr_machine_info, [], fn
|
||||
%{imei: imei}, acc ->
|
||||
acc ++ PacksFuncs.upload_machine_data(imei, pack_number, dt_start, dt_finish, 30) // Огреничение до 30 машин askr_logs
|
||||
|
||||
_, acc ->
|
||||
acc
|
||||
end)
|
||||
|> DynamicStructDestroyer.destroy()
|
||||
|
||||
Получение структуры пакета
|
||||
|
||||
pack_structs = Helper.get_structs_of_pack(pack_number)
|
||||
|
||||
def get_structs_of_pack(pack_number) do
|
||||
LiveMonitor.Packages.list_pack_struct()
|
||||
|> Enum.filter(&(&1.pack == pack_number))
|
||||
end
|
||||
|
||||
*/
|
||||
console.log('packNumber', packNumber)
|
||||
// const dataSource = !isEmpty(report) ? report.askr_logs.sort((a, b) => b.pack_dt - a.pack_dt) : []
|
||||
const dataSource = !isEmpty(multiReport) ? multiReport.askr_logs.sort((a, b) => b.pack_dt - a.pack_dt).slice(0, 30) : [] // Огреничение до 30 машин askr_logs
|
||||
// const columns = fetchColumn(packStructure, report)
|
||||
const columns = fetchColumn(multiPackStructure, multiReport)
|
||||
// const selectedPackStruct = packStructure.map((item) => ({id: item.id, name: item.name, packNumber: packNumber}))
|
||||
console.log('multiPackStructure', multiPackStructure)
|
||||
console.log('multiReport', multiReport)
|
||||
console.log('columns', columns)
|
||||
const selectPackStructs = multiPackStructure.map((item) => ({id: item.id, name: item.name, packNumber: packNumber}))
|
||||
commit('setStructPackDefault', multiPackStructure)
|
||||
commit('setSelectPackStructs', selectPackStructs)
|
||||
commit('setSelectedPackStruct', selectPackStructs[0])
|
||||
commit('setPackData', {dataSource, columns, height: '550px'})
|
||||
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
},
|
||||
updateModePack: async ({commit, getters, state}, updatedMode) => {
|
||||
try {
|
||||
const structPackDefault = toRaw(state.structPackDefault)
|
||||
const currentReport = multiReport[updatedMode] ? multiReport[updatedMode] : []
|
||||
const columns = updatedMode === 'askr_logs' ? fetchColumn(structPackDefault, multiReport, null) : prepareSetPackColumns(updatedMode, currentReport)
|
||||
console.log('columns', columns)
|
||||
console.log('currentReport', currentReport)
|
||||
commit('setSelectedPackMode', updatedMode)
|
||||
commit('setPackData', {dataSource: currentReport, columns, height: '550px'})
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
},
|
||||
updateSelectStruct: async ({commit, getters, state}, updatedStructId) => {
|
||||
try {
|
||||
const updatedMode = toRaw(getters.selectedPackMode)
|
||||
const currentReport = toRaw(state.packData.dataSource)
|
||||
const structPackDefault = toRaw(state.structPackDefault)
|
||||
const selectPackStructs = toRaw(getters.selectPackStructs)
|
||||
const [selectedPackStruct] = selectPackStructs.filter((item) => item.id === updatedStructId)
|
||||
console.log('selectedPackStruct', selectedPackStruct)
|
||||
// const currentReport = multiReport[updatedMode] ? multiReport[updatedMode] : []
|
||||
const columns = updatedMode === 'askr_logs' ? fetchColumn(structPackDefault, multiReport, updatedStructId) : prepareSetPackColumns(updatedMode, currentReport)
|
||||
console.log('updatedMode', updatedMode)
|
||||
console.log('structPackDefault', structPackDefault)
|
||||
console.log('columns', columns)
|
||||
console.log('currentReport', currentReport)
|
||||
commit('setSelectedPackStruct', selectedPackStruct)
|
||||
commit('setPackData', {dataSource: currentReport, columns, height: '550px'})
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
},
|
||||
clearFilters: async ({commit, state}) => {
|
||||
try {
|
||||
const machinesDataDefault = toRaw(state.machinesDataDefault)
|
||||
const updatedFiltersForSend = {filter: []}
|
||||
const updatedData = setUpdatedDataMachines(machinesDataDefault, updatedFiltersForSend)
|
||||
const updatedDataCharts = loadingChartsData({chartsSetup: chartsSetup, data: updatedData, dataMount: dataMount, prevGroupByData: {}, prevGroupByFilters: {}})
|
||||
commit('setSelectedSelects', {})
|
||||
commit('setSelectedData', [])
|
||||
commit('setMachinesData', updatedData)
|
||||
commit('setChartsData', updatedDataCharts)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
},
|
||||
resetStore: ({commit}) => {
|
||||
commit('resetStore')
|
||||
}
|
||||
};
|
||||
|
||||
export const store = {
|
||||
namespaced: true,
|
||||
state,
|
||||
getters,
|
||||
mutations,
|
||||
actions,
|
||||
};
|
||||
@@ -1,48 +1,7 @@
|
||||
import {toRaw} from 'vue'
|
||||
import {searchModes, leftTopButtons, rightTopButtons, selects, selectors, charts, dataMachines, dataMount, pagination, machineInfo, reportPacks, report, packStructure, multiReport, multiPackStructure} from './StaticData'
|
||||
import { chartsSetup } from '@/store/hooks/Echarts/staticData.js';
|
||||
import { prepareSelects, mergedMachines, setUpdatedDataMachines, colorSelection, loadingPagination, setPagination } from './helpers';
|
||||
import { loadingChartsData, setBarTypesChart, setNextLayoutGroupByKey, setBeforeLayoutGroupByData, typesCharts } from './helpersCharts';
|
||||
import { fetchColumn, prepareSetPackColumns } from '@organisms/PackColumns';
|
||||
import { get } from '../apiHelpers';
|
||||
import {equals, isEmpty, uniq} from 'ramda'
|
||||
import {equals, isEmpty} from 'ramda'
|
||||
|
||||
const initState = {
|
||||
leftTopButtons: leftTopButtons,
|
||||
rightTopButtons: rightTopButtons,
|
||||
searchModes: searchModes,
|
||||
pagination: pagination,
|
||||
toggleFilter: false,
|
||||
openMenuChart: false,
|
||||
initHistory: false,
|
||||
|
||||
selectedSearchMode: searchModes[0],
|
||||
selectedMode: leftTopButtons[0].key,
|
||||
selectedSelects: {},
|
||||
activeFilterBtn: null,
|
||||
activeChartData: null,
|
||||
activeMenuChartData: {openMenuChart: false},
|
||||
selectedPackStruct: null,
|
||||
selectedPackMode: 'askr_logs',
|
||||
|
||||
searchValue: '',
|
||||
selectedData: [],
|
||||
selectsData: [],
|
||||
machinesDataDefault: [],
|
||||
machinesData: [],
|
||||
tableData: [],
|
||||
chartsData: [],
|
||||
chartsMountData: [],
|
||||
mapData: null,
|
||||
machineInfo: null,
|
||||
reportPacks: [],
|
||||
structPackDefault: [],
|
||||
selectPackStructs: [],
|
||||
packData: {},
|
||||
|
||||
historyData: [],
|
||||
historyMachines: [],
|
||||
legendFiltersParams: [],
|
||||
modalMachines: [],
|
||||
};
|
||||
|
||||
const state = {
|
||||
@@ -50,400 +9,22 @@ const state = {
|
||||
};
|
||||
|
||||
const getters = {
|
||||
pages: (state) => state.pages,
|
||||
searchModes: (state) => state.searchModes,
|
||||
leftTopButtons: (state) => state.leftTopButtons,
|
||||
rightTopButtons: (state) => state.rightTopButtons,
|
||||
toggleFilter: (state) => state.toggleFilter,
|
||||
openMenuChart: (state) => state.openMenuChart,
|
||||
initHistory: (state) => state.initHistory,
|
||||
|
||||
selectedPage: (state) => state.selectedPage,
|
||||
selectedSearchMode: (state) => state.selectedSearchMode,
|
||||
selectedMode: (state) => state.selectedMode,
|
||||
selectedSelects: (state) => state.selectedSelects,
|
||||
activeFilterBtn: (state) => state.activeFilterBtn,
|
||||
activeChartData: (state) => state.activeChartData,
|
||||
activeMenuChartData: (state) => state.activeMenuChartData,
|
||||
selectedPackStruct: (state) => state.selectedPackStruct,
|
||||
selectedPackMode: (state) => state.selectedPackMode,
|
||||
|
||||
searchValue: (state) => state.searchValue,
|
||||
selectedData: (state) => state.selectedData,
|
||||
selectsData: (state) => state.selectsData,
|
||||
machinesDataDefault: (state) => state.machinesDataDefault,
|
||||
machinesData: (state) => state.machinesData,
|
||||
tableData: (state) => state.tableData,
|
||||
chartsData: (state) => state.chartsData,
|
||||
chartsMountData: (state) => state.chartsMountData,
|
||||
historyData: (state) => state.historyData,
|
||||
historyMachines: (state) => state.historyMachines,
|
||||
legendFiltersParams: (state) => state.legendFiltersParams,
|
||||
pagination: (state) => state.pagination,
|
||||
mapData: (state) => state.mapData,
|
||||
machineInfo: (state) => state.machineInfo,
|
||||
reportPacks: (state) => state.reportPacks,
|
||||
selectPackStructs: (state) => state.selectPackStructs,
|
||||
packData: (state) => state.packData,
|
||||
modalMachines: (state) => state.modalMachines,
|
||||
};
|
||||
|
||||
const mutations = {
|
||||
setPage: (state, updval) => state.selectedPage = updval,
|
||||
setToggleFilter: (state) => state.toggleFilter = !state.toggleFilter,
|
||||
setOpenMenuChart: (state, updval) => state.openMenuChart = updval,
|
||||
setInitHistory: (state, updval) => state.initHistory = updval,
|
||||
|
||||
setSearchMode: (state, updval) => state.selectedSearchMode = updval,
|
||||
setSelectedMode: (state, updval) => state.selectedMode = updval,
|
||||
setSelectedSelects: (state, updval) => state.selectedSelects = updval,
|
||||
setSelectedMachines: (state, updval) => state.selectedMachines = updval,
|
||||
setActiveFilterBtn: (state, updval) => state.activeFilterBtn = updval,
|
||||
setActiveChartData: (state, updval) => state.activeChartData = updval,
|
||||
setActiveMenuChartData: (state, updval) => state.activeMenuChartData = updval,
|
||||
setSelectedPackStruct: (state, updval) => state.selectedPackStruct = updval,
|
||||
setSelectedPackMode: (state, updval) => state.selectedPackMode = updval,
|
||||
|
||||
setSelectsData: (state, updval) => state.selectsData = updval,
|
||||
setSearchValue: (state, updval) => state.searchValue = updval,
|
||||
setSelectedData: (state, updval) => state.selectedData = updval,
|
||||
setMachinesDataDefault: (state, updval) => state.machinesDataDefault = updval,
|
||||
setMachinesData: (state, updval) => state.machinesData = updval,
|
||||
setTableData: (state, updval) => state.tableData = updval,
|
||||
setChartsData: (state, updval) => state.chartsData = updval,
|
||||
setChartsDataMount: (state, updval) => state.chartsMountData = updval,
|
||||
setHistoryData: (state, updval) => state.historyData = updval,
|
||||
setHistoryMachines: (state, updval) => state.historyMachines = updval,
|
||||
setLegendFiltersParams: (state, updval) => state.legendFiltersParams = updval,
|
||||
setPagination: (state, updval) => state.pagination = updval,
|
||||
setMapData: (state, updval) => state.mapData = updval,
|
||||
setMachineInfo: (state, updval) => state.machineInfo = updval,
|
||||
setReportPacks: (state, updval) => state.reportPacks = updval,
|
||||
setStructPackDefault: (state, updval) => state.structPackDefault = updval,
|
||||
setSelectPackStructs: (state, updval) => state.selectPackStructs = updval,
|
||||
setPackData: (state, updval) => state.packData = updval,
|
||||
setModalMachines: (state, updval) => state.modalMachines = updval,
|
||||
resetStore: (state) => {
|
||||
Object.entries(initState).forEach(([k,v]) => {
|
||||
state[k] = v
|
||||
})
|
||||
},
|
||||
for (let key in initState) {
|
||||
state[key] = initState[key]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const actions = {
|
||||
uploadData: async ({commit, getters, state}, externalParams) => {
|
||||
try{
|
||||
// const machinesData = toRaw(getters.machinesData)
|
||||
// const machinesDataDefault = toRaw(state.machinesDataDefault)
|
||||
const pagination = toRaw(getters.pagination)
|
||||
// const chartsData = toRaw(state.chartsData)
|
||||
const historyData = externalParams.historyData ? externalParams.historyData : toRaw(state.historyData)
|
||||
const chartsData = !isEmpty(dataMachines) ? dataMachines.filter((machine) => machine.machine_id !== null) : []
|
||||
const chartsMountData = !isEmpty(dataMount) ? dataMount.filter((el) => el.client_type !== null) : []
|
||||
|
||||
const updatedData = loadingChartsData({chartsSetup: chartsSetup, data: chartsData, dataMount: chartsMountData, prevGroupByData: {}, prevGroupByFilters: {}})
|
||||
const filteredSelects = prepareSelects(selects, selectors)
|
||||
const mergedData = mergedMachines(dataMachines, historyData)
|
||||
const currentTableData = loadingPagination(dataMachines, pagination)
|
||||
const currentSelectedMode = externalParams.urlParams ? externalParams.urlParams : 'cards'
|
||||
// console.log('updatedData', updatedData)
|
||||
|
||||
commit('setSelectedMode', currentSelectedMode)
|
||||
commit('setTableData', currentTableData)
|
||||
commit('setPagination', pagination)
|
||||
commit('setSelectsData', filteredSelects)
|
||||
commit('setChartsData', updatedData)
|
||||
commit('setChartsDataMount', chartsMountData)
|
||||
commit('setMachinesDataDefault', dataMachines)
|
||||
commit('setMachinesData', mergedData)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
},
|
||||
updateSearch: async ({commit, getters, state}, updatedSearchValue) => {
|
||||
try {
|
||||
const selectedSearchMode = toRaw(getters.selectedSearchMode)
|
||||
const selectedData = toRaw(getters.selectedData)
|
||||
const machinesDataDefault = toRaw(state.machinesDataDefault)
|
||||
// const machinesData = toRaw(state.machinesData)
|
||||
const isEmptyParams = isEmpty(selectedData)
|
||||
let updatedFilters = []
|
||||
if (updatedSearchValue) {
|
||||
console.log('isEmptyParams', isEmptyParams)
|
||||
console.log('selectedData', selectedData)
|
||||
// updatedFilters = isEmptyParams ? [{[selectedSearchMode.key]: updatedSearchValue}] : [...selectedData.filter, {[selectedSearchMode.key]: updatedSearchValue}]
|
||||
updatedFilters = [{[selectedSearchMode.key]: updatedSearchValue}]
|
||||
}
|
||||
if (!updatedSearchValue) {
|
||||
updatedFilters = !isEmptyParams ? selectedData.filter.filter((el) => !el[selectedSearchMode.key]) : selectedData
|
||||
}
|
||||
const updatedFiltersForSend = {filter: updatedFilters}
|
||||
// const currentData = !isEmptyParams && updatedSearchValue && !isEmpty(machinesData) ? machinesData : machinesDataDefault
|
||||
const updatedData = setUpdatedDataMachines(machinesDataDefault, updatedFiltersForSend)
|
||||
const updatedDataCharts = loadingChartsData({chartsSetup: chartsSetup, data: updatedData, dataMount: dataMount, prevGroupByData: {}, prevGroupByFilters: {}})
|
||||
commit('setSelectedData', updatedFiltersForSend)
|
||||
commit('setSelectedSelects', {})
|
||||
commit('setSearchValue', updatedSearchValue)
|
||||
commit('setMachinesData', updatedData)
|
||||
commit('setChartsData', updatedDataCharts)
|
||||
colorSelection(selectedSearchMode.key, updatedSearchValue)
|
||||
// console.log('updatedFilters', updatedFilters)
|
||||
// console.log('updatedData', updatedData)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
},
|
||||
updateSelects: async ({dispatch, commit, getters, state}, updatedSelect) => {
|
||||
try {
|
||||
const allSelects = toRaw(getters.selectsData)
|
||||
const selectedSelects = toRaw(getters.selectedSelects)
|
||||
const machinesDataDefault = toRaw(state.machinesDataDefault)
|
||||
dispatch('updateSearch', '')
|
||||
const curUpdatedSelectName = updatedSelect.key === 'set' ? updatedSelect.value[0].name : updatedSelect.value.name
|
||||
let updatedSelects = {}
|
||||
for (let i = 0; i < allSelects.length; i++) {
|
||||
const curSelect = allSelects[i]
|
||||
const newSelected = curSelect.data.find((el) => el.name === curUpdatedSelectName)
|
||||
if (!newSelected && (selectedSelects[curSelect.key] && selectedSelects[curSelect.key].length > 0)) {
|
||||
updatedSelects[curSelect.key] = selectedSelects[curSelect.key]
|
||||
}
|
||||
if (updatedSelect.key === 'removed' && newSelected && (selectedSelects[curSelect.key] && selectedSelects[curSelect.key].length === 0)) {
|
||||
break
|
||||
}
|
||||
if (updatedSelect.key === 'removed' && newSelected && (selectedSelects[curSelect.key] && selectedSelects[curSelect.key].length > 0)) {
|
||||
updatedSelects[curSelect.key] = selectedSelects[curSelect.key].filter((el) => el.name !== newSelected.name)
|
||||
break
|
||||
}
|
||||
if (updatedSelect.key === 'set' && newSelected && (selectedSelects[curSelect.key] && selectedSelects[curSelect.key].length > 0)) {
|
||||
updatedSelects[curSelect.key] = selectedSelects[curSelect.key]
|
||||
break
|
||||
}
|
||||
}
|
||||
const updatedFilters = Object.entries(updatedSelects).map(([key, value]) => ({[key]: value.map((el) => el.name)}))
|
||||
// const mergedFilters = searchValue ? [...updatedFilters, {[selectedSearchMode.key]: searchValue}] : updatedFilters
|
||||
// console.log('mergedFilters', mergedFilters)
|
||||
// const currentData = !isEmptyParams ? machinesData : machinesDataDefault
|
||||
const updatedFiltersForSend = {filter: updatedFilters}
|
||||
const updatedData = setUpdatedDataMachines(machinesDataDefault, updatedFiltersForSend)
|
||||
const updatedDataCharts = loadingChartsData({chartsSetup: chartsSetup, data: updatedData, dataMount: dataMount, prevGroupByData: {}, prevGroupByFilters: {}})
|
||||
// console.log('updatedData', updatedData)
|
||||
// console.log('updatedFilters', updatedFilters)
|
||||
commit('setMachinesData', updatedData)
|
||||
commit('setChartsData', updatedDataCharts)
|
||||
commit('setSelectedSelects', updatedSelects)
|
||||
commit('setSelectedData', updatedFiltersForSend)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
},
|
||||
updateCharts: async ({commit, getters, state}, updatedData) => {
|
||||
try {
|
||||
switch(updatedData.action) {
|
||||
case 'nextLayoutChart':
|
||||
// console.log('updatedDataNext', updatedData)
|
||||
const prevGroupByFiltersNext = updatedData.prevGroupByFilters
|
||||
const updatedFiltersNext = {...prevGroupByFiltersNext, ...updatedData.prevGroupByData}
|
||||
const prevGroupByValue = updatedData.prevGroupByData.type ? updatedData.prevGroupByData.type : null
|
||||
const groupByKeyNext = setNextLayoutGroupByKey(updatedData.groupByKey, prevGroupByValue)
|
||||
if (groupByKeyNext) {
|
||||
const activeChartData = {id: updatedData.id, data: updatedData.data, groupByKey: groupByKeyNext, filterKey: updatedData.filterKey, type: updatedData.type, groupByValue: updatedData.groupByValue}
|
||||
const newData = setBarTypesChart(activeChartData, updatedData.prevGroupByData, updatedFiltersNext, state.machinesDataDefault, toRaw(state.chartsData))
|
||||
return commit('setActiveChartData', {...activeChartData, data: newData})
|
||||
}
|
||||
break
|
||||
case 'beforeLayoutChart':
|
||||
// console.log('updatedDataBefore', updatedData)
|
||||
const prevGroupByData = updatedData.groupByInfo.prevGroupByData
|
||||
const prevGroupByFiltersBefore = updatedData.groupByInfo.prevGroupByFilters
|
||||
const groupByKeyBefore = Object.keys(prevGroupByData)[0] // Получаем уже предыдущее значение ключа
|
||||
delete prevGroupByFiltersBefore[groupByKeyBefore] // Удаляем значение после вычисления prevGroupByData, так как подымаемся на уровень выше, сохраняя актуальное значение для фильтрации
|
||||
const isOnlyFiltersParams = equals(prevGroupByData, prevGroupByFiltersBefore)
|
||||
const updatedPrevGroupByDataBefore = isOnlyFiltersParams ? {} : setBeforeLayoutGroupByData(prevGroupByData, prevGroupByFiltersBefore, updatedData.groupByInfo.type)
|
||||
if (groupByKeyBefore) {
|
||||
const activeChartData = {id: updatedData.id, data: updatedData.data, groupByKey: groupByKeyBefore, filterKey: updatedData.filterKey, type: updatedData.groupByInfo.type, groupByValue: updatedData.groupByInfo.groupByValue}
|
||||
const newData = setBarTypesChart(activeChartData, updatedPrevGroupByDataBefore, prevGroupByFiltersBefore, state.machinesDataDefault, toRaw(state.chartsData))
|
||||
return commit('setActiveChartData', {...activeChartData, data: newData})
|
||||
}
|
||||
break
|
||||
case 'openMenuChart':
|
||||
// console.log('updatedDataOpen', updatedData)
|
||||
const openMenuChart = toRaw(state.activeMenuChartData.openMenuChart)
|
||||
updatedData.groupByInfo.data[0].type = updatedData.groupByInfo.type
|
||||
const activeChartDataMenu = {chartId: updatedData.groupByInfo.chartId, data: updatedData.groupByInfo.data, groupByKey: updatedData.groupByInfo.groupByKey, filterKey: updatedData.groupByInfo.filterKey, type: updatedData.groupByInfo.type, groupByValue: updatedData.groupByInfo.groupByValue}
|
||||
const newDataMenu = setBarTypesChart(activeChartDataMenu, updatedData.groupByInfo.prevGroupByData, updatedData.groupByInfo.prevGroupByFilters, state.machinesDataDefault, toRaw(state.chartsData))
|
||||
const isNotTypesChartsMenu = typesCharts(updatedData.groupByInfo.type)
|
||||
const toggleActiveMenuChartData = {openMenuChart: !openMenuChart, groupByInfo: {...activeChartDataMenu, data: isNotTypesChartsMenu ? updatedData.groupByInfo.data[0] : newDataMenu}}
|
||||
commit('setActiveMenuChartData', toggleActiveMenuChartData)
|
||||
break
|
||||
case 'downloadChart':
|
||||
// console.log('updatedDataDownload', updatedData)
|
||||
const activeChartDataDownload = {chartId: updatedData.groupByInfo.chartId, isDownloadChart: updatedData.groupByInfo.isDownloadChart, data: updatedData.groupByInfo.data, groupByKey: updatedData.groupByInfo.groupByKey, prevGroupByData: updatedData.groupByInfo.prevGroupByData, prevGroupByFilters: updatedData.groupByInfo.prevGroupByFilters, filterKey: updatedData.groupByInfo.filterKey, type: updatedData.groupByInfo.type, groupByValue: updatedData.groupByInfo.groupByValue}
|
||||
const newDataDownload = setBarTypesChart(activeChartDataDownload, updatedData.groupByInfo.prevGroupByData, updatedData.groupByInfo.prevGroupByFilters, state.machinesDataDefault, toRaw(state.chartsData))
|
||||
const isNotTypesChartsDownload = typesCharts(updatedData.groupByInfo.type)
|
||||
const downloadActiveMenuChartData = {openMenuChart: false, groupByInfo: {...updatedData.groupByInfo, data: isNotTypesChartsDownload ? updatedData.groupByInfo.data[0] : newDataDownload}}
|
||||
commit('setActiveMenuChartData', downloadActiveMenuChartData)
|
||||
break
|
||||
case 'legendFiltersParams':
|
||||
commit('setLegendFiltersParams', updatedData.data)
|
||||
default: return false
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
},
|
||||
updatePagination: async ({commit, getters, state}, updatedData) => {
|
||||
try {
|
||||
const pagination = toRaw(getters.pagination)
|
||||
const machinesDataDefault = toRaw(state.machinesDataDefault)
|
||||
const newData = setPagination(machinesDataDefault, pagination, updatedData)
|
||||
console.log('currentTableData', newData.currentTableData)
|
||||
commit('setTableData', newData.currentTableData)
|
||||
commit('setPagination', newData.updatedPagination)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
},
|
||||
openMapModal: async ({commit, state}, machine) => {
|
||||
try {
|
||||
// Добавить запрос на получение координат
|
||||
/*
|
||||
machine_id = machine["machine_id"]
|
||||
last_loc = Communicator.PackFetcher.last_locations([machine_id])
|
||||
|
||||
*/
|
||||
const coords = [44.510345, 48.771025]
|
||||
const params = {machine: machine, coords: coords}
|
||||
commit('setMapData', params)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
},
|
||||
openDataModal: async ({commit, state}, machine) => {
|
||||
try {
|
||||
|
||||
// Добавить запрос на получение пакетов и информации о машине
|
||||
/*
|
||||
curr_machine_info = Communicator.Devices.askr_devices(where: "imei = #{imei}")
|
||||
|
||||
[{_, machine_name} | machine_info] =
|
||||
Analyzer.reparse_machine_info(curr_machine_info, :imei)
|
||||
|> Enum.reduce([], fn
|
||||
{"Текущая машина", _} = cur, acc -> [cur] ++ acc
|
||||
cur, acc -> acc ++ [cur]
|
||||
end)
|
||||
|
||||
report_packs =
|
||||
Enum.reduce(curr_machine_info, [], fn
|
||||
%{imei: imei}, acc ->
|
||||
acc ++
|
||||
PacksFuncs.get_pack_nums(
|
||||
imei,
|
||||
Timex.now() |> Timex.beginning_of_day(),
|
||||
Timex.now() |> Timex.end_of_day()
|
||||
)
|
||||
|
||||
_, acc ->
|
||||
acc
|
||||
end)
|
||||
|> DynamicStructDestroyer.destroy()
|
||||
|> Enum.sort_by(& &1.packNumber)
|
||||
|
||||
*/
|
||||
|
||||
commit('setMachineInfo', machineInfo)
|
||||
commit('setReportPacks', reportPacks)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
},
|
||||
loadPack: async ({commit, state}, packNumber) => {
|
||||
try {
|
||||
|
||||
/* Получение данных о пакете
|
||||
report =
|
||||
Enum.reduce(curr_machine_info, [], fn
|
||||
%{imei: imei}, acc ->
|
||||
acc ++ PacksFuncs.upload_machine_data(imei, pack_number, dt_start, dt_finish, 30) // Огреничение до 30 машин askr_logs
|
||||
|
||||
_, acc ->
|
||||
acc
|
||||
end)
|
||||
|> DynamicStructDestroyer.destroy()
|
||||
|
||||
Получение структуры пакета
|
||||
|
||||
pack_structs = Helper.get_structs_of_pack(pack_number)
|
||||
|
||||
def get_structs_of_pack(pack_number) do
|
||||
LiveMonitor.Packages.list_pack_struct()
|
||||
|> Enum.filter(&(&1.pack == pack_number))
|
||||
end
|
||||
|
||||
*/
|
||||
console.log('packNumber', packNumber)
|
||||
// const dataSource = !isEmpty(report) ? report.askr_logs.sort((a, b) => b.pack_dt - a.pack_dt) : []
|
||||
const dataSource = !isEmpty(multiReport) ? multiReport.askr_logs.sort((a, b) => b.pack_dt - a.pack_dt).slice(0, 30) : [] // Огреничение до 30 машин askr_logs
|
||||
// const columns = fetchColumn(packStructure, report)
|
||||
const columns = fetchColumn(multiPackStructure, multiReport)
|
||||
// const selectedPackStruct = packStructure.map((item) => ({id: item.id, name: item.name, packNumber: packNumber}))
|
||||
console.log('multiPackStructure', multiPackStructure)
|
||||
console.log('multiReport', multiReport)
|
||||
console.log('columns', columns)
|
||||
const selectPackStructs = multiPackStructure.map((item) => ({id: item.id, name: item.name, packNumber: packNumber}))
|
||||
commit('setStructPackDefault', multiPackStructure)
|
||||
commit('setSelectPackStructs', selectPackStructs)
|
||||
commit('setSelectedPackStruct', selectPackStructs[0])
|
||||
commit('setPackData', {dataSource, columns, height: '550px'})
|
||||
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
},
|
||||
updateModePack: async ({commit, getters, state}, updatedMode) => {
|
||||
try {
|
||||
const structPackDefault = toRaw(state.structPackDefault)
|
||||
const currentReport = multiReport[updatedMode] ? multiReport[updatedMode] : []
|
||||
const columns = updatedMode === 'askr_logs' ? fetchColumn(structPackDefault, multiReport, null) : prepareSetPackColumns(updatedMode, currentReport)
|
||||
console.log('columns', columns)
|
||||
console.log('currentReport', currentReport)
|
||||
commit('setSelectedPackMode', updatedMode)
|
||||
commit('setPackData', {dataSource: currentReport, columns, height: '550px'})
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
},
|
||||
updateSelectStruct: async ({commit, getters, state}, updatedStructId) => {
|
||||
try {
|
||||
const updatedMode = toRaw(getters.selectedPackMode)
|
||||
const currentReport = toRaw(state.packData.dataSource)
|
||||
const structPackDefault = toRaw(state.structPackDefault)
|
||||
const selectPackStructs = toRaw(getters.selectPackStructs)
|
||||
const [selectedPackStruct] = selectPackStructs.filter((item) => item.id === updatedStructId)
|
||||
console.log('selectedPackStruct', selectedPackStruct)
|
||||
// const currentReport = multiReport[updatedMode] ? multiReport[updatedMode] : []
|
||||
const columns = updatedMode === 'askr_logs' ? fetchColumn(structPackDefault, multiReport, updatedStructId) : prepareSetPackColumns(updatedMode, currentReport)
|
||||
console.log('updatedMode', updatedMode)
|
||||
console.log('structPackDefault', structPackDefault)
|
||||
console.log('columns', columns)
|
||||
console.log('currentReport', currentReport)
|
||||
commit('setSelectedPackStruct', selectedPackStruct)
|
||||
commit('setPackData', {dataSource: currentReport, columns, height: '550px'})
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
},
|
||||
clearFilters: async ({commit, state}) => {
|
||||
try {
|
||||
const machinesDataDefault = toRaw(state.machinesDataDefault)
|
||||
const updatedFiltersForSend = {filter: []}
|
||||
const updatedData = setUpdatedDataMachines(machinesDataDefault, updatedFiltersForSend)
|
||||
const updatedDataCharts = loadingChartsData({chartsSetup: chartsSetup, data: updatedData, dataMount: dataMount, prevGroupByData: {}, prevGroupByFilters: {}})
|
||||
commit('setSelectedSelects', {})
|
||||
commit('setSelectedData', [])
|
||||
commit('setMachinesData', updatedData)
|
||||
commit('setChartsData', updatedDataCharts)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
saveModalMachines: ({commit}, machines) => {
|
||||
commit('setModalMachines', machines)
|
||||
},
|
||||
resetStore: ({commit}) => {
|
||||
commit('resetStore')
|
||||
|
||||
Reference in New Issue
Block a user