DocumentExecution.vue 57.1 KB
Newer Older
1
2
<template>
    <div class="kn-height-full detail-page-container">
BojanSovticEngIT's avatar
BojanSovticEngIT committed
3
        <Toolbar v-if="!embed && !olapDesignerMode" class="kn-toolbar kn-toolbar--primary p-col-12">
4
            <template #start>
BojanSovticEngIT's avatar
BojanSovticEngIT committed
5
                <span>{{ document?.name }}</span>
6
7
            </template>

8
            <template #end>
9
                <div class="p-d-flex p-jc-around">
10
11
12
13
14
15
                    <Button icon="pi pi-pencil" class="p-button-text p-button-rounded p-button-plain p-mx-2" v-if="document?.typeCode === 'DOCUMENT_COMPOSITE' && documentMode === 'VIEW'" v-tooltip.left="$t('documentExecution.main.editCockpit')" @click="editCockpitDocumentConfirm"></Button>
                    <Button icon="fa fa-eye" class="p-button-text p-button-rounded p-button-plain p-mx-2" v-if="document?.typeCode === 'DOCUMENT_COMPOSITE' && documentMode === 'EDIT'" v-tooltip.left="$t('documentExecution.main.viewCockpit')" @click="editCockpitDocumentConfirm"></Button>
                    <Button icon="pi pi-book" class="p-button-text p-button-rounded p-button-plain p-mx-2" v-tooltip.left="$t('common.onlineHelp')" @click="openHelp"></Button>
                    <Button icon="pi pi-refresh" class="p-button-text p-button-rounded p-button-plain p-mx-2" v-tooltip.left="$t('common.refresh')" @click="refresh"></Button>
                    <Button icon="fa fa-filter" class="p-button-text p-button-rounded p-button-plain p-mx-2" v-if="isParameterSidebarVisible" v-tooltip.left="$t('common.parameters')" @click="parameterSidebarVisible = !parameterSidebarVisible" data-test="parameter-sidebar-icon"></Button>
                    <Button icon="fa fa-ellipsis-v" class="p-button-text p-button-rounded p-button-plain p-mx-2" v-tooltip.left="$t('common.menu')" @click="toggle"></Button>
BojanSovticEngIT's avatar
BojanSovticEngIT committed
16
                    <TieredMenu ref="menu" :model="toolbarMenuItems" :popup="true" />
17
                    <Button icon="fa fa-times" class="p-button-text p-button-rounded p-button-plain p-mx-2" v-tooltip.left="$t('common.close')" @click="closeDocument"></Button>
18
19
20
21
22
23
24
25
26
27
                </div>
            </template>
        </Toolbar>
        <ProgressBar v-if="loading" class="kn-progress-bar" mode="indeterminate" />
        <DocumentExecutionBreadcrumb v-if="breadcrumbs.length > 1" :breadcrumbs="breadcrumbs" @breadcrumbClicked="onBreadcrumbClick"></DocumentExecutionBreadcrumb>

        <div ref="document-execution-view" id="document-execution-view" class="p-d-flex p-flex-row myDivToPrint">
            <div v-if="parameterSidebarVisible" id="document-execution-backdrop" @click="parameterSidebarVisible = false"></div>

            <template v-if="filtersData && filtersData.isReadyForExecution && !loading && !schedulationsTableVisible">
BojanSovticEngIT's avatar
BojanSovticEngIT committed
28
                <Registry v-if="mode === 'registry'" :id="urlData?.sbiExecutionId" :reloadTrigger="reloadTrigger"></Registry>
29
                <Dossier v-else-if="mode === 'dossier'" :id="document.id" :reloadTrigger="reloadTrigger" :filterData="filtersData"></Dossier>
BojanSovticEngIT's avatar
BojanSovticEngIT committed
30
31
32
33
                <Olap
                    v-else-if="mode === 'olap'"
                    :id="urlData?.sbiExecutionId"
                    :olapId="document.id"
dbulatovicx32's avatar
dbulatovicx32 committed
34
                    :olapName="document.label"
BojanSovticEngIT's avatar
BojanSovticEngIT committed
35
36
                    :reloadTrigger="reloadTrigger"
                    :olapCustomViewVisible="olapCustomViewVisible"
dbulatovicx32's avatar
dbulatovicx32 committed
37
                    :hiddenFormDataProp="hiddenFormData"
BojanSovticEngIT's avatar
BojanSovticEngIT committed
38
39
40
41
                    @closeOlapCustomView="olapCustomViewVisible = false"
                    @applyCustomView="executeOlapCustomView"
                    @executeCrossNavigation="executeOLAPCrossNavigation"
                ></Olap>
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
            </template>

            <iframe
                v-for="(item, index) in breadcrumbs"
                :key="index"
                ref="documentFrame"
                :name="'documentFrame' + index"
                v-show="mode === 'iframe' && filtersData && filtersData.isReadyForExecution && !loading && !schedulationsTableVisible && item.label === document.label"
                class="document-execution-iframe"
            ></iframe>

            <DocumentExecutionSchedulationsTable id="document-execution-schedulations-table" v-if="schedulationsTableVisible" :propSchedulations="schedulations" @deleteSchedulation="onDeleteSchedulation" @close="schedulationsTableVisible = false"></DocumentExecutionSchedulationsTable>

            <KnParameterSidebar
                class="document-execution-parameter-sidebar kn-overflow-y"
                v-if="parameterSidebarVisible"
                :filtersData="filtersData"
                :propDocument="document"
                :userRole="userRole"
BojanSovticEngIT's avatar
BojanSovticEngIT committed
61
                :sessionEnabled="sessionEnabled"
BojanSovticEngIT's avatar
BojanSovticEngIT committed
62
                :dateFormat="dateFormat"
63
64
65
                @execute="onExecute"
                @exportCSV="onExportCSV"
                @roleChanged="onRoleChange"
66
                @parametersChanged="$emit('parametersChanged', $event)"
67
68
69
70
71
72
73
74
75
                data-test="parameter-sidebar"
            ></KnParameterSidebar>

            <DocumentExecutionHelpDialog :visible="helpDialogVisible" :propDocument="document" @close="helpDialogVisible = false"></DocumentExecutionHelpDialog>
            <DocumentExecutionRankDialog :visible="rankDialogVisible" :propDocumentRank="documentRank" @close="rankDialogVisible = false" @saveRank="onSaveRank"></DocumentExecutionRankDialog>
            <DocumentExecutionNotesDialog :visible="notesDialogVisible" :propDocument="document" @close="notesDialogVisible = false"></DocumentExecutionNotesDialog>
            <DocumentExecutionMetadataDialog :visible="metadataDialogVisible" :propDocument="document" :propMetadata="metadata" :propLoading="loading" @close="metadataDialogVisible = false" @saveMetadata="onMetadataSave"></DocumentExecutionMetadataDialog>
            <DocumentExecutionMailDialog :visible="mailDialogVisible" @close="mailDialogVisible = false" @sendMail="onMailSave"></DocumentExecutionMailDialog>
            <DocumentExecutionLinkDialog :visible="linkDialogVisible" :linkInfo="linkInfo" :embedHTML="embedHTML" :propDocument="document" :parameters="linkParameters" @close="linkDialogVisible = false"></DocumentExecutionLinkDialog>
BojanSovticEngIT's avatar
BojanSovticEngIT committed
76
            <DocumentExecutionSelectCrossNavigationDialog :visible="destinationSelectDialogVisible" :crossNavigationDocuments="crossNavigationDocuments" @close="destinationSelectDialogVisible = false" @selected="onCrossNavigationSelected"></DocumentExecutionSelectCrossNavigationDialog>
BojanSovticEngIT's avatar
BojanSovticEngIT committed
77
            <DocumentExecutionCNContainerDialog v-if="crossNavigationContainerData" :visible="crossNavigationContainerVisible" :data="crossNavigationContainerData" @close="onCrossNavigationContainerClose"></DocumentExecutionCNContainerDialog>
78
79
80
81
82
        </div>
    </div>
</template>

<script lang="ts">
Davide Vernassa's avatar
Davide Vernassa committed
83
84
85
86
87
88
89
90
91
92
93
94
95
import { defineComponent } from 'vue'
import { AxiosResponse } from 'axios'
import { iParameter } from '@/components/UI/KnParameterSidebar/KnParameterSidebar'
import { iURLData, iExporter, iSchedulation } from './DocumentExecution'
import DocumentExecutionBreadcrumb from './breadcrumbs/DocumentExecutionBreadcrumb.vue'
import DocumentExecutionHelpDialog from './dialogs/documentExecutionHelpDialog/DocumentExecutionHelpDialog.vue'
import DocumentExecutionRankDialog from './dialogs/documentExecutionRankDialog/DocumentExecutionRankDialog.vue'
import DocumentExecutionNotesDialog from './dialogs/documentExecutionNotesDialog/DocumentExecutionNotesDialog.vue'
import DocumentExecutionMetadataDialog from './dialogs/documentExecutionMetadataDialog/DocumentExecutionMetadataDialog.vue'
import DocumentExecutionMailDialog from './dialogs/documentExecutionMailDialog/DocumentExecutionMailDialog.vue'
import DocumentExecutionSchedulationsTable from './tables/documentExecutionSchedulationsTable/DocumentExecutionSchedulationsTable.vue'
import DocumentExecutionLinkDialog from './dialogs/documentExecutionLinkDialog/DocumentExecutionLinkDialog.vue'
import KnParameterSidebar from '@/components/UI/KnParameterSidebar/KnParameterSidebar.vue'
96
import { luxonFormatDate } from '@/helpers/commons/localeHelper'
BojanSovticEngIT's avatar
BojanSovticEngIT committed
97
import TieredMenu from 'primevue/tieredmenu'
Davide Vernassa's avatar
Davide Vernassa committed
98
99
100
101
import Registry from '../registry/Registry.vue'
import Dossier from '../dossier/Dossier.vue'
import Olap from '../olap/Olap.vue'
import moment from 'moment'
BojanSovticEngIT's avatar
BojanSovticEngIT committed
102
import DocumentExecutionSelectCrossNavigationDialog from './dialogs/documentExecutionSelectCrossNavigationDialog/DocumentExecutionSelectCrossNavigationDialog.vue'
BojanSovticEngIT's avatar
BojanSovticEngIT committed
103
import DocumentExecutionCNContainerDialog from './dialogs/documentExecutionCNContainerDialog/DocumentExecutionCNContainerDialog.vue'
Davide Vernassa's avatar
Davide Vernassa committed
104

BojanSovticEngIT's avatar
BojanSovticEngIT committed
105
106
const deepcopy = require('deepcopy')

Davide Vernassa's avatar
Davide Vernassa committed
107
108
109
110
111
112
113
114
115
116
117
118
export default defineComponent({
    name: 'document-execution',
    components: {
        DocumentExecutionBreadcrumb,
        DocumentExecutionHelpDialog,
        DocumentExecutionRankDialog,
        DocumentExecutionNotesDialog,
        DocumentExecutionMetadataDialog,
        DocumentExecutionMailDialog,
        DocumentExecutionSchedulationsTable,
        DocumentExecutionLinkDialog,
        KnParameterSidebar,
BojanSovticEngIT's avatar
BojanSovticEngIT committed
119
        TieredMenu,
Davide Vernassa's avatar
Davide Vernassa committed
120
121
        Registry,
        Dossier,
BojanSovticEngIT's avatar
BojanSovticEngIT committed
122
        Olap,
BojanSovticEngIT's avatar
BojanSovticEngIT committed
123
124
        DocumentExecutionSelectCrossNavigationDialog,
        DocumentExecutionCNContainerDialog
Davide Vernassa's avatar
Davide Vernassa committed
125
    },
BojanSovticEngIT's avatar
Hotfix    
BojanSovticEngIT committed
126
    props: { id: { type: String }, parameterValuesMap: { type: Object }, tabKey: { type: String }, propMode: { type: String } },
127
    emits: ['close', 'updateDocumentName', 'parametersChanged'],
Davide Vernassa's avatar
Davide Vernassa committed
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
    data() {
        return {
            document: null as any,
            hiddenFormData: {} as any,
            hiddenFormUrl: '' as string,
            documentMode: 'VIEW',
            filtersData: {} as { filterStatus: iParameter[]; isReadyForExecution: boolean },
            urlData: null as iURLData | null,
            exporters: null as iExporter[] | null,
            mode: null as string | null,
            parameterSidebarVisible: false,
            toolbarMenuItems: [] as any[],
            helpDialogVisible: false,
            documentRank: null as string | null,
            rankDialogVisible: false,
            notesDialogVisible: false,
            metadataDialogVisible: false,
            mailDialogVisible: false,
            metadata: {} as any,
            schedulationsTableVisible: false,
            schedulations: [] as any[],
            linkDialogVisible: false,
            linkInfo: null as { isPublic: boolean; noPublicRoleError: boolean } | null,
            sbiExecutionId: null as string | null,
            embedHTML: false,
            user: null as any,
            reloadTrigger: false,
            breadcrumbs: [] as any[],
            linkParameters: [],
            embed: false,
            olapCustomViewVisible: false,
            userRole: null,
            loading: false,
BojanSovticEngIT's avatar
BojanSovticEngIT committed
161
            olapDesignerMode: false,
162
            sessionEnabled: false,
BojanSovticEngIT's avatar
BojanSovticEngIT committed
163
164
165
            dateFormat: '' as string,
            destinationSelectDialogVisible: false,
            crossNavigationDocuments: [] as any[],
BojanSovticEngIT's avatar
BojanSovticEngIT committed
166
167
168
            angularData: null as any,
            crossNavigationContainerVisible: false,
            crossNavigationContainerData: null as any
Davide Vernassa's avatar
Davide Vernassa committed
169
170
171
        }
    },
    async activated() {
172
        if (this.mode === 'iframe' && this.$route.name !== 'new-dashboard') {
Davide Vernassa's avatar
Davide Vernassa committed
173
            if (this.userRole) {
174
                await this.loadPage(true)
Davide Vernassa's avatar
Davide Vernassa committed
175
176
            } else {
                this.parameterSidebarVisible = true
177
            }
Davide Vernassa's avatar
Davide Vernassa committed
178
179
180
181
182
183
184
        }
    },
    deactivated() {
        this.parameterSidebarVisible = false
    },
    computed: {
        sessionRole(): string {
BojanSovticEngIT's avatar
BojanSovticEngIT committed
185
            return this.user.sessionRole !== this.$t('role.defaultRolePlaceholder') ? this.user.sessionRole : null
186
        },
Davide Vernassa's avatar
Davide Vernassa committed
187
188
189
190
191
192
193
194
195
        url(): string {
            if (this.document) {
                return (
                    process.env.VUE_APP_HOST_URL +
                    `/knowage/restful-services/publish?PUBLISHER=documentExecutionNg&OBJECT_ID=${this.document.id}&OBJECT_LABEL=${this.document.label}&TOOLBAR_VISIBLE=false&MENU_PARAMETERS=%7B%7D&LIGHT_NAVIGATOR_DISABLED=TRUE&SBI_EXECUTION_ID=${this.sbiExecutionId}&OBJECT_NAME=${this.document.name}&CROSS_PARAMETER=null`
                )
            } else {
                return ''
            }
196
        },
Davide Vernassa's avatar
Davide Vernassa committed
197
198
199
200
201
202
203
        isParameterSidebarVisible(): boolean {
            let parameterVisible = false
            for (let i = 0; i < this.filtersData?.filterStatus?.length; i++) {
                const tempFilter = this.filtersData.filterStatus[i]
                if (tempFilter.showOnPanel === 'true') {
                    parameterVisible = true
                    break
204
                }
Davide Vernassa's avatar
Davide Vernassa committed
205
            }
206

Davide Vernassa's avatar
Davide Vernassa committed
207
208
209
210
211
212
213
            return parameterVisible || !this.sessionRole
        }
    },
    async created() {
        window.addEventListener('message', (event) => {
            if (event.data.type === 'crossNavigation') {
                this.executeCrossNavigation(event)
214
            }
Davide Vernassa's avatar
Davide Vernassa committed
215
        })
216

Davide Vernassa's avatar
Davide Vernassa committed
217
        this.user = (this.$store.state as any).user
BojanSovticEngIT's avatar
BojanSovticEngIT committed
218
        this.userRole = this.user.sessionRole !== this.$t('role.defaultRolePlaceholder') ? this.user.sessionRole : null
219

BojanSovticEngIT's avatar
BojanSovticEngIT committed
220
        if (this.propMode !== 'document-execution' && !this.$route.path.includes('olap-designer') && this.$route.name !== 'document-execution') return
BojanSovticEngIT's avatar
BojanSovticEngIT committed
221

BojanSovticEngIT's avatar
BojanSovticEngIT committed
222
223
        await this.loadUserConfig()

Davide Vernassa's avatar
Davide Vernassa committed
224
225
        this.isOlapDesignerMode()
        this.setMode()
226

Davide Vernassa's avatar
Davide Vernassa committed
227
        this.document = { label: this.id }
228
229

        if (!this.document.label) return
230

Davide Vernassa's avatar
Davide Vernassa committed
231
        await this.loadDocument()
BojanSovticEngIT's avatar
BojanSovticEngIT committed
232

Davide Vernassa's avatar
Davide Vernassa committed
233
        if (this.userRole) {
234
            await this.loadPage(true)
Davide Vernassa's avatar
Davide Vernassa committed
235
236
237
238
239
240
241
242
243
244
245
246
247
        } else {
            this.parameterSidebarVisible = true
        }
    },
    methods: {
        editCockpitDocumentConfirm() {
            if (this.documentMode === 'EDIT') {
                this.$confirm.require({
                    message: this.$t('documentExecution.main.editModeConfirm'),
                    header: this.$t('documentExecution.main.editCockpit'),
                    icon: 'pi pi-exclamation-triangle',
                    accept: () => this.editCockpitDocument()
                })
248
            } else {
Davide Vernassa's avatar
Davide Vernassa committed
249
                this.editCockpitDocument()
250
251
            }
        },
Davide Vernassa's avatar
Davide Vernassa committed
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
        async editCockpitDocument() {
            this.loading = true
            this.documentMode = this.documentMode === 'EDIT' ? 'VIEW' : 'EDIT'
            this.hiddenFormData.set('documentMode', this.documentMode)
            await this.loadURL(null)
            this.loading = false
        },
        openHelp() {
            this.helpDialogVisible = true
        },
        async refresh() {
            this.parameterSidebarVisible = false
            await this.loadURL(null)
            this.reloadTrigger = !this.reloadTrigger
        },
        toggle(event: Event) {
            this.createMenuItems()
            const menu = this.$refs.menu as any
            menu.toggle(event)
        },
        createMenuItems() {
            this.toolbarMenuItems = []
BojanSovticEngIT's avatar
BojanSovticEngIT committed
274
275
276
277
278
            this.toolbarMenuItems.push({
                label: this.$t('common.file'),
                items: [{ icon: 'pi pi-print', label: this.$t('common.print'), command: () => this.print() }]
            })

279
            if (this.exporters && this.exporters.length !== 0) {
BojanSovticEngIT's avatar
BojanSovticEngIT committed
280
                this.toolbarMenuItems.push({
Davide Vernassa's avatar
Davide Vernassa committed
281
282
                    label: this.$t('common.export'),
                    items: []
BojanSovticEngIT's avatar
BojanSovticEngIT committed
283
                })
284
            }
BojanSovticEngIT's avatar
BojanSovticEngIT committed
285

286
287
            if (this.user.enterprise) {
                this.toolbarMenuItems.push({
Davide Vernassa's avatar
Davide Vernassa committed
288
289
                    label: this.$t('common.info.info'),
                    items: [{ icon: 'pi pi-star', label: this.$t('common.rank'), command: () => this.openRank() }]
290
291
292
293
294
295
296
                })
            }

            this.toolbarMenuItems.push({
                label: this.$t('common.shortcuts'),
                items: []
            })
297

Davide Vernassa's avatar
Davide Vernassa committed
298
            this.exporters?.forEach((exporter: any) => this.toolbarMenuItems[1].items.push({ icon: 'fa fa-file-excel', label: exporter.name, command: () => this.export(exporter.name) }))
299

Davide Vernassa's avatar
Davide Vernassa committed
300
            if (this.user.functionalities.includes('SendMailFunctionality') && this.document.typeCode === 'REPORT') {
301
302
303
304
305
306
307
308
309
                const index = this.toolbarMenuItems.findIndex((item: any) => item.label === this.$t('common.info.info'))
                if (index !== -1) {
                    this.toolbarMenuItems[index].items.push({ icon: 'pi pi-envelope', label: this.$t('common.sendByEmail'), command: () => this.openMailDialog() })
                } else {
                    this.toolbarMenuItems.push({
                        label: this.$t('common.export'),
                        items: [{ icon: 'pi pi-envelope', label: this.$t('common.sendByEmail'), command: () => this.openMailDialog() }]
                    })
                }
Davide Vernassa's avatar
Davide Vernassa committed
310
            }
311

Davide Vernassa's avatar
Davide Vernassa committed
312
            if (this.user.functionalities.includes('SeeMetadataFunctionality')) {
313
314
                const index = this.toolbarMenuItems.findIndex((item: any) => item.label === this.$t('common.info.info'))
                if (index !== -1) this.toolbarMenuItems[index].items.unshift({ icon: 'pi pi-info-circle', label: this.$t('common.metadata'), command: () => this.openMetadata() })
Davide Vernassa's avatar
Davide Vernassa committed
315
            }
316

Davide Vernassa's avatar
Davide Vernassa committed
317
            if (this.user.functionalities.includes('SeeNotesFunctionality')) {
318
319
                const index = this.toolbarMenuItems.findIndex((item: any) => item.label === this.$t('common.info.info'))
                if (index !== -1) this.toolbarMenuItems[index].items.push({ icon: 'pi pi-file', label: this.$t('common.notes'), command: () => this.openNotes() })
Davide Vernassa's avatar
Davide Vernassa committed
320
            }
321

322
            if (this.user.functionalities.includes('SeeSnapshotsFunctionality') && this.user.enterprise) {
323
324
                const index = this.toolbarMenuItems.findIndex((item: any) => item.label === this.$t('common.shortcuts'))
                if (index !== -1) this.toolbarMenuItems[index].items.unshift({ icon: '', label: this.$t('documentExecution.main.showScheduledExecutions'), command: () => this.showScheduledExecutions() })
BojanSovticEngIT's avatar
BojanSovticEngIT committed
325
326
            }

dbulatovicx32's avatar
dbulatovicx32 committed
327
            if (this.isOrganizerEnabled()) {
328
329
                const index = this.toolbarMenuItems.findIndex((item: any) => item.label === this.$t('common.shortcuts'))
                if (index !== -1) this.toolbarMenuItems[index].items.unshift({ icon: 'fa fa-suitcase ', label: this.$t('documentExecution.main.addToWorkspace'), command: () => this.addToWorkspace() })
dbulatovicx32's avatar
dbulatovicx32 committed
330
331
            }

BojanSovticEngIT's avatar
BojanSovticEngIT committed
332
            if (this.mode === 'olap') {
333
334
                const index = this.toolbarMenuItems.findIndex((item: any) => item.label === this.$t('common.shortcuts'))
                if (index !== -1) this.toolbarMenuItems[index].items.unshift({ icon: '', label: this.$t('documentExecution.main.showOLAPCustomView'), command: () => this.showOLAPCustomView() })
BojanSovticEngIT's avatar
BojanSovticEngIT committed
335
            }
336

Davide Vernassa's avatar
Davide Vernassa committed
337
            if (this.user.functionalities.includes('EnableToCopyAndEmbed')) {
338
339
340
341
342
                const index = this.toolbarMenuItems.findIndex((item: any) => item.label === this.$t('common.shortcuts'))
                if (index !== -1) {
                    this.toolbarMenuItems[index].items.push({ icon: 'fa fa-share', label: this.$t('documentExecution.main.copyLink'), command: () => this.copyLink(false) })
                    this.toolbarMenuItems[index].items.push({ icon: 'fa fa-share', label: this.$t('documentExecution.main.embedInHtml'), command: () => this.copyLink(true) })
                }
Davide Vernassa's avatar
Davide Vernassa committed
343
344
345
346
347
348
            }
        },
        print() {
            window.print()
        },
        export(type: string) {
BojanSovticEngIT's avatar
BojanSovticEngIT committed
349
350
351
352
353
354
355
356
357
            if (this.document.typeCode === 'OLAP') {
                this.exportOlap(type)
            } else {
                const tempIndex = this.breadcrumbs.findIndex((el: any) => el.label === this.document.label)
                let tempFrame = window.frames[tempIndex]
                while (tempFrame && tempFrame.name !== 'documentFrame' + tempIndex) {
                    tempFrame = tempFrame[0].frames
                }
                tempFrame.postMessage({ type: 'export', format: type.toLowerCase() }, '*')
Davide Vernassa's avatar
Davide Vernassa committed
358
            }
BojanSovticEngIT's avatar
BojanSovticEngIT committed
359
360
361
362
        },
        exportOlap(type: string) {
            const url = type === 'PDF' ? `/knowagewhatifengine/restful-services/1.0/model/export/pdf?SBI_EXECUTION_ID=${this.sbiExecutionId}` : `/knowagewhatifengine/restful-services/1.0/model/export/excel?SBI_EXECUTION_ID=${this.sbiExecutionId}`
            window.open(url)
Davide Vernassa's avatar
Davide Vernassa committed
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
        },
        openMailDialog() {
            this.mailDialogVisible = true
        },
        async openMetadata() {
            this.loading = true
            await this.$http.get(process.env.VUE_APP_RESTFUL_SERVICES_PATH + `1.0/documentexecutionee/${this.document.id}/documentMetadata`).then((response: AxiosResponse<any>) => (this.metadata = response.data))
            this.metadataDialogVisible = true
            this.loading = false
        },
        async openRank() {
            await this.getRank()
            this.rankDialogVisible = true
        },
        openNotes() {
            this.notesDialogVisible = true
        },
        async showScheduledExecutions() {
            this.loading = true
            this.parameterSidebarVisible = false
            this.schedulationsTableVisible = true
            await this.$http.get(process.env.VUE_APP_RESTFUL_SERVICES_PATH + `1.0/documentsnapshot/getSnapshots?id=${this.document.id}`).then((response: AxiosResponse<any>) => {
                response.data?.schedulers.forEach((el: any) => this.schedulations.push({ ...el, urlPath: response.data.urlPath }))
            })
            this.loading = false
        },
        async copyLink(embedHTML: boolean) {
            this.loading = true
            this.linkParameters = this.getFormattedParameters()
            await this.$http
                .post(process.env.VUE_APP_RESTFUL_SERVICES_PATH + `1.0/documentexecution/canHavePublicExecutionUrl`, { label: this.document.label })
                .then((response: AxiosResponse<any>) => {
                    this.embedHTML = embedHTML
                    this.linkInfo = response.data
                    this.linkDialogVisible = true
398
                })
Davide Vernassa's avatar
Davide Vernassa committed
399
400
401
402
403
404
405
406
407
408
409
410
411
                .catch(() => {})
            this.loading = false
        },
        closeDocument() {
            const link = this.$route.path.includes('workspace') ? '/workspace' : '/document-browser'
            this.$router.push(link)
            this.$emit('close')
        },
        setMode() {
            this.embed = this.$route.path.includes('embed')
            if (this.embed) {
                this.$store.commit('setDocumentExecutionEmbed')
            }
412

Davide Vernassa's avatar
Davide Vernassa committed
413
414
415
416
417
418
419
420
421
422
            if (this.$route.path.includes('registry')) {
                this.mode = 'registry'
            } else if (this.$route.path.includes('dossier')) {
                this.mode = 'dossier'
            } else if (this.$route.path.includes('olap')) {
                this.mode = 'olap'
            } else {
                this.mode = 'iframe'
            }
        },
BojanSovticEngIT's avatar
BojanSovticEngIT committed
423
        async loadPage(initialLoading: boolean = false, documentLabel: string | null = null) {
Davide Vernassa's avatar
Davide Vernassa committed
424
            this.loading = true
425

426
            await this.loadFilters(initialLoading)
Davide Vernassa's avatar
Davide Vernassa committed
427
            if (this.filtersData?.isReadyForExecution) {
BojanSovticEngIT's avatar
BojanSovticEngIT committed
428
                await this.loadURL(null, documentLabel)
Davide Vernassa's avatar
Davide Vernassa committed
429
430
431
432
                await this.loadExporters()
            } else if (this.filtersData?.filterStatus) {
                this.parameterSidebarVisible = true
            }
433

Davide Vernassa's avatar
Davide Vernassa committed
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
            this.updateMode()
            this.loading = false
        },
        updateMode() {
            if (this.document.typeCode === 'DATAMART') {
                this.mode = 'registry'
            } else if (this.document.typeCode === 'DOSSIER') {
                this.mode = 'dossier'
            } else if (this.document.typeCode === 'OLAP') {
                this.mode = 'olap'
            } else {
                this.mode = 'iframe'
            }
        },
        async loadDocument() {
            await this.$http.get(process.env.VUE_APP_RESTFUL_SERVICES_PATH + `2.0/documents/${this.document?.label}`).then((response: AxiosResponse<any>) => (this.document = response.data))
450

Davide Vernassa's avatar
Davide Vernassa committed
451
            const index = this.breadcrumbs.findIndex((el: any) => el.label === this.document.label)
452

Davide Vernassa's avatar
Davide Vernassa committed
453
454
455
456
457
458
            if (index !== -1) {
                this.breadcrumbs[index].document = this.document
            } else {
                this.breadcrumbs.push({ label: this.document.label, document: this.document })
            }
        },
459
460
461
462
463
464
        async loadFilters(initialLoading: boolean = false) {
            if (this.parameterValuesMap && this.parameterValuesMap[this.document.label + '-' + this.tabKey] && initialLoading) {
                this.filtersData = this.parameterValuesMap[this.document.label + '-' + this.tabKey]
                return
            }

BojanSovticEngIT's avatar
BojanSovticEngIT committed
465
            if (this.sessionEnabled && !this.document.navigationParams) {
BojanSovticEngIT's avatar
BojanSovticEngIT committed
466
467
468
469
470
471
472
473
474
475
476
477
                const tempFilters = sessionStorage.getItem(this.document.label)
                if (tempFilters) {
                    this.filtersData = JSON.parse(tempFilters) as { filterStatus: iParameter[]; isReadyForExecution: boolean }
                    this.filtersData.filterStatus?.forEach((filter: any) => {
                        if (filter.type === 'DATE' && filter.parameterValue[0].value) {
                            filter.parameterValue[0].value = new Date(filter.parameterValue[0].value)
                        }
                    })
                    return
                }
            }

Davide Vernassa's avatar
Davide Vernassa committed
478
479
480
481
            await this.$http
                .post(process.env.VUE_APP_RESTFUL_SERVICES_PATH + `2.0/documentexecution/filters`, { label: this.document.label, role: this.userRole, parameters: this.document.navigationParams ?? {} })
                .then((response: AxiosResponse<any>) => (this.filtersData = response.data))
                .catch((error: any) => {
482
                    if (error.response?.status === 500) {
Davide Vernassa's avatar
Davide Vernassa committed
483
484
485
                        this.$store.commit('setError', {
                            title: this.$t('common.error.generic'),
                            msg: this.$t('documentExecution.main.userRoleError')
486
487
                        })
                    }
Davide Vernassa's avatar
Davide Vernassa committed
488
                })
489

Davide Vernassa's avatar
Davide Vernassa committed
490
491
492
493
494
495
496
497
            this.filtersData?.filterStatus?.forEach((el: iParameter) => {
                el.parameterValue = el.multivalue ? [] : [{ value: '', description: '' }]
                if (el.driverDefaultValue?.length > 0) {
                    let valueIndex = '_col0'
                    let descriptionIndex = 'col1'
                    if (el.metadata?.colsMap) {
                        valueIndex = Object.keys(el.metadata?.colsMap).find((key: string) => el.metadata.colsMap[key] === el.metadata.valueColumn) as any
                        descriptionIndex = Object.keys(el.metadata?.colsMap).find((key: string) => el.metadata.colsMap[key] === el.metadata.descriptionColumn) as any
498
                    }
499

Davide Vernassa's avatar
Davide Vernassa committed
500
501
502
503
504
505
                    el.parameterValue = el.driverDefaultValue.map((defaultValue: any) => {
                        return { value: defaultValue.value ?? defaultValue[valueIndex], description: defaultValue.desc ?? defaultValue[descriptionIndex] }
                    })

                    if (el.type === 'DATE' && !el.selectionType && el.valueSelection === 'man_in' && el.showOnPanel === 'true') {
                        el.parameterValue[0].value = moment(el.parameterValue[0].description?.split('#')[0]).toDate() as any
506
                    }
Davide Vernassa's avatar
Davide Vernassa committed
507
508
509
510
511
                }
                if (el.data) {
                    el.data = el.data.map((data: any) => {
                        return this.formatParameterDataOptions(el, data)
                    })
512

Davide Vernassa's avatar
Davide Vernassa committed
513
514
                    if (el.data.length === 1) {
                        el.parameterValue = [...el.data]
515
                    }
Davide Vernassa's avatar
Davide Vernassa committed
516
517
518
519
                }
                if ((el.selectionType === 'COMBOBOX' || el.selectionType === 'LIST') && el.multivalue && el.mandatory && el.data.length === 1) {
                    el.showOnPanel = 'false'
                }
520

Davide Vernassa's avatar
Davide Vernassa committed
521
522
                if (!el.parameterValue) {
                    el.parameterValue = [{ value: '', description: '' }]
523
524
                }

Davide Vernassa's avatar
Davide Vernassa committed
525
526
527
528
                if (el.parameterValue[0] && !el.parameterValue[0].description) {
                    el.parameterValue[0].description = el.parameterDescription ? el.parameterDescription[0] : ''
                }
            })
529

Davide Vernassa's avatar
Davide Vernassa committed
530
531
532
533
534
535
536
537
538
539
540
            if (this.document.navigationParams) {
                this.loadNavigationParamsInitialValue()
            }

            const index = this.breadcrumbs.findIndex((el: any) => el.label === this.document.label)
            if (index !== -1) this.breadcrumbs[index].filtersData = this.filtersData
        },
        loadNavigationParamsInitialValue() {
            Object.keys(this.document.navigationParams).forEach((key: string) => {
                for (let i = 0; i < this.filtersData.filterStatus.length; i++) {
                    const tempParam = this.filtersData.filterStatus[i]
541
                    if (key === tempParam.urlName || key === tempParam.label) {
Davide Vernassa's avatar
Davide Vernassa committed
542
                        tempParam.parameterValue[0].value = this.document.navigationParams[key]
BojanSovticEngIT's avatar
BojanSovticEngIT committed
543
                        if (this.document.navigationParams[key + '_field_visible_description']) tempParam.parameterValue[0].description = this.document.navigationParams[key + '_field_visible_description']
544
                        if (tempParam.selectionType === 'COMBOBOX') this.setCrossNavigationComboParameterDescription(tempParam)
545
546
                    }
                }
Davide Vernassa's avatar
Davide Vernassa committed
547
548
            })
        },
549
550
551
552
553
554
        setCrossNavigationComboParameterDescription(tempParam: any) {
            if (tempParam.parameterValue[0]) {
                const index = tempParam.data.findIndex((option: any) => option.value === tempParam.parameterValue[0].value)
                if (index !== -1) tempParam.parameterValue[0].description = tempParam.data[index].description
            }
        },
Davide Vernassa's avatar
Davide Vernassa committed
555
556
557
558
559
        formatParameterDataOptions(parameter: iParameter, data: any) {
            const valueColumn = parameter.metadata.valueColumn
            const descriptionColumn = parameter.metadata.descriptionColumn
            const valueIndex = Object.keys(parameter.metadata.colsMap).find((key: string) => parameter.metadata.colsMap[key] === valueColumn)
            const descriptionIndex = Object.keys(parameter.metadata.colsMap).find((key: string) => parameter.metadata.colsMap[key] === descriptionColumn)
560

Davide Vernassa's avatar
Davide Vernassa committed
561
562
            return { value: valueIndex ? data[valueIndex] : '', description: descriptionIndex ? data[descriptionIndex] : '' }
        },
BojanSovticEngIT's avatar
BojanSovticEngIT committed
563
        async loadURL(olapParameters: any, documentLabel: string | null = null) {
Davide Vernassa's avatar
Davide Vernassa committed
564
            const postData = { label: this.document.label, role: this.userRole, parameters: olapParameters ? olapParameters : this.getFormattedParameters(), EDIT_MODE: 'null', IS_FOR_EXPORT: true } as any
565
566
567
568
569

            if (this.sbiExecutionId) {
                postData.SBI_EXECUTION_ID = this.sbiExecutionId
            }

dbulatovicx32's avatar
dbulatovicx32 committed
570
571
572
573
            if (this.document.typeCode === 'MAP') {
                postData.EDIT_MODE = 'edit_map'
            }

574
            await this.$http
BojanSovticEngIT's avatar
BojanSovticEngIT committed
575
                .post(process.env.VUE_APP_RESTFUL_SERVICES_PATH + `1.0/documentexecution/url`, postData, { headers: { 'X-Disable-Interceptor': 'true' } })
576
577
                .then((response: AxiosResponse<any>) => {
                    this.urlData = response.data
578
                    this.sbiExecutionId = this.urlData?.sbiExecutionId as string
579
                })
BojanSovticEngIT's avatar
BojanSovticEngIT committed
580
581
582
583
                .catch((response: AxiosResponse<any>) => {
                    this.urlData = response.data
                    this.sbiExecutionId = this.urlData?.sbiExecutionId as string
                })
584

Davide Vernassa's avatar
Davide Vernassa committed
585
586
587
588
589
            const index = this.breadcrumbs.findIndex((el: any) => el.label === this.document.label)
            if (index !== -1) {
                this.breadcrumbs[index].urlData = this.urlData
                this.sbiExecutionId = this.urlData?.sbiExecutionId as string
            }
590

BojanSovticEngIT's avatar
BojanSovticEngIT committed
591
            await this.sendForm(documentLabel)
Davide Vernassa's avatar
Davide Vernassa committed
592
593
594
595
        },
        async loadExporters() {
            await this.$http.get(process.env.VUE_APP_RESTFUL_SERVICES_PATH + `2.0/exporters/${this.urlData?.engineLabel}`).then((response: AxiosResponse<any>) => (this.exporters = response.data.exporters))
        },
BojanSovticEngIT's avatar
BojanSovticEngIT committed
596
597
        async sendForm(documentLabel: string | null = null) {
            let tempIndex = this.breadcrumbs.findIndex((el: any) => el.label === this.document.label) as any
Davide Vernassa's avatar
Davide Vernassa committed
598
599
600
601
602
603
604
605
606
607

            const documentUrl = this.urlData?.url + '&timereloadurl=' + new Date().getTime()
            const postObject = { params: { document: null } as any, url: documentUrl.split('?')[0] }
            postObject.params.documentMode = this.documentMode
            this.hiddenFormUrl = postObject.url
            const paramsFromUrl = documentUrl.split('?')[1].split('&')

            for (let i in paramsFromUrl) {
                if (typeof paramsFromUrl !== 'function') {
                    postObject.params[paramsFromUrl[i].split('=')[0]] = paramsFromUrl[i].split('=')[1]
608
                }
Davide Vernassa's avatar
Davide Vernassa committed
609
610
611
612
613
614
615
616
            }

            let postForm = document.getElementById('postForm_' + postObject.params.document) as any
            if (!postForm) {
                postForm = document.createElement('form')
                postForm.id = 'postForm_' + postObject.params.document
                postForm.action = process.env.VUE_APP_HOST_URL + postObject.url
                postForm.method = 'post'
BojanSovticEngIT's avatar
BojanSovticEngIT committed
617
                postForm.target = tempIndex !== -1 ? 'documentFrame' + tempIndex : documentLabel
618
                postForm.acceptCharset = 'UTF-8'
Davide Vernassa's avatar
Davide Vernassa committed
619
620
                document.body.appendChild(postForm)
            }
621

Davide Vernassa's avatar
Davide Vernassa committed
622
            this.hiddenFormData = new URLSearchParams()
623

Davide Vernassa's avatar
Davide Vernassa committed
624
625
626
627
628
            for (let k in postObject.params) {
                const inputElement = document.getElementById('postForm_' + postObject.params.document + k) as any
                if (inputElement) {
                    inputElement.value = decodeURIComponent(postObject.params[k])
                    inputElement.value = inputElement.value.replace(/\+/g, ' ')
BojanSovticEngIT's avatar
BojanSovticEngIT committed
629

Davide Vernassa's avatar
Davide Vernassa committed
630
631
632
633
634
635
636
637
638
                    this.hiddenFormData.set(k, decodeURIComponent(postObject.params[k]).replace(/\+/g, ' '))
                } else {
                    const element = document.createElement('input')
                    element.type = 'hidden'
                    element.id = 'postForm_' + postObject.params.document + k
                    element.name = k
                    element.value = decodeURIComponent(postObject.params[k])
                    element.value = element.value.replace(/\+/g, ' ')

BojanSovticEngIT's avatar
BojanSovticEngIT committed
639
                    postForm.appendChild(element)
Davide Vernassa's avatar
Davide Vernassa committed
640
                    this.hiddenFormData.append(k, decodeURIComponent(postObject.params[k]).replace(/\+/g, ' '))
641
                }
Davide Vernassa's avatar
Davide Vernassa committed
642
            }
643

Davide Vernassa's avatar
Davide Vernassa committed
644
            for (let i = postForm.elements.length - 1; i >= 0; i--) {
BojanSovticEngIT's avatar
BojanSovticEngIT committed
645
                const postFormElement = postForm.elements[i].id.replace('postForm_' + postObject.params.document, '')
646

Davide Vernassa's avatar
Davide Vernassa committed
647
                if (!(postFormElement in postObject.params)) {
BojanSovticEngIT's avatar
BojanSovticEngIT committed
648
                    postForm.removeChild(postForm.elements[i])
Davide Vernassa's avatar
Davide Vernassa committed
649
                    this.hiddenFormData.delete(postFormElement)
650
                }
Davide Vernassa's avatar
Davide Vernassa committed
651
            }
652

Davide Vernassa's avatar
Davide Vernassa committed
653
            this.hiddenFormData.append('documentMode', this.documentMode)
654

Davide Vernassa's avatar
Davide Vernassa committed
655
656
657
658
659
            if (this.document.typeCode === 'DATAMART' || this.document.typeCode === 'DOSSIER' || this.document.typeCode === 'OLAP') {
                await this.sendHiddenFormData()
            } else {
                postForm.submit()
            }
660

Davide Vernassa's avatar
Davide Vernassa committed
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
            const index = this.breadcrumbs.findIndex((el: any) => el.label === this.document.label)
            if (index !== -1) this.breadcrumbs[index].hiddenFormData = this.hiddenFormData
        },
        async sendHiddenFormData() {
            await this.$http
                .post(this.hiddenFormUrl, this.hiddenFormData, {
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded',
                        Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9'
                    }
                })
                .then(() => {})
                .catch(() => {})
        },
        async onExecute() {
            this.loading = true
            this.filtersData.isReadyForExecution = true
            await this.loadURL(null)
            this.parameterSidebarVisible = false
            this.reloadTrigger = !this.reloadTrigger
BojanSovticEngIT's avatar
BojanSovticEngIT committed
681

682
683
684
685
686
687
688
689
690
691
692
693
694
            if (!this.exporters || this.exporters.length === 0) {
                await this.loadExporters()
                const index = this.toolbarMenuItems.findIndex((item: any) => item.label === this.$t('common.export'))
                if (index === -1) {
                    this.toolbarMenuItems.splice(1, 0, {
                        label: this.$t('common.export'),
                        items: []
                    })
                } else {
                    this.exporters?.forEach((exporter: any) => this.toolbarMenuItems[index].items.push({ icon: 'fa fa-file-excel', label: exporter.name, command: () => this.export(exporter.name) }))
                }
            }

BojanSovticEngIT's avatar
BojanSovticEngIT committed
695
696
697
            if (this.sessionEnabled) {
                this.saveParametersInSession()
            }
Davide Vernassa's avatar
Davide Vernassa committed
698
699
700
701
702
703
704
705
706
707
708
            this.loading = false
        },
        async onExportCSV() {
            const postData = { documentId: this.document.id, documentLabel: this.document.label, exportType: 'CSV', parameters: this.getFormattedParametersForCSVExport() }
            this.loading = true
            await this.$http
                .post(process.env.VUE_APP_RESTFUL_SERVICES_PATH + `2.0/export/cockpitData`, postData)
                .then(() => {
                    this.$store.commit('setInfo', {
                        title: this.$t('common.toast.updateTitle'),
                        msg: this.$t('common.exportSuccess')
709
                    })
Davide Vernassa's avatar
Davide Vernassa committed
710
711
712
713
714
715
716
717
                })
                .catch(() => {})
            this.loading = false
        },
        getFormattedParameters() {
            if (!this.filtersData || !this.filtersData.filterStatus) {
                return {}
            }
718

Davide Vernassa's avatar
Davide Vernassa committed
719
720
721
722
723
724
725
726
            let parameters = {} as any

            Object.keys(this.filtersData.filterStatus).forEach((key: any) => {
                const parameter = this.filtersData.filterStatus[key]

                if (parameter.parameterValue) {
                    if (parameter.type === 'DATE') {
                        parameters[parameter.urlName] = this.getFormattedDate(parameter.parameterValue[0].value)
727
                        parameters[parameter.urlName + '_field_visible_description'] = this.getFormattedDate(parameter.parameterValue[0].value, true)
Davide Vernassa's avatar
Davide Vernassa committed
728
729
730
731
732
733
734
735
736
                    } else if (parameter.valueSelection === 'man_in') {
                        parameters[parameter.urlName] = parameter.type === 'NUM' ? +parameter.parameterValue[0].value : parameter.parameterValue[0].value
                        parameters[parameter.urlName + '_field_visible_description'] = parameter.type === 'NUM' ? +parameter.parameterValue[0].description : parameter.parameterValue[0].description
                    } else if (parameter.selectionType === 'TREE' || parameter.selectionType === 'LOOKUP' || parameter.multivalue) {
                        parameters[parameter.urlName] = parameter.parameterValue.map((el: any) => el.value)
                        let tempString = ''
                        for (let i = 0; i < parameter.parameterValue.length; i++) {
                            tempString += parameter.parameterValue[i].description
                            tempString += i === parameter.parameterValue.length - 1 ? '' : ';'
737
                        }
Davide Vernassa's avatar
Davide Vernassa committed
738
739
740
741
                        parameters[parameter.urlName + '_field_visible_description'] = tempString
                    } else {
                        parameters[parameter.urlName] = parameter.parameterValue[0].value
                        parameters[parameter.urlName + '_field_visible_description'] = parameter.parameterValue[0].description
742
743
                    }
                }
Davide Vernassa's avatar
Davide Vernassa committed
744
            })
745

Davide Vernassa's avatar
Davide Vernassa committed
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
            return parameters
        },
        getFormattedParametersForCSVExport() {
            if (!this.filtersData) {
                return {}
            }

            let parameters = {} as any

            Object.keys(this.filtersData.filterStatus).forEach((key: any) => {
                const parameter = this.filtersData.filterStatus[key]

                if (parameter.parameterValue) {
                    if (parameter.type === 'DATE') {
                        parameters[parameter.urlName] = this.getFormattedDate(parameter.parameterValue[0].value)
                    } else if (parameter.valueSelection === 'man_in' && !parameter.multivalue) {
                        parameters[parameter.urlName] = parameter.type === 'NUM' ? +parameter.parameterValue[0].value : parameter.parameterValue[0].value
                    } else if (parameter.selectionType === 'TREE' || parameter.selectionType === 'LOOKUP' || parameter.multivalue) {
                        let tempString = ''
                        for (let i = 0; i < parameter.parameterValue.length; i++) {
                            tempString += parameter.parameterValue[i].value
                            tempString += i === parameter.parameterValue.length - 1 ? '' : ','
768
                        }
Davide Vernassa's avatar
Davide Vernassa committed
769
770
771
                        parameters[parameter.urlName] = tempString
                    } else {
                        parameters[parameter.urlName] = parameter.parameterValue[0].value
772
773
                    }
                }
Davide Vernassa's avatar
Davide Vernassa committed
774
            })
775

Davide Vernassa's avatar
Davide Vernassa committed
776
777
778
779
780
781
782
783
784
785
786
            return parameters
        },
        async getRank() {
            this.loading = true
            await this.$http
                .post(process.env.VUE_APP_RESTFUL_SERVICES_PATH + `documentrating/getvote`, { obj: this.document.id })
                .then((response: AxiosResponse<any>) => (this.documentRank = response.data))
                .catch((error: any) =>
                    this.$store.commit('setError', {
                        title: this.$t('common.error.generic'),
                        msg: error
787
                    })
Davide Vernassa's avatar
Davide Vernassa committed
788
789
790
791
792
                )
            this.loading = false
        },
        async onSaveRank(newRank: any) {
            if (newRank) {
793
794
                this.loading = true
                await this.$http
Davide Vernassa's avatar
Davide Vernassa committed
795
796
                    .post(process.env.VUE_APP_RESTFUL_SERVICES_PATH + `documentrating/vote`, { rating: newRank, obj: this.document.id })
                    .then(() =>
797
                        this.$store.commit('setInfo', {
Davide Vernassa's avatar
Davide Vernassa committed
798
799
                            title: this.$t('common.toast.updateTitle'),
                            msg: this.$t('documentExecution.main.rankSaveSucces')
800
                        })
Davide Vernassa's avatar
Davide Vernassa committed
801
802
                    )
                    .catch((error: any) =>
803
804
805
806
                        this.$store.commit('setError', {
                            title: this.$t('common.error.generic'),
                            msg: error
                        })
Davide Vernassa's avatar
Davide Vernassa committed
807
                    )
808
                this.loading = false
Davide Vernassa's avatar
Davide Vernassa committed
809
810
811
812
813
814
            }
            this.rankDialogVisible = false
        },
        async onMetadataSave(metadata: any) {
            this.loading = true
            const jsonMeta = [] as any[]
BojanSovticEngIT's avatar
BojanSovticEngIT committed
815
            const properties = ['shortText', 'longText', 'file']
Davide Vernassa's avatar
Davide Vernassa committed
816
817
            properties.forEach((property: string) =>
                metadata[property].forEach((el: any) => {
BojanSovticEngIT's avatar
BojanSovticEngIT committed
818
                    if (el.value || (property === 'file' && el.fileToSave)) {
Davide Vernassa's avatar
Davide Vernassa committed
819
                        jsonMeta.push(el)
820
                    }
BojanSovticEngIT's avatar
BojanSovticEngIT committed
821
                })
Davide Vernassa's avatar
Davide Vernassa committed
822
            )
BojanSovticEngIT's avatar
BojanSovticEngIT committed
823

Davide Vernassa's avatar
Davide Vernassa committed
824
825
826
827
828
829
830
831
832
833
            await this.$http
                .post(process.env.VUE_APP_RESTFUL_SERVICES_PATH + `1.0/documentexecutionee/saveDocumentMetadata`, { id: this.document.id, jsonMeta: jsonMeta })
                .then(() => {
                    this.$store.commit('setInfo', {
                        title: this.$t('common.toast.createTitle'),
                        msg: this.$t('common.toast.success')
                    })
                    this.metadataDialogVisible = false
                })
                .catch((error: any) => {
834
835
                    this.$store.commit('setError', {
                        title: this.$t('common.error.generic'),
Davide Vernassa's avatar
Davide Vernassa committed
836
                        msg: error
837
838
                    })
                })
Davide Vernassa's avatar
Davide Vernassa committed
839
            this.loading = false
BojanSovticEngIT's avatar
BojanSovticEngIT committed
840
        },
Davide Vernassa's avatar
Davide Vernassa committed
841
        async onMailSave(mail: any) {
BojanSovticEngIT's avatar
BojanSovticEngIT committed
842
            this.loading = true
Davide Vernassa's avatar
Davide Vernassa committed
843
            const postData = { ...mail, label: this.document.label, docId: this.document.id, userId: this.user.userId, parameters: this.getFormattedParameters() }
BojanSovticEngIT's avatar
BojanSovticEngIT committed
844
            await this.$http
Davide Vernassa's avatar
Davide Vernassa committed
845
                .post(process.env.VUE_APP_RESTFUL_SERVICES_PATH + `1.0/documentexecutionmail/sendMail`, postData)
BojanSovticEngIT's avatar
BojanSovticEngIT committed
846
847
                .then(() => {
                    this.$store.commit('setInfo', {
Davide Vernassa's avatar
Davide Vernassa committed
848
849
                        title: this.$t('common.toast.createTitle'),
                        msg: this.$t('common.sendMailSuccess')
BojanSovticEngIT's avatar
BojanSovticEngIT committed
850
                    })
Davide Vernassa's avatar
Davide Vernassa committed
851
                    this.mailDialogVisible = false
BojanSovticEngIT's avatar
BojanSovticEngIT committed
852
                })
Davide Vernassa's avatar
Davide Vernassa committed
853
                .catch((error: any) => {
BojanSovticEngIT's avatar
BojanSovticEngIT committed
854
                    this.$store.commit('setError', {
Davide Vernassa's avatar
Davide Vernassa committed
855
856
                        title: this.$t('common.error.generic'),
                        msg: error
BojanSovticEngIT's avatar
BojanSovticEngIT committed
857
858
859
                    })
                })
            this.loading = false
Davide Vernassa's avatar
Davide Vernassa committed
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
        },
        async onDeleteSchedulation(schedulation: any) {
            this.loading = true
            await this.$http
                .post(process.env.VUE_APP_RESTFUL_SERVICES_PATH + `1.0/documentsnapshot/deleteSnapshot`, { SNAPSHOT: '' + schedulation.id })
                .then(async () => {
                    this.removeSchedulation(schedulation)
                    this.$store.commit('setInfo', {
                        title: this.$t('common.toast.deleteTitle'),
                        msg: this.$t('common.toast.deleteSuccess')
                    })
                })
                .catch(() => {})
            this.loading = false
        },
        removeSchedulation(schedulation: iSchedulation) {
            const index = this.schedulations.findIndex((el: any) => el.id === schedulation.id)
            if (index !== -1) this.schedulations.splice(index, 1)
        },
879
        getFormattedDate(date: any, useDefaultFormat?: boolean) {
880
881
            const format = date instanceof Date ? undefined : process.env.VUE_APP_CROSS_NAVIGATION_DATE_FORMAT
            return luxonFormatDate(date, format, useDefaultFormat ? undefined : this.dateFormat)
Davide Vernassa's avatar
Davide Vernassa committed
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
        },
        onBreadcrumbClick(item: any) {
            this.document = item.document
            this.filtersData = item.filtersData
            this.urlData = item.urlData
            this.hiddenFormData = item.hiddenFormData
            this.updateMode()
        },
        async onRoleChange(role: string) {
            this.userRole = role as any
            this.filtersData = {} as { filterStatus: iParameter[]; isReadyForExecution: boolean }
            this.urlData = null
            this.exporters = null
            await this.loadPage()
        },
        async executeCrossNavigation(event: any) {
BojanSovticEngIT's avatar
BojanSovticEngIT committed
898
            this.angularData = event.data
Davide Vernassa's avatar
Davide Vernassa committed
899
900
901
902
            await this.loadCrossNavigationByDocument(event.data)
        },
        async loadCrossNavigationByDocument(angularData: any) {
            let temp = {} as any
903

Davide Vernassa's avatar
Davide Vernassa committed
904
905
906
            this.loading = true
            await this.$http.get(process.env.VUE_APP_RESTFUL_SERVICES_PATH + `1.0/crossNavigation/${this.document.label}/loadCrossNavigationByDocument`).then((response: AxiosResponse<any>) => (temp = response.data))
            this.loading = false
907

BojanSovticEngIT's avatar
Hotfix    
BojanSovticEngIT committed
908
            if (temp.length > 1) {
BojanSovticEngIT's avatar
BojanSovticEngIT committed
909
910
911
912
913
914
915
                this.crossNavigationDocuments = temp
                this.destinationSelectDialogVisible = true
            } else {
                this.loadCrossNavigation(temp[0], angularData)
            }
        },
        async loadCrossNavigation(crossNavigationDocument: any, angularData: any) {
916
            this.formatAngularOutputParameters(angularData.otherOutputParameters)
BojanSovticEngIT's avatar
BojanSovticEngIT committed
917
            const navigationParams = this.formatNavigationParams(angularData.otherOutputParameters, crossNavigationDocument.navigationParams)
918

BojanSovticEngIT's avatar
BojanSovticEngIT committed
919
            this.document = { ...crossNavigationDocument?.document, navigationParams: navigationParams }
920

BojanSovticEngIT's avatar
BojanSovticEngIT committed
921
922
923
924
925
926
927
928
929
            const popupOptions = crossNavigationDocument.popupOptions ? JSON.parse(crossNavigationDocument.popupOptions) : null

            if (crossNavigationDocument.crossType === 2) {
                this.openCrossNavigationInNewWindow(popupOptions, crossNavigationDocument, navigationParams)
            } else if (crossNavigationDocument.crossType === 1) {
                const documentLabel = crossNavigationDocument?.document.label
                this.crossNavigationContainerData = { documentLabel: documentLabel, iFrameName: documentLabel }
                this.crossNavigationContainerVisible = true
                await this.loadPage(false, documentLabel)
Davide Vernassa's avatar
Davide Vernassa committed
930
            } else {
BojanSovticEngIT's avatar
BojanSovticEngIT committed
931
932
933
934
935
936
                const index = this.breadcrumbs.findIndex((el: any) => el.label === this.document.label)
                if (index !== -1) {
                    this.breadcrumbs[index].document = this.document
                } else {
                    this.breadcrumbs.push({ label: this.document.label, document: this.document, crossBreadcrumb: crossNavigationDocument.crossBreadcrumb })
                }
937

BojanSovticEngIT's avatar
BojanSovticEngIT committed
938
939
940
941
942
943
944
945
946
947
                await this.loadPage()
            }
        },
        openCrossNavigationInNewWindow(popupOptions: any, crossNavigationDocument: any, navigationParams: any) {
            if (!crossNavigationDocument || !crossNavigationDocument.document) return
            const parameters = encodeURI(JSON.stringify(navigationParams))
            const url =
                process.env.VUE_APP_HOST_URL +
                `/knowage/restful-services/publish?PUBLISHER=documentExecutionNg&OBJECT_ID=${crossNavigationDocument.document.id}&OBJECT_LABEL=${crossNavigationDocument.document.label}&SELECTED_ROLE=${this.sessionRole}&SBI_EXECUTION_ID=null&OBJECT_NAME=${crossNavigationDocument.document.name}&CROSS_PARAMETER=${parameters}`
            window.open(url, '_blank', `toolbar=0,status=0,menubar=0,width=${popupOptions.width || '800'},height=${popupOptions.height || '600'}`)
Davide Vernassa's avatar
Davide Vernassa committed
948
        },
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
        formatAngularOutputParameters(otherOutputParameters: any[]) {
            const startDocumentInputParameters = deepcopy(this.document.drivers)
            const keys = [] as any[]
            otherOutputParameters.forEach((parameter: any) => keys.push(Object.keys(parameter)[0]))

            for (let i = 0; i < startDocumentInputParameters.length; i++) {
                if (!keys.includes(startDocumentInputParameters[i].label)) {
                    const tempObject = {} as any
                    tempObject[startDocumentInputParameters[i].label] = this.getParameterValueForCrossNavigation(startDocumentInputParameters[i].label)
                    otherOutputParameters.push(tempObject)
                }
            }
        },
        getParameterValueForCrossNavigation(parameterLabel: string) {
            const index = this.filtersData.filterStatus?.findIndex((param: any) => param.label === parameterLabel)
            return index !== -1 ? this.filtersData.filterStatus[index].parameterValue[0].value : ''
        },
Davide Vernassa's avatar
Davide Vernassa committed
966
967
        formatNavigationParams(otherOutputParameters: any[], navigationParams: any) {
            let formatedParams = {} as any
968

Davide Vernassa's avatar
Davide Vernassa committed
969
            otherOutputParameters.forEach((el: any) => {
970
971
972
973
974
975
976
977
978
979
980
981
982
983
                let found = false
                let label = ''

                for (let i = 0; i < Object.keys(navigationParams).length; i++) {
                    if (navigationParams[Object.keys(navigationParams)[i]].value.label === Object.keys(el)[0]) {
                        found = true
                        label = Object.keys(navigationParams)[i]
                        break
                    }
                }

                if (found) {
                    formatedParams[label] = el[Object.keys(el)[0]]
                    formatedParams[label + '_field_visible_description'] = el[Object.keys(el)[0]]
Davide Vernassa's avatar
Davide Vernassa committed
984
985
                }
            })
986

Davide Vernassa's avatar
Davide Vernassa committed
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
            return formatedParams
        },
        showOLAPCustomView() {
            this.olapCustomViewVisible = true
        },
        async executeOlapCustomView(payload: any) {
            this.loading = true
            this.olapCustomViewVisible = false
            await this.loadURL(payload)
            this.reloadTrigger = !this.reloadTrigger
            this.loading = false
        },
        async executeOLAPCrossNavigation(crossNavigationParams: any) {
            let temp = {} as any