mirror of
https://github.com/PanJiaChen/vue-element-admin.git
synced 2025-08-13 15:15:53 +08:00
Feature: Add preference service (#696)
* Add support to service of Save Preference from component * remove unnecessary values * Add service for delete preference * add service delete preference * Add translation for preference message Co-authored-by: elsiosanchez <elsiosanches@gmail.com>
This commit is contained in:
parent
31e6b7b3c8
commit
97830cdb47
@ -1,35 +1,53 @@
|
|||||||
export function getPreference({
|
// Service for backend based on API
|
||||||
|
// use this service for consume all related to preference of field
|
||||||
|
import {
|
||||||
|
ApiRest as serviceApi
|
||||||
|
} from '@/api/ADempiere/instances.js'
|
||||||
|
|
||||||
|
// Update preference from API using criteria
|
||||||
|
export function setPreference({
|
||||||
parentUuid,
|
parentUuid,
|
||||||
containerUuid,
|
|
||||||
panelType,
|
panelType,
|
||||||
attribute,
|
attribute,
|
||||||
value,
|
value,
|
||||||
level
|
isForCurrentUser,
|
||||||
|
isForCurrentClient,
|
||||||
|
isForCurrentOrganization,
|
||||||
|
isForCurrentContainer
|
||||||
}) {
|
}) {
|
||||||
return getPreference({
|
return serviceApi({
|
||||||
parentUuid,
|
url: '/ui/set-preference',
|
||||||
containerUuid,
|
data: {
|
||||||
panelType,
|
container_uuid: parentUuid,
|
||||||
attribute,
|
column_name: attribute,
|
||||||
value,
|
value: value,
|
||||||
level
|
is_for_current_user: isForCurrentUser,
|
||||||
|
is_for_current_client: isForCurrentClient,
|
||||||
|
is_for_current_organization: isForCurrentOrganization,
|
||||||
|
is_for_current_container: isForCurrentContainer
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updatePreference({
|
// Delete preference based on match
|
||||||
|
export function deletePreference({
|
||||||
parentUuid,
|
parentUuid,
|
||||||
containerUuid,
|
|
||||||
panelType,
|
panelType,
|
||||||
attribute,
|
attribute,
|
||||||
value,
|
isForCurrentUser,
|
||||||
level
|
isForCurrentClient,
|
||||||
|
isForCurrentOrganization,
|
||||||
|
isForCurrentContainer
|
||||||
}) {
|
}) {
|
||||||
return updatePreference({
|
return serviceApi({
|
||||||
parentUuid,
|
url: '/ui/delete-preference',
|
||||||
containerUuid,
|
data: {
|
||||||
panelType,
|
container_uuid: parentUuid,
|
||||||
attribute,
|
column_name: attribute,
|
||||||
value,
|
is_for_current_user: isForCurrentUser,
|
||||||
level
|
is_for_current_client: isForCurrentClient,
|
||||||
|
is_for_current_organization: isForCurrentOrganization,
|
||||||
|
is_for_current_container: isForCurrentContainer
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@
|
|||||||
:field-value="recordDataFields"
|
:field-value="recordDataFields"
|
||||||
/>
|
/>
|
||||||
<preference
|
<preference
|
||||||
:field-attributes="fieldAttributes"
|
:source-field="fieldAttributes"
|
||||||
:field-value="recordDataFields"
|
:field-value="recordDataFields"
|
||||||
:panel-type="field.panelType"
|
:panel-type="field.panelType"
|
||||||
/>
|
/>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<el-dropdown trigger="click">
|
<el-dropdown trigger="click">
|
||||||
<el-button type="text" :disabled="fieldAttributes.readonly">
|
<el-button type="text" :disabled="sourceField.readonly">
|
||||||
<i class="el-icon-notebook-2 el-icon--right" @click="isActive = !isActive" />
|
<i class="el-icon-notebook-2 el-icon--right" @click="isActive = !isActive" />
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-dropdown-menu slot="dropdown" class="dropdown-calc">
|
<el-dropdown-menu slot="dropdown" class="dropdown-calc">
|
||||||
@ -12,26 +12,14 @@
|
|||||||
<span>
|
<span>
|
||||||
{{ $t('components.preference.title') }}
|
{{ $t('components.preference.title') }}
|
||||||
<b>
|
<b>
|
||||||
{{ fieldAttributes.name }}
|
{{ sourceField.name }}
|
||||||
</b>
|
</b>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="!isEmptyValue(descriptionOfPreference)" class="text item">
|
<div class="text item">
|
||||||
{{
|
{{
|
||||||
descriptionOfPreference
|
getDescriptionOfPreference
|
||||||
}}
|
}}
|
||||||
<template
|
|
||||||
v-for="(index) in fieldsListPreference"
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
v-if="index.value"
|
|
||||||
:key="index.sequence"
|
|
||||||
>
|
|
||||||
{{
|
|
||||||
index.label
|
|
||||||
}}
|
|
||||||
</span>
|
|
||||||
</template>
|
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
<div class="text item">
|
<div class="text item">
|
||||||
@ -40,25 +28,8 @@
|
|||||||
>
|
>
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<p slot="label">
|
<p slot="label">
|
||||||
{{ fieldAttributes.name }}
|
{{ sourceField.name }}: {{ code }}
|
||||||
</p>
|
</p>
|
||||||
<el-switch
|
|
||||||
v-if="fieldAttributes.componentPath === 'FieldYesNo'"
|
|
||||||
v-model="code"
|
|
||||||
:active-text="$t('components.preference.yes')"
|
|
||||||
:inactive-text="$t('components.preference.no')"
|
|
||||||
:disabled="true"
|
|
||||||
style="padding-top: 30%"
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
v-else
|
|
||||||
>
|
|
||||||
<p>
|
|
||||||
{{
|
|
||||||
code
|
|
||||||
}}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
<el-form
|
<el-form
|
||||||
@ -83,6 +54,14 @@
|
|||||||
<br>
|
<br>
|
||||||
<el-row>
|
<el-row>
|
||||||
<el-col :span="24">
|
<el-col :span="24">
|
||||||
|
<samp style="float: left; padding-right: 10px;">
|
||||||
|
<el-button
|
||||||
|
type="danger"
|
||||||
|
class="custom-button-address-location"
|
||||||
|
icon="el-icon-delete"
|
||||||
|
@click="remove()"
|
||||||
|
/>
|
||||||
|
</samp>
|
||||||
<samp style="float: right; padding-right: 10px;">
|
<samp style="float: right; padding-right: 10px;">
|
||||||
<el-button
|
<el-button
|
||||||
type="danger"
|
type="danger"
|
||||||
@ -94,7 +73,7 @@
|
|||||||
type="primary"
|
type="primary"
|
||||||
class="custom-button-address-location"
|
class="custom-button-address-location"
|
||||||
icon="el-icon-check"
|
icon="el-icon-check"
|
||||||
@click="close()"
|
@click="sendValue()"
|
||||||
/>
|
/>
|
||||||
</samp>
|
</samp>
|
||||||
</el-col>
|
</el-col>
|
||||||
@ -112,16 +91,18 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// import { ID, INTEGER } from '@/utils/ADempiere/references'
|
import formMixin from '@/components/ADempiere/Form/formMixin'
|
||||||
import filelistPreference from './filelistPreference.js'
|
import preferenceFields from './preferenceFields.js'
|
||||||
import { getPreference } from '@/api/ADempiere/field/preference.js'
|
|
||||||
import { createFieldFromDictionary } from '@/utils/ADempiere/lookupFactory'
|
import { createFieldFromDictionary } from '@/utils/ADempiere/lookupFactory'
|
||||||
import { attributePreference } from '@/utils/ADempiere/valueUtils'
|
import { setPreference, deletePreference } from '@/api/ADempiere/field/preference.js'
|
||||||
|
import { showMessage } from '@/utils/ADempiere/notification.js'
|
||||||
|
import language from '@/lang'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Preference',
|
name: 'Preference',
|
||||||
|
mixins: [formMixin],
|
||||||
props: {
|
props: {
|
||||||
fieldAttributes: {
|
sourceField: {
|
||||||
type: [Object],
|
type: [Object],
|
||||||
required: true,
|
required: true,
|
||||||
default: null
|
default: null
|
||||||
@ -130,24 +111,15 @@ export default {
|
|||||||
type: [String, Number, Boolean, Date, Array, Object],
|
type: [String, Number, Boolean, Date, Array, Object],
|
||||||
required: true,
|
required: true,
|
||||||
default: ''
|
default: ''
|
||||||
},
|
|
||||||
containerUuid: {
|
|
||||||
type: String,
|
|
||||||
default: 'fiel-reference'
|
|
||||||
},
|
|
||||||
panelType: {
|
|
||||||
type: String,
|
|
||||||
default: undefined
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
filelistPreference,
|
preferenceFields,
|
||||||
metadataList: [],
|
metadataList: [],
|
||||||
code: '',
|
code: '',
|
||||||
description: [],
|
description: [],
|
||||||
isActive: false,
|
isActive: false
|
||||||
unsubscribe: () => {}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -161,17 +133,40 @@ export default {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
descriptionOfPreference() {
|
getDescriptionOfPreference() {
|
||||||
const label = this.fieldsListPreference.filter(element => {
|
if (this.isEmptyValue(this.metadataList)) {
|
||||||
return element.value
|
return ''
|
||||||
})
|
|
||||||
if (!this.isEmptyValue(label)) {
|
|
||||||
if (label[0].columnName === 'AD_User_ID') {
|
|
||||||
return this.$t('components.preference.defaulMessageUser')
|
|
||||||
}
|
}
|
||||||
return this.$t('components.preference.defaulMessage')
|
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')
|
||||||
|
if (!forCurrentClient) {
|
||||||
|
return ''
|
||||||
}
|
}
|
||||||
return []
|
// Create Message
|
||||||
|
var expl = language.t('components.preference.for')// components.preference.for
|
||||||
|
if (forCurrentClient.value && forCurrentOrganization.value) {
|
||||||
|
expl = expl.concat(language.t('components.preference.clientAndOrganization'))// components.preference.clientAndOrganization
|
||||||
|
} else if (forCurrentClient.value && !forCurrentOrganization.value) {
|
||||||
|
expl = expl.concat(language.t('components.preference.allOrganizationOfClient'))// components.preference.allOrganizationOfClient
|
||||||
|
} else if (!forCurrentClient.value && forCurrentOrganization.value) {
|
||||||
|
forCurrentOrganization.value = false
|
||||||
|
expl = expl.concat(language.t('components.preference.entireSystem'))// components.preference.entireSystem
|
||||||
|
} else {
|
||||||
|
expl = expl.concat(language.t('components.preference.entireSystem'))// components.preference.entireSystem
|
||||||
|
}
|
||||||
|
if (forCurrentUser.value) {
|
||||||
|
expl = expl.concat(language.t('components.preference.thisUser'))// components.preference.thisUser
|
||||||
|
} else {
|
||||||
|
expl = expl.concat(language.t('components.preference.allUsers'))// components.preference.allUsers
|
||||||
|
}
|
||||||
|
if (forCurrentContainer.value) {
|
||||||
|
expl = expl.concat(language.t('components.preference.thisWindow'))// components.preference.thisWindow
|
||||||
|
} else {
|
||||||
|
expl = expl.concat(language.t('components.preference.allWindows'))// components.preference.allWindows
|
||||||
|
}
|
||||||
|
return expl
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
@ -181,7 +176,7 @@ export default {
|
|||||||
this.setFieldsList()
|
this.setFieldsList()
|
||||||
}
|
}
|
||||||
if (!this.isEmptyValue(preferenceValue)) {
|
if (!this.isEmptyValue(preferenceValue)) {
|
||||||
if ((typeof preferenceValue !== 'string') && (this.fieldAttributes.componentPath !== 'FieldYesNo')) {
|
if ((typeof preferenceValue !== 'string') && (this.sourceField.componentPath !== 'FieldYesNo')) {
|
||||||
this.code = preferenceValue
|
this.code = preferenceValue
|
||||||
} else {
|
} else {
|
||||||
this.code = preferenceValue
|
this.code = preferenceValue
|
||||||
@ -189,18 +184,38 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
|
||||||
this.unsubscribe = this.subscribeChanges()
|
|
||||||
},
|
|
||||||
beforeDestroy() {
|
|
||||||
this.unsubscribe()
|
|
||||||
},
|
|
||||||
methods: {
|
methods: {
|
||||||
createFieldFromDictionary,
|
createFieldFromDictionary,
|
||||||
attributePreference,
|
|
||||||
close() {
|
close() {
|
||||||
this.$children[0].visible = false
|
this.$children[0].visible = false
|
||||||
},
|
},
|
||||||
|
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 isForCurrentContainer = this.metadataList.find(field => field.columnName === 'AD_Window_ID').value
|
||||||
|
deletePreference({
|
||||||
|
parentUuid: this.sourceField.parentUuid,
|
||||||
|
attribute: this.sourceField.columnName,
|
||||||
|
isForCurrentUser,
|
||||||
|
isForCurrentClient,
|
||||||
|
isForCurrentOrganization,
|
||||||
|
isForCurrentContainer
|
||||||
|
})
|
||||||
|
.then(preference => {
|
||||||
|
showMessage({
|
||||||
|
message: language.t('components.preference.preferenceRemoved')
|
||||||
|
})
|
||||||
|
this.close()
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
showMessage({
|
||||||
|
message: error.message,
|
||||||
|
type: 'error'
|
||||||
|
})
|
||||||
|
console.warn(`setPreference error: ${error.message}.`)
|
||||||
|
})
|
||||||
|
},
|
||||||
notSubmitForm(event) {
|
notSubmitForm(event) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
return false
|
return false
|
||||||
@ -208,13 +223,13 @@ export default {
|
|||||||
setFieldsList() {
|
setFieldsList() {
|
||||||
const fieldsList = []
|
const fieldsList = []
|
||||||
// Product Code
|
// Product Code
|
||||||
this.filelistPreference.forEach(element => {
|
this.preferenceFields.forEach(element => {
|
||||||
this.createFieldFromDictionary(element)
|
this.createFieldFromDictionary(element)
|
||||||
.then(metadata => {
|
.then(metadata => {
|
||||||
const data = metadata
|
const data = metadata
|
||||||
fieldsList.push({
|
fieldsList.push({
|
||||||
...data,
|
...data,
|
||||||
containerUuid: 'fiel-reference'
|
containerUuid: 'field-reference'
|
||||||
})
|
})
|
||||||
if (data.value) {
|
if (data.value) {
|
||||||
this.description.push(data.name)
|
this.description.push(data.name)
|
||||||
@ -226,57 +241,32 @@ export default {
|
|||||||
this.metadataList = fieldsList
|
this.metadataList = fieldsList
|
||||||
},
|
},
|
||||||
sendValue(list) {
|
sendValue(list) {
|
||||||
const preference = this.attributePreference({
|
const isForCurrentUser = this.metadataList.find(field => field.columnName === 'AD_User_ID').value
|
||||||
containerUuid: this.containerUuid,
|
const isForCurrentClient = this.metadataList.find(field => field.columnName === 'AD_Client_ID').value
|
||||||
panelType: this.panelType,
|
const isForCurrentOrganization = this.metadataList.find(field => field.columnName === 'AD_Org_ID').value
|
||||||
attribute: this.fieldAttributes.columnName,
|
const isForCurrentContainer = this.metadataList.find(field => field.columnName === 'AD_Window_ID').value
|
||||||
|
//
|
||||||
|
setPreference({
|
||||||
|
parentUuid: this.sourceField.parentUuid,
|
||||||
|
attribute: this.sourceField.columnName,
|
||||||
value: this.code,
|
value: this.code,
|
||||||
level: list
|
isForCurrentUser,
|
||||||
|
isForCurrentClient,
|
||||||
|
isForCurrentOrganization,
|
||||||
|
isForCurrentContainer
|
||||||
})
|
})
|
||||||
getPreference(preference)
|
.then(preference => {
|
||||||
},
|
showMessage({
|
||||||
changeValue(value) {
|
message: language.t('components.preference.preferenceIsOk')
|
||||||
switch (value.columName) {
|
|
||||||
// case 'options':
|
|
||||||
case 'AD_Client_ID':
|
|
||||||
this.$store.commit('updateValueOfField', {
|
|
||||||
containerUuid: 'fiel-reference',
|
|
||||||
columnName: value.columName,
|
|
||||||
value: value.value
|
|
||||||
})
|
})
|
||||||
break
|
this.close()
|
||||||
case 'AD_Org_ID':
|
|
||||||
this.$store.commit('updateValueOfField', {
|
|
||||||
containerUuid: 'fiel-reference',
|
|
||||||
columnName: value.columName,
|
|
||||||
value: value.value
|
|
||||||
})
|
})
|
||||||
break
|
.catch(error => {
|
||||||
case 'AD_User_ID':
|
showMessage({
|
||||||
this.$store.commit('updateValueOfField', {
|
message: error.message,
|
||||||
containerUuid: 'fiel-reference',
|
type: 'error'
|
||||||
columnName: value.columName,
|
|
||||||
value: value.value
|
|
||||||
})
|
})
|
||||||
break
|
console.warn(`setPreference error: ${error.message}.`)
|
||||||
case 'AD_Window_ID':
|
|
||||||
this.$store.commit('updateValueOfField', {
|
|
||||||
containerUuid: 'fiel-reference',
|
|
||||||
columnName: value.columName,
|
|
||||||
value: value.value
|
|
||||||
})
|
|
||||||
break
|
|
||||||
}
|
|
||||||
},
|
|
||||||
subscribeChanges() {
|
|
||||||
return this.$store.subscribe((mutation, state) => {
|
|
||||||
if (mutation.type === 'updateValueOfField') {
|
|
||||||
// const values = this.$store.getters.getValuesView({
|
|
||||||
// containerUuid: mutation.payload.containerUuid,
|
|
||||||
// format: 'object'
|
|
||||||
// })
|
|
||||||
// this.changeValue(values)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,8 +155,18 @@ export default {
|
|||||||
code: 'Code',
|
code: 'Code',
|
||||||
yes: 'Yes',
|
yes: 'Yes',
|
||||||
no: 'No',
|
no: 'No',
|
||||||
defaulMessage: 'Applies for this ',
|
defaultMessage: 'Applies for this ',
|
||||||
defaulMessageUser: 'Applies for this '
|
defaultMessageUser: 'Applies for this ',
|
||||||
|
preferenceIsOk: 'The preference is saved',
|
||||||
|
preferenceRemoved: 'Preference Removed',
|
||||||
|
for: 'For ',
|
||||||
|
clientAndOrganization: 'this Client and Organization',
|
||||||
|
allOrganizationOfClient: 'all Organizations of this Client',
|
||||||
|
entireSystem: 'entire System',
|
||||||
|
thisUser: ', this User',
|
||||||
|
allUsers: ', all Users',
|
||||||
|
thisWindow: ' and this Window',
|
||||||
|
allWindows: ' and all Windows'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
views: {
|
views: {
|
||||||
|
@ -155,8 +155,18 @@ export default {
|
|||||||
code: 'Codigo',
|
code: 'Codigo',
|
||||||
yes: 'Si',
|
yes: 'Si',
|
||||||
no: 'No',
|
no: 'No',
|
||||||
defaulMessage: 'Aplica para Esta ',
|
defaultMessage: 'Aplica para Esta ',
|
||||||
defaulMessageUser: 'Aplica para Este '
|
defaultMessageUser: 'Aplica para Este ',
|
||||||
|
preferenceIsOk: 'Preferencia guardada',
|
||||||
|
preferenceRemoved: 'Preferencia Eliminada',
|
||||||
|
for: 'Para ',
|
||||||
|
clientAndOrganization: 'esta Compañía y Organización',
|
||||||
|
allOrganizationOfClient: 'todas las Organizaciones de esta Compañía',
|
||||||
|
entireSystem: 'todo el Sistema',
|
||||||
|
thisUser: ', este Usuario',
|
||||||
|
allUsers: ', todos los Usuarios',
|
||||||
|
thisWindow: ' y esta Ventana',
|
||||||
|
allWindows: ' y todas las Ventanas'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
views: {
|
views: {
|
||||||
|
@ -530,39 +530,3 @@ export function tenderTypeFind({
|
|||||||
export function clearVariables() {
|
export function clearVariables() {
|
||||||
partialValue = ''
|
partialValue = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Search the Payment List for the Current Payment
|
|
||||||
* @param {string} parentUuid Uuid the Parent
|
|
||||||
* @param {string} containerUuid Uuid the Container
|
|
||||||
* @param {string} panelType Panel Type
|
|
||||||
* @param {string} attribute ColumName Field
|
|
||||||
* @param {boolean| string | number} value Value
|
|
||||||
* @param {array} level list value the preference
|
|
||||||
*/
|
|
||||||
export function attributePreference({
|
|
||||||
parentUuid,
|
|
||||||
containerUuid,
|
|
||||||
panelType,
|
|
||||||
attribute,
|
|
||||||
value,
|
|
||||||
level
|
|
||||||
}) {
|
|
||||||
let levelPanel
|
|
||||||
if (level) {
|
|
||||||
levelPanel = level.map(parameter => {
|
|
||||||
return {
|
|
||||||
key: parameter.columnName,
|
|
||||||
value: parameter.value
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
parentUuid,
|
|
||||||
containerUuid,
|
|
||||||
panelType,
|
|
||||||
attribute,
|
|
||||||
value,
|
|
||||||
level: levelPanel
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user