fix: Send context to process associated. (#263)

* fix: Send context values from parent view to process associated.

* change parseContext.

* fix get preference.
pull/3759/head
EdwinBetanc0urt 2020-01-24 11:38:55 -04:00 committed by Yamel Senih
parent 997b7fcfe3
commit fb08cf3c0a
14 changed files with 485 additions and 218 deletions

View File

@ -357,28 +357,22 @@ export const contextMixin = {
if (this.actions && this.actions.length) { if (this.actions && this.actions.length) {
this.actions.forEach(itemAction => { this.actions.forEach(itemAction => {
// if no exists set prop with value
itemAction.disabled = false
if (this.$route.name !== 'Report Viewer' && itemAction.action === 'changeParameters') {
itemAction.disabled = true
}
if (this.$route.meta.type === 'report' && itemAction.action === 'startProcess') { if (this.$route.meta.type === 'report' && itemAction.action === 'startProcess') {
itemAction.reportExportType = 'html' itemAction.reportExportType = 'html'
} }
if (this.$route.meta.type === 'process' && itemAction.type === 'summary') {
// if no exists set prop with value
itemAction.disabled = false
if ((this.$route.name !== 'Report Viewer' && itemAction.action === 'changeParameters') ||
(this.$route.meta.type === 'process' && itemAction.type === 'summary')) {
itemAction.disabled = true itemAction.disabled = true
} }
if (this.$route.meta.type === 'window') { if (this.$route.meta.type === 'window') {
if (this.recordUuid === 'create-new') { if (this.recordUuid === 'create-new' || !this.isInsertRecord) {
itemAction.disabled = true itemAction.disabled = true
} else {
if (this.isInsertRecord) {
itemAction.disabled = false
} else {
itemAction.disabled = true
}
} }
// rollback
if (itemAction.action === 'undoModifyData') { if (itemAction.action === 'undoModifyData') {
itemAction.disabled = Boolean(!this.getterDataLog && !this.getterWindowOldRoute) itemAction.disabled = Boolean(!this.getterDataLog && !this.getterWindowOldRoute)
} }
@ -389,6 +383,21 @@ export const contextMixin = {
showModal(action) { showModal(action) {
// TODO: Refactor and remove redundant dispatchs // TODO: Refactor and remove redundant dispatchs
if (action.type === 'process') { if (action.type === 'process') {
// Add context from view open in process to opening
if (action.parentUuidAssociated || action.containerUuidAssociated) {
const contextValues = this.$store.getters.getContextView({
parentUuid: action.parentUuidAssociated,
containerUuid: action.containerUuidAssociated
})
if (!this.isEmptyValue(contextValues)) {
this.$store.dispatch('setMultipleContextView', {
containerUuid: action.uuid,
values: contextValues
})
}
}
// open modal dialog with metadata
this.$store.dispatch('setShowDialog', { this.$store.dispatch('setShowDialog', {
type: action.type, type: action.type,
action: { action: {
@ -459,13 +468,6 @@ export const contextMixin = {
} else if (action.type === 'process') { } else if (action.type === 'process') {
// run process associate with view (window or browser) // run process associate with view (window or browser)
this.showModal(action) this.showModal(action)
if (this.panelType === 'process' || this.panelType === 'browser' || this.panelType === 'report') {
this.$store.dispatch('resetPanelToNew', {
parentUuid: this.parentUuid,
containerUuid: this.containerUuid,
panelType: this.panelType
})
}
} else if (action.type === 'dataAction') { } else if (action.type === 'dataAction') {
if (action.action === 'undoModifyData' && Boolean(!this.getterDataLog) && this.getterWindowOldRoute) { if (action.action === 'undoModifyData' && Boolean(!this.getterDataLog) && this.getterWindowOldRoute) {
this.$router.push({ this.$router.push({
@ -491,7 +493,10 @@ export const contextMixin = {
}) })
} }
} else if (action.type === 'reference') { } else if (action.type === 'reference') {
this.$store.dispatch('getWindowByUuid', { routes: this.permissionRoutes, windowUuid: action.windowUuid }) this.$store.dispatch('getWindowByUuid', {
routes: this.permissionRoutes,
windowUuid: action.windowUuid
})
if (action.windowUuid && action.recordUuid) { if (action.windowUuid && action.recordUuid) {
var windowRoute = this.$store.getters.getWindowRoute(action.windowUuid) var windowRoute = this.$store.getters.getWindowRoute(action.windowUuid)
this.$router.push({ this.$router.push({
@ -541,7 +546,10 @@ export const contextMixin = {
} }
response.url = link.href response.url = link.href
} }
this.$store.dispatch('finishProcess', { processOutput: response, routeToDelete: this.$route }) this.$store.dispatch('finishProcess', {
processOutput: response,
routeToDelete: this.$route
})
}) })
} }
}, },

View File

@ -340,8 +340,11 @@ export default {
} }
}, },
redirect({ window, columnName, value }) { redirect({ window, columnName, value }) {
this.$store.dispatch('getWindowByUuid', { routes: this.permissionRoutes, windowUuid: window.uuid }) this.$store.dispatch('getWindowByUuid', {
var windowRoute = this.$store.getters.getWindowRoute(window.uuid) routes: this.permissionRoutes,
windowUuid: window.uuid
})
const windowRoute = this.$store.getters.getWindowRoute(window.uuid)
if (windowRoute) { if (windowRoute) {
this.$router.push({ this.$router.push({
name: windowRoute.name, name: windowRoute.name,

View File

@ -81,8 +81,9 @@ export const tabMixin = {
metadataTab.whereClause = parseContext({ metadataTab.whereClause = parseContext({
parentUuid: metadataTab.parentUuid, parentUuid: metadataTab.parentUuid,
containerUuid: metadataTab.uuid, containerUuid: metadataTab.uuid,
value: metadataTab.whereClause value: metadataTab.whereClause,
}, true) isBoolToString: true
}).value
} }
} }
} }

View File

@ -111,7 +111,9 @@ const browser = {
name: process.name, name: process.name,
description: process.description, description: process.description,
isReport: process.isReport, isReport: process.isReport,
isDirectPrint: process.isDirectPrint isDirectPrint: process.isDirectPrint,
containerUuidAssociated: newBrowser.uuid,
panelTypeAssociated: panelType
}) })
// TODO: No list of parameters // TODO: No list of parameters
// // add process associated in vuex store // // add process associated in vuex store

View File

@ -38,7 +38,7 @@ const browserControl = {
parsedQuery = parseContext({ parsedQuery = parseContext({
containerUuid, containerUuid,
value: parsedQuery value: parsedQuery
}, true) }).value
} }
let parsedWhereClause = browser.whereClause let parsedWhereClause = browser.whereClause
@ -46,7 +46,7 @@ const browserControl = {
parsedWhereClause = parseContext({ parsedWhereClause = parseContext({
containerUuid, containerUuid,
value: parsedWhereClause value: parsedWhereClause
}, true) }).value
} }
let nextPageToken let nextPageToken
@ -114,7 +114,7 @@ const browserControl = {
summary: error.message, summary: error.message,
type: 'error' type: 'error'
}) })
console.warn(`Error getting browser search: ${error.message}. Code: ${error.code}`) console.warn(`Error getting browser search: ${error.message}. Code: ${error.code}.`)
}) })
} }
} }

View File

@ -15,7 +15,7 @@ const context = {
* @param {mixed} payload.value * @param {mixed} payload.value
*/ */
setContext(state, payload) { setContext(state, payload) {
var key = '' let key = ''
if (payload.parentUuid && !isEmptyValue(payload.value)) { if (payload.parentUuid && !isEmptyValue(payload.value)) {
key += payload.parentUuid + '|' key += payload.parentUuid + '|'
@ -40,15 +40,29 @@ const context = {
} }
}, },
actions: { actions: {
setContext: ({ commit }, objectValue) => { setContext({ commit }, objectValue) {
commit('setContext', objectValue) commit('setContext', objectValue)
}, },
setMultipleContext: ({ commit }, valuesToSetter) => { setMultipleContext({ commit }, valuesToSetter) {
valuesToSetter.forEach(itemToSetter => { valuesToSetter.forEach(itemToSetter => {
commit('setContext', itemToSetter) commit('setContext', itemToSetter)
}) })
}, },
setMultipleContextObject: ({ commit }, valuesToSetter) => { setMultipleContextView({ commit }, {
parentUuid,
containerUuid,
values
}) {
Object.keys(values).forEach(key => {
commit('setContext', {
parentUuid,
containerUuid,
columnName: key,
value: values[key]
})
})
},
setMultipleContextObject({ commit }, valuesToSetter) {
Object.keys(valuesToSetter).forEach(key => { Object.keys(valuesToSetter).forEach(key => {
commit('setContext', { commit('setContext', {
columnName: key, columnName: key,
@ -56,7 +70,7 @@ const context = {
}) })
}) })
}, },
setMultipleContextMap: ({ commit }, valuesToSetter) => { setMultipleContextMap({ commit }, valuesToSetter) {
return new Promise(resolve => { return new Promise(resolve => {
valuesToSetter.forEach((value, key) => { valuesToSetter.forEach((value, key) => {
commit('setContext', { commit('setContext', {
@ -67,19 +81,18 @@ const context = {
resolve() resolve()
}) })
}, },
setInitialContext: ({ commit }, otherContext = {}) => { setInitialContext({ commit }, otherContext = {}) {
commit('setInitialContext', otherContext) commit('setInitialContext', otherContext)
} }
}, },
getters: { getters: {
/** /**
* @param {object} findedContext * @param {string} parentUuid
* - parentUuid * @param {string} containerUuid
* - containerUuid * @param {string} columnName
* - columnName
*/ */
getContext: (state) => ({ parentUuid, containerUuid, columnName }) => { getContext: (state) => ({ parentUuid, containerUuid, columnName }) => {
var key = '' let key = ''
if (parentUuid) { if (parentUuid) {
key += parentUuid + '|' key += parentUuid + '|'
@ -98,8 +111,50 @@ const context = {
return state.context[key] return state.context[key]
}, },
/**
* @param {string} parentUuid
* @param {string} containerUuid
* @returns {object}
*/
getContextView: (state) => ({
parentUuid,
containerUuid
}) => {
// generate context with parent uuid or container uuid associated
const contextAllContainers = {}
Object.keys(state.context).forEach(key => {
if (key.includes(parentUuid) || key.includes(containerUuid)) {
contextAllContainers[key] = state.context[key]
}
})
// generate context only columnName
const contextContainer = {}
Object.keys(contextAllContainers).forEach(key => {
if (isEmptyValue(contextAllContainers[key])) {
return
}
let newKey
if (parentUuid) {
if (!key.includes(containerUuid)) {
newKey = key
.replace(`${parentUuid}|`, '')
.replace(`${containerUuid}|`, '')
// set window parent context
contextContainer[newKey] = contextAllContainers[key]
}
// next if is tab context
return
}
// set container context (smart browser, process/report)
newKey = key.replace(`${containerUuid}|`, '')
contextContainer[newKey] = contextAllContainers[key]
})
return contextContainer
},
getContextAll: (state) => { getContextAll: (state) => {
state.context return state.context
}, },
getContextClientId: (state) => { getContextClientId: (state) => {
return parseInt(state.context['#AD_Client_ID'], 10) return parseInt(state.context['#AD_Client_ID'], 10)

View File

@ -47,7 +47,7 @@ const data = {
notifyCellTableChange: (state, payload) => { notifyCellTableChange: (state, payload) => {
payload.row[payload.columnName] = payload.value payload.row[payload.columnName] = payload.value
if (payload.displayColumn !== undefined) { if (payload.displayColumn !== undefined) {
const key = 'DisplayColumn_' + payload.columnName const key = `DisplayColumn_${payload.columnName}`
payload.row[key] = payload.displayColumn payload.row[key] = payload.displayColumn
} }
}, },
@ -55,7 +55,7 @@ const data = {
if (payload.row !== undefined) { if (payload.row !== undefined) {
payload.row[payload.columnName] = payload.value payload.row[payload.columnName] = payload.value
if (payload.displayColumn !== undefined) { if (payload.displayColumn !== undefined) {
const key = 'DisplayColumn_' + payload.columnName const key = `DisplayColumn_${payload.columnName}`
payload.row[key] = payload.displayColumn payload.row[key] = payload.displayColumn
} }
} }
@ -106,15 +106,15 @@ const data = {
// refresh list table with data from server // refresh list table with data from server
if (panelType === 'window') { if (panelType === 'window') {
dispatch('getDataListTab', { dispatch('getDataListTab', {
parentUuid: parentUuid, parentUuid,
containerUuid: containerUuid, containerUuid,
isAddRecord: isAddRecord, isAddRecord,
isShowNotification: isShowNotification isShowNotification
}) })
} else if (panelType === 'browser') { } else if (panelType === 'browser') {
if (!rootGetters.isNotReadyForSubmit(containerUuid)) { if (!rootGetters.isNotReadyForSubmit(containerUuid)) {
dispatch('getBrowserSearch', { dispatch('getBrowserSearch', {
containerUuid: containerUuid, containerUuid,
isClearSelection: true isClearSelection: true
}) })
} }
@ -142,17 +142,17 @@ const data = {
if (isPanelValues) { if (isPanelValues) {
// add row with values used from record in panel // add row with values used from record in panel
values = rootGetters.getColumnNamesAndValues({ values = rootGetters.getColumnNamesAndValues({
containerUuid: containerUuid, containerUuid,
propertyName: 'value', propertyName: 'value',
isObjectReturn: true, isObjectReturn: true,
isAddDisplayColumn: true, isAddDisplayColumn: true,
fieldList: fieldList fieldList
}) })
} else { } else {
values = rootGetters.getParsedDefaultValues({ values = rootGetters.getParsedDefaultValues({
parentUuid: parentUuid, parentUuid,
containerUuid: containerUuid, containerUuid,
fieldList: fieldList fieldList
}) })
} }
values.isNew = isNew values.isNew = isNew
@ -170,8 +170,8 @@ const data = {
// get context value if link column exists and does not exist in row // get context value if link column exists and does not exist in row
if (!isEmptyValue(linkColumnName)) { if (!isEmptyValue(linkColumnName)) {
valueLink = rootGetters.getContext({ valueLink = rootGetters.getContext({
parentUuid: parentUuid, parentUuid,
containerUuid: containerUuid, containerUuid,
columnName: linkColumnName columnName: linkColumnName
}) })
} }
@ -188,7 +188,7 @@ const data = {
var valueGetDisplayColumn = values[itemField.columnName] var valueGetDisplayColumn = values[itemField.columnName]
if (String(values[itemField.columnName]) === '[object Object]' && itemField.componentPath === 'FieldSelect') { if (String(values[itemField.columnName]) === '[object Object]' && itemField.componentPath === 'FieldSelect') {
values[itemField.columnName] = ' ' values[itemField.columnName] = ' '
values['DisplayColumn_' + itemField.columnName] = ' ' values[`DisplayColumn_${itemField.columnName}`] = ' '
} else if (String(values[itemField.columnName]) === '[object Object]' && itemField.componentPath === 'FieldNumber') { } else if (String(values[itemField.columnName]) === '[object Object]' && itemField.componentPath === 'FieldNumber') {
values[itemField.columnName] = 0 values[itemField.columnName] = 0
} }
@ -211,19 +211,22 @@ const data = {
} }
if (!isEmptyValue(valueGetDisplayColumn) && String(valueGetDisplayColumn) === '[object Object]') { if (!isEmptyValue(valueGetDisplayColumn) && String(valueGetDisplayColumn) === '[object Object]') {
// get value from direct Query // get value from direct Query
dispatch('getRecordBySQL', { query: valueGetDisplayColumn.query, field: itemField }) dispatch('getRecordBySQL', {
query: valueGetDisplayColumn.query,
field: itemField
})
.then(defaultValue => { .then(defaultValue => {
if (itemField.componentPath === 'FieldSelect') { if (itemField.componentPath === 'FieldSelect') {
values[itemField.columnName] = defaultValue.key values[itemField.columnName] = defaultValue.key
values['DisplayColumn_' + itemField.columnName] = defaultValue.label values[`DisplayColumn_${itemField.columnName}`] = defaultValue.label
} else { } else {
values[itemField.columnName] = defaultValue.key values[itemField.columnName] = defaultValue.key
dispatch('notifyRowTableChange', { dispatch('notifyRowTableChange', {
parentUuid: parentUuid, parentUuid,
containerUuid: containerUuid, containerUuid,
isNew: isNew, isNew,
isEdit: isEdit, isEdit,
values: values values
}) })
} }
}) })
@ -231,8 +234,8 @@ const data = {
} }
// get label (DisplayColumn) from vuex store // get label (DisplayColumn) from vuex store
const options = rootGetters.getLookupAll({ const options = rootGetters.getLookupAll({
parentUuid: parentUuid, parentUuid,
containerUuid: containerUuid, containerUuid,
tableName: itemField.reference.tableName, tableName: itemField.reference.tableName,
query: itemField.reference.query, query: itemField.reference.query,
directQuery: itemField.reference.directQuery, directQuery: itemField.reference.directQuery,
@ -242,32 +245,32 @@ const data = {
const option = options.find(itemOption => itemOption.key === valueGetDisplayColumn) const option = options.find(itemOption => itemOption.key === valueGetDisplayColumn)
// if there is a lookup option, assign the display column with the label // if there is a lookup option, assign the display column with the label
if (option) { if (option) {
values['DisplayColumn_' + itemField.columnName] = option.label values[`DisplayColumn_${itemField.columnName}`] = option.label
return return
} }
if (linkColumnName === itemField.columnName) { if (linkColumnName === itemField.columnName) {
// get context value if link column exists and does not exist in row // get context value if link column exists and does not exist in row
const nameParent = rootGetters.getContext({ const nameParent = rootGetters.getContext({
parentUuid: parentUuid, parentUuid,
containerUuid: containerUuid, containerUuid,
columnName: 'Name' columnName: 'Name'
}) })
if (nameParent) { if (nameParent) {
values['DisplayColumn_' + itemField.columnName] = nameParent values[`DisplayColumn_${itemField.columnName}`] = nameParent
return return
} }
} }
// get from server // get from server
dispatch('getLookupItemFromServer', { dispatch('getLookupItemFromServer', {
parentUuid: parentUuid, parentUuid,
containerUuid: containerUuid, containerUuid,
tableName: itemField.reference.tableName, tableName: itemField.reference.tableName,
directQuery: itemField.reference.directQuery, directQuery: itemField.reference.directQuery,
value: valueGetDisplayColumn value: valueGetDisplayColumn
}) })
.then(responseLookup => { .then(responseLookup => {
dispatch('addDisplayColumn', { dispatch('addDisplayColumn', {
containerUuid: containerUuid, containerUuid,
columnName: itemField.columnName, columnName: itemField.columnName,
displayColumn: responseLookup.label displayColumn: responseLookup.label
}) })
@ -293,8 +296,8 @@ const data = {
commit('addDisplayColumn', { commit('addDisplayColumn', {
row: rowRecord, row: rowRecord,
displayColumn: displayColumn, displayColumn,
columnName: 'DisplayColumn_' + columnName columnName: `DisplayColumn_${columnName}`
}) })
}, },
/** /**
@ -335,20 +338,20 @@ const data = {
}) })
const newDataStore = { const newDataStore = {
parentUuid: parentUuid, parentUuid,
containerUuid: containerUuid, containerUuid,
record: record, record,
selection: selection, selection,
pageNumber: pageNumber, pageNumber,
recordCount: recordCount, recordCount,
nextPageToken: nextPageToken, nextPageToken,
originalNextPageToken: originalNextPageToken, originalNextPageToken,
panelType: panelType, panelType,
isLoaded: isLoaded, isLoaded,
isLoadedContext: false, isLoadedContext: false,
query: query, query,
whereClause: whereClause, whereClause,
orderByClause: orderByClause orderByClause
} }
if (dataStore) { if (dataStore) {
@ -478,9 +481,9 @@ const data = {
} }
commit('addInGetting', { commit('addInGetting', {
containerUuid: containerUuid, containerUuid,
tableName: tableName, tableName,
conditions: conditions conditions
}) })
// gets the default value of the fields (including whether it is empty or undefined) // gets the default value of the fields (including whether it is empty or undefined)
@ -560,8 +563,8 @@ const data = {
// Set default registry values so that the table does not say loading, // Set default registry values so that the table does not say loading,
// there was already a response from the server // there was already a response from the server
dispatch('setRecordSelection', { dispatch('setRecordSelection', {
parentUuid: parentUuid, parentUuid,
containerUuid: containerUuid containerUuid
}) })
if (isShowNotification) { if (isShowNotification) {
@ -571,7 +574,7 @@ const data = {
type: 'error' type: 'error'
}) })
} }
console.warn(`Error Get Object List ${error.message}. Code: ${error.code}`) console.warn(`Error Get Object List ${error.message}. Code: ${error.code}.`)
}) })
.finally(() => { .finally(() => {
commit('deleteInGetting', { commit('deleteInGetting', {
@ -580,8 +583,10 @@ const data = {
}) })
}) })
}, },
getRecordBySQL({ dispatch }, parameters) { getRecordBySQL({ dispatch }, {
const { query, field } = parameters query,
field
}) {
// TODO: Change to promise all // TODO: Change to promise all
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
getDefaultValueFromServer(query) getDefaultValueFromServer(query)
@ -628,8 +633,8 @@ const data = {
currentValues = objectParams.values currentValues = objectParams.values
} else { } else {
currentValues = rootGetters.getColumnNamesAndValues({ currentValues = rootGetters.getColumnNamesAndValues({
parentUuid: parentUuid, parentUuid,
containerUuid: containerUuid, containerUuid,
propertyName: 'value', propertyName: 'value',
isObjectReturn: true, isObjectReturn: true,
isAddDisplayColumn: true isAddDisplayColumn: true
@ -641,13 +646,13 @@ const data = {
var newRow = { var newRow = {
...currentValues, ...currentValues,
// ...objectParams.row, // ...objectParams.row,
isEdit: isEdit isEdit
} }
commit('notifyRowTableChange', { commit('notifyRowTableChange', {
isNew: objectParams.isNew, isNew: objectParams.isNew,
newRow: newRow, newRow,
row: row row
}) })
}, },
notifyCellTableChange({ commit, state, dispatch, rootGetters }, parameters) { notifyCellTableChange({ commit, state, dispatch, rootGetters }, parameters) {
@ -761,7 +766,7 @@ const data = {
return contextInfoResponse return contextInfoResponse
}) })
.catch(error => { .catch(error => {
console.warn(`Error ${error.code} getting context info value for field ${error.message}`) console.warn(`Error ${error.code} getting context info value for field ${error.message}.`)
}) })
}, },
getPrivateAccessFromServer({ rootGetters }, { getPrivateAccessFromServer({ rootGetters }, {
@ -792,7 +797,7 @@ const data = {
} }
}) })
.catch(error => { .catch(error => {
console.warn(`Error get private access: ${error.message}. Code: ${error.code}:`) console.warn(`Error get private access: ${error.message}. Code: ${error.code}.`)
}) })
}, },
lockRecord({ rootGetters }, { lockRecord({ rootGetters }, {
@ -829,7 +834,7 @@ const data = {
message: language.t('login.unexpectedError'), message: language.t('login.unexpectedError'),
type: 'error' type: 'error'
}) })
console.warn(`Error lock private access: ${error.message}. Code: ${error.code}:`) console.warn(`Error lock private access: ${error.message}. Code: ${error.code}.`)
}) })
}, },
unlockRecord({ rootGetters }, { unlockRecord({ rootGetters }, {
@ -866,7 +871,7 @@ const data = {
message: language.t('login.unexpectedError'), message: language.t('login.unexpectedError'),
type: 'error' type: 'error'
}) })
console.warn(`Error unlock private access: ${error.message}. Code: ${error.code}:`) console.warn(`Error unlock private access: ${error.message}. Code: ${error.code}.`)
}) })
} }
}, },
@ -882,7 +887,7 @@ const data = {
return state.recordSelection.find(itemRecord => { return state.recordSelection.find(itemRecord => {
return itemRecord.containerUuid === containerUuid return itemRecord.containerUuid === containerUuid
}) || { }) || {
containerUuid: containerUuid, containerUuid,
record: [], record: [],
recordCount: 0, recordCount: 0,
selection: [], selection: [],

View File

@ -38,7 +38,7 @@ const lookup = {
parentUuid, parentUuid,
containerUuid, containerUuid,
value: directQuery value: directQuery
}, true) }).value
} }
return getLookup({ return getLookup({
@ -86,7 +86,7 @@ const lookup = {
parentUuid, parentUuid,
containerUuid, containerUuid,
value: query value: query
}, true) }).value
} }
return getLookupList({ return getLookupList({
@ -128,7 +128,7 @@ const lookup = {
parentUuid, parentUuid,
containerUuid, containerUuid,
value: parsedDirectQuery value: parsedDirectQuery
}, true) }).value
} }
const lookupItem = state.lookupItem.filter(itemLookup => { const lookupItem = state.lookupItem.filter(itemLookup => {
return itemLookup.parsedDirectQuery !== parsedDirectQuery && return itemLookup.parsedDirectQuery !== parsedDirectQuery &&
@ -143,7 +143,7 @@ const lookup = {
parentUuid: parentUuid, parentUuid: parentUuid,
containerUuid: containerUuid, containerUuid: containerUuid,
value: parsedQuery value: parsedQuery
}, true) }).value
} }
const lookupList = state.lookupList.filter(itemLookup => { const lookupList = state.lookupList.filter(itemLookup => {
return itemLookup.parsedQuery !== parsedQuery && return itemLookup.parsedQuery !== parsedQuery &&
@ -170,7 +170,7 @@ const lookup = {
parentUuid, parentUuid,
containerUuid, containerUuid,
value: parsedDirectQuery value: parsedDirectQuery
}, true) }).value
} }
const lookupItem = state.lookupItem.find(itemLookup => { const lookupItem = state.lookupItem.find(itemLookup => {
return itemLookup.parsedDirectQuery === parsedDirectQuery && return itemLookup.parsedDirectQuery === parsedDirectQuery &&
@ -196,7 +196,7 @@ const lookup = {
parentUuid, parentUuid,
containerUuid, containerUuid,
value: parsedQuery value: parsedQuery
}, true) }).value
} }
const lookupList = state.lookupList.find(itemLookup => { const lookupList = state.lookupList.find(itemLookup => {
return itemLookup.parsedQuery === parsedQuery && return itemLookup.parsedQuery === parsedQuery &&

View File

@ -33,6 +33,9 @@ const panel = {
if (payload.isReportFromLogic !== undefined) { if (payload.isReportFromLogic !== undefined) {
payload.field.isReportFromLogic = payload.isReportFromLogic payload.field.isReportFromLogic = payload.isReportFromLogic
} }
if (payload.parsedDefaultValue !== undefined) {
payload.field.parsedDefaultValue = payload.parsedDefaultValue
}
}, },
dictionaryResetCache(state) { dictionaryResetCache(state) {
state.panel = [] state.panel = []
@ -87,7 +90,8 @@ const panel = {
count++ count++
} }
} else { } else {
if (params.isParentTab) { if (['browser', 'process', 'report'].includes(params.panelType) ||
params.panelType === 'window' && params.isParentTab) {
dispatch('setContext', { dispatch('setContext', {
parentUuid: params.parentUuid, parentUuid: params.parentUuid,
containerUuid: params.uuid, containerUuid: params.uuid,
@ -509,7 +513,7 @@ const panel = {
columnName, columnName,
value: sqlStatement, value: sqlStatement,
isSQL: isSQL isSQL: isSQL
}) }).value
if (isSQL && String(sqlStatement) === '[object Object]') { if (isSQL && String(sqlStatement) === '[object Object]') {
sqlStatement = sqlStatement.query sqlStatement = sqlStatement.query
} }
@ -532,49 +536,12 @@ const panel = {
} }
// Change Dependents // Change Dependents
let dependentsList = [] dispatch('changeDependentFieldsList', {
if (field.dependentFieldsList.length) { parentUuid,
dependentsList = fieldList.filter(fieldItem => { containerUuid,
return field.dependentFieldsList.includes(fieldItem.columnName) dependentFieldsList: field.dependentFieldsList,
}) fieldsList: fieldList,
} isSendToServer
// Iterate for change logic
dependentsList.forEach(dependent => {
// isDisplayed Logic
let isDisplayedFromLogic, isMandatoryFromLogic, isReadOnlyFromLogic
if (dependent.displayLogic.trim() !== '') {
isDisplayedFromLogic = evaluator.evaluateLogic({
context: getters,
parentUuid,
containerUuid,
logic: dependent.displayLogic,
type: 'displayed'
})
}
// Mandatory Logic
if (dependent.mandatoryLogic.trim() !== '') {
isMandatoryFromLogic = evaluator.evaluateLogic({
context: getters,
parentUuid,
containerUuid,
logic: dependent.mandatoryLogic
})
}
// Read Only Logic
if (dependent.readOnlyLogic.trim() !== '') {
isReadOnlyFromLogic = evaluator.evaluateLogic({
context: getters,
parentUuid,
containerUuid,
logic: dependent.readOnlyLogic
})
}
commit('changeFieldLogic', {
field: dependent,
isDisplayedFromLogic,
isMandatoryFromLogic,
isReadOnlyFromLogic
})
}) })
// the field has not changed, then the action is broken // the field has not changed, then the action is broken
@ -722,6 +689,90 @@ const panel = {
} }
} }
}, },
changeDependentFieldsList({ commit, dispatch, getters }, {
parentUuid,
containerUuid,
dependentFieldsList = [],
fieldsList = [],
isSendToServer
}) {
if (isEmptyValue(dependentFieldsList)) {
// breaks if there are no field dependencies
return
}
if (!fieldsList.length) {
fieldsList = getters.getFieldsListFromPanel(containerUuid)
}
const dependentsList = fieldsList.filter(fieldItem => {
return dependentFieldsList.includes(fieldItem.columnName)
})
// Iterate for change logic
dependentsList.forEach(fieldDependent => {
// isDisplayed Logic
let isDisplayedFromLogic, isMandatoryFromLogic, isReadOnlyFromLogic, defaultValue
if (fieldDependent.displayLogic.trim() !== '') {
isDisplayedFromLogic = evaluator.evaluateLogic({
context: getters,
parentUuid,
containerUuid,
logic: fieldDependent.displayLogic,
type: 'displayed'
})
}
// Mandatory Logic
if (fieldDependent.mandatoryLogic.trim() !== '') {
isMandatoryFromLogic = evaluator.evaluateLogic({
context: getters,
parentUuid,
containerUuid,
logic: fieldDependent.mandatoryLogic
})
}
// Read Only Logic
if (fieldDependent.readOnlyLogic.trim() !== '') {
isReadOnlyFromLogic = evaluator.evaluateLogic({
context: getters,
parentUuid,
containerUuid,
logic: fieldDependent.readOnlyLogic
})
}
// Default Value
if (fieldDependent.defaultValue.trim() !== '' &&
fieldDependent.defaultValue.includes('@')) {
defaultValue = parseContext({
parentUuid,
containerUuid,
value: fieldDependent.defaultValue
}).value
if (isSendToServer && defaultValue !== fieldDependent.defaultValue) {
dispatch('getRecordBySQL', {
field: fieldDependent,
query: defaultValue
})
.then(response => {
dispatch('notifyFieldChange', {
parentUuid,
containerUuid,
panelType: fieldDependent.panelType,
columnName: fieldDependent.columnName,
newValue: response.key
})
})
}
}
commit('changeFieldLogic', {
field: fieldDependent,
isDisplayedFromLogic,
isMandatoryFromLogic,
isReadOnlyFromLogic,
parsedDefaultValue: defaultValue
})
})
},
notifyFieldChangeDisplayColumn({ commit, getters }, { notifyFieldChangeDisplayColumn({ commit, getters }, {
containerUuid, containerUuid,
columnName, columnName,
@ -770,7 +821,7 @@ const panel = {
.catch(error => { .catch(error => {
return { return {
...error, ...error,
moreInfo: `Dictionary getPanelAndFields ${panelType} (State Panel)` moreInfo: `Dictionary getPanelAndFields ${panelType} (State Panel).`
} }
}) })
}, },
@ -1010,8 +1061,8 @@ const panel = {
containerUuid: containerUuid, containerUuid: containerUuid,
columnName: fieldItem.columnName, columnName: fieldItem.columnName,
value: fieldItem.defaultValue, value: fieldItem.defaultValue,
isSQL: isSQL isSQL
}) }).value
} }
valueToReturn = parsedValueComponent({ valueToReturn = parsedValueComponent({
@ -1024,7 +1075,7 @@ const panel = {
// add display column to default // add display column to default
if (fieldItem.componentPath === 'FieldSelect' && fieldItem.value === valueToReturn) { if (fieldItem.componentPath === 'FieldSelect' && fieldItem.value === valueToReturn) {
attributesObject['DisplayColumn_' + fieldItem.columnName] = fieldItem.displayColumn attributesObject[`DisplayColumn_${fieldItem.columnName}`] = fieldItem.displayColumn
} }
return { return {

View File

@ -26,8 +26,10 @@ const process = {
containerUuid, containerUuid,
routeToDelete routeToDelete
}) { }) {
var printFormatsAvailable let printFormatsAvailable
dispatch('requestPrintFormats', { processUuid: containerUuid }) dispatch('requestPrintFormats', {
processUuid: containerUuid
})
.then(response => { .then(response => {
printFormatsAvailable = response printFormatsAvailable = response
}) })
@ -51,13 +53,15 @@ const process = {
resolve(processDefinition) resolve(processDefinition)
}) })
.catch(error => { .catch(error => {
router.push({ path: '/dashboard' }) router.push({
path: '/dashboard'
})
dispatch('tagsView/delView', routeToDelete) dispatch('tagsView/delView', routeToDelete)
showMessage({ showMessage({
message: language.t('login.unexpectedError'), message: language.t('login.unexpectedError'),
type: 'error' type: 'error'
}) })
console.warn(`Dictionary Process (State) - Error ${error.message}`) console.warn(`Dictionary Process (State) - Error ${error.message}.`)
reject(error) reject(error)
}) })
}) })

View File

@ -179,7 +179,10 @@ const window = {
description: processItem.description, description: processItem.description,
help: processItem.help, help: processItem.help,
isReport: processItem.isReport, isReport: processItem.isReport,
isDirectPrint: processItem.isDirectPrint isDirectPrint: processItem.isDirectPrint,
containerUuidAssociated: tabItem.uuid,
parentUuidAssociated: windowUuid,
panelTypeAssociated: 'window'
} }
}) })
actions = actions.concat(processList) actions = actions.concat(processList)

View File

@ -574,7 +574,7 @@ const windowControl = {
parentUuid: parentUuid, parentUuid: parentUuid,
containerUuid: containerUuid, containerUuid: containerUuid,
value: tab.query value: tab.query
}, true) }).value
} }
let parsedWhereClause = tab.whereClause let parsedWhereClause = tab.whereClause
@ -583,7 +583,7 @@ const windowControl = {
parentUuid: parentUuid, parentUuid: parentUuid,
containerUuid: containerUuid, containerUuid: containerUuid,
value: tab.whereClause value: tab.whereClause
}, true) }).value
} }
if (isReference) { if (isReference) {

View File

@ -1,8 +1,22 @@
import { isEmptyValue } from '@/utils/ADempiere/valueUtils' import { isEmptyValue } from '@/utils/ADempiere/valueUtils'
import evaluator from '@/utils/ADempiere/evaluator' import evaluator from '@/utils/ADempiere/evaluator'
import store from '@/store'
export default evaluator export default evaluator
// get context state from vuex store
export const getContext = ({
parentUuid,
containerUuid,
columnName
}) => {
return store.getters.getContext({
parentUuid,
containerUuid,
columnName
})
}
/** /**
* Extracts the associated fields from the logics or default values * Extracts the associated fields from the logics or default values
* @param {string} displayLogic * @param {string} displayLogic
@ -45,19 +59,30 @@ export function getParentFields({ displayLogic, mandatoryLogic, readOnlyLogic, d
/** /**
* Parse Context String * Parse Context String
* @param {object} context * @param {string} value: (REQUIRED) String to parsing
* - value: (REQUIRED) String to parsing * @param {string} parentUuid: (REQUIRED from Window) UUID Window
* - parentUuid: (REQUIRED from Window) UUID Window * @param {string} containerUuid: (REQUIRED) UUID Tab, Process, SmartBrowser, Report and Form
* - containerUuid: (REQUIRED) UUID Tab, Process, SmartBrowser, Report and Form * @param {string} columnName: (Optional if exists in value) Column name to search in context
* - columnName: (Optional if exists in value) Column name to search in context
* @param {boolean} isBoolToString, convert boolean values to string * @param {boolean} isBoolToString, convert boolean values to string
*/ */
export function parseContext(context, isBoolToString = false) { export function parseContext({
const store = require('@/store') parentUuid,
var value = String(context.value) containerUuid,
var valueSQL = {} columnName,
value,
isSQL = false
}) {
const isBooleanToString = value.includes('@SQL=')
let isError = false
const errorsList = []
value = String(value)
if (isEmptyValue(value)) { if (isEmptyValue(value)) {
return '' return {
value: undefined,
isError: true,
errorsList: []
}
} }
if (value.includes('@SQL=')) { if (value.includes('@SQL=')) {
value = value.replace('@SQL=', '') value = value.replace('@SQL=', '')
@ -71,36 +96,47 @@ export function parseContext(context, isBoolToString = false) {
var inStr = value var inStr = value
var outStr = '' var outStr = ''
var i = inStr.indexOf('@') let firstIndexTag = inStr.indexOf('@')
while (i !== -1) { while (firstIndexTag !== -1) {
outStr = outStr + inStr.substring(0, i) // up to @ outStr = outStr + inStr.substring(0, firstIndexTag) // up to @
inStr = inStr.substring(i + 1, inStr.length) // from first @ inStr = inStr.substring(firstIndexTag + 1, inStr.length) // from first @
var j = inStr.indexOf('@') // next @ const secondIndexTag = inStr.indexOf('@') // next @
if (j < 0) { // no exists second tag
console.log('No second tag: ' + inStr) if (secondIndexTag < 0) {
return '' // no second tag console.log(`No second tag: ${inStr}`)
} return {
value: undefined,
token = inStr.substring(0, j) isError: true,
context.columnName = token errorsList
var ctxInfo = store.default.getters.getContext(context) // get context
if (isBoolToString && typeof ctxInfo === 'boolean') {
if (ctxInfo) {
ctxInfo = 'Y'
} else {
ctxInfo = 'N'
} }
} }
if ((ctxInfo === undefined || ctxInfo.length === 0) && (token.startsWith('#') || token.startsWith('$'))) { token = inStr.substring(0, secondIndexTag)
context.parentUuid = undefined columnName = token
context.containerUuid = undefined
ctxInfo = store.default.getters.getContext(context) // get global context var ctxInfo = getContext({
parentUuid,
containerUuid,
columnName
}) // get context
if (isBooleanToString && typeof ctxInfo === 'boolean') {
ctxInfo = 'N'
if (ctxInfo) {
ctxInfo = 'Y'
}
}
if ((ctxInfo === undefined || ctxInfo.length === 0) &&
(token.startsWith('#') || token.startsWith('$'))) {
ctxInfo = getContext({
columnName
}) // get global context
} }
if (ctxInfo === undefined || ctxInfo.length === 0) { if (ctxInfo === undefined || ctxInfo.length === 0) {
console.info('No Context for: ' + token) console.info(`No Context for: ${token}`)
isError = true
errorsList.push(token)
} else { } else {
if (typeof ctxInfo === 'object') { if (typeof ctxInfo === 'object') {
outStr = ctxInfo outStr = ctxInfo
@ -109,16 +145,85 @@ export function parseContext(context, isBoolToString = false) {
} }
} }
inStr = inStr.substring(j + 1, inStr.length) // from second @ inStr = inStr.substring(secondIndexTag + 1, inStr.length) // from second @
i = inStr.indexOf('@') firstIndexTag = inStr.indexOf('@')
} }
if (typeof ctxInfo !== 'object') { if (typeof ctxInfo !== 'object') {
outStr = outStr + inStr // add the rest of the string outStr = outStr + inStr // add the rest of the string
} }
if (context.isSQL) { if (isSQL) {
valueSQL['query'] = outStr return {
valueSQL['value'] = ctxInfo query: outStr,
return valueSQL value: ctxInfo
}
} }
return outStr return {
} // parseContext value: outStr,
isError,
errorsList
}
} // parseContext
/**
* Get Preference.
* <pre>
* 0) Current Setting
* 1) Window Preference
* 2) Global Preference
* 3) Login settings
* 4) Accounting settings
* </pre>
* @param {string} parentUuid UUID Window
* @param {string} containerUuid UUID Tab, Process, SmartBrowser, Report and Form
* @param {string} columnName (context) Entity to search
* @return preference value
*/
export function getPreference({
parentUuid,
containerUuid,
columnName
}) {
let retValue
if (isEmptyValue(columnName)) {
console.warn('Require Context ColumnName')
return retValue
}
// USER PREFERENCES
// View Preferences
retValue = getContext({
parentUuid: 'P' + parentUuid,
containerUuid,
columnName: columnName
})
if (!isEmptyValue(retValue)) {
return retValue
}
// Global Preferences
retValue = getContext({
columnName: 'P|' + columnName
})
if (!isEmptyValue(retValue)) {
return retValue
}
// SYSTEM PREFERENCES
// Login setting
if (!isEmptyValue(parentUuid)) {
// get # globals context only window
retValue = getContext({
columnName: '#' + columnName
})
if (!isEmptyValue(retValue)) {
return retValue
}
}
// Accounting setting
retValue = getContext({
columnName: '$' + columnName
})
return retValue
} // getPreference

View File

@ -1,6 +1,6 @@
import evaluator from '@/utils/ADempiere/evaluator' import evaluator from '@/utils/ADempiere/evaluator'
import { isEmptyValue, parsedValueComponent } from '@/utils/ADempiere/valueUtils' import { isEmptyValue, parsedValueComponent } from '@/utils/ADempiere/valueUtils'
import { getParentFields, parseContext } from '@/utils/ADempiere/contextUtils' import { getParentFields, getPreference, parseContext } from '@/utils/ADempiere/contextUtils'
import REFERENCES, { FIELD_NOT_SHOWED } from '@/components/ADempiere/Field/references' import REFERENCES, { FIELD_NOT_SHOWED } from '@/components/ADempiere/Field/references'
import { FIELD_DISPLAY_SIZES, DEFAULT_SIZE } from '@/components/ADempiere/Field/fieldSize' import { FIELD_DISPLAY_SIZES, DEFAULT_SIZE } from '@/components/ADempiere/Field/fieldSize'
import language from '@/lang' import language from '@/lang'
@ -22,15 +22,28 @@ export function generateField(fieldToGenerate, moreAttributes, typeRange = false
const referenceType = componentReference.alias[0] const referenceType = componentReference.alias[0]
let parsedDefaultValue = fieldToGenerate.defaultValue let parsedDefaultValue = fieldToGenerate.defaultValue
if (String(parsedDefaultValue).includes('@')) { if (isEmptyValue(parsedDefaultValue)) {
if (String(parsedDefaultValue).includes('@SQL=')) { parsedDefaultValue = getPreference({
parsedDefaultValue.replace('@SQL=', '') parentUuid: fieldToGenerate.parentUuid,
containerUuid: fieldToGenerate.containerUuid,
columnName: fieldToGenerate.columnName
})
if (isEmptyValue(parsedDefaultValue)) {
parsedDefaultValue = getPreference({
parentUuid: fieldToGenerate.parentUuid,
containerUuid: fieldToGenerate.containerUuid,
columnName: fieldToGenerate.elementName
})
} }
} else if (String(parsedDefaultValue).includes('@')) {
// if (String(parsedDefaultValue).includes('@SQL=')) {
// parsedDefaultValue.replace('@SQL=', '')
// }
parsedDefaultValue = parseContext({ parsedDefaultValue = parseContext({
...moreAttributes, ...moreAttributes,
columnName: fieldToGenerate.columnName, columnName: fieldToGenerate.columnName,
value: parsedDefaultValue value: parsedDefaultValue
}) }).value
} }
parsedDefaultValue = parsedValueComponent({ parsedDefaultValue = parsedValueComponent({
fieldType: componentReference.type, fieldType: componentReference.type,
@ -40,12 +53,28 @@ export function generateField(fieldToGenerate, moreAttributes, typeRange = false
}) })
let parsedDefaultValueTo = fieldToGenerate.defaultValueTo let parsedDefaultValueTo = fieldToGenerate.defaultValueTo
if (String(parsedDefaultValueTo).includes('@')) { if (isEmptyValue(parsedDefaultValueTo)) {
parsedDefaultValueTo = getPreference({
parentUuid: fieldToGenerate.parentUuid,
containerUuid: fieldToGenerate.containerUuid,
columnName: `${fieldToGenerate.columnName}_To`
})
if (isEmptyValue()) {
parsedDefaultValueTo = getPreference({
parentUuid: fieldToGenerate.parentUuid,
containerUuid: fieldToGenerate.containerUuid,
columnName: `${fieldToGenerate.elementName}_To`
})
}
} else if (String(parsedDefaultValueTo).includes('@')) {
// if (String(parsedDefaultValueTo).includes('@SQL=')) {
// parsedDefaultValueTo.replace('@SQL=', '')
// }
parsedDefaultValueTo = parseContext({ parsedDefaultValueTo = parseContext({
...moreAttributes, ...moreAttributes,
columnName: fieldToGenerate.columnName, columnName: fieldToGenerate.columnName,
value: fieldToGenerate.defaultValueTo value: fieldToGenerate.defaultValueTo
}) }).value
} }
parsedDefaultValueTo = parsedValueComponent({ parsedDefaultValueTo = parsedValueComponent({
fieldType: componentReference.type, fieldType: componentReference.type,
@ -53,6 +82,7 @@ export function generateField(fieldToGenerate, moreAttributes, typeRange = false
referenceType, referenceType,
isMandatory: fieldToGenerate.isMandatory isMandatory: fieldToGenerate.isMandatory
}) })
fieldToGenerate.reference.zoomWindowList = fieldToGenerate.reference.windowsList fieldToGenerate.reference.zoomWindowList = fieldToGenerate.reference.windowsList
const field = { const field = {
...fieldToGenerate, ...fieldToGenerate,