Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add window support ReadOnly field. #1159

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/components/ADempiere/Field/FieldOptions/preference/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
import formMixin from '@/components/ADempiere/Form/formMixin'
import preferenceFields from './preferenceFields.js'
import { createFieldFromDictionary } from '@/utils/ADempiere/lookupFactory'
import { CLIENT, ORGANIZATION } from '@/utils/ADempiere/constants/systemColumns'
import { setPreference, deletePreference } from '@/api/ADempiere/field/preference.js'
import { showMessage } from '@/utils/ADempiere/notification.js'
import language from '@/lang'
Expand Down Expand Up @@ -149,13 +150,13 @@ export default {
if (this.isEmptyValue(this.metadataList)) {
return ''
}
const forCurrentUser = this.metadataList.find(field => field.columnName === 'AD_User_ID')
const forCurrentClient = this.metadataList.find(field => field.columnName === 'AD_Client_ID')
const forCurrentOrganization = this.metadataList.find(field => field.columnName === 'AD_Org_ID')
const forCurrentContainer = this.metadataList.find(field => field.columnName === 'AD_Window_ID')
const forCurrentClient = this.metadataList.find(field => field.columnName === CLIENT)
if (!forCurrentClient) {
return ''
}
const forCurrentUser = this.metadataList.find(field => field.columnName === 'AD_User_ID')
const forCurrentOrganization = this.metadataList.find(field => field.columnName === ORGANIZATION)
const forCurrentContainer = this.metadataList.find(field => field.columnName === 'AD_Window_ID')
// Create Message
var expl = language.t('components.preference.for')// components.preference.for
if (forCurrentOrganization && forCurrentClient) {
Expand Down Expand Up @@ -224,8 +225,8 @@ export default {
},
remove() {
const isForCurrentUser = this.metadataList.find(field => field.columnName === 'AD_User_ID').value
const isForCurrentClient = this.metadataList.find(field => field.columnName === 'AD_Client_ID').value
const isForCurrentOrganization = this.metadataList.find(field => field.columnName === 'AD_Org_ID').value
const isForCurrentClient = this.metadataList.find(field => field.columnName === CLIENT).value
const isForCurrentOrganization = this.metadataList.find(field => field.columnName === ORGANIZATION).value
const isForCurrentContainer = this.metadataList.find(field => field.columnName === 'AD_Window_ID').value
deletePreference({
parentUuid: this.fieldAttributes.parentUuid,
Expand Down Expand Up @@ -275,8 +276,8 @@ export default {
},
sendValue(list) {
const isForCurrentUser = this.metadataList.find(field => field.columnName === 'AD_User_ID').value
const isForCurrentClient = this.metadataList.find(field => field.columnName === 'AD_Client_ID').value
const isForCurrentOrganization = this.metadataList.find(field => field.columnName === 'AD_Org_ID').value
const isForCurrentClient = this.metadataList.find(field => field.columnName === CLIENT).value
const isForCurrentOrganization = this.metadataList.find(field => field.columnName === ORGANIZATION).value
const isForCurrentContainer = this.metadataList.find(field => field.columnName === 'AD_Window_ID').value
//
setPreference({
Expand Down
71 changes: 60 additions & 11 deletions src/components/ADempiere/Field/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@

<script>
import { evalutateTypeField, fieldIsDisplayed } from '@/utils/ADempiere/dictionaryUtils'
import {
ACTIVE, CLIENT, PROCESSING, PROCESSED
} from '@/utils/ADempiere/constants/systemColumns'
import FieldOptions from '@/components/ADempiere/Field/FieldOptions'

/**
Expand Down Expand Up @@ -240,11 +243,49 @@ export default {
isPanelWindow() {
return this.field.panelType === 'window'
},

recordUuid() {
// is active record
return this.$store.getters.getValueOfField({
parentUuid: this.parentUuid,
containerUuid: this.containerUuid,
columnName: 'UUID'
})
},
containerIsActive() {
// panel processing value
return this.$store.getters.getValueOfField({
parentUuid: this.parentUuid,
containerUuid: this.containerUuid,
columnName: ACTIVE
})
},
containerIsProcessing() {
// panel processing value
return this.$store.getters.getValueOfField({
parentUuid: this.parentUuid,
containerUuid: this.containerUuid,
columnName: PROCESSING
})
},
containerIsProcessed() {
// panel processed value
return this.$store.getters.getValueOfField({
parentUuid: this.parentUuid,
containerUuid: this.containerUuid,
columnName: PROCESSED
})
},
containerClientId() {
// panel client value
return this.$store.getters.getValueOfField({
parentUuid: this.parentUuid,
containerUuid: this.containerUuid,
columnName: CLIENT
})
},
preferenceClientId() {
if (this.isPanelWindow) {
return this.$store.getters.getPreferenceClientId
}
return undefined
return this.$store.getters.getPreferenceClientId
},

/**
Expand All @@ -259,14 +300,23 @@ export default {
return false
}

if (!this.field.isActive) {
return true
}

// validate with container manager
if (!this.isEmptyValue(this.containerManager) &&
this.containerManager.validateReadOnly) {
return this.containerManager.validateReadOnly(this.field)
// TODO: Add validate method to record uuid uuid without route.action
// edit mode is diferent to create new
const isWithRecord = this.recordUuid !== 'create-new' &&
!this.isEmptyValue(this.recordUuid)
return this.containerManager.validateReadOnly({
field: this.field,
preferenceClientId: this.preferenceClientId,
// record values
clientId: this.containerClientId,
isActive: this.containerIsActive,
isProcessing: this.containerIsProcessing,
isProcessed: this.containerIsProcessed,
isWithRecord
})
}

const isUpdateableAllFields = this.field.isReadOnly || this.field.isReadOnlyFromLogic
Expand All @@ -275,9 +325,8 @@ export default {
// TODO: Evaluate record uuid without route.action
// edit mode is diferent to create new
let isWithRecord = this.field.recordUuid !== 'create-new'
// TODO: Remove false condition to production
// evaluate context
if ((this.preferenceClientId !== this.metadataField.clientId && 1 === 2) && isWithRecord) {
if ((this.preferenceClientId !== this.metadataField.clientId) && isWithRecord) {
return true
}

Expand Down
28 changes: 25 additions & 3 deletions src/store/modules/ADempiere/fieldValue.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
// ADempiere-Vue (Frontend) for ADempiere ERP & CRM Smart Business Solution
// Copyright (C) 2017-Present E.R.P. Consultores y Asociados, C.A.
// Contributor(s): Edwin Betancourt [email protected] www.erpya.com
// 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/>.

import Vue from 'vue'
import { isEmptyValue } from '@/utils/ADempiere/valueUtils.js'
import { convertStringToBoolean } from '@/utils/ADempiere/valueFormat.js'
import {
ACTIVE, PROCESSING, PROCESSED
} from '@/utils/ADempiere/constants/systemColumns'

const UUID_KEY = 'UUID'

const value = {
state: {
field: {}
},

mutations: {
resetStatevalue(state) {
state = {
Expand Down Expand Up @@ -84,6 +104,7 @@ const value = {
})
}
},

actions: {
updateValuesOfContainer({ commit }, {
parentUuid,
Expand All @@ -99,6 +120,7 @@ const value = {
})
}
},

getters: {
getValueOfField: (state) => ({
parentUuid,
Expand Down Expand Up @@ -173,17 +195,17 @@ const value = {
},
// Using to read only in data tables in Window
getContainerIsActive: (state) => (parentUuid) => {
const valueIsActive = state.field[`${parentUuid}_IsActive`]
const valueIsActive = state.field[`${parentUuid}_${ACTIVE}`]

return convertStringToBoolean(valueIsActive)
},
getContainerProcessing: (state) => (parentUuid) => {
const valueProcessing = state.field[`${parentUuid}_Processing`]
const valueProcessing = state.field[`${parentUuid}_${PROCESSING}`]

return convertStringToBoolean(valueProcessing)
},
getContainerProcessed: (state) => (parentUuid) => {
const valueProcessed = state.field[`${parentUuid}_Processed`]
const valueProcessed = state.field[`${parentUuid}_${PROCESSED}`]

return convertStringToBoolean(valueProcessed)
}
Expand Down
21 changes: 19 additions & 2 deletions src/store/modules/ADempiere/preference.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
// ADempiere-Vue (Frontend) for ADempiere ERP & CRM Smart Business Solution
// Copyright (C) 2017-Present E.R.P. Consultores y Asociados, C.A.
// Contributor(s): Edwin Betancourt [email protected] www.erpya.com
// 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.
yamelsenih marked this conversation as resolved.
Show resolved Hide resolved

// 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/>.

import Vue from 'vue'
// Delete when get global context and account context
import { isEmptyValue, typeValue } from '@/utils/ADempiere/valueUtils.js'
import { CLIENT, ORGANIZATION } from '@/utils/ADempiere/constants/systemColumns.js'

const preference = {
state: {
Expand Down Expand Up @@ -170,10 +187,10 @@ const preference = {
return state.preference
},
getPreferenceClientId: (state) => {
return parseInt(state.preference['#AD_Client_ID'], 10)
return parseInt(state.preference['#' + CLIENT], 10)
},
getPreferenceOrgId: (state) => {
return parseInt(state.preference['#AD_Org_ID'], 10)
return parseInt(state.preference['#' + ORGANIZATION], 10)
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/store/modules/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
import { resetRouter } from '@/router'
import { showMessage } from '@/utils/ADempiere/notification'
import { isEmptyValue } from '@/utils/ADempiere/valueUtils'
import { ORGANIZATION } from '@/utils/ADempiere/constants/systemColumns'
import language from '@/lang'

const state = {
Expand Down Expand Up @@ -173,7 +174,7 @@ const actions = {
commit('SET_ROLE', role)
setCurrentRole(role.uuid)
const currentOrganizationSession = sessionInfo.defaultContext.find(context => {
if (context.key === '#AD_Org_ID') {
if (context.key === '#' + ORGANIZATION) {
return context
}
})
Expand Down Expand Up @@ -367,7 +368,7 @@ const actions = {
}
commit('SET_ORGANIZATION', organization)
commit('setPreferenceContext', {
columnName: '#AD_Org_ID',
columnName: '#' + ORGANIZATION,
value: organization.id
}, {
root: true
Expand Down Expand Up @@ -409,7 +410,7 @@ const actions = {
commit('SET_ORGANIZATION', organization)

// commit('setPreferenceContext', {
// columnName: '#AD_Org_ID',
// columnName: '#' + ORGANIZATION,
// value: organizationId
// }, {
// root: true
Expand Down
25 changes: 25 additions & 0 deletions src/utils/ADempiere/constants/systemColumns.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ADempiere-Vue (Frontend) for ADempiere ERP & CRM Smart Business Solution
// Copyright (C) 2017-Present E.R.P. Consultores y Asociados, C.A.
// Contributor(s): Edwin Betancourt [email protected] www.erpya.com
// 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/>.

export const CLIENT = 'AD_Client_ID'

export const ORGANIZATION = 'AD_Org_ID'

export const ACTIVE = 'IsActive'

export const PROCESSING = 'Processing'

export const PROCESSED = 'Processed'
34 changes: 34 additions & 0 deletions src/views/ADempiere/Window/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,40 @@ export default defineComponent({
}

return isDisplayed && isDisplayedFromLogic
},

validateReadOnly({
field,
// records values
preferenceClientId,
clientId,
isActive,
isProcessing,
isProcessed,
isWithRecord
}) {
// evaluate context
if (preferenceClientId !== clientId && isWithRecord) {
return true
}
// record is inactive
if (!isActive && field.columnName !== 'IsActive') {
return true
}
if (field.isAlwaysUpdateable) {
return false
}
if (isWithRecord && (isProcessing || isProcessed)) {
return true
}

// not updateable and record saved
if (!field.isUpdateable && isWithRecord) {
return true
}
return (
field.isReadOnly || field.isReadOnlyFromLogic || field.isReadOnlyFromForm
)
}
}

Expand Down