KnParameterSidebar.vue 40.9 KB
Newer Older
1
<template>
2
    <div id="kn-parameter-sidebar" :class="positionClass">
BojanSovticEngIT's avatar
BojanSovticEngIT committed
3
        <Toolbar v-if="mode !== 'workspaceView' && mode !== 'qbeView' && mode !== 'datasetManagement'" id="kn-parameter-sidebar-toolbar" class="kn-toolbar kn-toolbar--secondary">
4
            <template #start>
5
                <div id="kn-parameter-sidebar-toolbar-icons-container" class="p-d-flex p-flex-row p-jc-around">
6
7
8
                    <Button icon="fa fa-eraser" class="p-button-text p-button-rounded p-button-plain p-mx-2" v-tooltip.top="$t('documentExecution.main.resetParametersTooltip')" @click="resetAllParameters"></Button>
                    <Button icon="pi pi-pencil" class="p-button-text p-button-rounded p-button-plain p-mx-2" v-tooltip.top="$t('documentExecution.main.savedParametersTooltip')" @click="openSavedParametersDialog"></Button>
                    <Button icon="fas fa-save" class="p-button-text p-button-rounded p-button-plain p-mx-2" v-tooltip.top="$t('documentExecution.main.saveParametersFromStateTooltip')" @click="openSaveParameterDialog"></Button>
9
10
11
12
                </div>
            </template>
        </Toolbar>

13
        <div class="p-fluid kn-parameter-sidebar-content kn-alternated-rows">
BojanSovticEngIT's avatar
BojanSovticEngIT committed
14
            <div class="p-field p-my-1 p-p-2" v-if="user && (!sessionRole || sessionRole === $t('role.defaultRolePlaceholder'))">
15
16
17
18
19
20
                <div class="p-d-flex">
                    <label class="kn-material-input-label">{{ $t('common.roles') }}</label>
                </div>
                <Dropdown class="kn-material-input" v-model="role" :options="user.roles" @change="setNewSessionRole" />
            </div>

dbulatovicx32's avatar
dbulatovicx32 committed
21
            <template v-if="mode === 'qbeView' || mode === 'workspaceView' || mode === 'datasetManagement'">
BojanSovticEngIT's avatar
BojanSovticEngIT committed
22
23
24
                <div v-for="(qbeParameter, index) in qbeParameters" :key="index">
                    <div class="p-field p-m-4">
                        <div class="p-d-flex">
dbulatovicx32's avatar
dbulatovicx32 committed
25
                            <label class="kn-material-input-label">{{ qbeParameter.name }} <span v-if="mode !== 'datasetManagement'"> *</span> </label>
BojanSovticEngIT's avatar
BojanSovticEngIT committed
26
27
                            <i class="fa fa-eraser parameter-clear-icon kn-cursor-pointer" v-tooltip.left="$t('documentExecution.main.parameterClearTooltip')" @click="qbeParameter.value = qbeParameter.defaultValue"></i>
                        </div>
28
                        <Chips v-if="qbeParameter.multiValue" v-model="qbeParameter.value" />
29
                        <InputText
30
                            v-else
31
32
33
                            class="kn-material-input p-inputtext-sm"
                            v-model="qbeParameter.value"
                            :class="{
dbulatovicx32's avatar
dbulatovicx32 committed
34
                                'p-invalid': !qbeParameter.value && mode !== 'datasetManagement'
35
36
                            }"
                        />
BojanSovticEngIT's avatar
BojanSovticEngIT committed
37
38
39
40
                    </div>
                </div>
            </template>

41
42
            <template v-for="(parameter, index) in parameters.filterStatus" :key="index">
                <div class="p-field p-my-1 p-p-2" v-if="(parameter.type === 'STRING' || parameter.type === 'NUM') && !parameter.selectionType && parameter.valueSelection === 'man_in' && parameter.showOnPanel === 'true'">
43
                    <div class="p-d-flex">
BojanSovticEngIT's avatar
BojanSovticEngIT committed
44
                        <label class="kn-material-input-label" :class="{ 'p-text-italic': parameter.dependsOnParameters || parameter.lovDependsOnParameters }" :data-test="'parameter-input-label-' + parameter.id">{{ parameter.label }} {{ parameter.mandatory ? '*' : '' }}</label>
45
46
47
48
49
50
51
52
53
54
55
56
57
58
                        <i class="fa fa-eraser parameter-clear-icon kn-cursor-pointer" v-tooltip.left="$t('documentExecution.main.parameterClearTooltip')" @click="resetParameterValue(parameter)" :data-test="'parameter-input-clear-' + parameter.id"></i>
                    </div>
                    <InputText
                        v-if="parameter.parameterValue"
                        class="kn-material-input p-inputtext-sm"
                        :type="parameter.type === 'NUM' ? 'number' : 'text'"
                        v-model="parameter.parameterValue[0].value"
                        :class="{
                            'p-invalid': parameter.mandatory && parameter.parameterValue && !parameter.parameterValue[0]?.value
                        }"
                        @input="updateDependency(parameter)"
                        :data-test="'parameter-input-' + parameter.id"
                    />
                </div>
59
                <div class="p-field p-my-1 p-p-2" v-if="parameter.type === 'DATE' && !parameter.selectionType && parameter.valueSelection === 'man_in' && parameter.showOnPanel === 'true'">
60
                    <div class="p-d-flex">
BojanSovticEngIT's avatar
BojanSovticEngIT committed
61
                        <label class="kn-material-input-label" :class="{ 'p-text-italic': parameter.dependsOnParameters || parameter.lovDependsOnParameters }" :data-test="'parameter-date-label-' + parameter.id">{{ parameter.label }} {{ parameter.mandatory ? '*' : '' }}</label>
62
63
64
65
66
67
68
69
                        <i class="fa fa-eraser parameter-clear-icon kn-cursor-pointer" v-tooltip.left="$t('documentExecution.main.parameterClearTooltip')" @click="resetParameterValue(parameter)" :data-test="'parameter-date-clear-' + parameter.id"></i>
                    </div>
                    <Calendar
                        v-if="parameter.parameterValue"
                        v-model="parameter.parameterValue[0].value"
                        :showButtonBar="true"
                        :showIcon="true"
                        :manualInput="true"
70
71
                        class="kn-material-input custom-timepicker"
                        :class="{ 'p-invalid': parameter.mandatory && parameter.parameterValue && !parameter.parameterValue[0]?.value }"
72
73
74
75
76
                        @change="updateDependency(parameter)"
                        @date-select="updateDependency(parameter)"
                        :data-test="'parameter-date-input-' + parameter.id"
                    />
                </div>
77
                <div class="p-field p-my-1 p-p-2" v-if="parameter.selectionType === 'LIST' && parameter.showOnPanel === 'true'">
78
79
80
81
                    <div class="p-d-flex">
                        <label
                            class="kn-material-input-label"
                            :class="{
82
                                'kn-required-alert': parameter.mandatory && ((!parameter.multivalue && parameter.parameterValue && !parameter.parameterValue[0]?.value) || (parameter.multivalue && parameter.parameterValue && parameter.parameterValue.length === 0)),
BojanSovticEngIT's avatar
BojanSovticEngIT committed
83
                                'p-text-italic': parameter.dependsOnParameters || parameter.lovDependsOnParameters
84
85
86
87
88
89
                            }"
                            :data-test="'parameter-checkbox-label-' + parameter.id"
                            >{{ parameter.label }} {{ parameter.mandatory ? '*' : '' }}</label
                        >
                        <i class="fa fa-eraser parameter-clear-icon kn-cursor-pointer" v-tooltip.left="$t('documentExecution.main.parameterClearTooltip')" @click="resetParameterValue(parameter)" :data-test="'parameter-checkbox-clear-' + parameter.id"></i>
                    </div>
90
                    <ScrollPanel class="inputScrollPanel">
91
                        <div class="p-field-radiobutton" v-for="(option, index) in parameter.data" :key="index" :data-test="'parameter-list-' + parameter.id">
BojanSovticEngIT's avatar
BojanSovticEngIT committed
92
                            <RadioButton v-if="!parameter.multivalue && parameter.parameterValue" :value="option.value" v-model="parameter.parameterValue[0].value" @change="setRadioButtonValue(parameter)" />
93
                            <Checkbox v-if="parameter.multivalue && parameter.parameterValue" :value="option.value" v-model="selectedParameterCheckbox[parameter.id]" @change="setCheckboxValue(parameter)" />
94
                            <label>{{ option.description }}</label>
95
                        </div>
96
                    </ScrollPanel>
97
                </div>
98
                <div class="p-field p-my-1 p-p-2" v-if="parameter.selectionType === 'COMBOBOX' && parameter.showOnPanel === 'true'">
99
100
101
102
103
                    <div class="p-d-flex">
                        <label
                            class="kn-material-input-label"
                            :class="{
                                'kn-required-alert': parameter.mandatory && ((!parameter.multivalue && parameter.parameterValue && !parameter.parameterValue[0]?.value) || (parameter.multivalue && parameter.parameterValue.length === 0)),
BojanSovticEngIT's avatar
BojanSovticEngIT committed
104
                                'p-text-italic': parameter.dependsOnParameters || parameter.lovDependsOnParameters
105
106
107
108
109
                            }"
                            >{{ parameter.label }} {{ parameter.mandatory ? '*' : '' }}</label
                        >
                        <i class="fa fa-eraser parameter-clear-icon kn-cursor-pointer" v-tooltip.left="$t('documentExecution.main.parameterClearTooltip')" @click="resetParameterValue(parameter)"></i>
                    </div>
110
111
                    <Dropdown v-if="!parameter.multivalue && parameter.parameterValue" class="kn-material-input" v-model="parameter.parameterValue[0]" :options="parameter.data" optionLabel="description" @change="updateDependency(parameter)" />
                    <MultiSelect v-else v-model="parameter.parameterValue" :options="parameter.data" optionLabel="description" @change="updateDependency(parameter)" />
112
                </div>
113
                <div class="p-field p-my-1 p-p-2" v-if="parameter.selectionType === 'LOOKUP' && parameter.showOnPanel === 'true'">
114
115
116
117
118
                    <div class="p-d-flex">
                        <label
                            class="kn-material-input-label"
                            :class="{
                                'kn-required-alert': parameter.mandatory && ((!parameter.multivalue && parameter.parameterValue && !parameter.parameterValue[0]?.value) || (parameter.multivalue && parameter.parameterValue.length === 0)),
BojanSovticEngIT's avatar
BojanSovticEngIT committed
119
                                'p-text-italic': parameter.dependsOnParameters || parameter.lovDependsOnParameters
120
121
122
123
124
125
126
                            }"
                            >{{ parameter.label }} {{ parameter.mandatory ? '*' : '' }}</label
                        >
                        <i class="fa fa-eraser parameter-clear-icon kn-cursor-pointer" v-tooltip.left="$t('documentExecution.main.parameterClearTooltip')" @click="resetParameterValue(parameter)"></i>
                    </div>
                    <div class="p-d-flex p-flex-row">
                        <i class="pi pi-external-link kn-cursor-pointer p-mr-2" @click="openPopupDialog(parameter)"></i>
127
                        <ScrollPanel class="lookupScrollPanel">
BojanSovticEngIT's avatar
BojanSovticEngIT committed
128
                            <Chip class="parameterValueChip" v-for="(parameterValue, index) in parameter.parameterValue" :key="index">{{ parameterValue.description ?? parameterValue.value }}</Chip>
129
                        </ScrollPanel>
130
131
                    </div>
                </div>
132
                <div class="p-field p-my-1 p-p-2" v-if="parameter.selectionType === 'TREE' && parameter.showOnPanel === 'true'">
133
134
135
136
137
                    <div class="p-d-flex">
                        <label
                            class="kn-material-input-label"
                            :class="{
                                'kn-required-alert': parameter.mandatory && ((!parameter.multivalue && parameter.parameterValue && !parameter.parameterValue[0]?.value) || (parameter.multivalue && parameter.parameterValue.length === 0)),
BojanSovticEngIT's avatar
BojanSovticEngIT committed
138
                                'p-text-italic': parameter.dependsOnParameters || parameter.lovDependsOnParameters
139
140
141
142
143
144
145
146
                            }"
                            >{{ parameter.label }} {{ parameter.mandatory ? '*' : '' }}</label
                        >
                        <i class="fa fa-eraser parameter-clear-icon kn-cursor-pointer" v-tooltip.left="$t('documentExecution.main.parameterClearTooltip')" @click="resetParameterValue(parameter)"></i>
                    </div>
                    <div class="p-d-flex p-flex-row">
                        <i class="pi pi-external-link kn-cursor-pointer p-mr-2" @click="openTreeDialog(parameter)"></i>
                        <div>
BojanSovticEngIT's avatar
BojanSovticEngIT committed
147
                            <Chip v-for="(parameterValue, index) in parameter.parameterValue" :key="index">{{ parameterValue.description ?? parameterValue.value }}</Chip>
148
149
150
                        </div>
                    </div>
                </div>
151
            </template>
152
        </div>
153
        <div v-if="(parameters && parameters.filterStatus.length > 0) || mode === 'qbeView' || mode === 'workspaceView' || mode === 'datasetManagement'" class="p-fluid p-d-flex p-flex-row p-m-2 kn-parameter-sidebar-buttons">
BojanSovticEngIT's avatar
BojanSovticEngIT committed
154
155
            <Button class="kn-button kn-button--primary" :disabled="buttonsDisabled" @click="$emit('execute', qbeParameters)"> {{ $t('common.execute') }}</Button>
            <Button v-if="mode !== 'qbeView' && mode !== 'workspaceView'" class="kn-button kn-button--primary p-ml-1" icon="fa fa-chevron-down" :disabled="buttonsDisabled" @click="toggle($event)" />
156
157
            <Menu ref="executeButtonMenu" :model="executeMenuItems" :popup="true" />
        </div>
BojanSovticEngIT's avatar
BojanSovticEngIT committed
158
159
        <KnParameterPopupDialog v-if="popupDialogVisible" :visible="popupDialogVisible" :selectedParameter="selectedParameter" :propLoading="loading" :parameterPopUpData="parameterPopUpData" @close="popupDialogVisible = false" @save="onPopupSave"></KnParameterPopupDialog>
        <KnParameterTreeDialog v-if="treeDialogVisible" :visible="treeDialogVisible" :selectedParameter="selectedParameter" :formatedParameterValues="formatedParameterValues" :document="document" :mode="mode" @close="onTreeClose" @save="onTreeSave"></KnParameterTreeDialog>
160
161
162
163
164
        <KnParameterSaveDialog :visible="parameterSaveDialogVisible" :propLoading="loading" @close="parameterSaveDialogVisible = false" @saveViewpoint="saveViewpoint"></KnParameterSaveDialog>
        <KnParameterSavedParametersDialog :visible="savedParametersDialogVisible" :propViewpoints="viewpoints" @close="savedParametersDialogVisible = false" @fillForm="fillParameterForm" @executeViewpoint="executeViewpoint" @deleteViewpoint="deleteViewpoint"></KnParameterSavedParametersDialog>
    </div>
</template>
<script lang="ts">
165
166
167
168
169
170
import { defineComponent } from 'vue'
import { AxiosResponse } from 'axios'
import { formatDate } from '@/helpers/commons/localeHelper'
import { iDocument, iParameter, iAdmissibleValues } from './KnParameterSidebar'
import { setVisualDependency, updateVisualDependency } from './KnParameterSidebarVisualDependency'
import { setDataDependency, updateDataDependency } from './KnParameterSidebarDataDependency'
BojanSovticEngIT's avatar
BojanSovticEngIT committed
171
import { setLovsDependency, updateLovDependency } from './KnParameterSidebarLovsDependency'
172
173
import Calendar from 'primevue/calendar'
import Chip from 'primevue/chip'
174
import Chips from 'primevue/chips'
175
176
177
178
179
180
181
182
183
import Checkbox from 'primevue/checkbox'
import Dropdown from 'primevue/dropdown'
import KnParameterPopupDialog from './dialogs/KnParameterPopupDialog.vue'
import KnParameterTreeDialog from './dialogs/KnParameterTreeDialog.vue'
import KnParameterSaveDialog from './dialogs/KnParameterSaveDialog.vue'
import KnParameterSavedParametersDialog from './dialogs/KnParameterSavedParametersDialog.vue'
import Menu from 'primevue/menu'
import MultiSelect from 'primevue/multiselect'
import RadioButton from 'primevue/radiobutton'
184
import ScrollPanel from 'primevue/scrollpanel'
BojanSovticEngIT's avatar
BojanSovticEngIT committed
185

186
187
export default defineComponent({
    name: 'kn-parameter-sidebar',
188
    components: { Calendar, Chip, Chips, Checkbox, Dropdown, KnParameterPopupDialog, KnParameterTreeDialog, KnParameterSaveDialog, KnParameterSavedParametersDialog, Menu, MultiSelect, RadioButton, ScrollPanel },
189
    props: { filtersData: { type: Object }, propDocument: { type: Object }, userRole: { type: String }, propMode: { type: String }, propQBEParameters: { type: Array }, dateFormat: { type: String } },
BojanSovticEngIT's avatar
BojanSovticEngIT committed
190
    emits: ['execute', 'exportCSV', 'roleChanged', 'parametersChanged'],
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
    data() {
        return {
            document: null as iDocument | null,
            parameters: { isReadyForExecution: false, filterStatus: [] } as { filterStatus: iParameter[]; isReadyForExecution: boolean },
            executeMenuItems: [] as { label: string; command: Function }[],
            selectedParameterCheckbox: {} as any,
            popupDialogVisible: false,
            selectedParameter: null as iParameter | null,
            parameterPopUpData: null as iAdmissibleValues | null,
            treeDialogVisible: false,
            formatedParameterValues: null as any,
            parameterSaveDialogVisible: false,
            savedParametersDialogVisible: false,
            viewpoints: [],
            user: null as any,
            role: null as string | null,
            loading: false,
            updateVisualDependency,
BojanSovticEngIT's avatar
BojanSovticEngIT committed
209
210
            mode: 'execution',
            qbeParameters: [] as any,
211
212
            primary: true,
            userDateFormat: '' as string
213
214
215
216
217
218
        }
    },
    watch: {
        sessionRole() {
            this.role = ''
            this.parameters = { isReadyForExecution: false, filterStatus: [] }
219
        },
Davide Vernassa's avatar
Davide Vernassa committed
220
        filtersData() {
221
222
            this.loadDocument()
            this.loadParameters()
223
224
225
        },
        userRole() {
            this.role = this.userRole as string
BojanSovticEngIT's avatar
BojanSovticEngIT committed
226
227
228
229
230
231
        },
        propMode() {
            this.loadMode()
        },
        propQBEParameters() {
            this.loadQBEParameters()
232
233
234
        },
        dateFormat() {
            this.userDateFormat = this.dateFormat as string
235
236
237
238
239
240
241
242
        }
    },
    computed: {
        sessionRole(): string {
            return (this.$store.state as any).user.sessionRole
        },
        buttonsDisabled(): boolean {
            return this.requiredFiledMissing()
243
244
        },
        positionClass(): string {
245
            return this.document?.parametersRegion ? 'kn-parameter-sidebar-' + this.document.parametersRegion : 'kn-parameter-sidebar'
246
247
248
        }
    },
    created() {
BojanSovticEngIT's avatar
BojanSovticEngIT committed
249
        this.loadMode()
dbulatovicx32's avatar
dbulatovicx32 committed
250
        if (this.mode === 'qbeView' || this.mode === 'workspaceView' || this.mode === 'datasetManagement') this.loadQBEParameters()
BojanSovticEngIT's avatar
BojanSovticEngIT committed
251

252
253
254
255
        this.user = (this.$store.state as any).user
        this.role = this.userRole as string
        this.loadDocument()
        this.loadParameters()
256
        this.userDateFormat = this.dateFormat as string
257
258
    },
    methods: {
259
260
261
262
263
        applyFieldClass(cssClass: string): string {
            let cssCompleteClass = this.primary ? cssClass + ' fieldBackgroundColorPrimary' : cssClass + ' fieldBackgroundColorSecondary'
            this.primary = !this.primary
            return cssCompleteClass
        },
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
        setNewSessionRole() {
            this.$emit('roleChanged', this.role)
            this.parameters = { isReadyForExecution: false, filterStatus: [] }
        },
        loadDocument() {
            this.document = this.propDocument as iDocument
        },
        loadParameters() {
            this.parameters.isReadyForExecution = this.filtersData?.isReadyForExecution
            this.parameters.filterStatus = []
            this.filtersData?.filterStatus?.forEach((el: iParameter) => {
                if (el.selectionType == 'LIST' && el.showOnPanel == 'true' && el.multivalue) {
                    this.selectedParameterCheckbox[el.id] = el.parameterValue?.map((parameterValue: any) => parameterValue.value)
                }
                this.parameters.filterStatus.push(el)
            })
            this.parameters?.filterStatus.forEach((el: any) => setVisualDependency(this.parameters, el))
            this.parameters?.filterStatus.forEach((el: any) => setDataDependency(this.parameters, el))
BojanSovticEngIT's avatar
BojanSovticEngIT committed
282
            this.parameters?.filterStatus.forEach((el: any) => setLovsDependency(this.parameters, el))
283
284
            this.parameters?.filterStatus.forEach((el: any) => this.updateVisualDependency(el))
        },
Davide Vernassa's avatar
Davide Vernassa committed
285
286
287
288
289
290
291
292
293
294
295
296
297
298
        setDataDependency(parameter: iParameter) {
            if (parameter.dependencies.data.length !== 0) {
                parameter.dependencies.data.forEach((dependency: any) => {
                    const index = this.parameters.filterStatus.findIndex((param: any) => {
                        return param.urlName === dependency.parFatherUrlName
                    })
                    if (index !== -1) {
                        const tempParameter = this.parameters.filterStatus[index]
                        parameter.dataDependsOnParameters ? parameter.dataDependsOnParameters.push(tempParameter) : (parameter.dataDependsOnParameters = [tempParameter])
                        tempParameter.dataDependentParameters ? tempParameter.dataDependentParameters.push(parameter) : (tempParameter.dataDependentParameters = [parameter])
                    }
                })
            }
        },
299
300
        resetParameterValue(parameter: any) {
            if (!parameter.driverDefaultValue) {
301
302
303
304
305
306
                if (parameter.multivalue) {
                    parameter.parameterValue = []
                    this.selectedParameterCheckbox[parameter.id] = []
                } else {
                    parameter.parameterValue[0] = { value: '', description: '' }
                }
BojanSovticEngIT's avatar
BojanSovticEngIT committed
307
                this.parameters.filterStatus.forEach((el: any) => this.updateDependency(el))
308
309
                return
            }
310

311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
            const valueColumn = parameter.metadata.valueColumn
            const descriptionColumn = parameter.metadata.descriptionColumn
            let valueIndex = null as any
            if (parameter.metadata.colsMap) {
                valueIndex = Object.keys(parameter.metadata.colsMap).find((key: string) => parameter.metadata.colsMap[key] === valueColumn)
            }
            let descriptionIndex = null as any
            if (parameter.metadata.colsMap) {
                descriptionIndex = Object.keys(parameter.metadata.colsMap).find((key: string) => parameter.metadata.colsMap[key] === descriptionColumn)
            }
            if ((parameter.selectionType === 'LIST' || parameter.selectionType === 'COMBOBOX') && parameter.showOnPanel === 'true' && parameter.multivalue) {
                parameter.parameterValue = [] as { value: string; description: string }[]
                this.selectedParameterCheckbox[parameter.id] = []
                for (let i = 0; i < parameter.driverDefaultValue.length; i++) {
                    const temp = parameter.driverDefaultValue[i]
                    parameter.parameterValue.push({ value: valueIndex ? temp[valueIndex] : '', description: descriptionIndex ? temp[descriptionIndex] : '' })
                    if (valueIndex) {
                        this.selectedParameterCheckbox[parameter.id].push(temp[valueIndex])
329
                    }
330
                }
Davide Vernassa's avatar
Davide Vernassa committed
331
            } else if (parameter.selectionType === 'TREE' && parameter.showOnPanel === 'true' && parameter.multivalue) {
332
333
334
                parameter.parameterValue = parameter.driverDefaultValue?.map((el: { value: string; desc: string }) => {
                    return { value: el.value, description: el.desc }
                })
BojanSovticEngIT's avatar
BojanSovticEngIT committed
335
336
            } else if (parameter.selectionType === 'TREE' && parameter.showOnPanel === 'true' && !parameter.multivalue) {
                parameter.parameterValue[0] = { value: parameter.driverDefaultValue[0].value, description: parameter.driverDefaultValue[0].desc }
Davide Vernassa's avatar
Davide Vernassa committed
337
338
339
340
341
342
            } else if ((parameter.selectionType === 'COMBOBOX' || parameter.selectionType === 'LOOKUP') && parameter.showOnPanel === 'true' && !parameter.multivalue) {
                parameter.parameterValue[0] = { value: parameter.driverDefaultValue[0][valueIndex], description: parameter.driverDefaultValue[0][descriptionIndex] }
            } else if (parameter.selectionType === 'LOOKUP' && parameter.showOnPanel === 'true' && parameter.multivalue) {
                parameter.parameterValue = parameter.driverDefaultValue.map((el: any) => {
                    return { value: valueIndex ? el[valueIndex] : '', description: descriptionIndex ? el[descriptionIndex] : '' }
                })
BojanSovticEngIT's avatar
BojanSovticEngIT committed
343
            } else if (parameter.type === 'DATE' && parameter.showOnPanel === 'true') {
344
                if (parameter.driverDefaultValue[0].desc?.split('#')[0]) {
BojanSovticEngIT's avatar
BojanSovticEngIT committed
345
                    parameter.parameterValue[0].value = this.getFormattedDate(parameter.driverDefaultValue[0].desc?.split('#')[0], undefined)
BojanSovticEngIT's avatar
BojanSovticEngIT committed
346
                }
Davide Vernassa's avatar
Davide Vernassa committed
347
348
            } else {
                if (!parameter.parameterValue[0]) {
349
                    parameter.parameterValue[0] = { value: '', description: '' }
350
                }
351
352
                parameter.parameterValue[0].value = parameter.driverDefaultValue[0].value ?? parameter.driverDefaultValue[0][valueIndex]
            }
353
            this.parameters.filterStatus.forEach((el: any) => this.updateDependency(el))
354
355
356
        },
        resetAllParameters() {
            this.parameters.filterStatus.forEach((el: any) => this.resetParameterValue(el))
357
            this.parameters.filterStatus.forEach((el: any) => this.updateDependency(el))
358
359
360
361
362
363
364
365
366
367
368
        },
        toggle(event: Event) {
            this.createMenuItems()
            const menu = this.$refs.executeButtonMenu as any
            menu.toggle(event)
        },
        createMenuItems() {
            this.executeMenuItems = []
            this.executeMenuItems.push({ label: this.$t('common.exportCSV'), command: () => this.$emit('exportCSV') })
        },
        requiredFiledMissing() {
369
370
371
372
373
374
375
376
            if (this.mode === 'qbeView' || this.mode === 'workspaceView') {
                for (let i = 0; i < this.qbeParameters.length; i++) {
                    if (!this.qbeParameters[i].value) {
                        return true
                    }
                }
            }

377
378
379
380
381
382
383
384
385
386
            for (let i = 0; i < this.parameters.filterStatus.length; i++) {
                const parameter = this.parameters.filterStatus[i]
                if (parameter.mandatory && parameter.showOnPanel == 'true') {
                    if (!parameter.parameterValue || parameter.parameterValue.length === 0) {
                        return true
                    } else {
                        for (let i = 0; i < parameter.parameterValue.length; i++) {
                            if (!parameter.parameterValue[i].value) {
                                return true
                            }
387
388
                        }
                    }
Davide Vernassa's avatar
Davide Vernassa committed
389
390
391
392
                }
            }
            return false
        },
BojanSovticEngIT's avatar
BojanSovticEngIT committed
393
394
395
396
397
        setRadioButtonValue(parameter: iParameter) {
            const index = parameter.data?.findIndex((el: any) => el.value === parameter.parameterValue[0].value)
            if (index !== -1) parameter.parameterValue[0].description = parameter.data[index].description
            this.updateDependency(parameter)
        },
Davide Vernassa's avatar
Davide Vernassa committed
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
        setCheckboxValue(parameter: iParameter) {
            parameter.parameterValue = this.selectedParameterCheckbox[parameter.id].map((el: any) => {
                return { value: el, description: el }
            })
            this.updateDependency(parameter)
        },
        openPopupDialog(parameter: iParameter) {
            this.selectedParameter = parameter
            this.getParameterPopupInfo(parameter)
            this.popupDialogVisible = true
        },
        openTreeDialog(parameter: iParameter) {
            this.selectedParameter = parameter
            this.formatedParameterValues = this.getFormattedParameters()
            this.treeDialogVisible = true
        },
        onTreeClose() {
            this.selectedParameter = null
            this.formatedParameterValues = null
            this.treeDialogVisible = false
        },
        async getParameterPopupInfo(parameter: iParameter) {
            this.loading = true
            const postData = { label: this.document?.label, parameters: this.getFormattedParameters(), paramId: parameter.urlName, role: this.sessionRole }
BojanSovticEngIT's avatar
BojanSovticEngIT committed
422
423
424
425
426
427

            let url = '2.0/documentExeParameters/admissibleValues'
            if (this.mode !== 'execution' && this.document) {
                url = this.document.type === 'businessModel' ? `1.0/businessmodel/${this.document.name}/admissibleValues` : `/3.0/datasets/${this.document.label}/admissibleValues`
            }

Davide Vernassa's avatar
Davide Vernassa committed
428
            await this.$http
BojanSovticEngIT's avatar
BojanSovticEngIT committed
429
                .post(process.env.VUE_APP_RESTFUL_SERVICES_PATH + url, postData)
Davide Vernassa's avatar
Davide Vernassa committed
430
431
432
433
434
435
436
437
438
                .then((response: AxiosResponse<any>) => (this.parameterPopUpData = response.data))
                .catch((error: any) => console.log('ERROR: ', error))
            this.loading = false
        },
        getFormattedParameters() {
            let parameters = [] as any[]
            Object.keys(this.parameters.filterStatus).forEach((key: any) => {
                const parameter = this.parameters.filterStatus[key]
                if (!parameter.multivalue) {
BojanSovticEngIT's avatar
BojanSovticEngIT committed
439
                    parameters.push({ label: parameter.label, value: parameter.parameterValue[0].value, description: parameter.parameterValue[0].description ?? '' })
440
                } else {
BojanSovticEngIT's avatar
BojanSovticEngIT committed
441
                    parameters.push({ label: parameter.label, value: parameter.parameterValue?.map((el: any) => el.value), description: parameter.parameterDescription ?? '' })
442
                }
Davide Vernassa's avatar
Davide Vernassa committed
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
            })
            return parameters
        },
        getParameterValues() {
            let parameters = {} as any
            Object.keys(this.parameters.filterStatus).forEach((key: any) => {
                const parameter = this.parameters.filterStatus[key]
                if (parameter.type === 'DATE') {
                    parameters[parameter.urlName] = parameter.parameterValue[0].value
                    parameters[parameter.urlName + '_field_visible_description'] = 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
                    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 ? '' : ';'
462
                    }
Davide Vernassa's avatar
Davide Vernassa committed
463
                    parameters[parameter.urlName + '_field_visible_description'] = tempString
BojanSovticEngIT's avatar
BojanSovticEngIT committed
464
465
466
                } else {
                    parameters[parameter.urlName] = parameter.parameterValue[0].value
                    parameters[parameter.urlName + '_field_visible_description'] = parameter.parameterValue[0].description
467
                }
468
469
470
471
472
473
474
475
476
477
478
479
480
            })
            return parameters
        },
        onPopupSave(parameter: iParameter) {
            this.updateDependency(parameter)
            this.popupDialogVisible = false
        },
        onTreeSave(parameter: iParameter) {
            this.updateVisualDependency(parameter)
            this.treeDialogVisible = false
        },
        updateDependency(parameter: iParameter) {
            this.updateVisualDependency(parameter)
BojanSovticEngIT's avatar
BojanSovticEngIT committed
481
482
            updateDataDependency(this.parameters, parameter, this.loading, this.document, this.sessionRole, this.$http, this.mode)
            updateLovDependency(this.parameters, parameter, this.loading, this.document, this.sessionRole, this.$http, this.mode)
BojanSovticEngIT's avatar
BojanSovticEngIT committed
483
            this.$emit('parametersChanged', { parameters: this.parameters, document: this.propDocument })
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
        },
        openSaveParameterDialog() {
            this.parameterSaveDialogVisible = true
        },
        async saveViewpoint(viewpoint: any) {
            const postData = { ...viewpoint, OBJECT_LABEL: this.document?.label, ROLE: this.sessionRole, VIEWPOINT: this.getParameterValues() }
            this.loading = true
            await this.$http
                .post(process.env.VUE_APP_RESTFUL_SERVICES_PATH + `1.0/documentviewpoint/addViewpoint`, postData)
                .then(() => {
                    this.$store.commit('setInfo', {
                        title: this.$t('common.toast.createTitle'),
                        msg: this.$t('common.toast.success')
                    })
                    this.parameterSaveDialogVisible = false
499
                })
Davide Vernassa's avatar
Davide Vernassa committed
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
                .catch(() => {})
            this.loading = false
        },
        async openSavedParametersDialog() {
            this.loading = true
            await this.$http.get(process.env.VUE_APP_RESTFUL_SERVICES_PATH + `1.0/documentviewpoint/getViewpoints?label=${this.document?.label}&role=${this.sessionRole}`).then((response: AxiosResponse<any>) => {
                this.viewpoints = response.data.viewpoints
                this.savedParametersDialogVisible = true
            })
            this.loading = false
        },
        fillParameterForm(viewpoint: any) {
            const tempParameters = this.decodeViewpointPrameterValues(viewpoint.vpValueParams)
            Object.keys(tempParameters)?.forEach((key: any) => {
                const index = this.parameters.filterStatus.findIndex((el: any) => el.urlName === key)
                if (index !== -1) {
                    const parameter = this.parameters.filterStatus[index]
517
                    if (parameter.type === 'DATE') {
Davide Vernassa's avatar
Davide Vernassa committed
518
519
520
521
                        parameter.parameterValue[0].value = this.getFormattedDate(tempParameters[key], 'MM/DD/YYYY')
                    } else if ((parameter.valueSelection === 'man_in' || parameter.selectionType === 'COMBOBOX') && !parameter.multivalue) {
                        parameter.parameterValue[0].value = tempParameters[key]
                        parameter.parameterValue[0].description = tempParameters[key + '_field_visible_description']
522
                    } else if (parameter.selectionType === 'TREE' || parameter.selectionType === 'LOOKUP' || parameter.multivalue) {
Davide Vernassa's avatar
Davide Vernassa committed
523
524
525
526
527
                        const tempArrayValues = JSON.parse(tempParameters[key])
                        const tempArrayDescriptions = tempParameters[key + '_field_visible_description'].split(';')
                        parameter.parameterValue = []
                        for (let i = 0; i < tempArrayValues.length; i++) {
                            parameter.parameterValue[i] = { value: tempArrayValues[i], description: tempArrayDescriptions[i] ?? '' }
528
                        }
Davide Vernassa's avatar
Davide Vernassa committed
529
530
                        if (parameter.selectionType === 'LIST') {
                            this.selectedParameterCheckbox[parameter.id] = parameter.parameterValue?.map((parameterValue: any) => parameterValue.value)
531
                        }
BojanSovticEngIT's avatar
BojanSovticEngIT committed
532
533
534
                    } else {
                        parameter.parameterValue[0].value = tempParameters[key]
                        parameter.parameterValue[0].description = tempParameters[key + '_field_visible_description']
535
536
537
                    }
                }
                this.savedParametersDialogVisible = false
Davide Vernassa's avatar
Davide Vernassa committed
538
539
540
541
542
543
544
545
546
547
548
            })
        },
        getFormattedDate(date: any, format: any) {
            return formatDate(date, format)
        },
        decodeViewpointPrameterValues(string: string) {
            const parametersJson = {}
            const parameterArray = string.split('%26')
            for (let i = 0; i < parameterArray.length; i++) {
                const temp = parameterArray[i].split('%3D')
                parametersJson[temp[0]] = temp[1]
549
            }
Davide Vernassa's avatar
Davide Vernassa committed
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
            return parametersJson
        },
        executeViewpoint(viewpoint: any) {
            this.fillParameterForm(viewpoint)
            this.$emit('execute')
            this.savedParametersDialogVisible = false
        },
        async deleteViewpoint(viewpoint: any) {
            this.loading = true
            await this.$http
                .post(process.env.VUE_APP_RESTFUL_SERVICES_PATH + `1.0/documentviewpoint/deleteViewpoint`, { VIEWPOINT: '' + viewpoint.vpId })
                .then(async () => {
                    this.removeViewpoint(viewpoint)
                    this.$store.commit('setInfo', {
                        title: this.$t('common.toast.deleteTitle'),
                        msg: this.$t('common.toast.deleteSuccess')
                    })
                })
                .catch(() => {})
            this.loading = false
        },
        removeViewpoint(viewpoint: any) {
            const index = this.viewpoints.findIndex((el: any) => el.vpId === viewpoint.vpId)
            if (index !== -1) this.viewpoints.splice(index, 1)
BojanSovticEngIT's avatar
BojanSovticEngIT committed
574
575
576
577
578
579
580
        },
        loadMode() {
            this.mode = this.propMode ? this.propMode : 'execution'
        },
        loadQBEParameters() {
            this.qbeParameters = []
            this.propQBEParameters?.forEach((parameter: any) => {
581
582
583
                if (parameter.multiValue && parameter.defaultValue && !Array.isArray(parameter.defaultValue)) {
                    parameter.defaultValue = parameter.defaultValue?.split(',').map((el: any) => el.trim())
                }
BojanSovticEngIT's avatar
BojanSovticEngIT committed
584
585
586
                if (!parameter.value) parameter.value = parameter.defaultValue
                this.qbeParameters.push(parameter)
            })
587
        }
Davide Vernassa's avatar
Davide Vernassa committed
588
589
    }
})
590
591
</script>
<style lang="scss">
Davide Vernassa's avatar
Davide Vernassa committed
592
593
594
595
596
597
598
599
600
601
#kn-parameter-sidebar-toolbar .p-toolbar-group-left {
    width: 100%;
}
#kn-parameter-sidebar-toolbar-icons-container {
    width: 100%;
}
#kn-parameter-sidebar {
    z-index: 100;
    background-color: white;
    height: 100%;
602
    min-height: 0;
Davide Vernassa's avatar
Davide Vernassa committed
603
604
605
606
607
608
609
    width: 350px;
    position: absolute;
    top: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    font-size: 0.9rem;
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
    border-left: 1px solid var(--kn-color-borders);
    .kn-parameter-sidebar-content {
        min-height: 0;
        flex: 1;
        overflow: auto;
        position: relative;
        .p-field {
            label {
                padding: 4px 0;
            }
            display: flex;
            flex-direction: column;
            min-height: 70px;
            .inputScrollPanel {
                height: 150px;
            }
            .lookupScrollPanel {
                height: 50px;
            }
            .p-flex-row {
                min-height: 0;
                flex: 1;
            }
        }
    }
635
    &.kn-parameter-sidebar-west {
636
637
638
639
        right: unset;
        border-left: unset;
        border-right: 1px solid var(--kn-color-borders);
    }
640
    &.kn-parameter-sidebar-north {
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
        right: unset;
        border-left: unset;
        border-bottom: 1px solid var(--kn-color-borders);
        width: 100%;
        height: 200px;
        .kn-parameter-sidebar-content {
            display: flex;
            flex-direction: row;
            overflow-y: clip;
            .p-field {
                margin: 0 !important;
                min-width: 300px;
                max-width: 300px;
                .inputScrollPanel,
                .lookupScrollPanel {
                    height: 75px;
                }
                .p-flex-row,
                .p-flex-column {
                    overflow-y: auto;
                    overflow-x: clip;
                    max-height: 79px;
                }
            }
        }

        .kn-parameter-sidebar-buttons {
            justify-content: flex-end;
            .kn-button {
                width: auto;
            }
        }
    }
674
    &.kn-parameter-sidebar-south {
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
        right: unset;
        top: unset;
        bottom: 0;
        border-left: unset;
        border-top: 1px solid var(--kn-color-borders);
        width: 100%;
        height: 200px;
        .kn-parameter-sidebar-content {
            display: flex;
            flex-direction: row;
            overflow-y: clip;
            .p-field {
                margin: 0 !important;
                min-width: 300px;
                max-width: 300px;
                .inputScrollPanel,
                .lookupScrollPanel {
                    height: 75px;
                }
                .p-flex-row,
                .p-flex-column {
                    overflow-y: auto;
                    overflow-x: clip;
                    max-height: 79px;
                }
            }
        }
    }
    .parameter-clear-icon {
        margin-left: auto;
        line-height: 22px;
    }
    .p-calendar {
        background-color: transparent;
    }
    .p-field-radiobutton {
        font-size: 1rem;
        margin: 0.1rem;
        width: calc(100% - 3px);
714
        height: 15px;
715
        .p-radiobutton {
716
717
            width: 15px;
            height: 15px;
718
719
720
721
722
723
724
            .p-radiobutton-box {
                width: 15px;
                height: 15px;
                .p-radiobutton-icon {
                    width: 5px;
                    height: 5px;
                }
725
726
            }
        }
727
        .p-checkbox {
728
729
            width: 15px;
            height: 15px;
730
731
732
733
734
735
736
737
738
739
            .p-checkbox-box {
                width: 15px;
                height: 15px;
                .p-checkbox-icon {
                    width: 5px;
                    height: 5px;
                    &.pi-check::before {
                        top: 4px;
                        left: -1px;
                    }
740
741
742
743
                }
            }
        }
    }
744
745
746
747
748
    .p-dropdown {
        background-color: transparent;
        font-size: 0.9rem;
    }
    .p-inputtext {
749
        padding: 0.5rem 0.5rem;
750
751
752
753
754
755
756
757
        background-color: transparent;
        &.p-inputtext-sm {
            padding: 0.5rem 0.5rem;
        }
    }
    .parameterValueChip {
        font-size: 0.9rem;
        margin: 2px;
758
    }
Davide Vernassa's avatar
Davide Vernassa committed
759
}
760
</style>