WorkspaceAdvancedDataView.vue 20.9 KB
Newer Older
1
<template>
2
    <DataPreparationMonitoringDialog v-model:visibility="showMonitoring" @close="showMonitoring = false" @save="updateDatasetAndSave" :dataset="selectedDataset"></DataPreparationMonitoringDialog>
3
    <Toolbar class="kn-toolbar kn-toolbar--secondary">
4
        <template #start>
5
            {{ $t('workspace.advancedData.title') }}
6
        </template>
7
        <template #end>
8
9
            <Button v-if="toggleCardDisplay" icon="fas fa-list" class="p-button-text p-button-rounded p-button-plain" @click="toggleDisplayView" />
            <Button v-if="!toggleCardDisplay" icon="fas fa-th-large" class="p-button-text p-button-rounded p-button-plain" @click="toggleDisplayView" />
10
            <KnFabButton icon="fas fa-plus" data-test="new-folder-button" @click="showDataSetCatalog" />
11
12
13
        </template>
    </Toolbar>
    <ProgressBar mode="indeterminate" class="kn-progress-bar p-ml-2" v-if="loading" data-test="progress-bar" />
14
    <KnDatasetList :visibility="showDatasetList" :items="availableDatasets" @selected="newDataPrep" @save="goToDataPrep" @cancel="hideDataSetCatalog" />
15

16
17
18
19
    <div class="p-d-flex p-flex-row p-ai-center">
        <InputText class="kn-material-input p-m-2" :style="mainDescriptor.style.filterInput" v-model="searchWord" type="text" :placeholder="$t('common.search')" @input="searchItems" data-test="search-input" />
    </div>

20
    <div class="kn-overflow">
21
        <DataTable v-if="!toggleCardDisplay" class="p-datatable-sm kn-table p-mx-2" :value="preparedDatasets" :loading="loading" dataKey="objId" responsiveLayout="stack" breakpoint="600px" data-test="datasets-table">
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
            <template #empty>
                {{ $t('common.info.noDataFound') }}
            </template>
            <Column field="label" :header="$t('importExport.catalogFunction.column.label')" class="kn-truncated" :sortable="true" />
            <Column field="name" :header="$t('importExport.gallery.column.name')" class="kn-truncated" :sortable="true" />
            <Column field="tags" :header="$t('importExport.gallery.column.tags')" :sortable="true">
                <template #body="slotProps">
                    <span v-if="slotProps.data.tags.length > 0">
                        <Chip v-for="(tag, index) of slotProps.data.tags" :key="index"> {{ tag.name }} </Chip>
                    </span>
                </template>
            </Column>
            <Column :style="mainDescriptor.style.iconColumn">
                <template #header> &ensp; </template>
                <template #body="slotProps">
                    <Button icon="fas fa-ellipsis-v" class="p-button-link" @click.stop="showMenu($event, slotProps.data)" />
                    <Button icon="fas fa-info-circle" class="p-button-link" v-tooltip.left="$t('workspace.myModels.showInfo')" @click.stop="showSidebar(slotProps.data)" :data-test="'info-button-' + slotProps.data.name" />
                    <Button icon="fas fa-eye" class="p-button-link" @click.stop="previewDataset(slotProps.data)" />
                </template>
            </Column>
        </DataTable>
        <div v-if="toggleCardDisplay" class="p-grid p-m-2" data-test="card-container">
            <Message v-if="preparedDatasets.length === 0" class="kn-flex p-m-2" severity="info" :closable="false" :style="mainDescriptor.style.message">
                {{ $t('common.info.noDataFound') }}
            </Message>
            <template v-else>
                <WorkspaceCard
                    v-for="(dataset, index) of preparedDatasets"
                    :key="index"
                    :viewType="'dataset'"
                    :document="dataset"
                    @previewDataset="previewDataset"
                    @editFileDataset="editFileDataset"
                    @exportToXlsx="exportDataset($event, 'xls')"
                    @exportToCsv="exportDataset($event, 'csv')"
                    @shareDataset="shareDataset"
                    @cloneDataset="cloneDataset"
                    @deleteDataset="deleteDatasetConfirm"
                    @openDataPreparation="openDataPreparation"
                    @openSidebar="showSidebar"
62
                    @monitoring="showMonitoring = !showMonitoring"
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
                />
            </template>
        </div>
    </div>

    <DetailSidebar
        :visible="showDetailSidebar"
        :viewType="'dataset'"
        :document="selectedDataset"
        @previewDataset="previewDataset"
        @editFileDataset="editFileDataset"
        @exportToXlsx="exportDataset($event, 'xls')"
        @exportToCsv="exportDataset($event, 'csv')"
        @shareDataset="shareDataset"
        @cloneDataset="cloneDataset"
        @deleteDataset="deleteDatasetConfirm"
        @openDataPreparation="openDataPreparation"
        @close="showDetailSidebar = false"
81
        @monitoring="showMonitoring = !showMonitoring"
82
83
84
        data-test="detail-sidebar"
    />

85
86
    <Menu id="optionsMenu" ref="optionsMenu" :model="menuButtons" />
    <Menu id="creationMenu" ref="creationMenu" :model="creationMenuButtons" />
87
88
89

    <WorkspaceDataCloneDialog :visible="cloneDialogVisible" :propDataset="selectedDataset" @close="cloneDialogVisible = false" @clone="handleDatasetClone"></WorkspaceDataCloneDialog>
    <WorkspaceDataPreviewDialog :visible="previewDialogVisible" :propDataset="selectedDataset" @close="previewDialogVisible = false"></WorkspaceDataPreviewDialog>
Marco Balestri's avatar
Marco Balestri committed
90
    <WorkspaceWarningDialog :visible="warningDialogVisbile" :title="$t('workspace.advancedData.title')" :warningMessage="warningMessage" @close="closeWarningDialog"></WorkspaceWarningDialog>
91
92
</template>
<script lang="ts">
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
    import { defineComponent } from 'vue'
    import { filterDefault } from '@/helpers/commons/filterHelper'
    import KnFabButton from '@/components/UI/KnFabButton.vue'
    import mainDescriptor from '@/modules/workspace/WorkspaceDescriptor.json'
    import DetailSidebar from '@/modules/workspace/genericComponents/DetailSidebar.vue'
    import WorkspaceCard from '@/modules/workspace/genericComponents/WorkspaceCard.vue'
    import DataTable from 'primevue/datatable'
    import KnDatasetList from '@/components/functionalities/KnDatasetList/KnDatasetList.vue'
    import Column from 'primevue/column'
    import Chip from 'primevue/chip'
    import Menu from 'primevue/contextmenu'
    import { IDataset } from '@/modules/workspace/Workspace'
    import Message from 'primevue/message'
    import WorkspaceDataCloneDialog from '@/modules/workspace/views/dataView/dialogs/WorkspaceDataCloneDialog.vue'
    import WorkspaceDataPreviewDialog from '@/modules/workspace/views/dataView/dialogs/WorkspaceDataPreviewDialog.vue'
    import WorkspaceWarningDialog from '@/modules/workspace/genericComponents/WorkspaceWarningDialog.vue'
    import { AxiosResponse } from 'axios'
    import DataPreparationMonitoringDialog from '@/modules/workspace/dataPreparation/DataPreparationMonitoring/DataPreparationMonitoringDialog.vue'
111

112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
    export default defineComponent({
        components: { DataTable, KnDatasetList, Column, Chip, DataPreparationMonitoringDialog, DetailSidebar, WorkspaceCard, KnFabButton, WorkspaceDataCloneDialog, WorkspaceWarningDialog, WorkspaceDataPreviewDialog, Message, Menu },
        emits: ['toggleDisplayView'],
        props: { toggleCardDisplay: { type: Boolean } },
        computed: {
            isDatasetOwner(): any {
                return (this.$store.state as any).user.userId === this.selectedDataset.owner
            },
            canLoadData(): any {
                if (this.selectedDataset.actions) {
                    for (let i = 0; i < this.selectedDataset.actions.length; i++) {
                        const action = this.selectedDataset.actions[i]
                        if (action.name == 'loaddata') {
                            return true
                        }
127
128
                    }
                }
129
                return false
130
            }
131
        },
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
        data() {
            return {
                mainDescriptor,
                loading: false,
                showDetailSidebar: false,
                showDatasetList: false as Boolean,
                showDatasetDialog: false,
                datasetList: [] as Array<IDataset>,
                preparedDatasets: [] as any,
                availableDatasets: [] as any,
                selectedDataset: {} as any,
                selectedDsForDataPrep: {} as any,
                menuButtons: [] as any,
                creationMenuButtons: [] as any,
                filters: {
                    global: [filterDefault]
                } as Object,
                cloneDialogVisible: false,
                shareDialogVisible: false,
                previewDialogVisible: false,
                warningDialogVisbile: false,
                warningMessage: '',
                searchWord: '' as string,
                showMonitoring: false
            }
157
        },
158
159
        created() {
            this.getDatasets()
160
        },
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209

        methods: {
            async loadDataset(datasetLabel: string) {
                this.loading = true
                await this.$http
                    .get(process.env.VUE_APP_RESTFUL_SERVICES_PATH + `1.0/datasets/${datasetLabel}`)
                    .then((response: AxiosResponse<any>) => {
                        this.selectedDataset = response.data[0]
                    })
                    .catch(() => {})
                this.loading = false
            },
            toggleDisplayView() {
                this.$emit('toggleDisplayView')
            },
            newDataPrep(dataset) {
                this.selectedDsForDataPrep = dataset
            },
            showSidebar(clickedDataset) {
                this.selectedDataset = clickedDataset
                this.showDetailSidebar = true
            },
            hideDataSetCatalog() {
                this.showDatasetList = false
                this.selectedDsForDataPrep = {}
            },
            goToDataPrep() {
                this.$router.push({ name: 'data-preparation', params: { id: this.selectedDsForDataPrep.label } })
            },
            showDataSetCatalog() {
                this.$http.get(process.env.VUE_APP_RESTFUL_SERVICES_PATH + `3.0/datasets/for-dataprep`).then(
                    (response: AxiosResponse<any>) => {
                        this.availableDatasets = [...response.data.root]
                        this.showDatasetList = true
                    },
                    () => {
                        this.$store.commit('setError', { title: 'Error', msg: 'Cannot load dataset list' })
                    }
                )
            },
            showMenu(event, clickedDocument) {
                this.selectedDataset = clickedDocument
                this.createMenuItems(clickedDocument)
                // eslint-disable-next-line
                // @ts-ignore
                this.$refs.optionsMenu.toggle(event)
            },
            // prettier-ignore
            createMenuItems(clickedDocument: any) {
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
                let tmp = [] as any

                tmp.push(
                    { key: '0', label: this.$t('workspace.myData.xlsxExport'), icon: 'fas fa-file-excel', command: () => this.exportDataset(clickedDocument, 'xls'), visible: this.canLoadData && this.selectedDataset.dsTypeCd != 'File' },
                    { key: '1', label: this.$t('workspace.myData.csvExport'), icon: 'fas fa-file-csv', command: () => this.exportDataset(clickedDocument, 'csv'), visible: this.canLoadData && this.selectedDataset.dsTypeCd != 'File' },
                    { key: '4', label: this.$t('workspace.myData.deleteDataset'), icon: 'fas fa-trash', command: () => this.deleteDatasetConfirm(clickedDocument), visible: this.isDatasetOwner }
                )

                if ((this.$store.state as any).user?.functionalities.includes('DataPreparation')) {

                    tmp.push(
                        { key: '2', label: this.$t('workspace.myData.openDataPreparation'), icon: 'fas fa-cogs', command: () => this.openDataPreparation(clickedDocument), visible: true },
                        { key: '3', label: this.$t('workspace.myData.monitoring'), icon: 'pi pi-chart-line', command: () => this.handleMonitoring(clickedDocument), visible: true }
                    )
                }

                tmp = tmp.sort((a,b)=>a.key.localeCompare(b.key))
                this.menuButtons = tmp
228
229

        },
230
231
232
233
234
235
236
237
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
            createCreationMenuButtons() {
                this.creationMenuButtons = []
                this.creationMenuButtons.push({ key: '0', label: this.$t('workspace.myData.prepareData'), visible: true })
            },
            toggleDatasetDialog() {
                this.selectedDataset = {}
                this.showDatasetDialog = true
            },
            async previewDataset(dataset: any) {
                await this.loadDataset(dataset.label)
                this.previewDialogVisible = true
            },
            editFileDataset() {
                this.showDatasetDialog = true
            },
            handleMonitoring(dataset: any) {
                console.log(dataset)
                this.showMonitoring = !this.showMonitoring
            },
            openDataPreparation(dataset: any) {
                if (dataset.dsTypeCd == 'Prepared') {
                    this.$http.get(process.env.VUE_APP_RESTFUL_SERVICES_PATH + `3.0/datasets/advanced/${dataset.label}`).then(
                        (response: AxiosResponse<any>) => {
                            let instanceId = response.data.configuration.dataPrepInstanceId
                            this.$http.get(process.env.VUE_APP_DATA_PREPARATION_PATH + `1.0/process/by-instance-id/${instanceId}`).then(
                                (response: AxiosResponse<any>) => {
                                    let transformations = response.data.definition
                                    let datasetLabel = response.data.instance.dataSetLabel
                                    this.$router.push({ name: 'data-preparation', params: { id: datasetLabel, transformations: JSON.stringify(transformations) } })
                                },
                                () => {
                                    this.$store.commit('setError', { title: 'Save error', msg: 'Cannot create process' })
                                }
                            )
                        },
                        () => {
                            this.$store.commit('setError', {
                                title: 'Cannot open data preparation'
                            })
                        }
                    )
                } else {
                    this.$router.push({ name: 'data-preparation', params: { id: dataset.label } })
                }
            },
            async exportDataset(dataset: any, format: string) {
                this.loading = true
                //  { 'Content-Type': 'application/x-www-form-urlencoded' }
                await this.$http
                    .post(
                        process.env.VUE_APP_RESTFUL_SERVICES_PATH + `2.0/export/dataset/${dataset.id}/${format}`,
                        {},
                        {
                            headers: {
                                Accept: 'application/json, text/plain, */*',
                                'Content-Type': 'application/json;charset=UTF-8'
286
                            }
287
                        }
288
289
290
291
292
293
                    )
                    .then(() => {
                        this.$store.commit('setInfo', {
                            title: this.$t('common.toast.updateTitle'),
                            msg: this.$t('workspace.myData.exportSuccess')
                        })
294
                    })
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
                    .catch(() => {})
                this.loading = false
            },
            getFileType(type: string) {
                switch (type) {
                    case 'csv':
                        return 'text/csv'
                    case 'xls':
                        return 'application/vnd.ms-excel'
                    case 'xlsx':
                        return 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
                }
            },
            shareDataset() {
                this.shareDialogVisible = true
            },
            async handleDatasetShare(dataset: any) {
                this.loading = true
313

314
                const url = dataset.catTypeId ? `selfservicedataset/share/?catTypeId=${dataset.catTypeId}&id=${dataset.id}` : `selfservicedataset/share/?id=${dataset.id}`
315

316
317
318
319
320
321
322
323
324
325
                await this.$http
                    .post(process.env.VUE_APP_RESTFUL_SERVICES_PATH + url)
                    .then(() => {
                        this.$store.commit('setInfo', {
                            title: this.$t('common.toast.updateTitle'),
                            msg: this.$t('common.toast.success')
                        })
                        this.showDetailSidebar = false
                        this.shareDialogVisible = false
                        this.getDatasets()
326
                    })
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
                    .catch(() => {})
                this.loading = false
            },
            async cloneDataset(dataset: any) {
                await this.loadDataset(dataset.label)
                this.cloneDialogVisible = true
            },
            async handleDatasetClone(dataset: any) {
                await this.$http
                    .post(process.env.VUE_APP_RESTFUL_SERVICES_PATH + `1.0/datasets`, dataset, { headers: { 'X-Disable-Errors': 'true' } })
                    .then(() => {
                        this.$store.commit('setInfo', {
                            title: this.$t('common.toast.deleteTitle'),
                            msg: this.$t('common.toast.success')
                        })
                        this.showDetailSidebar = false
                        this.cloneDialogVisible = false
                        this.getDatasets()
345
                    })
346
347
348
                    .catch((response: any) => {
                        this.warningDialogVisbile = true
                        this.warningMessage = response
349
                    })
350
351
352
353
354
355
356
357
358
359
360
            },
            datasetPreparation(dataset: any) {
                this.$router.push({ name: 'data-preparation', params: { id: dataset.label } })
            },

            deleteDatasetConfirm(dataset: any) {
                this.$confirm.require({
                    message: this.$t('common.toast.deleteMessage'),
                    header: this.$t('common.toast.deleteTitle'),
                    icon: 'pi pi-exclamation-triangle',
                    accept: async () => await this.deleteDataset(dataset)
361
                })
362
363
364
365
366
367
368
369
370
371
372
373
            },
            async deleteDataset(dataset: any) {
                this.loading = true
                await this.$http
                    .delete(process.env.VUE_APP_RESTFUL_SERVICES_PATH + `1.0/datasets/${dataset.label}`)
                    .then(() => {
                        this.$store.commit('setInfo', {
                            title: this.$t('common.toast.deleteTitle'),
                            msg: this.$t('common.toast.success')
                        })
                        this.showDetailSidebar = false
                        this.getDatasets()
374
                    })
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
                    .catch(() => {})
                this.loading = false
            },
            closeWarningDialog() {
                this.warningMessage = ''
                this.warningDialogVisbile = false
            },
            async getDatasets() {
                this.loading = true
                this.searchWord = ''
                this.preparedDatasets = this.$http
                    .get(process.env.VUE_APP_RESTFUL_SERVICES_PATH + `3.0/datasets/advanced`)
                    .then((response: AxiosResponse<any>) => {
                        this.datasetList = [...response.data.root]
                        this.preparedDatasets = [...this.datasetList]
                    })
                    .finally(() => (this.loading = false))
            },
            searchItems() {
                setTimeout(() => {
                    if (!this.searchWord.trim().length) {
                        this.preparedDatasets = [...this.datasetList] as any[]
                    } else {
                        this.preparedDatasets = this.datasetList.filter((el: any) => {
                            return el.label?.toLowerCase().includes(this.searchWord.toLowerCase()) || el.name?.toLowerCase().includes(this.searchWord.toLowerCase()) || el.dsTypeCd?.toLowerCase().includes(this.searchWord.toLowerCase())
                        })
                    }
                }, 250)
            },
            async updateDatasetAndSave(newCron) {
                this.showMonitoring = false
406

407
408
409
410
411
412
413
414
415
                await this.$http.post(process.env.VUE_APP_DATA_PREPARATION_PATH + '1.0/process', newCron).then(
                    () => {
                        this.loadDataset(this.selectedDataset.label)
                    },
                    () => {
                        this.$store.commit('setError', { title: this.$t('common.error.saving'), msg: this.$t('managers.workspaceManagement.dataPreparation.errors.updatingSchedulation') })
                    }
                )
            }
416
        }
417
    })
418
</script>