QBE.vue 44.6 KB
Newer Older
BojanSovticEngIT's avatar
BojanSovticEngIT committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<template>
    <Dialog class="full-screen-dialog" :visible="true" :modal="false" :closable="false" position="right" :baseZIndex="1" :autoZIndex="true">
        <template #header>
            <Toolbar class="kn-toolbar kn-toolbar--primary p-col-12">
                <template #start>
                    <span v-if="qbe">{{ qbe.label ? qbe.label : qbe.qbeDatamarts }}</span>
                </template>
                <template #end>
                    <Button v-if="isParameterSidebarVisible" icon="pi pi-filter" class="p-button-text p-button-rounded p-button-plain" v-tooltip.bottom="$t('common.filter')" @click="parameterSidebarVisible = !parameterSidebarVisible" />
                    <Button icon="pi pi-save" class="p-button-text p-button-rounded p-button-plain" v-tooltip.bottom="$t('common.save')" @click="savingDialogVisible = true" />
                    <Button icon="pi pi-times" class="p-button-text p-button-rounded p-button-plain" v-tooltip.bottom="$t('common.close')" @click="$emit('close')" />
                </template>
            </Toolbar>
        </template>
15
        <ProgressSpinner class="kn-progress-spinner" v-if="loading" />
dbulatovicx32's avatar
dbulatovicx32 committed
16
        <div v-if="!qbePreviewDialogVisible" class="kn-relative p-d-flex p-flex-row kn-height-full kn-width-full">
BojanSovticEngIT's avatar
BojanSovticEngIT committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
            <div v-if="parameterSidebarVisible" :style="qbeDescriptor.style.backdrop" @click="parameterSidebarVisible = false"></div>
            <div v-show="showEntitiesLists && qbeLoaded" :style="qbeDescriptor.style.entitiesLists">
                <div class="p-d-flex p-flex-column kn-flex kn-overflow-hidden">
                    <Toolbar class="kn-toolbar kn-toolbar--secondary kn-flex-0">
                        <template #start>
                            <span>{{ $t('qbe.entities.title') }}</span>
                        </template>
                        <template #end>
                            <Chip style="background-color:white"> {{ entities?.entities?.length }} </Chip>
                        </template>
                    </Toolbar>
                    <div class="kn-flex kn-overflow-hidden">
                        <ScrollPanel class="kn-height-full qbe-scroll-panel">
                            <ExpandableEntity :availableEntities="entities.entities" :query="mainQuery" @showRelationDialog="showRelationDialog" @entityClicked="onDropComplete($event, false)" @entityChildClicked="onDropComplete($event, false)" @openFilterDialog="openFilterDialog" />
                        </ScrollPanel>
                    </div>
                </div>
                <div class="p-d-flex p-flex-column kn-overflow-hidden" :class="{ 'derived-entities-toggle': showDerivedList }">
                    <Toolbar class="kn-toolbar kn-toolbar--secondary kn-flex-0">
                        <template #start>
                            <span>{{ $t('qbe.entities.derived') }}</span>
                        </template>
                        <template #end>
                            <Button v-if="showEntitiesLists" icon="fas fa-plus-circle" class="p-button-text p-button-rounded p-button-plain" v-tooltip.top="$t('common.add')" @click="createSubquery" />
BojanSovticEngIT's avatar
BojanSovticEngIT committed
41
                            <Chip style="background-color:white"> {{ mainQuery?.subqueries?.length }} </Chip>
BojanSovticEngIT's avatar
BojanSovticEngIT committed
42
43
44
45
46
47
                            <Button v-if="showDerivedList" icon="pi pi-chevron-down" class="p-button-text p-button-rounded p-button-plain" @click="collapseDerivedList" />
                            <Button v-else icon="pi pi-chevron-up" class="p-button-text p-button-rounded p-button-plain" @click="collapseDerivedList" />
                        </template>
                    </Toolbar>
                    <div v-show="showDerivedList" class="kn-flex kn-overflow-hidden">
                        <ScrollPanel class="kn-height-full qbe-scroll-panel">
BojanSovticEngIT's avatar
BojanSovticEngIT committed
48
                            <SubqueryEntity :availableEntities="mainQuery?.subqueries" @editSubquery="selectSubquery" @deleteSubquery="deleteSubquery" />
BojanSovticEngIT's avatar
BojanSovticEngIT committed
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
                        </ScrollPanel>
                    </div>
                </div>
            </div>
            <div class="qbe-detail-view p-m-1" v-if="qbe && qbeLoaded">
                <Toolbar class="kn-toolbar kn-toolbar--primary kn-width-full">
                    <template #start>
                        <Button v-if="showEntitiesLists" icon="pi pi-chevron-left" class="p-button-text p-button-rounded p-button-plain" v-tooltip.bottom="$t('qbe.detailView.hideList')" @click="toggleEntitiesLists" />
                        <Button v-else icon="pi pi-chevron-right" class="p-button-text p-button-rounded p-button-plain" v-tooltip.bottom="$t('qbe.detailView.showList')" @click="toggleEntitiesLists" />
                        <span v-if="selectedQuery.id !== 'q1'">
                            <Button label="MAIN" class="p-button-text p-button-plain kn-uppercase" @click="selectMainQuery" />
                            <Button icon="pi pi-chevron-right" class="p-button-text p-button-plain" />
                            <Button :label="selectedQuery?.name" class="p-button-text p-button-plain kn-uppercase" />
                        </span>
                    </template>
                    <template #end>
                        <i v-if="selectedQuery.fields.length > 0" class="fas fa-eraser kn-cursor-pointer p-mx-2" v-tooltip.top="$t('qbe.viewToolbar.deleteAllSelectedFields')" @click="deleteAllSelectedFields"></i>
                        <i v-if="hiddenColumnsExist" class="pi pi-eye kn-cursor-pointer p-mx-2" v-tooltip.top="$t('qbe.viewToolbar.showHiddenColumns')" @click="showHiddenColumns"></i>
                        <span v-if="selectedQuery.filters.length > 0" class="fa-stack p-mx-2">
                            <i class="fas fa-ban fa-stack-2x"></i>
                            <i class="fas fa-filter fa-stack-1x kn-cursor-pointer" v-tooltip.top="$t('qbe.viewToolbar.deleteAllFilters')" @click="deleteAllFilters"></i>
                        </span>
                        <InputSwitch class="p-mr-2" v-model="smartView" @change="updateSmartView" />
                        <span>{{ $t('qbe.viewToolbar.smartView') }}</span>
                        <i v-show="!smartView" class="fas fa-play p-m-2 kn-cursor-pointer" @click="openPreviewDialog"></i>
                        <Button icon="fas fa-ellipsis-v kn-cursor-pointer" class="p-button-text p-button-rounded p-button-plain" @click="showMenu" />
                    </template>
                </Toolbar>
                <div class="kn-relative kn-flex p-mt-2">
                    <div class="kn-height-full kn-width-full kn-absolute">
                        <QBESimpleTable
                            v-if="!smartView"
                            :query="selectedQuery"
                            @columnVisibilityChanged="checkIfHiddenColumnsExist"
                            @openFilterDialog="openFilterDialog"
                            @openHavingDialog="openHavingDialog"
                            @entityDropped="onDropComplete($event, false)"
                            @groupingChanged="onGroupingChanged"
dbulatovicx32's avatar
dbulatovicx32 committed
87
                            @openCalculatedFieldDialog="editCalcField"
BojanSovticEngIT's avatar
BojanSovticEngIT committed
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
                        ></QBESimpleTable>
                        <QBESmartTable
                            v-else
                            :query="selectedQuery"
                            :previewData="queryPreviewData"
                            :pagination="pagination"
                            @removeFieldFromQuery="onQueryFieldRemoved"
                            @orderChanged="updateSmartView"
                            @fieldHidden="smartViewFieldHidden"
                            @fieldGrouped="updateSmartView"
                            @fieldAggregated="updateSmartView"
                            @aliasChanged="updateSmartView"
                            @reordered="smartViewReorder"
                            @entityDropped="onDropComplete($event, false)"
                            @pageChanged="updatePagination($event)"
                            @openFilterDialog="openFilterDialog"
                        />
                    </div>
                </div>
            </div>
BojanSovticEngIT's avatar
BojanSovticEngIT committed
108
            <KnParameterSidebar v-if="parameterSidebarVisible" :filtersData="filtersData" :propDocument="dataset" :userRole="userRole" :propMode="'qbeView'" :propQBEParameters="qbe?.pars" @execute="onExecute" @roleChanged="onRoleChange"></KnParameterSidebar>
BojanSovticEngIT's avatar
BojanSovticEngIT committed
109
110
        </div>

BojanSovticEngIT's avatar
BojanSovticEngIT committed
111
        <QBEPreviewDialog v-show="!loading && qbePreviewDialogVisible" :id="uniqueID" :queryPreviewData="queryPreviewData" :pagination="pagination" :entities="entities?.entities" :selectedQuery="selectedQuery" @close="closePreview" @pageChanged="updatePagination($event)"></QBEPreviewDialog>
BojanSovticEngIT's avatar
BojanSovticEngIT committed
112
113
114
        <QBEFilterDialog :visible="filterDialogVisible" :filterDialogData="filterDialogData" :id="uniqueID" :entities="entities?.entities" :propParameters="qbe?.pars" :propExpression="selectedQuery?.expression" @close="filterDialogVisible = false" @save="onFiltersSave"></QBEFilterDialog>
        <QBESqlDialog :visible="sqlDialogVisible" :sqlData="sqlData" @close="sqlDialogVisible = false" />
        <QBERelationDialog :visible="relationDialogVisible" :propEntity="relationEntity" @close="relationDialogVisible = false" />
BojanSovticEngIT's avatar
BojanSovticEngIT committed
115
        <QBEParamDialog v-if="paramDialogVisible" :visible="paramDialogVisible" :propDataset="qbe" @close="paramDialogVisible = false" @save="onParametersSave" />
BojanSovticEngIT's avatar
BojanSovticEngIT committed
116
117
        <QBEHavingDialog :visible="havingDialogVisible" :havingDialogData="havingDialogData" :entities="selectedQuery?.fields" @close="havingDialogVisible = false" @save="onHavingsSave"></QBEHavingDialog>
        <QBEAdvancedFilterDialog :visible="advancedFilterDialogVisible" :query="selectedQuery" @close="advancedFilterDialogVisible = false" @save="onAdvancedFiltersSave"></QBEAdvancedFilterDialog>
118
        <QBESavingDialog :visible="savingDialogVisible" :propDataset="qbe" @close="savingDialogVisible = false" @datasetSaved="$emit('datasetSaved')" />
BojanSovticEngIT's avatar
BojanSovticEngIT committed
119
        <QBEJoinDefinitionDialog v-if="joinDefinitionDialogVisible" :visible="joinDefinitionDialogVisible" :qbe="qbe" :propEntities="entities?.entities" :id="uniqueID" :selectedQuery="selectedQuery" @close="onJoinDefinitionDialogClose"></QBEJoinDefinitionDialog>
dbulatovicx32's avatar
dbulatovicx32 committed
120

121
122
123
124
125
126
127
128
129
130
131
132
133
        <KnCalculatedField
            v-if="calcFieldDialogVisible"
            v-model:template="selectedCalcField"
            v-model:visibility="calcFieldDialogVisible"
            :fields="calcFieldColumns"
            :descriptor="calcFieldDescriptor"
            :propCalcFieldFunctions="calcFieldFunctions"
            :readOnly="false"
            :valid="true"
            source="QBE"
            @save="onCalcFieldSave"
            @cancel="calcFieldDialogVisible = false"
        >
dbulatovicx32's avatar
dbulatovicx32 committed
134
135
136
137
138
139
140
141
142
143
            <template #additionalInputs>
                <div class="p-field" :class="[selectedCalcField.type === 'DATE' ? 'p-col-3' : 'p-col-4']">
                    <span class="p-float-label ">
                        <Dropdown id="type" class="kn-material-input" v-model="selectedCalcField.type" :options="qbeDescriptor.types" optionLabel="label" optionValue="name" />
                        <label for="type" class="kn-material-input-label"> {{ $t('components.knCalculatedField.type') }} </label>
                    </span>
                </div>
                <div v-if="selectedCalcField.type === 'DATE'" class="p-field p-col-3">
                    <span class="p-float-label ">
                        <Dropdown id="type" class="kn-material-input" v-model="selectedCalcField.format" :options="qbeDescriptor.admissibleDateFormats">
144
145
146
                            <template #value>
                                <span>{{ selectedCalcField.format ? moment().format(selectedCalcField.format) : '' }}</span>
                            </template>
dbulatovicx32's avatar
dbulatovicx32 committed
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
                            <template #option="slotProps">
                                <span>{{ moment().format(slotProps.option) }}</span>
                            </template>
                        </Dropdown>
                        <label for="type" class="kn-material-input-label"> {{ $t('managers.datasetManagement.ckanDateFormat') }} </label>
                    </span>
                </div>
                <div class="p-field" :class="[selectedCalcField.type === 'DATE' ? 'p-col-3' : 'p-col-4']">
                    <span class="p-float-label ">
                        <Dropdown id="columnType" class="kn-material-input" v-model="selectedCalcField.nature" :options="qbeDescriptor.columnTypes" optionLabel="label" optionValue="name" />
                        <label for="columnType" class="kn-material-input-label"> {{ $t('managers.functionsCatalog.columnType') }} </label>
                    </span>
                </div>
            </template>
        </KnCalculatedField>
BojanSovticEngIT's avatar
BojanSovticEngIT committed
162
163
164
165
166
167
168
169
170
171
172
173
174

        <Menu id="optionsMenu" ref="optionsMenu" :model="menuButtons" />
    </Dialog>
</template>

<script lang="ts">
import { AxiosResponse } from 'axios'
import { defineComponent } from 'vue'
import { downloadDirect } from '@/helpers/commons/fileHelper'
import { iQBE, iQuery, iField, iQueryResult, iFilter } from './QBE'
import { onFiltersSaveCallback } from './QBEFilterService'
import { formatDrivers } from './QBEDriversService'
import { onHavingsSaveCallback } from './QBEHavingsService'
175
import { buildCalculatedField } from '@/helpers/commons/buildQbeCalculatedField'
dbulatovicx32's avatar
dbulatovicx32 committed
176
import moment from 'moment'
BojanSovticEngIT's avatar
BojanSovticEngIT committed
177
import { removeInPlace } from './qbeDialogs/qbeAdvancedFilterDialog/treeService'
BojanSovticEngIT's avatar
BojanSovticEngIT committed
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import Dialog from 'primevue/dialog'
import Chip from 'primevue/chip'
import InputSwitch from 'primevue/inputswitch'
import QBEAdvancedFilterDialog from './qbeDialogs/qbeAdvancedFilterDialog/QBEAdvancedFilterDialog.vue'
import QBEFilterDialog from './qbeDialogs/qbeFilterDialog/QBEFilterDialog.vue'
import QBEHavingDialog from './qbeDialogs/qbeHavingDialog/QBEHavingDialog.vue'
import QBESimpleTable from './qbeTables/qbeSimpleTable/QBESimpleTable.vue'
import QBESqlDialog from './qbeDialogs/QBESqlDialog.vue'
import QBERelationDialog from './qbeDialogs/QBEEntityRelationDialog.vue'
import QBEParamDialog from './qbeDialogs/QBEParameterDialog.vue'
import QBESavingDialog from './qbeDialogs/qbeSavingDialog/QBESavingDialog.vue'
import QBESmartTable from './qbeTables/qbeSmartTable/QBESmartTable.vue'
import ExpandableEntity from '@/modules/qbe/qbeComponents/QBEExpandableEntity.vue'
import SubqueryEntity from '@/modules/qbe/qbeComponents/QBESubqueryEntity.vue'
import ScrollPanel from 'primevue/scrollpanel'
import Menu from 'primevue/contextmenu'
import QBEJoinDefinitionDialog from './qbeDialogs/qbeJoinDefinitionDialog/QBEJoinDefinitionDialog.vue'
import KnParameterSidebar from '@/components/UI/KnParameterSidebar/KnParameterSidebar.vue'
import QBEPreviewDialog from './qbeDialogs/qbePreviewDialog/QBEPreviewDialog.vue'
import qbeDescriptor from './QBEDescriptor.json'
dbulatovicx32's avatar
dbulatovicx32 committed
198
import ProgressSpinner from 'primevue/progressspinner'
199
200
import calcFieldDescriptor from './QBECalcFieldDescriptor.json'
import KnCalculatedField from '@/components/functionalities/KnCalculatedField/KnCalculatedField.vue'
dbulatovicx32's avatar
dbulatovicx32 committed
201
import Dropdown from 'primevue/dropdown'
202

BojanSovticEngIT's avatar
BojanSovticEngIT committed
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
const crypto = require('crypto')

export default defineComponent({
    name: 'qbe',
    components: {
        Dialog,
        Chip,
        InputSwitch,
        ScrollPanel,
        Menu,
        QBEFilterDialog,
        QBESavingDialog,
        QBESqlDialog,
        QBESimpleTable,
        QBERelationDialog,
        QBEParamDialog,
        ExpandableEntity,
        SubqueryEntity,
        QBEHavingDialog,
        QBEAdvancedFilterDialog,
        QBEJoinDefinitionDialog,
        KnParameterSidebar,
        QBEPreviewDialog,
226
        QBESmartTable,
227
        ProgressSpinner,
dbulatovicx32's avatar
dbulatovicx32 committed
228
229
        KnCalculatedField,
        Dropdown
BojanSovticEngIT's avatar
BojanSovticEngIT committed
230
231
232
233
234
    },
    props: { visible: { type: Boolean }, dataset: { type: Object } },
    emits: ['close'],
    data() {
        return {
dbulatovicx32's avatar
dbulatovicx32 committed
235
236
            moment,
            qbeDescriptor,
237
            calcFieldDescriptor,
BojanSovticEngIT's avatar
BojanSovticEngIT committed
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
            qbe: null as iQBE | null,
            customizedDatasetFunctions: {} as any,
            entities: {} as any,
            queryPreviewData: {} as iQueryResult,
            selectedQuery: {} as any,
            mainQuery: {} as any,
            loading: false,
            showEntitiesLists: true,
            smartView: true,
            hiddenColumnsExist: false,
            filterDialogVisible: false,
            sqlDialogVisible: false,
            paramDialogVisible: false,
            relationDialogVisible: false,
            savingDialogVisible: false,
            filterDialogData: {} as { field: iField; query: iQuery },
            showDerivedList: true,
            discardRepetitions: false,
            sqlData: {} as any,
            menuButtons: [] as any,
            relationEntity: {} as any,
            havingDialogVisible: false,
            havingDialogData: {} as { field: iField; query: iQuery },
            advancedFilterDialogVisible: false,
            joinDefinitionDialogVisible: false,
            parameterSidebarVisible: false,
            user: null as any,
            userRole: null,
            qbePreviewDialogVisible: false,
            pagination: { start: 0, limit: 25 } as any,
            uniqueID: null,
            filtersData: {} as any,
            qbeLoaded: false,
dbulatovicx32's avatar
dbulatovicx32 committed
271
            calcFieldDialogVisible: false,
272
            calcFieldColumns: [] as any,
dbulatovicx32's avatar
dbulatovicx32 committed
273
            selectedCalcField: null as any,
274
            calcFieldFunctions: [] as any,
275
            colors: ['#D7263D', '#F46036', '#2E294E', '#1B998B', '#C5D86D', '#3F51B5', '#8BC34A', '#009688', '#F44336']
BojanSovticEngIT's avatar
BojanSovticEngIT committed
276
277
278
279
280
281
282
283
284
285
286
287
        }
    },
    computed: {
        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
                }
            }
BojanSovticEngIT's avatar
BojanSovticEngIT committed
288
            return parameterVisible || this.qbe?.pars?.length !== 0
BojanSovticEngIT's avatar
BojanSovticEngIT committed
289
290
291
292
293
294
295
296
297
298
        }
    },
    watch: {
        async dataset() {
            await this.loadPage()
        }
    },
    async created() {
        this.uniqueID = crypto.randomBytes(16).toString('hex')
        this.user = (this.$store.state as any).user
BojanSovticEngIT's avatar
BojanSovticEngIT committed
299
        this.userRole = this.user.sessionRole && this.user.sessionRole !== this.$t('role.defaultRolePlaceholder') ? this.user.sessionRole : null
BojanSovticEngIT's avatar
BojanSovticEngIT committed
300
301
302
303
304
        if (this.userRole) {
            await this.loadPage()
        } else {
            this.parameterSidebarVisible = true
        }
BojanSovticEngIT's avatar
BojanSovticEngIT committed
305
306
307
308
309
310
311
312
313
314
315
    },
    methods: {
        async loadPage() {
            this.loading = true
            if (this.dataset && !this.dataset.dataSourceId) {
                await this.loadDataset()
            } else {
                this.qbe = this.getQBEFromModel()
            }
            this.loadQuery()
            await this.loadDatasetDrivers()
BojanSovticEngIT's avatar
BojanSovticEngIT committed
316
            if (this.qbe?.pars?.length === 0 && this.filtersData?.isReadyForExecution) {
BojanSovticEngIT's avatar
BojanSovticEngIT committed
317
318
                await this.loadQBE()
                this.qbeLoaded = true
BojanSovticEngIT's avatar
BojanSovticEngIT committed
319
            } else if (this.qbe?.pars?.length !== 0 || !this.filtersData?.isReadyForExecution) {
BojanSovticEngIT's avatar
BojanSovticEngIT committed
320
321
322
323
324
                this.parameterSidebarVisible = true
            }
            this.loading = false
        },
        async loadQBE() {
325
            this.loadCalcFieldFunctions()
BojanSovticEngIT's avatar
BojanSovticEngIT committed
326
327
328
329
330
            await this.initializeQBE()
            await this.loadCustomizedDatasetFunctions()
            await this.loadEntities()

            if (!this.dataset?.dataSourceLabel) {
331
                await this.executeQBEQuery(false)
BojanSovticEngIT's avatar
BojanSovticEngIT committed
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
            }
        },
        async loadDataset() {
            if (!this.dataset) {
                return
            }

            await this.$http.get(process.env.VUE_APP_RESTFUL_SERVICES_PATH + `1.0/datasets/${this.dataset.label}`).then((response: AxiosResponse<any>) => {
                this.qbe = response.data[0]
                if (this.qbe && this.qbe.qbeJSONQuery) this.qbe.qbeJSONQuery = JSON.parse(this.qbe.qbeJSONQuery)
            })
        },
        loadQuery() {
            this.mainQuery = this.qbe?.qbeJSONQuery?.catalogue?.queries[0]
            this.selectedQuery = this.qbe?.qbeJSONQuery?.catalogue?.queries[0]
        },
348
349
350
        loadCalcFieldFunctions() {
            this.calcFieldFunctions = calcFieldDescriptor.availableFunctions
        },
BojanSovticEngIT's avatar
BojanSovticEngIT committed
351
352
353
        getQBEFromModel() {
            if (!this.dataset) return {}

BojanSovticEngIT's avatar
BojanSovticEngIT committed
354
355
            this.smartView = this.dataset.smartView

BojanSovticEngIT's avatar
BojanSovticEngIT committed
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
            return {
                dsTypeCd: 'Qbe',
                qbeDatamarts: this.dataset.name,
                qbeDataSource: this.dataset.dataSourceLabel,
                qbeJSONQuery: {
                    catalogue: {
                        queries: [{ id: 'q1', name: 'Main', fields: [], distinct: false, filters: [], calendar: {}, expression: {}, isNestedExpression: false, havings: [], graph: [], relationRoles: [], subqueries: [] }]
                    }
                },
                meta: [],
                pars: [],
                scopeId: null,
                scopeCd: '',
                label: '',
                name: ''
            } as any
        },
        async loadDatasetDrivers() {
            if (!this.qbe) return
            const label = this.qbe.label ? this.qbe.label : this.qbe.qbeDatamarts
            const url = this.qbe.label ? `3.0/datasets/${label}/filters` : `1.0/businessmodel/${this.qbe.qbeDatamarts}/filters`

BojanSovticEngIT's avatar
BojanSovticEngIT committed
378
379
380
381
382
383
384
385
386
            await this.$http
                .post(process.env.VUE_APP_RESTFUL_SERVICES_PATH + url, { role: this.userRole })
                .then((response: AxiosResponse<any>) => {
                    this.filtersData = response.data
                    if (this.filtersData.filterStatus) {
                        this.filtersData.filterStatus = this.filtersData.filterStatus.filter((filter: any) => filter.id)
                    }
                })
                .catch(() => {})
BojanSovticEngIT's avatar
BojanSovticEngIT committed
387
388
389
390
391
392

            formatDrivers(this.filtersData)
        },
        async initializeQBE() {
            const label = this.dataset?.dataSourceLabel ? this.dataset.dataSourceLabel : this.qbe?.qbeDataSource
            const datamart = this.dataset?.dataSourceLabel ? this.dataset.name : this.qbe?.qbeDatamarts
BojanSovticEngIT's avatar
BojanSovticEngIT committed
393
394
            const temp = this.getFormattedParameters(this.filtersData)
            const drivers = encodeURI(JSON.stringify(temp))
BojanSovticEngIT's avatar
BojanSovticEngIT committed
395
396
            if (this.dataset) {
                await this.$http
BojanSovticEngIT's avatar
BojanSovticEngIT committed
397
                    .get(process.env.VUE_APP_QBE_PATH + `start-qbe?datamart=${datamart}&user_id=${this.user?.userUniqueIdentifier}&SBI_EXECUTION_ID=${this.uniqueID}&DATA_SOURCE_LABEL=${label}&drivers=${drivers}`)
BojanSovticEngIT's avatar
BojanSovticEngIT committed
398
399
400
401
                    .then(() => {})
                    .catch(() => {})
            }
        },
BojanSovticEngIT's avatar
BojanSovticEngIT committed
402
403
404
405
406
        getFormattedParameters(loadedParameters: { filterStatus: any[]; isReadyForExecution: boolean }) {
            let parameters = {} as any
            Object.keys(loadedParameters.filterStatus).forEach((key: any) => {
                const parameter = loadedParameters.filterStatus[key]
                if (!parameter.multivalue) {
407
                    parameters[parameter.urlName] = [{ value: parameter.parameterValue[0].value, description: parameter.parameterValue[0].description }]
BojanSovticEngIT's avatar
BojanSovticEngIT committed
408
                } else {
409
                    parameters[parameter.urlName] = [{ value: parameter.parameterValue?.map((el: any) => el.value), description: parameter.parameterDescription }]
BojanSovticEngIT's avatar
BojanSovticEngIT committed
410
411
412
413
                }
            })
            return parameters
        },
BojanSovticEngIT's avatar
BojanSovticEngIT committed
414
415
        async loadCustomizedDatasetFunctions() {
            const id = this.dataset?.dataSourceId ? this.dataset.dataSourceId : this.qbe?.qbeDataSourceId
416
417
418
419
420
421
422
423
424
            await this.$http.get(process.env.VUE_APP_RESTFUL_SERVICES_PATH + `2.0/configs/KNOWAGE.CUSTOMIZED_DATABASE_FUNCTIONS/${id}`).then((response: AxiosResponse<any>) => {
                this.customizedDatasetFunctions = response.data
                if (response.data.data && response.data.data.length > 0) {
                    let customFunctions = response.data.data.map((funct) => ({ category: 'CUSTOM', formula: funct.value, label: funct.label, name: funct.name, help: 'dataPreparation.custom' }))
                    customFunctions.forEach((funct) => {
                        this.calcFieldFunctions.push(funct)
                    })
                }
            })
BojanSovticEngIT's avatar
BojanSovticEngIT committed
425
426
427
428
429
        },
        async loadEntities() {
            const datamartName = this.dataset?.dataSourceId ? this.dataset.name : this.qbe?.qbeDatamarts
            await this.$http
                .get(`/knowageqbeengine/servlet/AdapterHTTP?ACTION_NAME=GET_TREE_ACTION&SBI_EXECUTION_ID=${this.uniqueID}&datamartName=${datamartName}`)
430
431
432
433
                .then((response: AxiosResponse<any>) => {
                    this.addExpandedProperty(response.data.entities)
                    this.entities = response.data
                })
BojanSovticEngIT's avatar
BojanSovticEngIT committed
434
435
                .catch((error: any) => console.log('ERROR: ', error))
        },
436
437
438
439
440
        addExpandedProperty(entities) {
            entities.forEach((entity) => {
                entity.expanded = false
            })
        },
441
        async executeQBEQuery(showPreview: boolean) {
BojanSovticEngIT's avatar
BojanSovticEngIT committed
442
443
444
445
            this.loading = true

            if (!this.qbe) return

BojanSovticEngIT's avatar
BojanSovticEngIT committed
446
            const postData = { catalogue: this.qbe?.qbeJSONQuery?.catalogue.queries, meta: this.formatQbeMeta(), pars: this.qbe?.pars, qbeJSONQuery: {}, schedulingCronLine: '0 * * * * ?' }
BojanSovticEngIT's avatar
BojanSovticEngIT committed
447
448
449
450
451
            await this.$http
                .post(process.env.VUE_APP_QBE_PATH + `qbequery/executeQuery/?SBI_EXECUTION_ID=${this.uniqueID}&currentQueryId=${this.selectedQuery.id}&start=${this.pagination.start}&limit=${this.pagination.limit}`, postData)
                .then((response: AxiosResponse<any>) => {
                    this.queryPreviewData = response.data
                    this.pagination.size = response.data.results
452
453
454
455
                    if (showPreview) this.qbePreviewDialogVisible = true
                })
                .catch(() => {
                    if (showPreview) this.qbePreviewDialogVisible = false
BojanSovticEngIT's avatar
BojanSovticEngIT committed
456
                })
dbulatovicx32's avatar
dbulatovicx32 committed
457
            this.selectedQuery.fields.forEach((field) => (field.uniqueID = crypto.randomBytes(4).toString('hex')))
BojanSovticEngIT's avatar
BojanSovticEngIT committed
458
459
460
461
462
            this.loading = false
        },
        async updatePagination(lazyParams: any) {
            this.pagination.start = lazyParams.paginationStart
            this.pagination.limit = lazyParams.paginationLimit
463
            await this.executeQBEQuery(false)
BojanSovticEngIT's avatar
BojanSovticEngIT committed
464
465
466
        },
        formatQbeMeta() {
            const meta = [] as any[]
BojanSovticEngIT's avatar
BojanSovticEngIT committed
467
            this.qbe?.qbeJSONQuery?.catalogue.queries?.forEach((query: iQuery) => {
BojanSovticEngIT's avatar
BojanSovticEngIT committed
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
                query.fields?.forEach((field: iField) => {
                    meta.push({ dataType: field.dataType, displayedName: field.alias, fieldType: field.fieldType.toUpperCase(), format: field.format, name: field.alias, type: field.type })
                })
            })
            return meta
        },
        toggleEntitiesLists() {
            this.showEntitiesLists = !this.showEntitiesLists
        },
        collapseDerivedList() {
            this.showDerivedList = !this.showDerivedList
        },
        deleteAllSelectedFields() {
            this.selectedQuery.fields = []
            this.selectedQuery.havings = []
483
            if (this.smartView) this.executeQBEQuery(false)
BojanSovticEngIT's avatar
BojanSovticEngIT committed
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
        },
        checkIfHiddenColumnsExist() {
            if (this.qbe) {
                this.hiddenColumnsExist = false
                for (let i = 0; i < this.selectedQuery.fields.length; i++) {
                    if (!this.selectedQuery.fields[i].visible) {
                        this.hiddenColumnsExist = true
                        break
                    }
                }
            }
        },
        showHiddenColumns() {
            this.selectedQuery.fields.forEach((field: iField) => (field.visible = true))
            if (this.smartView) {
                this.updateSmartView()
            }
            this.hiddenColumnsExist = false
        },
        openFilterDialog(field: iField) {
            this.filterDialogData = { field: field, query: this.selectedQuery }
            this.filterDialogVisible = true
        },
        openHavingDialog(payload: { field: iField; query: iQuery }) {
            this.havingDialogData = payload
            this.havingDialogVisible = true
        },
        onFiltersSave(filters: iFilter[], field: iField, parameters: any[], expression: any) {
            onFiltersSaveCallback(filters, field, parameters, expression, this.qbe, this.selectedQuery, this.smartView, this.executeQBEQuery)
            this.filterDialogVisible = false
        },
        onAdvancedFiltersSave(expression: any) {
            this.selectedQuery.expression = expression
            this.advancedFilterDialogVisible = false
BojanSovticEngIT's avatar
BojanSovticEngIT committed
518
            this.updateSmartView()
BojanSovticEngIT's avatar
BojanSovticEngIT committed
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
        },
        showMenu(event) {
            this.createMenuItems()
            // eslint-disable-next-line
            // @ts-ignore
            this.$refs.optionsMenu.toggle(event)
        },
        showRelationDialog(entity) {
            this.relationEntity = entity
            this.relationDialogVisible = true
        },
        showParamDialog() {
            this.paramDialogVisible = true
        },
        createMenuItems() {
            this.menuButtons = []
            let repetitionIcon = this.discardRepetitions ? 'fas fa-check' : 'fas fa-times'
            this.menuButtons.push(
                { key: '1', label: this.$t('qbe.detailView.toolbarMenu.sql'), command: () => this.showSQLQuery() },
                { key: '2', icon: repetitionIcon, label: this.$t('qbe.detailView.toolbarMenu.repetitions'), command: () => this.toggleDiscardRepetitions() },
                { key: '3', label: this.$t('common.parameters'), command: () => this.showParamDialog() },
dbulatovicx32's avatar
dbulatovicx32 committed
540
                { key: '4', label: this.$t('components.knCalculatedField.title'), visible: !this.smartView && this.selectedQuery.fields.length > 0, command: () => this.addCalcField() },
541
542
                { key: '5', label: this.$t('qbe.advancedFilters.advancedFilterVisualisation'), command: () => this.showAdvancedFilters() },
                { key: '6', label: this.$t('qbe.joinDefinitions.title'), command: () => this.showJoinDefinitions() },
BojanSovticEngIT's avatar
BojanSovticEngIT committed
543
                {
544
                    key: '7',
BojanSovticEngIT's avatar
BojanSovticEngIT committed
545
546
547
548
549
550
551
552
553
554
                    label: this.$t('qbe.detailView.toolbarMenu.exportTo'),
                    items: [
                        { label: 'CSV', command: () => this.exportQueryResults('csv') },
                        { label: 'XLSX', command: () => this.exportQueryResults('xlsx') }
                    ]
                }
            )
        },
        async exportQueryResults(mimeType) {
            var fileName = ''
dbulatovicx32's avatar
dbulatovicx32 committed
555
            mimeType == 'csv' ? (fileName = 'report.csv') : (fileName = 'report.xlsx')
dbulatovicx32's avatar
dbulatovicx32 committed
556

BojanSovticEngIT's avatar
BojanSovticEngIT committed
557
            const postData = { catalogue: this.qbe?.qbeJSONQuery?.catalogue.queries, meta: this.formatQbeMeta(), pars: this.qbe?.pars, qbeJSONQuery: {}, schedulingCronLine: '0 * * * * ?' }
BojanSovticEngIT's avatar
BojanSovticEngIT committed
558
            await this.$http
dbulatovicx32's avatar
dbulatovicx32 committed
559
                .post(process.env.VUE_APP_QBE_PATH + `qbequery/export/?SBI_EXECUTION_ID=${this.uniqueID}&currentQueryId=${this.selectedQuery.id}&outputType=${mimeType}`, postData, { headers: { Accept: 'application/json, text/plain, */*' }, responseType: 'blob' })
BojanSovticEngIT's avatar
BojanSovticEngIT committed
560
                .then((response: AxiosResponse<any>) => {
dbulatovicx32's avatar
dbulatovicx32 committed
561
                    downloadDirect(response.data, fileName, response.headers['content-type'])
BojanSovticEngIT's avatar
BojanSovticEngIT committed
562
563
564
565
566
567
568
                })
                .catch(() => {})
        },
        toggleDiscardRepetitions() {
            this.discardRepetitions = !this.discardRepetitions
            this.qbe ? (this.qbe.qbeJSONQuery.catalogue.queries[0].distinct = this.discardRepetitions) : ''
            if (this.smartView) {
569
                this.executeQBEQuery(false)
BojanSovticEngIT's avatar
BojanSovticEngIT committed
570
571
572
573
574
575
576
577
578
579
580
581
582
583
            }
        },
        onHavingsSave(havings: iFilter[]) {
            onHavingsSaveCallback(havings, this.qbe, this.selectedQuery)
            this.havingDialogVisible = false
        },
        onGroupingChanged(field: iField) {
            if (field.group && this.selectedQuery) {
                this.selectedQuery.havings = this.selectedQuery.havings.filter((having: any) => having.letOperandValue !== field.id)
            }
        },
        showAdvancedFilters() {
            this.advancedFilterDialogVisible = true
        },
584

BojanSovticEngIT's avatar
BojanSovticEngIT committed
585
586
587
588
589
590
        showJoinDefinitions() {
            this.joinDefinitionDialogVisible = true
        },
        onJoinDefinitionDialogClose() {
            this.joinDefinitionDialogVisible = false
            if (this.smartView) {
591
                this.executeQBEQuery(false)
BojanSovticEngIT's avatar
BojanSovticEngIT committed
592
593
594
595
596
597
598
            }
        },
        deleteAllFilters() {
            if (this.qbe) {
                this.selectedQuery.filters = []
                this.selectedQuery.havings = []
                this.selectedQuery.expression = {}
599
                if (this.smartView) this.executeQBEQuery(false)
BojanSovticEngIT's avatar
BojanSovticEngIT committed
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
            }
        },
        async showSQLQuery() {
            var item = {} as any
            item.catalogue = JSON.stringify(this.qbe?.qbeJSONQuery?.catalogue?.queries)
            item.currentQueryId = 'q1'
            item.ambiguousFieldsPaths = []
            item.ambiguousRoles = []
            item.pars = this.qbe?.pars

            let conf = {} as any
            conf.headers = { 'Content-Type': 'application/x-www-form-urlencoded' } as any
            conf.transformRequest = function(obj) {
                var str = [] as any
                for (var p in obj) str.push(encodeURIComponent(p) + '=' + encodeURIComponent(obj[p]))
                return str.join('&')
            }

            await this.$http
                .post(`/knowageqbeengine/servlet/AdapterHTTP?ACTION_NAME=SET_CATALOGUE_ACTION&SBI_EXECUTION_ID=${this.uniqueID}`, item, conf)
                .then(() => {
                    this.getSQL()
                })
                .catch((error) => {
                    this.$store.commit('setError', { title: this.$t('common.toast.error'), msg: error.errors[0].message })
                })
        },
        async getSQL() {
            var item = {} as any
            item.replaceParametersWithQuestion = true
            item.queryId = this.selectedQuery.id

            let conf = {} as any
            conf.headers = { 'Content-Type': 'application/x-www-form-urlencoded' } as any
            conf.transformRequest = function(obj) {
                var str = [] as any
                for (var p in obj) str.push(encodeURIComponent(p) + '=' + encodeURIComponent(obj[p]))
                return str.join('&')
            }

            await this.$http
                .post(`/knowageqbeengine/servlet/AdapterHTTP?ACTION_NAME=GET_SQL_QUERY_ACTION&SBI_EXECUTION_ID=${this.uniqueID}`, item, conf)
                .then((response: AxiosResponse<any>) => {
                    this.sqlData = response.data
                    this.sqlDialogVisible = true
                })
                .catch((error) => {
                    this.$store.commit('setError', { title: this.$t('common.toast.error'), msg: error.errors[0].message })
                })
        },
        onDropComplete(field) {
            if (field.connector) return
            if (field.children) {
                for (var i in field.children) {
                    this.addEntityToMainQuery(field.children[i])
                }
            } else {
                this.addEntityToMainQuery(field)
            }
            this.updateSmartView()
        },
        addEntityToMainQuery(field, isCalcField?) {
            let queryModel = this.selectedQuery.fields
            let editQueryObj = this.selectedQuery
            for (var i = 0; i < queryModel.length; i++) {
                if (queryModel != undefined && !this.smartView && queryModel.length > 0) {
                    editQueryObj.fields[i].group = queryModel[i].group
                    editQueryObj.fields[i].funct = queryModel[i].funct
                    editQueryObj.fields[i].visible = queryModel[i].visible
                    editQueryObj.fields[i].distinct = queryModel[i].distinct
                    editQueryObj.fields[i].iconCls = queryModel[i].visible
                    editQueryObj.fields[i].inUse = queryModel[i].inUse
                }
                editQueryObj.fields[i].alias = queryModel[i].alias
            }

            if (!isCalcField) {
                var newField = {
                    id: field.attributes.type === 'inLineCalculatedField' ? field.attributes.formState : field.id,
                    alias: field.attributes.field,
                    type: field.attributes.type === 'inLineCalculatedField' ? 'inline.calculated.field' : 'datamartField',
                    fieldType: field.attributes.iconCls,
                    entity: field.attributes.entity,
                    field: field.attributes.field,
                    funct: this.getFunct(field),
                    color: field.color,
                    group: this.getGroup(field),
                    order: 'NONE',
                    include: true,
                    // eslint-disable-next-line no-prototype-builtins
                    inUse: field.hasOwnProperty('inUse') ? field.inUse : true,
                    visible: true,
                    iconCls: field.iconCls,
                    dataType: field.dataType,
                    format: field.format,
                    longDescription: field.attributes.longDescription,
                    distinct: editQueryObj.distinct,
                    leaf: field.leaf
                } as any
            }
            // eslint-disable-next-line no-prototype-builtins
            if (!field.hasOwnProperty('id')) {
                newField.id = field.alias
                newField.alias = field.text
                newField.field = field.text
                newField.temporal = field.temporal
            }

            if (!isCalcField) {
                editQueryObj.fields.push(newField)
            }
        },
        getFunct(field) {
            if (this.isColumnType(field, 'measure') && field.aggtype) {
                return field.aggtype
            } else if (this.isColumnType(field, 'measure')) {
                return 'SUM'
            }
            return 'NONE'
        },
        getGroup(field) {
            return this.isColumnType(field, 'attribute') && !this.isDataType(field, 'com.vividsolutions.jts.geom.Geometry')
        },
        isDataType(field, dataType) {
            return field.dataType == dataType
        },
        isColumnType(field, columnType) {
            return field.iconCls == columnType || this.isCalculatedFieldColumnType(field, columnType)
        },
        isCalculatedFieldColumnType(inLineCalculatedField, columnType) {
            return this.isInLineCalculatedField(inLineCalculatedField) && inLineCalculatedField.attributes.formState.nature === columnType
        },
        isInLineCalculatedField(field) {
            return field.attributes.type === 'inLineCalculatedField'
        },
        selectSubquery(subquery) {
            this.selectedQuery = subquery
            this.updateSmartView()
        },
        selectMainQuery() {
            if (this.selectedQuery.fields.length < 1) {
                this.$store.commit('setInfo', { title: this.$t('common.toast.error'), msg: 'Sub entities must have one and one only field' })
            } else {
                this.selectedQuery = this.mainQuery
            }
            this.updateSmartView()
        },
        deleteSubquery(index, subquery) {
            subquery.id === this.selectedQuery.id ? (this.selectedQuery = this.mainQuery) : ''
            this.mainQuery.subqueries.splice(index, 1)
            this.updateSmartView()
        },
        createSubquery() {
            let newSubquery = { id: 'q' + this.createQueryName(), name: 'subentity-q' + this.createQueryName(), fields: [], distinct: false, filters: [], calendar: {}, expression: {}, isNestedExpression: false, havings: [], graph: [], relationRoles: [], subqueries: [] } as any
            this.mainQuery.subqueries.push(newSubquery)
            this.selectedQuery = newSubquery
            this.queryPreviewData = null as any
        },
        createQueryName() {
            var lastcount = 0
            var lastIndex = this.mainQuery.subqueries?.length - 1
BojanSovticEngIT's avatar
BojanSovticEngIT committed
761
            if (lastIndex != -1 && this.mainQuery.subqueries) {
BojanSovticEngIT's avatar
BojanSovticEngIT committed
762
763
764
765
766
767
768
769
770
771
                var lastQueryId = this.mainQuery.subqueries[lastIndex].id
                lastcount = parseInt(lastQueryId.substr(1))
            } else {
                lastcount = 1
            }
            return lastcount + 1
        },
        async onExecute(qbeParameters: any[]) {
            if (this.qbe) {
                this.qbe.pars = [...qbeParameters]
BojanSovticEngIT's avatar
BojanSovticEngIT committed
772
773
774
775
776
                if (this.dataset && !this.dataset.dataSourceId) {
                    await this.loadDataset()
                } else {
                    this.qbe = this.getQBEFromModel()
                }
BojanSovticEngIT's avatar
BojanSovticEngIT committed
777
                await this.loadQBE()
BojanSovticEngIT's avatar
BojanSovticEngIT committed
778
                this.loadQuery()
BojanSovticEngIT's avatar
BojanSovticEngIT committed
779
780
781
782
783
784
                this.qbeLoaded = true
                this.parameterSidebarVisible = false
            }
        },
        async openPreviewDialog() {
            this.pagination.limit = 20
785
            await this.executeQBEQuery(true)
BojanSovticEngIT's avatar
BojanSovticEngIT committed
786
787
        },
        updateSmartView() {
788
            this.smartView ? this.executeQBEQuery(false) : ''
BojanSovticEngIT's avatar
BojanSovticEngIT committed
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
        },
        smartViewFieldHidden() {
            this.checkIfHiddenColumnsExist()
            this.updateSmartView()
        },
        smartViewReorder(event) {
            var temp = this.selectedQuery.fields[event.dragIndex]
            this.selectedQuery.fields[event.dragIndex] = this.selectedQuery.fields[event.dropIndex]
            this.selectedQuery.fields[event.dropIndex] = temp
            this.updateSmartView()
        },
        closePreview() {
            this.qbePreviewDialogVisible = false
            this.pagination = { start: 0, limit: 25 }
        },
dbulatovicx32's avatar
dbulatovicx32 committed
804
805
806
807
808
        onQueryFieldRemoved(uniqueID) {
            let indexOfFieldToDelete = this.selectedQuery.fields.findIndex((field) => {
                return field.uniqueID === uniqueID
            })
            this.selectedQuery.fields.splice(indexOfFieldToDelete, 1)
BojanSovticEngIT's avatar
BojanSovticEngIT committed
809
            this.updateSmartView()
810
        },
dbulatovicx32's avatar
dbulatovicx32 committed
811
        addCalcField() {
812
            this.createCalcFieldColumns()
dbulatovicx32's avatar
dbulatovicx32 committed
813
814
            this.selectedCalcField = { alias: '', expression: '', format: undefined, nature: 'ATTRIBUTE', type: 'STRING' } as any
            this.calcFieldDialogVisible = true
815
816
817
818
        },
        createCalcFieldColumns() {
            this.calcFieldColumns = []
            this.selectedQuery.fields.forEach((field) => {
dbulatovicx32's avatar
dbulatovicx32 committed
819
                field.type != 'inline.calculated.field' ? this.calcFieldColumns.push({ fieldAlias: `$F{${field.alias}}`, fieldLabel: field.alias }) : ''
820
821
            })
        },
dbulatovicx32's avatar
dbulatovicx32 committed
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
        editCalcField(calcField, index) {
            this.createCalcFieldColumns()
            this.selectedCalcField = this.formatCalcFieldForComponent(calcField)
            this.selectedCalcField.index = index
            this.calcFieldDialogVisible = true
        },
        formatCalcFieldForComponent(calcField) {
            let formatField = {
                alias: calcField.id.alias,
                type: calcField.id.type,
                expression: calcField.id.expressionSimple,
                nature: calcField.id.nature,
                format: calcField.id.format
            } as any
            return formatField
837
        },
dbulatovicx32's avatar
dbulatovicx32 committed
838
839
840
841
        onCalcFieldSave(calcFieldOutput) {
            this.selectedCalcField.alias = calcFieldOutput.colName
            this.selectedCalcField.expression = calcFieldOutput.formula
            let calculatedField = buildCalculatedField(this.selectedCalcField, this.selectedQuery.fields)
842
            this.selectedCalcField.index || this.selectedCalcField.index === 0 ? this.selectedQuery.fields.splice(this.selectedCalcField.index, 1) : ''
843
844
845

            this.selectedQuery.fields.push(calculatedField)
            this.addEntityToMainQuery(calculatedField, true)
dbulatovicx32's avatar
dbulatovicx32 committed
846
            this.calcFieldDialogVisible = false
847
        },
BojanSovticEngIT's avatar
BojanSovticEngIT committed
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
        onParametersSave() {
            this.paramDialogVisible = false

            for (let i = this.selectedQuery.filters.length - 1; i >= 0; i--) {
                if (this.selectedQuery.filters[i].rightType === 'parameter') {
                    const index = this.qbe?.pars.findIndex((parameter: any) => parameter.name === this.selectedQuery.filters[i].paramName)
                    if (index === -1) {
                        removeInPlace(this.selectedQuery.expression, '$F{' + this.selectedQuery.filters[i].filterId + '}')
                        this.selectedQuery.filters.splice(index, 1)
                    }
                }
            }

            if (this.selectedQuery.expression.childNodes?.length === 0) this.selectedQuery.expression = {}
            this.updateSmartView()
BojanSovticEngIT's avatar
BojanSovticEngIT committed
863
864
865
866
867
        },
        async onRoleChange(role: string) {
            this.userRole = role as any
            this.filtersData = {}
            await this.loadPage()
BojanSovticEngIT's avatar
BojanSovticEngIT committed
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
        }
    }
})
</script>
<style lang="scss">
.full-screen-dialog.p-dialog {
    max-height: 100%;
    height: 100vh;
    width: calc(100vw - #{54px});
    margin: 0;
    .p-dialog-content {
        padding: 0;
        margin: 0;
        flex: 1;
        overflow: hidden;
    }
    .p-dialog-header {
        padding: 0;
        margin: 0;
    }
}
.qbe-detail-view {
    display: flex;
    flex-direction: column;
    flex: 3;
}
.derived-entities-toggle {
    height: 25%;
}
.qbe-scroll-panel .p-scrollpanel-content {
    padding: 0 !important;
}
.qbe-scroll-panel .p-scrollpanel-bar {
    background-color: #43749eb6;
    width: 5px;
}
</style>