Skip to content

Commit

Permalink
feat: Add zoom with button or record id.
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwinBetanc0urt committed Aug 28, 2024
1 parent 7fe59f0 commit e97bf21
Show file tree
Hide file tree
Showing 4 changed files with 236 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/api/ADempiere/recordManagement/zoomWindows.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* 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): 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
* 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/>.
*/

// Get Instance for connection
import { request } from '@/utils/ADempiere/request'

/**
* Reference List from Window
* @param {number} tableId
* @param {string} tableName
*/
export function listZoomWindowsRequest({
tableId,
tableName
}) {
let url
if (tableId > 0) {
url = `record-management/zooms/id/${tableId}`
} else {
url = `record-management/zooms/${tableName}`
}
return request({
url: url,
method: 'get'
})
}
95 changes: 95 additions & 0 deletions src/components/ADempiere/FieldDefinition/FieldButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import {
TRUE_STRING, FALSE_STRING
} from '@/utils/ADempiere/formatValue/booleanFormat'
import { RECORD_ID } from '@/utils/ADempiere/constants/systemColumns'
import { IDENTIFIER_COLUMN_SUFFIX } from '@/utils/ADempiere/dictionaryUtils'

// Utils and Helpers Methods
import {
Expand All @@ -75,10 +76,12 @@ import {
openBrowserAssociated
} from '@/utils/ADempiere/dictionary/window/actionsMenu'
import { isEmptyValue, isSameValues } from '@/utils/ADempiere/valueUtils'
import { isSalesTransaction } from '@/utils/ADempiere/contextUtils'
import { getContextAttributes, generateContextKey } from '@/utils/ADempiere/contextUtils/contextAttributes'
import {
convertBooleanToString, convertBooleanToTranslationLang
} from '@/utils/ADempiere/formatValue/booleanFormat'
import { zoomIn } from '@/utils/ADempiere/coreUtils.js'

export default {
name: 'FieldButton',
Expand Down Expand Up @@ -148,6 +151,55 @@ export default {
},
isEnabled: () => true
}
} else if (this.metadata.columnName === RECORD_ID) {
return {
// is: 'svg-icon',
// 'icon-class': 'zoom-in',
is: 'i',
class: 'el-icon-zoom-in',
start: () => {
const storedZoomWindowsList = store.getters.getZoomWindowsList({
tableId: this.currentTableId
})
if (isEmptyValue(storedZoomWindowsList)) {
return
}
let windowToOpen = storedZoomWindowsList.at()
if (storedZoomWindowsList.length > 0) {
const isSalesTransactionContext = isSalesTransaction({
parentUuid: this.metadata.parentUuid,
containerUuid: this.metadata.containerUuid
})
windowToOpen = storedZoomWindowsList.find(windowToZoom => {
return windowToZoom.is_sales_transaction === isSalesTransactionContext
})
}
const tableName = store.getters.getTableNameById({
tableId: this.currentTableId
})
zoomIn({
attributeValue: `window_${windowToOpen.id}`,
attributeName: 'containerKey',
query: {
recordId: this.value,
[tableName + IDENTIFIER_COLUMN_SUFFIX]: this.value
},
params: {
recordId: this.value,
[tableName + IDENTIFIER_COLUMN_SUFFIX]: this.value
}
})
},
isEnabled: () => {
if (isEmptyValue(this.value)) {
return false
}
if (isEmptyValue(this.currentTableId)) {
return false
}
return true
}
}
}
// button without process associated
if (isEmptyValue(this.metadata.process)) {
Expand Down Expand Up @@ -252,6 +304,30 @@ export default {
keyName: 'key'
})
return generateContextKey(contextAttributesList, 'key')
},

currentTableId() {
if (this.metadata.displayed && this.metadata.columnName === RECORD_ID) {
const { containerUuid, inTable } = this.metadata
// table records values
if (inTable) {
const value = this.containerManager.getCell({
containerUuid,
rowIndex: this.metadata.rowIndex,
rowUid: this.metadata.rowUid,
columnName: 'AD_Table_ID'
})
return value
} else {
const value = store.getters.getValueOfFieldOnContainer({
parentUuid: this.metadata.parentUuid,
containerUuid,
columnName: 'AD_Table_ID'
})
return value
}
}
return -1
}
},

Expand All @@ -262,6 +338,13 @@ export default {
this.setDefaultValue()
}
}
},
currentTableId(newValue, oldValue) {
if (!isSameValues(newValue, oldValue)) {
if (!isEmptyValue(newValue)) {
this.getZoomWindowsList()
}
}
}
},

Expand All @@ -272,13 +355,25 @@ export default {
// request lookup
this.loadDefaultValueFromServer()
}
this.getZoomWindowsList()
}
}
},

methods: {
startProcess() {
this.actionAssociated.start()
},
getZoomWindowsList() {
const storedZoomWindowsList = store.getters.getZoomWindowsList({
tableId: this.currentTableId
})
if (!isEmptyValue(storedZoomWindowsList)) {
return
}
store.dispatch('getZoomWindowsListFromServer', {
tableId: this.currentTableId
})
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/icons/svg/zoom-in.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
99 changes: 99 additions & 0 deletions src/store/modules/ADempiere/zoomManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/**
* 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): 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
* 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'

// API Request Methods
import { listZoomWindowsRequest } from '@/api/ADempiere/recordManagement/zoomWindows.ts'
import { isEmptyValue } from '@/utils/ADempiere'

const initState = {
tables: {},
zoomWindows: {}
}

const zoomManager = {
state: initState,

mutations: {
setTableName(state, {
tableId,
tableName
}) {
Vue.set(state.tables, tableId, tableName)
},
setZoomWindows(state, {
tableId,
tableName,
zoomWindows = []
}) {
Vue.set(state.zoomWindows, tableId, {
tableId,
tableName,
zoomWindows
})
}
},

actions: {
getZoomWindowsListFromServer({ commit, getters }, {
tableId,
tableName
}) {
return new Promise(resolve => {
listZoomWindowsRequest({
tableId,
tableName
}).then(response => {
const { table_id, table_name, zoom_windows } = response

commit('setZoomWindows', {
tableId: table_id,
tableName: table_name,
zoomWindows: zoom_windows
})
commit('setTableName', {
tableId: table_id,
tableName: table_name
})

resolve(zoom_windows)
})
})
}
},

getters: {
getTableNameById: (state) => ({
tableId
}) => {
return state.tables[tableId]
},
getZoomWindowsList: (state) => ({
tableId
}) => {
const storedWindows = state.zoomWindows[tableId]
if (!isEmptyValue(storedWindows)) {
return storedWindows.zoomWindows
}
return []
}
}
}

export default zoomManager

0 comments on commit e97bf21

Please sign in to comment.