Skip to content

Commit

Permalink
feat: Run Process with window selection. (PanJiaChen#2814)
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwinBetanc0urt authored Oct 16, 2024
1 parent 1d85649 commit 9821c7e
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 18 deletions.
15 changes: 12 additions & 3 deletions src/api/ADempiere/business-data/runBusinessProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
// Get Instance for connection
import { request } from '@/utils/ADempiere/request'

// Utils and Helper Methods
import { isEmptyValue } from '@/utils/ADempiere/valueUtils'

/**
* Get default value for a field, parameter or query criteria
* @param {integer} id, identifier of field
Expand Down Expand Up @@ -72,13 +75,19 @@ export function requestRunBusinessProcessAsWindow({
id,
parametersList,
tableName,
recordId
recordId,
selectionsList
}) {
let url = `/business-data/process/${id}/window/${tableName}`
if (isEmptyValue(selectionsList) || (!isEmptyValue(selectionsList) && selectionsList.length === 1)) {
url += `/${recordId}`
}
return request({
url: `/business-data/process/${id}/window/${tableName}/${recordId}`,
url: url,
method: 'post',
data: {
parameters: parametersList
parameters: parametersList,
selections: selectionsList
}
})
}
36 changes: 31 additions & 5 deletions src/store/modules/ADempiere/processManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,10 @@ const processManager = {
const processModal = getters.getModalDialogManager({
containerUuid: containerUuid
})
const currentProcess = storedTab.processes.find(process => process.name === processModal.title)
const storedProcessDefinition = storedTab.processes.find(process => {
// return process.name === processModal.title
return process.uuid === processModal.containerUuid
})
if (isEmptyValue(parametersList)) {
const fieldsList = getters.getStoredFieldsFromProcess(containerUuid)
parametersList = rootGetters.getProcessParameters({
Expand All @@ -363,15 +366,37 @@ const processManager = {
})
}

let selectionsList = []
if (storedProcessDefinition.is_multi_selection) {
let recordsSelection = []
if (storedTab.isShowedTableRecords) {
recordsSelection = getters.getTabSelectionsList({
containerUuid
})
} else {
const currentRow = getters.getTabCurrentRow({
containerUuid: storedTab.uuid
})
recordsSelection = [
currentRow
]
}
selectionsList = rootGetters.getTabSelectionToServer({
parentUuid: windowsUuid,
containerUuid: storedTab.uuid,
selectionsList: recordsSelection
})
}

const isSession = !isEmptyValue(getToken())
let procesingNotification = {
close: () => false
}
if (isSession) {
procesingNotification = showNotification({
title: lang.t('notifications.processing'),
message: currentProcess.name,
summary: currentProcess.description,
message: storedProcessDefinition.name,
summary: storedProcessDefinition.description,
type: 'info'
})
}
Expand All @@ -387,8 +412,9 @@ const processManager = {
}

requestRunBusinessProcessAsWindow({
id: currentProcess.internal_id,
id: storedProcessDefinition.internal_id,
parametersList,
selectionsList,
tableName,
recordId: recordId
})
Expand All @@ -413,7 +439,7 @@ const processManager = {

dispatch('finishProcess', {
summary,
name: currentProcess.name,
name: storedProcessDefinition.name,
isError: isProcessedError
})
.then(() => {
Expand Down
100 changes: 96 additions & 4 deletions src/store/modules/ADempiere/windowManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,25 @@ import {

// Constants
import { UUID } from '@/utils/ADempiere/constants/systemColumns'
import { ROW_ATTRIBUTES } from '@/utils/ADempiere/tableUtils'
import { IS_ADVANCED_QUERY } from '@/utils/ADempiere/dictionaryUtils'
import { ROW_ATTRIBUTES, ROW_KEY_ATTRIBUTES } from '@/utils/ADempiere/tableUtils'
import {
IGNORE_VALUE_OPERATORS_LIST, MULTIPLE_VALUES_OPERATORS_LIST, RANGE_VALUE_OPERATORS_LIST
DISPLAY_COLUMN_PREFIX, IDENTIFIER_COLUMN_SUFFIX, IS_ADVANCED_QUERY
} from '@/utils/ADempiere/dictionaryUtils'
import {
IGNORE_VALUE_OPERATORS_LIST, MULTIPLE_VALUES_OPERATORS_LIST,
RANGE_VALUE_OPERATORS_LIST
} from '@/utils/ADempiere/dataUtils'
import { FIELDS_DATE } from '@/utils/ADempiere/references'

// Utils and Helper Methods
import { containerManager } from '@/utils/ADempiere/dictionary/window'
import { isSalesTransaction } from '@/utils/ADempiere/contextUtils'
import { getContextAttributes, generateContextKey } from '@/utils/ADempiere/contextUtils/contextAttributes'
import { isEmptyValue, setRecordPath } from '@/utils/ADempiere/valueUtils.js'
import { getTypeOfValue, isEmptyValue, setRecordPath } from '@/utils/ADempiere/valueUtils.js'
import { convertObjectToKeyValue } from '@/utils/ADempiere/valueFormat'
import { showMessage } from '@/utils/ADempiere/notification'
import { generatePageToken } from '@/utils/ADempiere/dataUtils'
import { isDateField, isDecimalField } from '@/utils/ADempiere/references'

const initState = {
tabData: {},
Expand Down Expand Up @@ -1006,6 +1010,94 @@ const windowManager = {
getTabSelectionsList: (state, getters) => ({ containerUuid }) => {
return getters.getTabData({ containerUuid }).selectionsList
},

/**
* Getter converter selection data record in format
* @param {string} containerUuid
* @param {array} selection
* [{
* selectionId: keyColumn Value,
* values: [{ columnName, value }]
* }]
*/
getTabSelectionToServer: (state, getters, rootState, rootGetters) => ({
parentUuid,
containerUuid,
selectionsList = []
}) => {
const selectionToServer = []

if (isEmptyValue(selectionsList)) {
selectionsList = getters.getTabSelectionsList({
containerUuid
})
}

if (isEmptyValue(selectionsList)) {
return selectionToServer
}

const { fieldsList, table_name, table } = rootGetters.getStoredTab(
parentUuid,
containerUuid
)
let keyColumn = table_name + IDENTIFIER_COLUMN_SUFFIX
if (!isEmptyValue(table.key_columns) && table.key_columns.length === 1) {
keyColumn = table.key_columns.at(0)
}

// reduce list
const fieldsListSelection = fieldsList
.filter(itemField => {
return itemField.is_key || itemField.is_identifier
})
.map(itemField => {
return {
columnName: itemField.column_name,
display_type: itemField.display_type
}
})

selectionsList.forEach(itemRow => {
const attributesList = {}

Object.keys(itemRow).forEach(columnName => {
if (!columnName.startsWith(DISPLAY_COLUMN_PREFIX) && !ROW_KEY_ATTRIBUTES.includes(columnName)) {
const currentField = fieldsListSelection.find(itemField => {
return itemField.columnName === columnName
})
// evaluate metadata attributes before to convert
if (!isEmptyValue(currentField)) {
const value = itemRow[columnName]
let serverValue = value
// types `decimal` and `date` is a object struct
if (getTypeOfValue(value) !== 'OBJECT' || isEmptyValue(value.type)) {
if (isDateField(currentField.display_type)) {
serverValue = {
type: 'date',
value: value
}
} else if (isDecimalField(currentField.display_type)) {
serverValue = {
type: 'decimal',
value: value
}
}
}
attributesList[columnName] = serverValue
}
}
})

selectionToServer.push({
selectionId: itemRow[keyColumn],
values: attributesList
})
})

return selectionToServer
},

getTabPageNumber: (state, getters) => ({ containerUuid }) => {
return getters.getTabData({ containerUuid }).pageNumber
},
Expand Down
50 changes: 44 additions & 6 deletions src/utils/ADempiere/dictionary/window/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -863,9 +863,28 @@ export const exportCurrentRecord = {
*/
export const runProcessOfWindow = {
name: language.t('actionMenu.runProcess'),
enabled: ({ parentUuid, containerUuid }) => {
const recordUuid = store.getters.getUuidOfContainer(containerUuid)
return !isEmptyValue(recordUuid)
enabled: ({ parentUuid, containerUuid, uuid }) => {
const storedTab = store.getters.getStoredTab(
parentUuid,
containerUuid
)
if (!storedTab.isShowedTableRecords) {
const recordUuid = store.getters.getUuidOfContainer(containerUuid)
return !isEmptyValue(recordUuid)
}

// multi selection process
const recordsSelection = store.getters.getTabSelectionsList({
containerUuid
})
if (isEmptyValue(recordsSelection)) {
return false
}
const currentProcess = storedTab.processes.find(process => {
// return process.name === processModal.title
return process.uuid === uuid
})
return currentProcess.is_multi_selection
},
svg: false,
icon: 'el-icon-setting',
Expand All @@ -886,9 +905,28 @@ export const runProcessOfWindow = {
*/
export const generateReportOfWindow = {
name: language.t('actionMenu.generateReport'),
enabled: ({ parentUuid, containerUuid }) => {
const recordUuid = store.getters.getUuidOfContainer(containerUuid)
return !isEmptyValue(recordUuid)
enabled: ({ parentUuid, containerUuid, uuid }) => {
const storedTab = store.getters.getStoredTab(
parentUuid,
containerUuid
)
if (!storedTab.isShowedTableRecords) {
const recordUuid = store.getters.getUuidOfContainer(containerUuid)
return !isEmptyValue(recordUuid)
}

// multi selection process
const recordsSelection = store.getters.getTabSelectionsList({
containerUuid
})
if (isEmptyValue(recordsSelection)) {
return false
}
const currentProcess = storedTab.processes.find(process => {
// return process.name === processModal.title
return process.uuid === uuid
})
return currentProcess.is_multi_selection
},
isSvgIcon: true,
icon: 'skill',
Expand Down

0 comments on commit 9821c7e

Please sign in to comment.