WorkspaceAdvancedDataView.vue 21.3 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="openDataPreparation(selectedDsForDataPrep)" @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
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
126
127
128
                    }
                }
            }
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
            return false
        }
    },
    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,
            avroDatasets: [] as any,
            creationMenuButtons: [] as any,
            filters: {
                global: [filterDefault]
            } as Object,
            cloneDialogVisible: false,
            shareDialogVisible: false,
            previewDialogVisible: false,
            warningDialogVisbile: false,
            warningMessage: '',
            searchWord: '' as string,
            showMonitoring: false
        }
    },
    async created() {
        await this.getAllAvroDataSets()
        await this.getDatasets()
    },

    methods: {
165
        async loadDataset(datasetId: number) {
166
167
            this.loading = true
            await this.$http
168
                .get(process.env.VUE_APP_RESTFUL_SERVICES_PATH + `1.0/datasets/id/${datasetId}`)
169
170
171
172
173
                .then((response: AxiosResponse<any>) => {
                    this.selectedDataset = response.data[0]
                })
                .catch(() => {})
            this.loading = false
174
        },
175
176
        toggleDisplayView() {
            this.$emit('toggleDisplayView')
177
        },
178
179
        newDataPrep(dataset) {
            this.selectedDsForDataPrep = dataset
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
        showSidebar(clickedDataset) {
            this.selectedDataset = clickedDataset
            this.showDetailSidebar = true
        },
        hideDataSetCatalog() {
            this.showDatasetList = false
            this.selectedDsForDataPrep = {}
        },
        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) {
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
                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
227
228

        },
229
230
231
232
233
234
235
236
237
        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) {
238
            await this.loadDataset(dataset.id)
239
240
241
242
243
244
245
246
247
248
            this.previewDialogVisible = true
        },
        editFileDataset() {
            this.showDatasetDialog = true
        },
        handleMonitoring(dataset: any) {
            console.log(dataset)
            this.showMonitoring = !this.showMonitoring
        },
        openDataPreparation(dataset: any) {
249
250
            if (dataset.dsTypeCd == 'Prepared') {
                //edit existing data prep
251
                this.$http.get(process.env.VUE_APP_RESTFUL_SERVICES_PATH + `3.0/datasets/advanced/${dataset.id}`).then(
252
253
254
255
256
257
                    (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 processId = response.data.id
258
259
                                let datasetId = response.data.instance.dataSetId
                                if (this.isAvroReady(datasetId))
260
                                    // check if Avro file has been deleted or not
261
                                    this.$router.push({ name: 'data-preparation', params: { id: datasetId, transformations: JSON.stringify(transformations), processId: processId, instanceId: instanceId, dataset: JSON.stringify(dataset) } })
262
263
264
265
266
267
268
269
270
                                else {
                                    this.$store.commit('setInfo', {
                                        title: 'Avro file is missing',
                                        msg: 'Generate it again and then retry'
                                    })
                                }
                            },
                            () => {
                                this.$store.commit('setError', { title: 'Save error', msg: 'Cannot create process' })
271
                            }
272
273
274
275
276
277
278
279
                        )
                    },
                    () => {
                        this.$store.commit('setError', {
                            title: 'Cannot open data preparation'
                        })
                    }
                )
280
            } else if (this.isAvroReady(dataset.id)) {
281
                // original dataset already exported in Avro
282
                this.$router.push({ name: 'data-preparation', params: { id: dataset.id } })
283
284
285
286
287
288
            } else {
                this.$store.commit('setInfo', {
                    title: 'Avro file is missing',
                    msg: 'Generate it again and then retry'
                })
            }
289
        },
290
        isAvroReady(dsId: Number) {
291
            if (this.avroDatasets.indexOf(dsId) >= 0 || (dsId && this.avroDatasets.indexOf(dsId.toString())) >= 0) return true
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
            else return false
        },
        async getAllAvroDataSets() {
            await this.$http
                .get(process.env.VUE_APP_RESTFUL_SERVICES_PATH + `3.0/datasets/avro`)
                .then((response: AxiosResponse<any>) => {
                    this.avroDatasets = response.data
                })
                .catch(() => {})
        },
        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'
313
                        }
314
315
316
317
318
319
                    }
                )
                .then(() => {
                    this.$store.commit('setInfo', {
                        title: this.$t('common.toast.updateTitle'),
                        msg: this.$t('workspace.myData.exportSuccess')
320
                    })
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
                })
                .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
340

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

343
344
345
346
347
348
            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')
349
                    })
350
351
352
353
354
355
356
357
                    this.showDetailSidebar = false
                    this.shareDialogVisible = false
                    this.getDatasets()
                })
                .catch(() => {})
            this.loading = false
        },
        async cloneDataset(dataset: any) {
358
            await this.loadDataset(dataset.id)
359
360
361
362
363
364
365
366
367
            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')
368
                    })
369
370
371
372
373
374
375
                    this.showDetailSidebar = false
                    this.cloneDialogVisible = false
                    this.getDatasets()
                })
                .catch((response: any) => {
                    this.warningDialogVisbile = true
                    this.warningMessage = response
376
                })
377
378
        },
        datasetPreparation(dataset: any) {
379
            this.$router.push({ name: 'data-preparation', params: { id: dataset.id } })
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
        },

        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)
            })
        },
        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')
398
                    })
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
                    this.showDetailSidebar = false
                    this.getDatasets()
                })
                .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())
427
                    })
428
429
430
431
432
                }
            }, 250)
        },
        async updateDatasetAndSave(newConfig) {
            this.showMonitoring = false
433

434
            await this.$http.patch(process.env.VUE_APP_DATA_PREPARATION_PATH + '1.0/instance/' + newConfig.instanceId, { config: newConfig.config },{ headers: { Accept: 'application/json, */*'} }).then(
435
                () => {
436
                    this.loadDataset(this.selectedDataset.id)
437
438
439
440
441
                },
                () => {
                    this.$store.commit('setError', { title: this.$t('common.error.saving'), msg: this.$t('managers.workspaceManagement.dataPreparation.errors.updatingSchedulation') })
                }
            )
442
        }
443
444
    }
})
445
</script>