DocumentBrowser.vue 12.4 KB
Newer Older
BojanSovticEngIT's avatar
BojanSovticEngIT committed
1
2
<template>
    <div class="kn-page">
3
        <div class="document-browser-tab-container kn-page-content">
4
            <TabView id="document-browser-tab-view" class="p-d-flex p-flex-column kn-flex kn-tab" v-model:activeIndex="activeIndex" @tab-change="onTabChange">
BojanSovticEngIT's avatar
BojanSovticEngIT committed
5
6
7
8
9
10
11
12
13
14
                <TabPanel>
                    <template #header>
                        <i class="fa fa-folder-open"></i>
                    </template>

                    <DocumentBrowserHome @itemSelected="onItemSelect($event)"></DocumentBrowserHome>
                </TabPanel>

                <TabPanel v-for="(tab, index) in tabs" :key="index">
                    <template #header>
BojanSovticEngIT's avatar
BojanSovticEngIT committed
15
                        <span>{{ getTabName(tab) }}</span>
BojanSovticEngIT's avatar
BojanSovticEngIT committed
16
17
18
                    </template>
                </TabPanel>
            </TabView>
19

BojanSovticEngIT's avatar
Update    
BojanSovticEngIT committed
20
            <DocumentBrowserTab
21
                v-show="selectedItem && selectedItem.mode"
BojanSovticEngIT's avatar
Update    
BojanSovticEngIT committed
22
23
24
25
26
27
28
29
                :item="selectedItem?.item"
                :mode="selectedItem?.mode"
                :functionalityId="selectedItem?.functionalityId"
                @close="closeDocument('current')"
                @iframeCreated="onIFrameCreated"
                @closeIframe="closeIframe"
                @documentSaved="onDocumentSaved"
            ></DocumentBrowserTab>
30
31
32
            <div v-for="(iframe, index) in iFrameContainers" :key="index">
                <iframe v-show="iframe.item?.routerId === selectedItem?.item.routerId" ref="iframe" class="document-browser-cockpit-iframe" :src="iframe.iframe"></iframe>
            </div>
BojanSovticEngIT's avatar
BojanSovticEngIT committed
33
34
35
36
37
38
39
40
41
42
            <div id="document-browser-tab-icon-container" v-if="activeIndex !== 0">
                <i id="document-browser-tab-icon" class="fa fa-times-circle" @click="toggle($event)"></i>
                <Menu ref="menu" :model="menuItems" :popup="true" />
            </div>
        </div>
    </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue'
BojanSovticEngIT's avatar
BojanSovticEngIT committed
43
import { AxiosResponse } from 'axios'
BojanSovticEngIT's avatar
BojanSovticEngIT committed
44
45
46
47
48
49
import DocumentBrowserHome from './documentBrowserHome/DocumentBrowserHome.vue'
import DocumentBrowserTab from './DocumentBrowserTab.vue'
import Menu from 'primevue/menu'
import TabView from 'primevue/tabview'
import TabPanel from 'primevue/tabpanel'

50
51
const crypto = require('crypto')

BojanSovticEngIT's avatar
BojanSovticEngIT committed
52
53
54
55
56
57
58
export default defineComponent({
    name: 'document-browser',
    components: { DocumentBrowserHome, DocumentBrowserTab, Menu, TabView, TabPanel },
    data() {
        return {
            tabs: [] as any[],
            activeIndex: 0,
59
60
            menuItems: [] as any[],
            selectedItem: null as any,
61
62
            id: 0,
            iFrameContainers: [] as any[]
BojanSovticEngIT's avatar
BojanSovticEngIT committed
63
64
        }
    },
BojanSovticEngIT's avatar
BojanSovticEngIT committed
65
    async created() {
66
        window.addEventListener('message', (event) => {
BojanSovticEngIT's avatar
Update    
BojanSovticEngIT committed
67
            if (event.data.type === 'saveCockpit' && this.$router.currentRoute.value.name === 'new-dashboard') {
68
69
70
71
                this.loadSavedCockpit(event.data.model)
            }
        })

BojanSovticEngIT's avatar
Update    
BojanSovticEngIT committed
72
        if (this.$router.currentRoute.value.params.id && (this.$router.currentRoute.value.name === 'document-browser-document-execution' || this.$router.currentRoute.value.name === 'document-browser-document-details-edit')) {
BojanSovticEngIT's avatar
BojanSovticEngIT committed
73
            let tempDocument = {} as any
BojanSovticEngIT's avatar
Update    
BojanSovticEngIT committed
74
75
76
77
78
            await this.$http.get(process.env.VUE_APP_RESTFUL_SERVICES_PATH + `2.0/documents/${this.$router.currentRoute.value.params.id}`).then((response: AxiosResponse<any>) => (tempDocument = response.data))
            const tempItem = {
                item: { name: tempDocument.name, label: this.$router.currentRoute.value.params.id, mode: this.$router.currentRoute.value.params.mode, routerId: crypto.randomBytes(16).toString('hex'), id: this.$router.currentRoute.value.params.id },
                mode: this.$router.currentRoute.value.name === 'document-browser-document-execution' ? 'execute' : 'documentDetail'
            }
79
80
            this.tabs.push(tempItem)

BojanSovticEngIT's avatar
BojanSovticEngIT committed
81
            this.activeIndex = 1
82
            this.selectedItem = tempItem
BojanSovticEngIT's avatar
BojanSovticEngIT committed
83
84
85
86
87
        }
    },
    methods: {
        onTabChange() {
            if (this.activeIndex === 0) {
88
                this.selectedItem = null
BojanSovticEngIT's avatar
BojanSovticEngIT committed
89
90
91
92
                this.$router.push('/document-browser')
                return
            }

93
94
95
96
            const id = this.tabs[this.activeIndex - 1].item ? this.tabs[this.activeIndex - 1].item.label : 'new-dashboard'

            this.selectedItem = this.tabs[this.activeIndex - 1]

BojanSovticEngIT's avatar
Routing    
BojanSovticEngIT committed
97
            if (this.selectedItem.mode === 'documentDetail') {
BojanSovticEngIT's avatar
Update    
BojanSovticEngIT committed
98
                const path = this.selectedItem.functionalityId ? `/document-browser/document-details/new/${this.selectedItem.functionalityId}` : `/document-browser/document-details/${this.selectedItem.item.id}`
BojanSovticEngIT's avatar
BojanSovticEngIT committed
99
                this.$router.push(path)
BojanSovticEngIT's avatar
Routing    
BojanSovticEngIT committed
100
101
102
103
            } else {
                let routeDocumentType = this.tabs[this.activeIndex - 1].item.mode ? this.tabs[this.activeIndex - 1].item.mode : this.getRouteDocumentType(this.tabs[this.activeIndex - 1].item)
                routeDocumentType ? this.$router.push(`/document-browser/${routeDocumentType}/` + id) : this.$router.push('/document-browser/new-dashboard')
            }
BojanSovticEngIT's avatar
BojanSovticEngIT committed
104
105
        },
        onItemSelect(payload: any) {
BojanSovticEngIT's avatar
BojanSovticEngIT committed
106
            if (payload.item) {
107
                payload.item.routerId = crypto.randomBytes(16).toString('hex')
BojanSovticEngIT's avatar
BojanSovticEngIT committed
108
            }
109
110

            const tempItem = { ...payload, item: { ...payload.item } }
BojanSovticEngIT's avatar
Routing    
BojanSovticEngIT committed
111
            if (payload.mode === 'documentDetail') tempItem.mode = 'documentDetail'
112
113
114
115
116

            this.tabs.push(tempItem)

            this.selectedItem = tempItem

BojanSovticEngIT's avatar
BojanSovticEngIT committed
117
118
119
120
121
122
            if (payload.mode === 'documentDetail') {
                const path = payload.functionalityId ? `/document-browser/document-details/new/${payload.functionalityId}` : `/document-browser/document-details/${payload.item.id}`
                this.$router.push(path)
            } else {
                const id = payload.item ? payload.item.label : 'new-dashboard'
                if (payload.item) {
BojanSovticEngIT's avatar
Routing    
BojanSovticEngIT committed
123
124
                    let routeDocumentType = this.getRouteDocumentType(payload.item)
                    this.$router.push(`/document-browser/${routeDocumentType}/` + id)
BojanSovticEngIT's avatar
BojanSovticEngIT committed
125
126
127
                } else {
                    this.selectedItem.item = { routerId: crypto.randomBytes(16).toString('hex') }
                    this.$router.push(`/document-browser/new-dashboard`)
BojanSovticEngIT's avatar
Routing    
BojanSovticEngIT committed
128
                }
BojanSovticEngIT's avatar
BojanSovticEngIT committed
129
            }
130

BojanSovticEngIT's avatar
BojanSovticEngIT committed
131
132
            this.activeIndex = this.tabs.length
        },
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
165
166
167
        getRouteDocumentType(item: any) {
            let routeDocumentType = ''

            switch (item.typeCode) {
                case 'DATAMART':
                    routeDocumentType = 'registry'
                    break
                case 'DOCUMENT_COMPOSITE':
                    routeDocumentType = 'document-composite'
                    break
                case 'OFFICE_DOC':
                    routeDocumentType = 'office-doc'
                    break
                case 'OLAP':
                    routeDocumentType = 'olap'
                    break
                case 'MAP':
                    routeDocumentType = 'map'
                    break
                case 'REPORT':
                    routeDocumentType = 'report'
                    break
                case 'KPI':
                    routeDocumentType = 'kpi'
                    break
                case 'DOSSIER':
                    routeDocumentType = 'dossier'
                    break
                case 'ETL':
                    routeDocumentType = 'etl'
                    break
            }

            return routeDocumentType
        },
BojanSovticEngIT's avatar
BojanSovticEngIT committed
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
        toggle(event: any) {
            this.createMenuItems()
            const menu = this.$refs.menu as any
            menu.toggle(event)
        },
        createMenuItems() {
            this.menuItems = []
            this.menuItems.push({ label: this.$t('documentBrowser.closeCurrentDocument'), command: () => this.closeDocumentConfirm('current') })
            this.menuItems.push({ label: this.$t('documentBrowser.closeOtherDocuments'), command: () => this.closeDocumentConfirm('other') })
            this.menuItems.push({ label: this.$t('documentBrowser.closeDocumentRight'), command: () => this.closeDocumentConfirm('right') })
            this.menuItems.push({ label: this.$t('documentBrowser.closeAllDocuments'), command: () => this.closeDocumentConfirm('all') })
        },
        closeDocumentConfirm(mode: string) {
            this.$confirm.require({
                message: this.$t('documentBrowser.closeDocumentConfirmMessage'),
                header: this.$t('documentBrowser.closeDocumentConfirmTitle', { numberOfDocuments: this.getNumberOfDocuments(mode) }),
                accept: () => this.closeDocument(mode)
            })
        },
        getNumberOfDocuments(mode: string) {
            switch (mode) {
                case 'current':
                    return 1
                case 'other':
                    return this.tabs.length - 1
                case 'right':
                    return this.tabs.length - this.activeIndex
                case 'all':
                    return this.tabs.length
            }
        },
        closeDocument(mode: string) {
200
            let index = -1
BojanSovticEngIT's avatar
BojanSovticEngIT committed
201
202
203
204
            switch (mode) {
                case 'current':
                    this.tabs.splice(this.activeIndex - 1, 1)
                    this.activeIndex = 0
205
206
                    index = this.iFrameContainers.findIndex((iframe: any) => iframe.item?.routerId === this.selectedItem?.item.routerId)
                    if (index !== -1) this.iFrameContainers.splice(index, 1)
BojanSovticEngIT's avatar
BojanSovticEngIT committed
207
208
209
210
211
                    this.$router.push('/document-browser')
                    break
                case 'other':
                    this.tabs = [this.tabs[this.activeIndex - 1]]
                    this.activeIndex = 1
212
                    this.iFrameContainers = this.iFrameContainers.filter((iframe: any) => iframe.item?.routerId === this.selectedItem?.item.routerId)
BojanSovticEngIT's avatar
BojanSovticEngIT committed
213
214
215
                    break
                case 'right':
                    this.tabs.splice(this.activeIndex)
216
217
                    index = this.iFrameContainers.findIndex((iframe: any) => iframe.item?.routerId === this.selectedItem?.item.routerId)
                    if (index !== -1) this.iFrameContainers.splice(index + 1)
BojanSovticEngIT's avatar
BojanSovticEngIT committed
218
219
220
221
222
                    break
                case 'all':
                    this.$router.push('/document-browser')
                    this.tabs = []
                    this.activeIndex = 0
223
                    this.iFrameContainers = []
BojanSovticEngIT's avatar
BojanSovticEngIT committed
224
            }
225
226
227
228
229
230
231
232
233
234
235
236
237
238
        },
        onIFrameCreated(payload: any) {
            const index = this.iFrameContainers.findIndex((iframe: any) => iframe.item?.routerId === this.selectedItem?.item.routerId)
            if (index === -1) this.iFrameContainers.push(payload)
        },
        closeIframe() {
            const index = this.iFrameContainers.findIndex((iframe: any) => iframe.item?.routerId === this.selectedItem?.item.routerId)
            if (index !== -1) this.iFrameContainers.splice(index, 1)
        },
        loadSavedCockpit(cockpit: any) {
            this.closeIframe()
            this.selectedItem = { item: { ...cockpit, routerId: crypto.randomBytes(16).toString('hex'), name: cockpit.DOCUMENT_NAME, label: cockpit.DOCUMENT_LABEL, mode: 'document-composite' } }
            this.tabs[this.activeIndex - 1] = this.selectedItem
            this.$router.push(`/document-browser/document-composite/${cockpit.DOCUMENT_LABEL}`)
BojanSovticEngIT's avatar
BojanSovticEngIT committed
239
240
241
242
243
244
245
        },
        getTabName(tab: any) {
            if (tab.item && tab.item.name) {
                return tab.item.name
            } else {
                return tab.mode === 'documentDetail' ? 'new document' : 'new dashboard'
            }
BojanSovticEngIT's avatar
Update    
BojanSovticEngIT committed
246
247
        },
        onDocumentSaved(document: any) {
BojanSovticEngIT's avatar
Update    
BojanSovticEngIT committed
248
            this.selectedItem.functionalityId = null
BojanSovticEngIT's avatar
Fix    
BojanSovticEngIT committed
249
            this.selectedItem.item = { name: document.name, label: document.id, routerId: crypto.randomBytes(16).toString('hex'), id: document.id }
BojanSovticEngIT's avatar
Update    
BojanSovticEngIT committed
250
            this.$router.push(`/document-browser/document-details/${document.id}`)
BojanSovticEngIT's avatar
BojanSovticEngIT committed
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
        }
    }
})
</script>

<style lang="scss">
#document-browser-tab-view .p-tabview-panels {
    padding: 0;
}

#document-browser-tab-icon-container {
    position: absolute;
    top: 0.8rem;
    right: 2rem;
}

#document-browser-tab-icon {
    font-size: 1.2rem;
    color: rgba(0, 0, 0, 0.6);
    cursor: pointer;
}

273
274
.document-browser-tab-container {
    position: relative;
275
    display: flex;
276
    flex-direction: column;
277
278
}

BojanSovticEngIT's avatar
BojanSovticEngIT committed
279
280
281
282
283
284
.document-browser-tab-container .p-tabview .p-tabview-panel,
.document-browser-tab-container .p-tabview .p-tabview-panels {
    display: flex;
    flex-direction: column;
    flex: 1;
}
285
286
287
288
289
290
291
292

.document-browser-cockpit-iframe {
    position: absolute;
    top: 39px;
    width: 100%;
    height: calc(100% - 39px);
    border: none;
}
BojanSovticEngIT's avatar
BojanSovticEngIT committed
293
</style>