Skip to content

Commit bc17c03

Browse files
committed
[KNOWAGE-9888] enhance import documents summary information
1 parent c8f98e2 commit bc17c03

1 file changed

Lines changed: 129 additions & 10 deletions

File tree

src/modules/managers/importExportDocuments/importDialog/ImportDocumentsDialog.vue

Lines changed: 129 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@
175175
</div>
176176
<ul class="summary-list p-mt-0">
177177
<li v-for="(doc, index) in importData.summary.toCreateObjects.documents" :key="'new-doc-' + index" class="p-p-2">
178-
{{ doc }}
178+
<div class="summary-item-detail"><b>{{ $t('common.label') }}:</b> {{ getDocumentSummaryLabel(doc, 'new', index) }}</div>
179+
<div class="summary-item-detail"><b>{{ $t('common.name') }}:</b> {{ getDocumentSummaryName(doc, 'new', index) }}</div>
179180
</li>
180181
</ul>
181182
</div>
@@ -187,7 +188,8 @@
187188
</div>
188189
<ul class="summary-list p-mt-0">
189190
<li v-for="(doc, index) in importData.summary.existingObjects.documents" :key="'exist-doc-' + index" class="p-p-2">
190-
{{ doc }}
191+
<div class="summary-item-detail"><b>{{ $t('common.label') }}:</b> {{ getDocumentSummaryLabel(doc, 'existing', index) }}</div>
192+
<div class="summary-item-detail"><b>{{ $t('common.name') }}:</b> {{ getDocumentSummaryName(doc, 'existing', index) }}</div>
191193
</li>
192194
</ul>
193195
</div>
@@ -299,7 +301,8 @@
299301
</div>
300302
<ul class="summary-list p-mt-0">
301303
<li v-for="(func, index) in importData.summary.toCreateObjects.functionalities" :key="'new-func-' + index" class="p-p-2">
302-
{{ func }}
304+
<div v-if="getFunctionalitySummaryName(func, 'new', index)" class="summary-item-detail"><b>{{ $t('common.name') }}:</b> {{ getFunctionalitySummaryName(func, 'new', index) }}</div>
305+
<div class="summary-item-detail"><b>{{ $t('common.path') }}:</b> {{ getFunctionalitySummaryPath(func, 'new', index) }}</div>
303306
</li>
304307
</ul>
305308
</div>
@@ -311,7 +314,8 @@
311314
</div>
312315
<ul class="summary-list p-mt-0">
313316
<li v-for="(func, index) in importData.summary.existingObjects.functionalities" :key="'exist-func-' + index" class="p-p-2">
314-
{{ func }}
317+
<div v-if="getFunctionalitySummaryName(func, 'existing', index)" class="summary-item-detail"><b>{{ $t('common.name') }}:</b> {{ getFunctionalitySummaryName(func, 'existing', index) }}</div>
318+
<div class="summary-item-detail"><b>{{ $t('common.path') }}:</b> {{ getFunctionalitySummaryPath(func, 'existing', index) }}</div>
315319
</li>
316320
</ul>
317321
</div>
@@ -361,6 +365,16 @@
361365
</template>
362366
</q-stepper>
363367
</Dialog>
368+
<Dialog :visible="warningDialogVisible" :modal="true" class="p-fluid kn-dialog--toolbar--primary import-docs-warning-dialog" :header="$t('common.warning')" :closable="false">
369+
<div class="warning-dialog-content">
370+
<Message v-for="(warning, index) in warningMessages" :key="'import-warning-' + index" class="p-mb-2" severity="warn" :closable="false">
371+
{{ warning }}
372+
</Message>
373+
</div>
374+
<template #footer>
375+
<Button class="kn-button kn-button--primary" :label="$t('common.ok')" @click="confirmWarnings" />
376+
</template>
377+
</Dialog>
364378
</template>
365379

366380
<script lang="ts">
@@ -370,10 +384,11 @@ import mainStore from '../../../../App.store'
370384
import Dialog from 'primevue/dialog'
371385
import { AxiosResponse } from 'axios'
372386
import Dropdown from 'primevue/dropdown'
387+
import Message from 'primevue/message'
373388
374389
export default defineComponent({
375390
name: 'import-dialog',
376-
components: { FileUpload, Dialog, Dropdown },
391+
components: { FileUpload, Dialog, Dropdown, Message },
377392
props: {},
378393
emits: ['close', 'import'],
379394
setup() {
@@ -390,7 +405,9 @@ export default defineComponent({
390405
importData: {} as any,
391406
// server side import errors (returned in upload response)
392407
// example: { service: "", errors: [{ message: "..." }] }
393-
importErrors: [] as any[]
408+
importErrors: [] as any[],
409+
warningDialogVisible: false,
410+
warningMessages: [] as string[]
394411
}
395412
},
396413
computed: {
@@ -435,6 +452,12 @@ export default defineComponent({
435452
closeDialog() {
436453
this.$emit('close')
437454
},
455+
confirmWarnings() {
456+
this.warningDialogVisible = false
457+
this.warningMessages = []
458+
this.store.setInfo({ title: this.$t('managers.importExportDocs.importComplete'), msg: `${this.importData.logFileName}` })
459+
this.closeDialog()
460+
},
438461
emitImport(): void {
439462
this.$emit('import', { files: this.uploadedFiles })
440463
},
@@ -652,10 +675,10 @@ export default defineComponent({
652675
this.importData.logFileName = response.data.logFileName
653676
this.importData.folderName = response.data.folderName
654677
655-
if (response.data?.warnings?.length > 0) {
656-
response.data.warnings.forEach((i) => {
657-
this.store.setWarning({ title: this.$t('managers.importExportDocs.importComplete'), msg: `${this.$t(i.MESSAGE, { count: i.PARAMETERS?.length || 1, parameters: i.PARAMETERS?.toString() })}` })
658-
})
678+
this.warningMessages = this.getWarningMessages(this.extractWarnings(response.data))
679+
if (this.warningMessages.length > 0) {
680+
this.warningDialogVisible = true
681+
return
659682
}
660683
661684
this.store.setInfo({ title: this.$t('managers.importExportDocs.importComplete'), msg: `${this.importData.logFileName}` })
@@ -679,6 +702,87 @@ export default defineComponent({
679702
}
680703
}
681704
return false
705+
},
706+
normalizeWarnings(warnings: any): any[] {
707+
if (!warnings) return []
708+
if (Array.isArray(warnings)) return warnings
709+
if (typeof warnings === 'string') return [warnings]
710+
if (typeof warnings === 'object') {
711+
if ('MESSAGE' in warnings || 'message' in warnings) return [warnings]
712+
if (Array.isArray(warnings.warnings)) return warnings.warnings
713+
return Object.values(warnings).flatMap((warning) => this.normalizeWarnings(warning))
714+
}
715+
return []
716+
},
717+
collectWarningsFromObject(payload: any): any[] {
718+
if (!payload || typeof payload !== 'object') return []
719+
return Object.entries(payload).flatMap(([key, value]) => {
720+
if (/warning/i.test(key)) return this.normalizeWarnings(value)
721+
if (value && typeof value === 'object') return this.collectWarningsFromObject(value)
722+
return []
723+
})
724+
},
725+
extractWarnings(payload: any) {
726+
const candidates = [payload?.warnings, payload?.warning, payload?.WARNINGS, payload?.messages?.warnings, payload?.messages?.warning]
727+
const normalizedCandidates = candidates.flatMap((candidate) => this.normalizeWarnings(candidate))
728+
if (normalizedCandidates.length > 0) return normalizedCandidates
729+
return this.collectWarningsFromObject(payload)
730+
},
731+
getWarningMessages(warnings: any[] = []) {
732+
return warnings
733+
.map((warning) => {
734+
if (typeof warning === 'string') return warning
735+
const messageKey = warning?.MESSAGE ?? warning?.message
736+
const parameters = warning?.PARAMETERS ?? warning?.parameters
737+
if (!messageKey) return ''
738+
return `${this.$t(messageKey, { count: parameters?.length || 1, parameters: parameters?.toString() })}`
739+
})
740+
.filter((warningMessage) => warningMessage)
741+
},
742+
getFirstNonEmptyValue(...values: any[]) {
743+
return values.find((value) => value !== undefined && value !== null && value !== '') ?? ''
744+
},
745+
resolveDocumentSummaryItem(doc: any, type: 'new' | 'existing', index = 0) {
746+
const candidate = type === 'existing' ? doc?.biobjExist : doc?.biobjExp
747+
if (candidate) return candidate
748+
if (doc && typeof doc === 'object' && !Array.isArray(doc)) return doc
749+
if (!Array.isArray(this.importData.summary?.SbiObjects) || typeof doc !== 'string') return null
750+
751+
const legacyKey = type === 'existing' ? 'biobjExist' : 'biobjExp'
752+
const legacyItems = this.importData.summary.SbiObjects.map((item: any) => item?.[legacyKey]).filter((item: any) => item)
753+
const matchingItems = legacyItems.filter((item: any) => [item.label, item.name, item.documentLabel, item.documentName, item.biobjLabel, item.biobjName].includes(doc))
754+
return matchingItems[index] ?? matchingItems[0] ?? legacyItems[index] ?? null
755+
},
756+
getDocumentSummaryLabel(doc: any, type: 'new' | 'existing', index = 0) {
757+
const resolved = this.resolveDocumentSummaryItem(doc, type, index)
758+
return this.getFirstNonEmptyValue(resolved?.label, resolved?.documentLabel, resolved?.biobjLabel, resolved?.name, resolved?.documentName, typeof doc === 'string' ? doc : '')
759+
},
760+
getDocumentSummaryName(doc: any, type: 'new' | 'existing', index = 0) {
761+
const resolved = this.resolveDocumentSummaryItem(doc, type, index)
762+
return this.getFirstNonEmptyValue(resolved?.name, resolved?.documentName, resolved?.biobjName, this.getDocumentSummaryLabel(doc, type, index))
763+
},
764+
resolveFunctionalitySummaryItem(func: any, type: 'new' | 'existing', index = 0) {
765+
const candidate = type === 'existing' ? func?.functExist : func?.functExp
766+
if (candidate) return candidate
767+
if (func && typeof func === 'object' && !Array.isArray(func)) return func
768+
if (!Array.isArray(this.importData.summary?.SbiFunctions) || typeof func !== 'string') return null
769+
770+
const legacyKey = type === 'existing' ? 'functExist' : 'functExp'
771+
const matchingItems = this.importData.summary.SbiFunctions.map((item: any) => item?.[legacyKey]).filter((item: any) => {
772+
if (!item) return false
773+
const path = item.path ?? item.fullPath ?? item.completePath
774+
const pathLeaf = path ? path.split('/').filter(Boolean).pop() : undefined
775+
return [item.code, item.name, path, pathLeaf].includes(func)
776+
})
777+
return matchingItems[index] ?? matchingItems[0] ?? null
778+
},
779+
getFunctionalitySummaryName(func: any, type: 'new' | 'existing', index = 0) {
780+
const resolved = this.resolveFunctionalitySummaryItem(func, type, index)
781+
return resolved?.name ?? resolved?.code ?? ''
782+
},
783+
getFunctionalitySummaryPath(func: any, type: 'new' | 'existing', index = 0) {
784+
const resolved = this.resolveFunctionalitySummaryItem(func, type, index)
785+
return resolved?.path ?? resolved?.fullPath ?? resolved?.completePath ?? (typeof func === 'string' ? func : '')
682786
}
683787
}
684788
})
@@ -730,6 +834,17 @@ export default defineComponent({
730834
padding: 0.75em;
731835
}
732836
837+
.import-docs-warning-dialog {
838+
.p-dialog-content {
839+
max-width: 700px;
840+
}
841+
}
842+
843+
.warning-dialog-content {
844+
max-height: 400px;
845+
overflow-y: auto;
846+
}
847+
733848
.metadata-summary-container {
734849
overflow-y: auto;
735850
max-height: 600px;
@@ -786,6 +901,10 @@ export default defineComponent({
786901
background-color: rgba(0, 0, 0, 0.03);
787902
}
788903
}
904+
905+
.summary-item-detail + .summary-item-detail {
906+
margin-top: 0.25rem;
907+
}
789908
}
790909
}
791910

0 commit comments

Comments
 (0)