Skip to content

Commit

Permalink
feat: (Transcoding) Load Lookups.
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwinBetanc0urt committed Oct 23, 2023
1 parent fb8ac6f commit 8f48981
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 143 deletions.
2 changes: 1 addition & 1 deletion src/api/ADempiere/dictionary/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function requestFieldMetadata({
case (!isEmptyValue(tableName) && isEmptyValue(columnName)):
url = `/dictionary/fields/${tableName}/${columnName}`
break
case !isEmptyValue(columnName):
case !isEmptyValue(columnId):
url = `/dictionary/fields/column/${columnId}`
break
case !isEmptyValue(elementId):
Expand Down
21 changes: 8 additions & 13 deletions src/api/ADempiere/userInterface/lookups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,27 @@ export function requestLookupList({
//
tableName,
columnName,
columnUuid,
columnId,
//
pageToken,
pageSize = RECORD_ROWS_BY_LIST
}) {
const column_name = columnName
const table_name = tableName
const process_parameter_id = processParameterId
const browse_field_id = browseFieldId
const id = fieldId
let url
switch (true) {
case (!isEmptyValue(columnName) && isEmptyValue(tableName)):
url = `/user-interface/lookups/column/${column_name}`
case (!isEmptyValue(columnId)):
url = `/user-interface/lookups/column/${columnId}`
break
case !isEmptyValue(fieldId):
url = `/user-interface/lookups/field/${id}`
url = `/user-interface/lookups/field/${fieldId}`
break
case !isEmptyValue(processParameterId):
url = `/user-interface/lookups/parameter/${process_parameter_id}`
url = `/user-interface/lookups/parameter/${processParameterId}`
break
case !isEmptyValue(browseFieldId):
url = `/user-interface/lookups/query-criteria/${browse_field_id}`
url = `/user-interface/lookups/query-criteria/${browseFieldId}`
break
default:
url = `/user-interface/lookups/${table_name}/${column_name}`
url = `/user-interface/lookups/${tableName}/${columnName}`
break
}

Expand All @@ -81,7 +76,7 @@ export function requestLookupList({
//
table_name: tableName,
column_name: columnName,
column_uuid: columnUuid,
column_id: columnId,
// Page Data
page_token: pageToken,
page_size: pageSize
Expand Down
71 changes: 1 addition & 70 deletions src/api/ADempiere/window.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* ADempiere-Vue (Frontend) for ADempiere ERP & CRM Smart Business Solution
* Copyright (C) 2017-Present E.R.P. Consultores y Asociados, C.A. www.erpya.com
* Copyright (C) 2018-Present E.R.P. Consultores y Asociados, C.A. www.erpya.com
* Contributor(s): Edwin Betancourt [email protected] https://github.com/EdwinBetanc0urt
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -18,78 +18,9 @@

// Get Instance for connection
import { request } from '@/utils/ADempiere/request'
import { isEmptyValue } from '@/utils/ADempiere/valueUtils.js'

// Constants
import { ROWS_OF_RECORDS_BY_PAGE } from '@/utils/ADempiere/tableUtils'
import { RECORD_ROWS_BY_LIST } from '@/utils/ADempiere/references.js'

/**
* Request a Lookup list data from Reference
* The main attributes that function hope are:
* @param {string} fieldUuid
* @param {string} browseFieldUuid
* @param {string} processParameterUuid
* @param {array} contextAttributesList
* @param {string} pageToken
* @param {number} pageSize
*/
export function requestLookupList({
contextAttributesList,
fieldUuid,
processParameterUuid,
browseFieldUuid,
id,
//
referenceUuid,
searchValue,
//
tableName,
columnName,
columnUuid,
//
pageToken,
pageSize = RECORD_ROWS_BY_LIST
}) {
let contextAttributes = []
if (!isEmptyValue(contextAttributesList)) {
contextAttributes = contextAttributesList.map(attribute => {
return {
key: attribute.columnName,
value: attribute.value
}
})
}

return request({
url: '/user-interface/window/lookup-items',
method: 'get',
params: {
context_attributes: contextAttributes,
field_uuid: fieldUuid,
process_parameter_uuid: processParameterUuid,
browse_field_uuid: browseFieldUuid,
id,
//
reference_uuid: referenceUuid,
search_value: searchValue,
//
table_name: tableName,
column_name: columnName,
column_uuid: columnUuid,
// Page Data
page_token: pageToken,
page_size: pageSize
}
})
.then(lookupListResponse => {
return {
nextPageToken: lookupListResponse.next_page_token,
recordCount: lookupListResponse.record_count,
recordsList: lookupListResponse.records
}
})
}

/**
* Reference List from Window
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<!--
ADempiere-Vue (Frontend) for ADempiere ERP & CRM Smart Business Solution
Copyright (C) 2017-Present E.R.P. Consultores y Asociados, C.A.
Contributor(s): Elsio Sanchez elsiosanchez15@outlook.com https://github.com/elsiosanchez
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https:www.gnu.org/licenses/>.
ADempiere-Vue (Frontend) for ADempiere ERP & CRM Smart Business Solution
Copyright (C) 2018-Present E.R.P. Consultores y Asociados, C.A. www.erpya.com
Contributor(s): Elsio Sanchez elsiosanchez15@outlook.com https://github.com/elsiosanchez
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https:www.gnu.org/licenses/>.
-->

<template>
Expand Down Expand Up @@ -159,7 +159,9 @@ import {
// watch,
ref
} from '@vue/composition-api'

import store from '@/store'

// Components and Mixins
// import ProductListTable from './ProductListTable'
// utils and helper methods
Expand All @@ -168,8 +170,9 @@ import store from '@/store'
// formatQuantity
// } from '@/utils/ADempiere/formatValue/numberFormat'
// import { isEmptyValue } from '@/utils/ADempiere'
// api request methods
import { requestLookupList } from '@/api/ADempiere/window.js'

// API Request Methods
import { requestLookupList } from '@/api/ADempiere/userInterface/lookups.ts'

export default defineComponent({
name: 'NewCustomer',
Expand Down
115 changes: 72 additions & 43 deletions src/store/modules/ADempiere/lookupManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { requestLookupList } from '@/api/ADempiere/userInterface/lookups.ts'
import { isEmptyValue } from '@/utils/ADempiere/valueUtils.js'
import { getContextAttributes, generateContextKey } from '@/utils/ADempiere/contextUtils/contextAttributes'
import { showMessage } from '@/utils/ADempiere/notification'
import { getOptionsList } from '@/utils/ADempiere/lookups.ts'

const initStateLookup = {
lookupList: {}
Expand Down Expand Up @@ -65,6 +66,51 @@ const lookupManager = {
},

actions: {
addLookupsList({ commit, rootGetters }, {
isAddBlankValue = true,
blankValue,
parentUuid,
containerUuid,
uuid,
contextColumnNames = [],
recordsList = []
}) {
return new Promise(resolve => {
const contextAttributesList = getContextAttributes({
parentUuid,
containerUuid,
contextColumnNames,
isBooleanToString: true
})

const clientId = rootGetters.getSessionContextClientId

let key = clientId
if (!isEmptyValue(uuid)) {
key += `|${uuid}`
}

const contextKey = generateContextKey(contextAttributesList)
key += contextKey

const optionsList = getOptionsList({
recordsList: recordsList,
isAddBlankValue,
blankValue
})

commit('setLookupList', {
clientId,
parentUuid, // used by suscription filter
containerUuid, // used by suscription filter
contextAttributesList,
optionsList,
key
})

resolve(optionsList)
})
},

/**
* Get display column from lookup
Expand All @@ -82,20 +128,19 @@ const lookupManager = {
parentUuid,
containerUuid,
contextColumnNames = [],
fieldId,
fieldUuid,
processParameterId,
browseFieldId,
browseFieldUuid,
processParameterUuid,
fieldId,
id,
//
referenceUuid,
searchValue,
//
tableName,
columnName,
columnUuid
columnId
}) {
return new Promise(resolve => {
// if (isEmptyValue(referenceUuid) && isEmptyValue(fieldUuid) && isEmptyValue(processParameterUuid) && isEmptyValue(browseFieldUuid) &&
Expand All @@ -111,59 +156,43 @@ const lookupManager = {
isBooleanToString: true
})

const clientId = rootGetters.getSessionContextClientId

let key = clientId
if (!isEmptyValue(fieldId)) {
key += `|${fieldUuid}`
} else if (!isEmptyValue(processParameterId)) {
key += `|${processParameterUuid}`
} else if (!isEmptyValue(browseFieldId)) {
key += `|${browseFieldUuid}`
} else if (!isEmptyValue(columnId)) {
key += `|${columnId}`
} else if (!isEmptyValue(tableName) && !isEmptyValue(columnName)) {
key += `|${tableName}.${columnName}`
}

const contextKey = generateContextKey(contextAttributesList)
key += contextKey

requestLookupList({
contextAttributesList,
browseFieldId,
processParameterId,
fieldId: id,
fieldId,
//
referenceUuid,
searchValue,
tableName,
columnName,
columnUuid
columnId
})
.then(lookupListResponse => {
const optionsList = []

lookupListResponse.recordsList.forEach(itemLookup => {
const {
KeyColumn: value,
DisplayColumn: displayedValue
} = itemLookup.values

if (!isEmptyValue(value)) {
optionsList.push({
displayedValue,
value,
uuid: itemLookup.uuid
})
}
const optionsList = getOptionsList({
recordsList: lookupListResponse.recordsList,
isAddBlankValue,
blankValue
})

// add blanck value option in fist element on list
if (isAddBlankValue) {
optionsList.unshift({
displayedValue: ' ',
value: blankValue,
uuid: undefined
})
}

const clientId = rootGetters.getSessionContextClientId

let key = clientId
if (!isEmptyValue(fieldUuid)) {
key += `|${fieldUuid}`
} else if (!isEmptyValue(processParameterId)) {
key += `|${processParameterUuid}`
} else if (!isEmptyValue(browseFieldId)) {
key += `|${browseFieldUuid}`
}

const contextKey = generateContextKey(contextAttributesList)
key += contextKey

commit('setLookupList', {
clientId,
parentUuid, // used by suscription filter
Expand Down
2 changes: 1 addition & 1 deletion src/utils/ADempiere/dictionary/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -2089,7 +2089,7 @@ export const containerManager = {
containerUuid,
contextColumnNames,
fieldUuid: uuid,
id,
fieldId: id,
columnName,
searchValue,
tableName,
Expand Down
Loading

0 comments on commit 8f48981

Please sign in to comment.