RED-10557 - updated logic for file attributes mapping
This commit is contained in:
parent
8505d500d3
commit
84cdb2f567
@ -102,8 +102,6 @@ export class DossierOverviewScreenHeaderComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async downloadDossierAsCSV() {
|
async downloadDossierAsCSV() {
|
||||||
console.log('FILE ATTRIBUTES: ', this._fileAttributesService.getFileAttributeConfig(this.dossier().dossierTemplateId));
|
|
||||||
|
|
||||||
const displayedEntities = await firstValueFrom(this.listingService.displayed$);
|
const displayedEntities = await firstValueFrom(this.listingService.displayed$);
|
||||||
const entities = this.sortingService.defaultSort(displayedEntities);
|
const entities = this.sortingService.defaultSort(displayedEntities);
|
||||||
const fileName = this.dossier().dossierName + '.export.csv';
|
const fileName = this.dossier().dossierName + '.export.csv';
|
||||||
@ -111,31 +109,13 @@ export class DossierOverviewScreenHeaderComponent {
|
|||||||
.getFileAttributeConfig(this.dossier().dossierTemplateId)
|
.getFileAttributeConfig(this.dossier().dossierTemplateId)
|
||||||
.fileAttributeConfigs.filter(a => a.includeInCsvExport)
|
.fileAttributeConfigs.filter(a => a.includeInCsvExport)
|
||||||
.map(c => ({ label: c.label, id: c.id }));
|
.map(c => ({ label: c.label, id: c.id }));
|
||||||
for (const entity of entities) {
|
|
||||||
console.log('--------------------------');
|
|
||||||
console.log(
|
|
||||||
...Object.keys(entity.fileAttributes.attributeIdToValue).reduce((result, key) => {
|
|
||||||
const match = configNames.find(item => item.id === key);
|
|
||||||
if (match) {
|
|
||||||
result.push(entity.fileAttributes.attributeIdToValue[key]);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}, []),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const mapper = (file?: File) => ({
|
const mapper = (file?: File) => ({
|
||||||
...file,
|
...file,
|
||||||
hasAnnotations: file.hasRedactions,
|
hasAnnotations: file.hasRedactions,
|
||||||
assignee: this._userService.getName(file.assignee) || '-',
|
assignee: this._userService.getName(file.assignee) || '-',
|
||||||
primaryAttribute: this._primaryFileAttributeService.getPrimaryFileAttributeValue(file, this.dossier().dossierTemplateId),
|
primaryAttribute: this._primaryFileAttributeService.getPrimaryFileAttributeValue(file, this.dossier().dossierTemplateId),
|
||||||
...Object.keys(file.fileAttributes.attributeIdToValue).reduce((result, key) => {
|
...this.#mapFileAttributes(file, displayedEntities, configNames),
|
||||||
const match = configNames.find(item => item.id === key);
|
|
||||||
if (match) {
|
|
||||||
result.push(match.label);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}, []),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const documineOnlyFields = ['hasAnnotations'];
|
const documineOnlyFields = ['hasAnnotations'];
|
||||||
@ -158,4 +138,21 @@ export class DossierOverviewScreenHeaderComponent {
|
|||||||
];
|
];
|
||||||
saveAsCSV(fileName, entities, fileFields, mapper);
|
saveAsCSV(fileName, entities, fileFields, mapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#mapFileAttributes(file: File, displayedEntities: File[], configNames: { label: string; id: string }[]) {
|
||||||
|
const entity = displayedEntities.find(e => e.id === file.id);
|
||||||
|
|
||||||
|
if (!entity) return {};
|
||||||
|
|
||||||
|
return Object.keys(entity.fileAttributes.attributeIdToValue).reduce(
|
||||||
|
(result, key) => {
|
||||||
|
const match = configNames.find(item => item.id === key);
|
||||||
|
if (match) {
|
||||||
|
result[match.label] = entity.fileAttributes.attributeIdToValue[key];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
{} as Record<string, any>,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,8 +22,6 @@ export function saveAsCSV(fileName: string, objects: readonly any[], fields: str
|
|||||||
const headerLine = fields.map(f => '"' + humanize(camelCaseToSnakeCase(f)) + '"').join(',') + '\n';
|
const headerLine = fields.map(f => '"' + humanize(camelCaseToSnakeCase(f)) + '"').join(',') + '\n';
|
||||||
const csvContent = toCSVContent(objects.map(mapper), fields);
|
const csvContent = toCSVContent(objects.map(mapper), fields);
|
||||||
|
|
||||||
console.log('toCSVContent: ', objects.map(mapper));
|
|
||||||
|
|
||||||
const blob = new Blob([headerLine + csvContent], {
|
const blob = new Blob([headerLine + csvContent], {
|
||||||
type: 'text/csv;charset=utf-8',
|
type: 'text/csv;charset=utf-8',
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user