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

17
18
19
20
21
    <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" />
        <SelectButton id="model-select-buttons" v-model="tableMode" :options="selectButtonOptions" @click="getDatasetsByFilter" data-test="dataset-select" />
    </div>

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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
    <div class="p-mx-2 kn-overflow">
        <DataTable v-if="!toggleCardDisplay" style="width:100%" class="p-datatable-sm kn-table" :value="preparedDatasets" :loading="loading" dataKey="objId" responsiveLayout="stack" breakpoint="600px" data-test="datasets-table">
            <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"
                    @openDatasetInQBE="openDatasetInQBE"
                    @exportToXlsx="exportDataset($event, 'xls')"
                    @exportToCsv="exportDataset($event, 'csv')"
                    @shareDataset="shareDataset"
                    @cloneDataset="cloneDataset"
                    @deleteDataset="deleteDatasetConfirm"
                    @openDataPreparation="openDataPreparation"
                    @openSidebar="showSidebar"
                />
            </template>
        </div>
    </div>

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

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

    <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
92
    <WorkspaceWarningDialog :visible="warningDialogVisbile" :title="$t('workspace.advancedData.title')" :warningMessage="warningMessage" @close="closeWarningDialog"></WorkspaceWarningDialog>
93
94
</template>
<script lang="ts">
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
    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'
113

114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
    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
                        }
129
130
                    }
                }
131
                return false
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
        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
            }
159
        },
160
161
        created() {
            this.getDatasets()
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
210
211

        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) {
212
213
            this.menuButtons = []
            this.menuButtons.push(
214
215
216
                { 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: '2', label: this.$t('workspace.myData.openDataPreparation'), icon: 'fas fa-cogs', command: () => this.openDataPreparation(clickedDocument), visible: this.isDatasetOwner },
217
218
                { key: '3', label: this.$t('workspace.myData.deleteDataset'), icon: 'fas fa-trash', command: () => this.deleteDatasetConfirm(clickedDocument), visible: this.isDatasetOwner },
                { key: '4', label: this.$t('workspace.myData.monitoring'), icon: 'pi pi-chart-line', command: () => this.handleMonitoring(clickedDocument), visible: this.isDatasetOwner }
219
220
221
            )

        },
222
223
224
225
226
227
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
            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.instances[0].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'
278
                            }
279
                        }
280
281
282
283
284
285
                    )
                    .then(() => {
                        this.$store.commit('setInfo', {
                            title: this.$t('common.toast.updateTitle'),
                            msg: this.$t('workspace.myData.exportSuccess')
                        })
286
                    })
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
                    .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
305

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

308
309
310
311
312
313
314
315
316
317
                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()
318
                    })
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
                    .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()
337
                    })
338
339
340
                    .catch((response: any) => {
                        this.warningDialogVisbile = true
                        this.warningMessage = response
341
                    })
342
343
344
345
346
347
348
349
350
351
352
            },
            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)
353
                })
354
355
356
357
358
359
360
361
362
363
364
365
            },
            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()
366
                    })
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
                    .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)
            }
396
        }
397
    })
398
</script>