Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
Adding Download, Send and Share Functionality (#2492)
Browse files Browse the repository at this point in the history
  • Loading branch information
elsiosanchez authored Jul 25, 2024
1 parent 0672676 commit 9e23bea
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 55 deletions.
16 changes: 14 additions & 2 deletions src/api/ADempiere/reportManagement/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,17 @@ export function getView({

export function runExport({
format = 'xlsx',
reportViewId,
printFormatId,
reportId
}) {
return request({
url: `/report-engine/export/${reportId}/${format}`,
method: 'post'
// data: {
// print_format_id: printFormatId,
// report_view_id: reportViewId,
// }
})
}

Expand All @@ -203,14 +209,20 @@ export function SendNotification({
notification_type,
attachments
}) {
const recipientsList = recipients.map(recipient => {
return {
account_name: recipient.label,
contact_id: recipient.value
}
})
return request({
url: '/send_notifications/notification',
method: 'post',
params: {
user_id,
title,
recipients,
subject,
recipients: recipientsList,
body: subject,
notification_type,
attachments
}
Expand Down
4 changes: 2 additions & 2 deletions src/lang/ADempiere/es/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ const report = {
Detail: 'Ver Detallado',
summary: 'Ver Resumido',
exportFormat: 'Formato de Exportación',
download: 'Link de Descarga Generado',
download: 'Descargando Archivo',
sharedReport: 'Reporte Compartido',
mesajeDownload: 'Haga clic en el Siguiente Enlace para ir a la Descarga ',
mesajeDownload: 'Descargando Reporte ',
openLink: 'Abrir Enlace',
mesajeShear: 'Su Enlace a Sido Copiado Exitosamente al Portapapeles',
refreshRecord: 'Refrescar'
Expand Down
47 changes: 37 additions & 10 deletions src/store/modules/ADempiere/reportManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,11 +571,29 @@ const reportManager = {
sortBy
})
.then(reportResponse => {
const {
id,
name,
instance_id,
report_view_id
} = reportResponse
router.push({
path: `report-viewer-engine/${id}/${instance_id}/${report_view_id}`,
name: 'Report Viewer Engine',
params: {
instanceUuid: instance_id,
name: name + instance_id,
fileName: name,
reportId: id,
reportUuid: reportDefinition.uuid,
tableName
}
}, () => {})
commit('setReportOutput', {
...reportResponse,
containerUuid,
rowCells: reportResponse.rows,
instanceUuid: reportResponse.id
instanceUuid: id
})
resolve(reportResponse)
})
Expand Down Expand Up @@ -676,27 +694,36 @@ const reportManager = {
commit
}, {
reportId,
reportName
reportName,
printFormatId,
reportViewId,
isDownload = true
}) {
return new Promise(resolve => {
runExport({
reportId
reportId,
printFormatId,
reportViewId
})
.then(response => {
const { file_name } = response
const file = document.createElement('a')
file.href = `${config.adempiere.resource.url}${file_name}`
file.download = `${reportName}`
commit('setExportReport', response)
resolve(response)
if (isDownload) {
const file = document.createElement('a')
file.href = `${config.adempiere.resource.url}${file_name}`
file.download = `${reportName}`
file.target = '_blank'
file.click()
}
resolve(file_name)
})
.catch(error => {
showNotification({
title: language.t('notifications.error'),
message: error.message,
message: `Error exporting report: ${error.message}. Code: ${error.code}.`,
type: 'error'
})
console.warn(`Error exporting report: ${error.message}. Code: ${error.code}.`)
resolve(error)
})
})
},
Expand Down Expand Up @@ -732,7 +759,7 @@ const reportManager = {
})
})
},
getSendNotification({ commit }, {
sendNotification({ commit }, {
user_id,
title,
recipients,
Expand Down
5 changes: 3 additions & 2 deletions src/views/ADempiere/ReportViewerEngine/dialog/contactSend.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
v-model="contantSend"
filterable
allow-create
multiple
@change="setUser"
@visible-change="searchUser"
>
<el-option
v-for="(item, key) in listUserSend"
:key="key"
:label="item.label"
:value="item.value"
:value="item"
/>
</el-select>
</el-form-item>
Expand All @@ -26,7 +27,7 @@ import { isEmptyValue } from '@/utils/ADempiere/valueUtils'
export default defineComponent({
name: 'contactSend',
setup() {
const contantSend = ref('')
const contantSend = ref([])
const listUserSend = ref([])
function searchUser() {
store.dispatch('ListUser')
Expand Down
118 changes: 79 additions & 39 deletions src/views/ADempiere/ReportViewerEngine/dialog/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
:label="0"
label-position="left"
style="font-size: 18px; padding-right: 1%; padding-bottom: 2%"
@change="setCheckedItemGeneral"
>
{{ $t('report.reportEnginer.optionsImport.download') }}
<svg-icon
Expand All @@ -70,7 +69,6 @@
:label="1"
label-position="left"
style="font-size: 18px; padding-right: 1%; padding-bottom: 2%"
@change="setCheckedItemGeneral"
>
{{ $t('report.reportEnginer.optionsImport.send') }}
<i class="el-icon-upload" />
Expand All @@ -79,10 +77,9 @@
<el-col :span="6" style="width: 30%; text-align: center;">
<el-radio
v-model="checkedItemGeneral"
:label="3"
:label="2"
label-position="left"
style="font-size: 18px; padding-bottom: 2%"
@change="setCheckedItemGeneral"
>
{{ $t('report.reportEnginer.optionsImport.copyLink') }}
<i class="el-icon-share" />
Expand All @@ -103,7 +100,7 @@
</el-form>
</el-col>
</el-row>
<el-row v-if="checkedItemGeneral === 3" :gutter="12" style="margin-top: 50px; text-align: center;">
<el-row v-if="checkedItemGeneral === 2" :gutter="12" style="margin-top: 50px; text-align: center;">
<p style="width: 630px; margin: 0 auto; font-size: 14px; text-align: center;">
{{ $t('component.attachment.share.description') }}
</p>
Expand All @@ -115,7 +112,6 @@
<el-radio-group
v-model="validTime"
style="display: flex; justify-content: center; padding-bottom: 1%;"
@change="loadData"
>
<el-radio class="radio-padding" :label="3600">1 {{ ' ' + $t('component.attachment.share.time.hour') }}</el-radio>
<el-radio class="radio-padding" :label="21600">6 {{ ' ' + $t('component.attachment.share.time.hours') }}</el-radio>
Expand Down Expand Up @@ -169,6 +165,7 @@ import { isEmptyValue } from '@/utils/ADempiere/valueUtils'
import { config } from '@/utils/ADempiere/config'
import { REPORT_EXPORT_TYPES } from '@/utils/ADempiere/constants/report'
import { showNotificationReport } from '@/utils/ADempiere/notification.js'
import { showNotification } from '@/utils/ADempiere/notification'
import {
requestShareResources
} from '@/api/ADempiere/file-management/resource-reference.ts'
Expand All @@ -195,7 +192,7 @@ export default defineComponent({
const checkedItemGeneral = ref(0)
const checkedItem = ref(0)
const printFormat = ref([])
const printFormatValue = ref('')
const printFormatValue = ref('xlsx')
const typeNotification = ref('')
const linkShare = ref('')
const isLoading = ref(false)
Expand All @@ -206,6 +203,9 @@ export default defineComponent({
}
return true
})
const getStoreReport = computed(() => {
return store.getters.getStoredReport(props.reportOutput.containerUuid)
})
function loadData() {
isLoading.value = true
requestShareResources({
Expand Down Expand Up @@ -235,35 +235,64 @@ export default defineComponent({
store.commit('setShowDialog', false)
}
function sendNotify() {
let link = 'https://www.google.com'
let title = ''
let message = ''
if (!isEmptyValue(exportData.value)) {
link = exportData.value.file_name
}
switch (checkedItemGeneral.value) {
case 1:
sendLink()
title = this.$t('report.reportEnginer.sharedReport')
message = this.$t('report.reportEnginer.mesajeDownload')
break
case 3:
copyValue()
message = this.$t('report.reportEnginer.mesajeShear')
link = linkShare.value
break
default:
title = this.$t('report.reportEnginer.download')
break
if (checkedItemGeneral.value === 0) {
downloadFile()
} else if (checkedItemGeneral.value === 1) {
sendLink()
} else if (checkedItemGeneral.value === 2) {
shareUrl()
}
showNotificationReport({
title,
message,
link,
openLink: this.$t('report.reportEnginer.openLink')
showNotification({
title: this.$t('notifications.processing'),
message: props.reportOutput.name,
type: 'info'
})
store.commit('setShowDialog', false)
}
function downloadFile() {
store.dispatch('exportReport', {
reportId: getStoreReport.value.id,
reportName: props.reportOutput.name,
printFormatId: props.reportOutput.print_format_id,
reportViewId: props.reportOutput.report_view_id
})
}
function shareUrl() {
store.dispatch('exportReport', {
reportId: getStoreReport.value.id,
reportName: props.reportOutput.name,
printFormatId: props.reportOutput.print_format_id,
reportViewId: props.reportOutput.report_view_id,
seconds: validTime.value,
isDownload: false
})
.then(fileNameResource => {
requestShareResources({
fileName: fileNameResource,
seconds: validTime.value
})
.then(response => {
linkShare.value = response
copyValue()
showNotificationReport({
title: 'Reporte Compartido',
message: 'Su Enlace a Sido Copiado Exitosamente al Portapapeles',
link: response,
openLink: 'Abrir Enlace'
})
})
.catch(error => {
showNotification({
title: 'Error',
message: `Error exporting report: ${error.message}.`,
type: 'error'
})
})
})
}
function handleDownload() {
const link = document.createElement('a')
const imageURL = config.adempiere.resource.url + props.reportOutput.name
Expand All @@ -272,7 +301,7 @@ export default defineComponent({
link.click()
}
function optionPrintFormat() {
const xlsTypes = REPORT_EXPORT_TYPES.filter(type => type.type === 'xls')
const xlsTypes = REPORT_EXPORT_TYPES.filter(type => type.type === 'xlsx')
printFormat.value = xlsTypes
}
const exportData = computed(() => {
Expand All @@ -289,13 +318,23 @@ export default defineComponent({
})
function sendLink() {
const user_id = store.getters['user/userInfo'].id
store.dispatch('getSendNotification', {
user_id,
title: props.reportOutput.name,
recipients: contactSend.value,
notification_type: typeNotify.value,
attachments: exportData.file_name
store.dispatch('exportReport', {
reportId: getStoreReport.value.id,
reportName: props.reportOutput.name,
printFormatId: props.reportOutput.print_format_id,
reportViewId: props.reportOutput.report_view_id,
seconds: validTime.value,
isDownload: false
})
.then(fileNameResource => {
store.dispatch('sendNotification', {
user_id,
title: props.reportOutput.name,
recipients: contactSend.value,
notification_type: typeNotify.value,
attachments: fileNameResource
})
})
}
function copyValue() {
Expand Down Expand Up @@ -332,6 +371,7 @@ export default defineComponent({
sendLink,
copyValue,
loadData,
downloadFile,
markdownContent
}
}
Expand Down

0 comments on commit 9e23bea

Please sign in to comment.