Skip to content

Commit

Permalink
feat: Add run process or report panel. (#1392)
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwinBetanc0urt authored Nov 22, 2021
1 parent 06d7c86 commit bc2d3a5
Show file tree
Hide file tree
Showing 15 changed files with 467 additions and 60 deletions.
2 changes: 1 addition & 1 deletion src/components/ADempiere/ActionMenu/Actions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export default defineComponent({
}
return root.$t('data.undo')
}
return root.$t('components.RunProcess')
return root.$t('actionMenu.runProcessOrReport')
})
const defaultActionToRun = computed(() => {
Expand Down
1 change: 1 addition & 0 deletions src/components/ADempiere/FileRender/EmptyFile/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

<script>
import { defineComponent } from '@vue/composition-api'
export default defineComponent({
name: 'Empty-File'
})
Expand Down
49 changes: 30 additions & 19 deletions src/components/ADempiere/FileRender/ExcelFile/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,17 @@

<script>
import { defineComponent, ref } from '@vue/composition-api'
// components and mixins
import XLSX from 'xlsx'
// utils and helper methods
import { exportFileFromJson } from '@/utils/ADempiere/exportUtil.js'
import { buildLinkHref, buildBlobAndValues } from '@/utils/ADempiere/resource'
export default defineComponent({
name: 'ExcelFile',
props: {
mimeType: {
type: String,
Expand All @@ -74,23 +81,19 @@ export default defineComponent({
required: true
}
},
setup(props) {
const excelData = ref({})
function downloadWithLink() {
let link = {
href: undefined,
download: undefined
}
const reportObject = Object.values(props.stream)
const blob = new Blob([Uint8Array.from(reportObject)], {
type: props.mimeType
buildLinkHref({
fileName: `${props.name}.${props.format}`,
mimeType: props.mimeType,
outputStream: props.stream,
isDownload: true
})
link = document.createElement('a')
link.href = window.URL.createObjectURL(blob)
link.download = `${props.name}.${props.format}`
// download report file
link.click()
}
function handleDownload() {
const header = excelData.value.header
const data = excelData.value.results
Expand All @@ -105,6 +108,7 @@ export default defineComponent({
resolve(file)
})
}
function getHeaderRow(sheet) {
const headers = []
const range = XLSX.utils.decode_range(sheet['!ref'])
Expand All @@ -122,38 +126,45 @@ export default defineComponent({
}
return headers
}
function generateReaderData() {
const data = Object.values(props.stream)
const blob = new Blob([
Uint8Array.from(data)
], {
type: props.mimeType
const { blobFile, dataValues } = buildBlobAndValues({
mimeType: props.mimeType,
outputStream: props.stream
})
return new Promise((resolve) => {
const reader = new FileReader()
reader.onload = (e) => {
const workbook = XLSX.read(data, { type: 'array' })
const workbook = XLSX.read(dataValues, {
type: 'array'
})
const firstSheetName = workbook.SheetNames[0]
const worksheet = workbook.Sheets[firstSheetName]
const header = getHeaderRow(worksheet)
const results = XLSX.utils.sheet_to_json(worksheet)
// value to render
excelData.value = {
header,
results
}
resolve()
}
reader.readAsArrayBuffer(blob)
reader.readAsArrayBuffer(blobFile)
})
}
generateReaderData()
return {
excelData,
// methods
downloadWithLink,
handleDownload
}
}
})
</script>
5 changes: 5 additions & 0 deletions src/components/ADempiere/FileRender/HtmlFile/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@

<script>
import { defineComponent } from '@vue/composition-api'
export default defineComponent({
name: 'HTML-TXT-File',
props: {
content: {
type: [Object, String],
required: true
}
}
})
</script>

Expand All @@ -46,6 +49,7 @@ export default defineComponent({
height: inherit;
padding-left: 10px;
padding-right: 10px;
.sub-content-html {
min-height: inherit;
height: inherit;
Expand All @@ -55,5 +59,6 @@ export default defineComponent({
width: 100%;
padding-bottom: 4%;
}
}
</style>
3 changes: 3 additions & 0 deletions src/components/ADempiere/FileRender/PdfFile/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@

<script>
import { defineComponent } from '@vue/composition-api'
export default defineComponent({
name: 'PDF-File',
props: {
src: {
type: String,
required: true
}
}
})
</script>

Expand Down
2 changes: 2 additions & 0 deletions src/lang/ADempiere/en/actionMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const actionMenu = {
shareLink: 'Share Link',
withoutActions: 'Without Actions',
zoomWindow: 'Zoom Window',
// process
runProcessOrReport: 'Run',
// relations
relations: 'Relations',
withoutRelations: 'Without Relations',
Expand Down
2 changes: 2 additions & 0 deletions src/lang/ADempiere/es/actionMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const actionMenu = {
shareLink: 'Compartir Enlace',
withoutActions: 'Sin Actiones',
zoomWindow: 'Acercar Ventana',
// process
runProcessOrReport: 'Ejecutar',
// relations
relations: 'Relaciones',
withoutRelations: 'Sin Relaciones',
Expand Down
11 changes: 11 additions & 0 deletions src/store/modules/ADempiere/dictionary/process/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export default {
})
},

/**
* Get process dictionary definition
* @param {string} uuid of dictionary
*/
getProcessDefinitionFromServer({ dispatch }, {
uuid
}) {
Expand All @@ -51,6 +55,13 @@ export default {

dispatch('addProcessToList', processDefinition)
resolve(processDefinition)

if (processDefinition.isReport) {
dispatch('getListPrintFormats', {
processUuid: uuid,
processId: processDefinition.id
})
}
})
.catch(error => {
reject(error)
Expand Down
60 changes: 60 additions & 0 deletions src/store/modules/ADempiere/dictionary/process/getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

import { isEmptyValue } from '@/utils/ADempiere/valueUtils'
import { isDisplayedField, isMandatoryField } from '@/utils/ADempiere/dictionary/process'
import { isNumberField } from '@/utils/ADempiere/references'

/**
* Dictionary Process Getters
Expand All @@ -34,5 +36,63 @@ export default {
return process.fieldsList
}
return undefined
},

/**
* Getter converter params with value format
* @param {String} containerUuid
* @param {Array<Object>} fieldsList
* @returns {Array<Object>} [{ columnName: name key, value: value to send }]
*/
getProcessParameters: (state, getters, rootState, rootGetters) => ({
containerUuid,
fieldsList = []
}) => {
if (isEmptyValue(fieldsList)) {
fieldsList = getters.getStoredFieldsFromProcess(containerUuid)
}

const processParameters = []

fieldsList.forEach(fieldItem => {
const { columnName } = fieldItem
const isMandatory = isMandatoryField(fieldItem)
// evaluate displayed fields
const isDisplayed = isDisplayedField(fieldItem) &&
(fieldItem.isShowedFromUser || isMandatory)

if (!isDisplayed) {
return
}

const value = rootGetters.getValueOfField({
containerUuid,
columnName
})

if (fieldItem.isRange && isNumberField(fieldItem.displayType)) {
const valueTo = rootGetters.getValueOfField({
containerUuid,
columnName: fieldItem.columnNameTo
})
if (!isEmptyValue(valueTo)) {
processParameters.push({
columnName: fieldItem.columnNameTo,
value: valueTo
})
}
}

if (isEmptyValue(value)) {
return
}
processParameters.push({
columnName,
value
})
})

return processParameters
}

}
Loading

0 comments on commit bc2d3a5

Please sign in to comment.