diff --git a/package.json b/package.json index b4c3c78e..aa4f2a06 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ }, "dependencies": { "@adempiere/grpc-access-client": "^1.2.1", + "@adempiere/grpc-core-client": "^1.0.7", "@adempiere/grpc-data-client": "^2.3.6", "@adempiere/grpc-dictionary-client": "^1.4.2", "@adempiere/grpc-enrollment-client": "^1.1.0", @@ -87,7 +88,6 @@ "xlsx": "0.15.6" }, "devDependencies": { - "@adempiere/grpc-core-client": "^1.0.4", "@babel/core": "7.9.0", "@babel/register": "7.9.0", "@vue/cli-plugin-babel": "4.3.1", diff --git a/src/api/ADempiere/instances.js b/src/api/ADempiere/instances.js index 015269fd..8412376c 100644 --- a/src/api/ADempiere/instances.js +++ b/src/api/ADempiere/instances.js @@ -1,3 +1,19 @@ +// Get Instance for connection System Core +export const SystemCoreInstance = () => { + const SystemCore = require('@adempiere/grpc-core-client') + const { BUSINESS_DATA_ADDRESS } = require('@/api/ADempiere/constants') + const { getLanguage } = require('@/lang/index') + const { getToken, getCurrentOrganization, getCurrentWarehouse } = require('@/utils/auth') + + return new SystemCore({ + host: BUSINESS_DATA_ADDRESS, + sessionUuid: getToken(), + organizationUuid: getCurrentOrganization(), + warehouseUuid: getCurrentWarehouse(), + language: getLanguage() || 'en_US' + }) +} + // Instance for connection Access (or Security) export const AccessInstance = () => { const Access = require('@adempiere/grpc-access-client') diff --git a/src/api/ADempiere/system-core.js b/src/api/ADempiere/system-core.js index 8c4bad71..0cff82bf 100644 --- a/src/api/ADempiere/system-core.js +++ b/src/api/ADempiere/system-core.js @@ -1,5 +1,17 @@ // Get Instance for connection -import { BusinessDataInstance as Instance } from '@/api/ADempiere/instances.js' +import { BusinessDataInstance as Instance, SystemCoreInstance } from '@/api/ADempiere/instances.js' + +/** + * Checks if value is empty. Deep-checks arrays and objects + * Note: isEmpty([]) == true, isEmpty({}) == true, isEmpty([{0:false},"",0]) == true, isEmpty({0:1}) == false + * @param {boolean|array|object|number|string|date|map|set|function} value + * @returns {boolean} + */ +export function isEmptyValue(value) { + const { isEmptyValue } = require('@adempiere/grpc-core-client/src/convertValues.js') + + return isEmptyValue(value) +} // Get Organization list from role export function getOrganizationsList({ @@ -33,7 +45,7 @@ export function getWarehousesList({ // Get Country definition from server using id or uuid for record export function getCountryDefinition({ countryUuid, countryId }) { - return Instance.call(this).requestGetCountry({ + return SystemCoreInstance.call(this).requestGetCountry({ countryUuid, countryId }) diff --git a/src/utils/ADempiere/globalMethods.js b/src/utils/ADempiere/globalMethods.js index 0c3f7ee8..894afd07 100644 --- a/src/utils/ADempiere/globalMethods.js +++ b/src/utils/ADempiere/globalMethods.js @@ -1,8 +1,9 @@ export { - isEmptyValue, zeroPad, tagStatus, calculationValue, clearVariables } from '@/utils/ADempiere/valueUtils.js' + +export { isEmptyValue } from '@/api/ADempiere/system-core.js' diff --git a/src/utils/ADempiere/valueUtils.js b/src/utils/ADempiere/valueUtils.js index b89ba3b4..1a511029 100644 --- a/src/utils/ADempiere/valueUtils.js +++ b/src/utils/ADempiere/valueUtils.js @@ -2,29 +2,14 @@ import { TABLE, TABLE_DIRECT } from '@/utils/ADempiere/references' /** * Checks if value is empty. Deep-checks arrays and objects - * Note: isEmpty([]) == true, isEmpty({}) == true, - * isEmpty([{0: false}, "", 0]) == true, isEmpty({0: 1}) == false - * @param {boolean|array|object|number|string} value + * Note: isEmpty([]) == true, isEmpty({}) == true, isEmpty([{0:false},"",0]) == true, isEmpty({0:1}) == false + * @param {boolean|array|object|number|string|date|map|set|function} value * @returns {boolean} */ export function isEmptyValue(value) { - if (value === undefined || value == null) { - return true - } else if (String(value).trim() === '-1') { - return true - } else if (typeof value === 'string') { - return Boolean(!value.trim().length) - } else if (typeof value === 'function' || typeof value === 'number' || typeof value === 'boolean' || Object.prototype.toString.call(value) === '[object Date]') { - return false - } else if (Object.prototype.toString.call(value) === '[object Map]' || Object.prototype.toString.call(value) === '[object Set]') { - return Boolean(!value.size) - } else if (Array.isArray(value)) { - return Boolean(!value.length) - } else if (typeof value === 'object') { - return Boolean(!Object.keys(value).length) - } + const { isEmptyValue } = require('@/api/ADempiere/system-core') - return true + return isEmptyValue(value) } export function typeValue(value) { @@ -330,7 +315,7 @@ export function parsedValueComponent({ value = value ? 'Y' : 'N' } // Table (18) or Table Direct (19) - if (displayType === TABLE.id || (displayType === TABLE_DIRECT.id && isIdentifier)) { + if (displayType === TABLE_DIRECT.id || (displayType === TABLE.id && isIdentifier)) { if (!isEmptyValue(value)) { value = Number(value) }