From d03de8b2a2581ca590526aeaa76a4f7a76c0b3b8 Mon Sep 17 00:00:00 2001 From: Edwin Betancourt Date: Wed, 11 Mar 2020 21:38:41 -0400 Subject: [PATCH] improves: Add state restart for modules that manage and store data. (#397) --- plop-templates/ADempiere/store/index.hbs | 8 ++- src/store/modules/ADempiere/containerInfo.js | 57 ++++++++++------ src/store/modules/ADempiere/contextMenu.js | 37 ++++++----- src/store/modules/ADempiere/data.js | 29 +++++++-- .../modules/ADempiere/languageControl.js | 4 ++ src/store/modules/ADempiere/lookup.js | 13 ++-- src/store/modules/ADempiere/processControl.js | 53 ++++++--------- src/store/modules/ADempiere/reportControl.js | 37 +++++++---- src/store/modules/ADempiere/utils.js | 65 ++++++++++--------- src/store/modules/ADempiere/window.js | 13 ++-- src/store/modules/ADempiere/windowControl.js | 31 +++++---- src/store/modules/user.js | 4 +- 12 files changed, 207 insertions(+), 144 deletions(-) diff --git a/plop-templates/ADempiere/store/index.hbs b/plop-templates/ADempiere/store/index.hbs index a6c13b6c..0a9320d6 100644 --- a/plop-templates/ADempiere/store/index.hbs +++ b/plop-templates/ADempiere/store/index.hbs @@ -5,7 +5,13 @@ const {{name}} = { }, {{/if}} {{#if mutations}} - mutations: {}, + mutations: { + {{#if state}} + resetState{{name}}(state) { + state = {} + } + {{/if}} + }, {{/if}} {{#if actions}} actions: {}, diff --git a/src/store/modules/ADempiere/containerInfo.js b/src/store/modules/ADempiere/containerInfo.js index a312e53e..4a27ea52 100644 --- a/src/store/modules/ADempiere/containerInfo.js +++ b/src/store/modules/ADempiere/containerInfo.js @@ -1,17 +1,26 @@ -import { requestListRecordsLogs, requestListWorkflowsLogs, requestListWorkflows, requestListRecordChats, requestListChatEntries, requestCreateChatEntry } from '@/api/ADempiere/data' +import { + requestListRecordsLogs, + requestListWorkflowsLogs, + requestListWorkflows, + requestListRecordChats, + requestListChatEntries, + requestCreateChatEntry +} from '@/api/ADempiere/data' import { isEmptyValue } from '@/utils/ADempiere/valueUtils' +const initStateContainerInfo = { + listworkflowLog: [], + listRecordLogs: [], + listRecordChats: [], + listChatEntries: [], + listWorkflows: [], + chat: [], + note: [], + isNote: false +} + const containerInfo = { - state: { - listworkflowLog: [], - listRecordLogs: [], - listRecordChats: [], - listChatEntries: [], - listWorkflows: [], - chat: [], - note: [], - isNote: false - }, + state: initStateContainerInfo, mutations: { addListWorkflow(state, payload) { state.listworkflowLog = payload @@ -36,6 +45,9 @@ const containerInfo = { }, isNote(state, payload) { state.isNote = payload + }, + resetStateContainerInfo(state) { + state = initStateContainerInfo } }, actions: { @@ -66,17 +78,17 @@ const containerInfo = { const pageToken = 0 return requestListRecordChats({ tableName, recordId, pageSize, pageToken }) .then(response => { - var chatList = response.recordChatsList - var listRecord = { + const chatList = response.recordChatsList + const listRecord = { recordChatsList: response.recordChatsList, recordCount: response.recordCount, nextPageToken: response.nextPageToken } chatList.forEach(chat => { - var uuid = chat.chatUuid + const uuid = chat.chatUuid requestListChatEntries({ uuid, pageSize, pageToken }) .then(response => { - var listlogsChat = state.chat + const listlogsChat = state.chat let chatUpgrade = [] let chatAll if (recordId === chat.recordId) { @@ -102,24 +114,25 @@ const containerInfo = { console.warn(`Error getting List Chat: ${error.message}. Code: ${error.code}.`) }) }, - listRecordLogs({ commit, state }, params) { + listRecordLogs({ commit }, params) { const tableName = params.tableName const recordId = params.recordId const pageSize = 0 const pageToken = 0 return requestListRecordsLogs({ tableName, recordId, pageSize, pageToken }) .then(response => { - var listRecord = { + const listRecord = { recordCount: response.recordCount, recorLogs: response.recordLogsList } commit('addListRecordLogs', listRecord) + return listRecord }) .catch(error => { console.warn(`Error getting List Record Logs: ${error.message}. Code: ${error.code}.`) }) }, - listWorkflowLogs({ commit, state, dispatch }, params) { + listWorkflowLogs({ commit, dispatch }, params) { const tableName = params.tableName const recordId = params.recordId const pageSize = 0 @@ -127,28 +140,30 @@ const containerInfo = { dispatch('listWorkflows', tableName) return requestListWorkflowsLogs({ tableName, recordId, pageSize, pageToken }) .then(response => { - var workflowLog = { + const workflowLog = { recordCount: response.recordCount, workflowLogsList: response.workflowLogsList, nextPageToken: response.nextPageToken } commit('addListWorkflow', workflowLog) + return workflowLog }) .catch(error => { console.warn(`Error getting List workflow: ${error.message}. Code: ${error.code}.`) }) }, - listWorkflows({ commit, state }, tableName) { + listWorkflows({ commit }, tableName) { const pageSize = 0 const pageToken = 0 return requestListWorkflows({ tableName, pageSize, pageToken }) .then(response => { - var nodeWorflow = { + const nodeWorflow = { nextPageToken: response.nextPageToken, recordCount: response.recordCount, workflowsList: response.workflowsList } commit('addListWorkflows', nodeWorflow) + return nodeWorflow }) .catch(error => { console.warn(`Error getting List workflow: ${error.message}. Code: ${error.code}.`) diff --git a/src/store/modules/ADempiere/contextMenu.js b/src/store/modules/ADempiere/contextMenu.js index 8edb8e08..86e3d31b 100644 --- a/src/store/modules/ADempiere/contextMenu.js +++ b/src/store/modules/ADempiere/contextMenu.js @@ -4,7 +4,7 @@ import { requestListDocumentActions, requestListDocumentStatuses } from '@/api/A // Store used for set all related to context menu // for Window, Process, Smart Browser andother customized component // See structure: -// menu: [ +// contextMenu: [ // { // containerUuid: '', // relations: [], @@ -14,22 +14,24 @@ import { requestListDocumentActions, requestListDocumentStatuses } from '@/api/A // lastAction: {} // } // ] -const contextMenu = { - state: { - contextMenu: [], - listDocumentStatus: { - defaultDocumentAction: undefined, - documentActionsList: [], - recordId: undefined, - recordUuid: undefined - }, - listDocumentAction: { - defaultDocumentAction: undefined, - documentActionsList: [], - recordId: undefined, - recordUuid: undefined - } +const initStateContextMenu = { + contextMenu: [], + listDocumentStatus: { + defaultDocumentAction: undefined, + documentActionsList: [], + recordId: undefined, + recordUuid: undefined }, + listDocumentAction: { + defaultDocumentAction: undefined, + documentActionsList: [], + recordId: undefined, + recordUuid: undefined + } +} + +const contextMenu = { + state: initStateContextMenu, mutations: { setContextMenu(state, payload) { state.contextMenu.push(payload) @@ -42,6 +44,9 @@ const contextMenu = { }, addlistDocumentStatus(state, payload) { state.listDocumentStatus = payload + }, + resetContextMenu(state) { + state = initStateContextMenu } }, actions: { diff --git a/src/store/modules/ADempiere/data.js b/src/store/modules/ADempiere/data.js index 88a654b2..3688a7b3 100644 --- a/src/store/modules/ADempiere/data.js +++ b/src/store/modules/ADempiere/data.js @@ -13,13 +13,15 @@ import { parseContext } from '@/utils/ADempiere/contextUtils' import { showMessage } from '@/utils/ADempiere/notification' import language from '@/lang' +const initStateBusinessData = { + recordSelection: [], // record data and selection + inGetting: [], + contextInfoField: [], + recordPrivateAccess: {} +} + const data = { - state: { - recordSelection: [], // record data and selection - inGetting: [], - contextInfoField: [], - recordPrivateAccess: {} - }, + state: initStateBusinessData, mutations: { addInGetting(state, payload) { state.inGetting.push(payload) @@ -81,6 +83,9 @@ const data = { }, setPrivateAccess(state, payload) { state.recordPrivateAccess = payload + }, + resetStateBusinessData(state) { + state = initStateBusinessData } }, actions: { @@ -900,6 +905,18 @@ const data = { }) console.warn(`Error unlock private access: ${error.message}. Code: ${error.code}.`) }) + }, + resetStateBusinessData({ commit }) { + commit('resetStateContainerInfo') + commit('setInitialContext', {}) + commit('resetStateTranslations') + commit('resetStateBusinessData') + commit('resetContextMenu') + commit('resetStateTranslations') + commit('resetStateLookup') + commit('resetStateProcessControl') + commit('resetStateUtils') + commit('resetStateWindowControl') } }, getters: { diff --git a/src/store/modules/ADempiere/languageControl.js b/src/store/modules/ADempiere/languageControl.js index 771d3f77..f62a9cb1 100644 --- a/src/store/modules/ADempiere/languageControl.js +++ b/src/store/modules/ADempiere/languageControl.js @@ -4,6 +4,7 @@ import { updateEntity } from '@/api/ADempiere/data' import { isEmptyValue } from '@/utils/ADempiere/valueUtils' + const languageControl = { state: { languagesList: [], @@ -25,6 +26,9 @@ const languageControl = { }, addTranslationChangeRecord(state, payload) { payload.currentTranslation = payload.newTranlation + }, + resetStateTranslations(state) { + state.translationsList = [] } }, actions: { diff --git a/src/store/modules/ADempiere/lookup.js b/src/store/modules/ADempiere/lookup.js index 2214bad2..6eb8e983 100644 --- a/src/store/modules/ADempiere/lookup.js +++ b/src/store/modules/ADempiere/lookup.js @@ -3,11 +3,13 @@ import { getCurrentRole } from '@/utils/ADempiere/auth' import { isEmptyValue } from '@/utils/ADempiere/valueUtils' import { parseContext } from '@/utils/ADempiere/contextUtils' +const initStateLookup = { + lookupItem: [], + lookupList: [] +} + const lookup = { - state: { - lookupItem: [], - lookupList: [] - }, + state: initStateLookup, mutations: { addLoockupItem(state, payload) { state.lookupItem.push(payload) @@ -18,6 +20,9 @@ const lookup = { deleteLookupList(state, payload) { state.lookupItem = payload.lookupItem state.lookupList = payload.lookupList + }, + resetStateLookup(state) { + state = initStateLookup } }, actions: { diff --git a/src/store/modules/ADempiere/processControl.js b/src/store/modules/ADempiere/processControl.js index 6a8679da..a8f1ed6d 100644 --- a/src/store/modules/ADempiere/processControl.js +++ b/src/store/modules/ADempiere/processControl.js @@ -7,24 +7,26 @@ import { isEmptyValue } from '@/utils/ADempiere/valueUtils' import language from '@/lang' import router from '@/router' +const initStateProcessControl = { + inExecution: [], // process not response from server + isVisibleDialog: false, + reportObject: {}, + reportList: [], + metadata: {}, + process: [], // process to run finish + sessionProcess: [], + notificationProcess: [], + inRequestMetadata: [], + reportViewList: [], + totalResponse: 0, + totalRequest: 0, + totalSelection: 0, + errorSelection: 0, + successSelection: 0 +} + const processControl = { - state: { - inExecution: [], // process not response from server - isVisibleDialog: false, - reportObject: {}, - reportList: [], - metadata: {}, - process: [], // process to run finish - sessionProcess: [], - notificationProcess: [], - inRequestMetadata: [], - reportViewList: [], - totalResponse: 0, - totalRequest: 0, - totalSelection: 0, - errorSelection: 0, - successSelection: 0 - }, + state: initStateProcessControl, mutations: { // Add process in execution addInExecution(state, payload) { @@ -49,8 +51,8 @@ const processControl = { addStartedProcess(state, payload) { state.process.push(payload) }, - dataResetCacheProcess(state, payload) { - state.process = payload + resetStateProcessControl(state) { + state = initStateProcessControl }, /** * @@ -78,16 +80,6 @@ const processControl = { changeFormatReport(state, payload) { state.reportFormat = payload }, - clearProcessControl(state) { - state.inExecution = [] // process not response from server - state.reportObject = {} - state.reportList = [] - state.metadata = {} - state.process = [] // process to run finish - state.sessionProcess = [] - state.notificationProcess = [] - state.inRequestMetadata = [] - }, setReportViewsList(state, payload) { state.reportViewList.push(payload) }, @@ -913,9 +905,6 @@ const processControl = { if (reportFormat !== undefined) { commit('changeFormatReport', reportFormat) } - }, - clearProcessControl({ commit }) { - commit('clearProcessControl') } }, getters: { diff --git a/src/store/modules/ADempiere/reportControl.js b/src/store/modules/ADempiere/reportControl.js index b0a770c7..3475b9de 100644 --- a/src/store/modules/ADempiere/reportControl.js +++ b/src/store/modules/ADempiere/reportControl.js @@ -1,12 +1,20 @@ -import { requestReportViews, requestPrintFormats, requestDrillTables, getReportOutput } from '@/api/ADempiere' -import { isEmptyValue } from '@/utils/ADempiere' -const contextMenu = { - state: { - reportFormatsList: [], - reportViewsList: [], - drillTablesList: [], - reportOutput: {} - }, +import { + requestReportViews, + requestPrintFormats, + requestDrillTables, + getReportOutput +} from '@/api/ADempiere/data' +import { isEmptyValue } from '@/utils/ADempiere/valueUtils' + +const initStateReportControl = { + reportFormatsList: [], + reportViewsList: [], + drillTablesList: [], + reportOutput: {} +} + +const reportControl = { + state: initStateReportControl, mutations: { setReportFormatsList(state, payload) { state.reportFormatsList.push(payload) @@ -19,6 +27,9 @@ const contextMenu = { }, setNewReportOutput(state, payload) { state.reportOutput = payload + }, + resetReportControl(state) { + state = initStateReportControl } }, actions: { @@ -181,7 +192,7 @@ const contextMenu = { }, getters: { getPrintFormatList: (state) => (containerUuid) => { - var printFormatList = state.reportFormatsList.find(list => list.containerUuid === containerUuid) + const printFormatList = state.reportFormatsList.find(list => list.containerUuid === containerUuid) if (printFormatList) { return printFormatList.printFormatList } @@ -191,14 +202,14 @@ const contextMenu = { return getters.getPrintFormatList(containerUuid).find(printFormat => printFormat.isDefault) }, getReportViewList: (state) => (containerUuid) => { - var reportViewList = state.reportViewsList.find(list => list.containerUuid === containerUuid) + const reportViewList = state.reportViewsList.find(list => list.containerUuid === containerUuid) if (reportViewList) { return reportViewList.viewList } return [] }, getDrillTablesList: (state) => (containerUuid) => { - var drillTablesList = state.drillTablesList.find(list => list.containerUuid === containerUuid) + const drillTablesList = state.drillTablesList.find(list => list.containerUuid === containerUuid) if (drillTablesList) { return drillTablesList.viewList } @@ -207,4 +218,4 @@ const contextMenu = { } } -export default contextMenu +export default reportControl diff --git a/src/store/modules/ADempiere/utils.js b/src/store/modules/ADempiere/utils.js index 21a39c00..7998a840 100644 --- a/src/store/modules/ADempiere/utils.js +++ b/src/store/modules/ADempiere/utils.js @@ -1,36 +1,38 @@ import Vue from 'vue' -const utils = { - state: { - width: 0, - height: 0, - splitHeight: 50, - splitHeightTop: 0, - widthLayout: 0, - tempShareLink: '', - oldAction: undefined, - reportType: '', - isShowedTable: false, - recordUuidTable: 0, - isShowedTabChildren: false, - recordTable: 0, - selectionProcess: [], - isContainerInfo: false, - documentAction: [], - chatText: '', - markDown: false, - openRoute: { - path: '', - name: '', - route: {}, - params: {}, - definedParameters: {}, - query: {}, - isReaded: false, - isLoaded: false - }, - panelRight: '' +const initStateUtils = { + width: 0, + height: 0, + splitHeight: 50, + splitHeightTop: 0, + widthLayout: 0, + tempShareLink: '', + oldAction: undefined, + reportType: '', + isShowedTable: false, + recordUuidTable: 0, + isShowedTabChildren: false, + recordTable: 0, + selectionProcess: [], + isContainerInfo: false, + documentAction: [], + chatText: '', + markDown: false, + openRoute: { + path: '', + name: '', + route: {}, + params: {}, + definedParameters: {}, + query: {}, + isReaded: false, + isLoaded: false }, + panelRight: '' +} + +const utils = { + state: initStateUtils, mutations: { setWidth(state, width) { state.width = width @@ -92,6 +94,9 @@ const utils = { }, setPanelRight(state, payload) { state.panelRight = payload + }, + resetStateUtils(state) { + state = initStateUtils } }, actions: { diff --git a/src/store/modules/ADempiere/window.js b/src/store/modules/ADempiere/window.js index 9300c472..19717232 100644 --- a/src/store/modules/ADempiere/window.js +++ b/src/store/modules/ADempiere/window.js @@ -8,19 +8,20 @@ import language from '@/lang' import router from '@/router' import { generateField, getFieldTemplate } from '@/utils/ADempiere/dictionaryUtils' +const initStateWindow = { + window: [], + windowIndex: 0 +} + const window = { - state: { - window: [], - windowIndex: 0 - }, + state: initStateWindow, mutations: { addWindow(state, payload) { state.window.push(payload) state.windowIndex++ }, dictionaryResetCacheWindow(state) { - state.window = [] - state.windowIndex = 0 + state = initStateWindow }, changeWindow(state, payload) { payload.window = payload.newWindow diff --git a/src/store/modules/ADempiere/windowControl.js b/src/store/modules/ADempiere/windowControl.js index 86b63df9..94327987 100644 --- a/src/store/modules/ADempiere/windowControl.js +++ b/src/store/modules/ADempiere/windowControl.js @@ -5,20 +5,22 @@ import { showMessage } from '@/utils/ADempiere/notification' import language from '@/lang' import router from '@/router' -const windowControl = { - state: { - inCreate: [], - references: [], - windowOldRoute: { - path: '', - fullPath: '', - query: {} - }, - dataLog: {}, // { containerUuid, recordId, tableName, eventType } - tabSequenceRecord: [], - totalResponse: 0, - totalRequest: 0 +const initStateWindowControl = { + inCreate: [], + references: [], + windowOldRoute: { + path: '', + fullPath: '', + query: {} }, + dataLog: {}, // { containerUuid, recordId, tableName, eventType } + tabSequenceRecord: [], + totalResponse: 0, + totalRequest: 0 +} + +const windowControl = { + state: initStateWindowControl, mutations: { addInCreate(state, payload) { state.inCreate.push(payload) @@ -43,6 +45,9 @@ const windowControl = { }, setTotalRequest(state, payload) { state.totalRequest = payload + }, + resetStateWindowControl(state) { + state = initStateWindowControl } }, actions: { diff --git a/src/store/modules/user.js b/src/store/modules/user.js index 8b276787..964267e3 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -162,7 +162,7 @@ const actions = { commit('SET_TOKEN', '') commit('SET_ROLES', []) commit('setIsSession', false) - dispatch('clearProcessControl', null, { + dispatch('resetStateBusinessData', null, { root: true }) dispatch('dictionaryResetCache', null, { @@ -227,7 +227,7 @@ const actions = { // Update user info and context associated with session dispatch('getInfo', changeRoleResponse.uuid) - dispatch('clearProcessControl', null, { + dispatch('resetStateBusinessData', null, { root: true }) dispatch('dictionaryResetCache', null, {