From 8280d7c34b69d8313deab1fdc14f0c617fc20d97 Mon Sep 17 00:00:00 2001 From: Timo Bejan Date: Wed, 25 Aug 2021 10:32:40 +0300 Subject: [PATCH] events from app-state for dossier template reload - refactor file status model --- .../file/dossier-template-model.wrapper.ts | 4 +- .../app/models/file/file-status.wrapper.ts | 1 + .../dictionary-listing-screen.component.scss | 10 ---- ...r-attributes-listing-screen.component.scss | 12 ---- ...e-attributes-listing-screen.component.scss | 10 ---- ...ile-attributes-listing-screen.component.ts | 2 + .../document-info/document-info.component.ts | 20 +++++-- .../dossier-overview-screen.component.ts | 11 +++- .../file-preview-screen.component.html | 2 +- .../red-ui/src/app/state/app-state.service.ts | 57 ++++++++++++------- apps/red-ui/src/assets/styles/red-tables.scss | 10 ++++ 11 files changed, 78 insertions(+), 61 deletions(-) diff --git a/apps/red-ui/src/app/models/file/dossier-template-model.wrapper.ts b/apps/red-ui/src/app/models/file/dossier-template-model.wrapper.ts index 4feac23f7..7c751350b 100644 --- a/apps/red-ui/src/app/models/file/dossier-template-model.wrapper.ts +++ b/apps/red-ui/src/app/models/file/dossier-template-model.wrapper.ts @@ -1,11 +1,11 @@ -import { DossierTemplateModel } from '@redaction/red-ui-http'; +import { DossierTemplateModel, FileAttributesConfig } from '@redaction/red-ui-http'; import { Listable } from '@iqser/common-ui'; export class DossierTemplateModelWrapper implements Listable { dictionariesCount = 0; totalDictionaryEntries = 0; - constructor(public dossierTemplateModel: DossierTemplateModel) {} + constructor(public dossierTemplateModel: DossierTemplateModel, public fileAttributesConfig: FileAttributesConfig) {} get id() { return this.dossierTemplateModel.dossierTemplateId; diff --git a/apps/red-ui/src/app/models/file/file-status.wrapper.ts b/apps/red-ui/src/app/models/file/file-status.wrapper.ts index aeb911d41..7caf8e6d7 100644 --- a/apps/red-ui/src/app/models/file/file-status.wrapper.ts +++ b/apps/red-ui/src/app/models/file/file-status.wrapper.ts @@ -42,6 +42,7 @@ export class FileStatusWrapper implements FileStatus, Listable { readonly uploader = this.fileStatus.uploader; readonly excludedPages = this.fileStatus.excludedPages; readonly hasSuggestions = this.fileStatus.hasSuggestions; + readonly dossierTemplateId = this.fileStatus.dossierTemplateId; primaryAttribute: string; lastOpened: boolean; diff --git a/apps/red-ui/src/app/modules/admin/screens/dictionary-listing/dictionary-listing-screen.component.scss b/apps/red-ui/src/app/modules/admin/screens/dictionary-listing/dictionary-listing-screen.component.scss index 4aeda9197..d1d12b4c9 100644 --- a/apps/red-ui/src/app/modules/admin/screens/dictionary-listing/dictionary-listing-screen.component.scss +++ b/apps/red-ui/src/app/modules/admin/screens/dictionary-listing/dictionary-listing-screen.component.scss @@ -5,16 +5,6 @@ iqser-table-header::ng-deep .header-item { padding-right: 16px; } -.attributes-actions-container { - display: flex; - flex: 1; - justify-content: flex-end; - - > *:not(:last-child) { - margin-right: 16px; - } -} - .content-container cdk-virtual-scroll-viewport { ::ng-deep.cdk-virtual-scroll-content-wrapper { grid-template-columns: auto 2fr 1fr 1fr 1fr 11px; diff --git a/apps/red-ui/src/app/modules/admin/screens/dossier-attributes-listing/dossier-attributes-listing-screen.component.scss b/apps/red-ui/src/app/modules/admin/screens/dossier-attributes-listing/dossier-attributes-listing-screen.component.scss index 2016db53d..d6144291e 100644 --- a/apps/red-ui/src/app/modules/admin/screens/dossier-attributes-listing/dossier-attributes-listing-screen.component.scss +++ b/apps/red-ui/src/app/modules/admin/screens/dossier-attributes-listing/dossier-attributes-listing-screen.component.scss @@ -16,18 +16,6 @@ iqser-table-column-name::ng-deep { } .content-container { - .header-item { - .attributes-actions-container { - display: flex; - flex: 1; - justify-content: flex-end; - - > *:not(:last-child) { - margin-right: 10px; - } - } - } - cdk-virtual-scroll-viewport { ::ng-deep.cdk-virtual-scroll-content-wrapper { grid-template-columns: auto 2fr 2fr 1fr 1fr 11px; diff --git a/apps/red-ui/src/app/modules/admin/screens/file-attributes-listing/file-attributes-listing-screen.component.scss b/apps/red-ui/src/app/modules/admin/screens/file-attributes-listing/file-attributes-listing-screen.component.scss index 404839f0e..1eae4af34 100644 --- a/apps/red-ui/src/app/modules/admin/screens/file-attributes-listing/file-attributes-listing-screen.component.scss +++ b/apps/red-ui/src/app/modules/admin/screens/file-attributes-listing/file-attributes-listing-screen.component.scss @@ -40,16 +40,6 @@ iqser-table-header::ng-deep .header-item { } } -.attributes-actions-container { - display: flex; - flex: 1; - justify-content: flex-end; - - > *:not(:last-child) { - margin-right: 10px; - } -} - .csv-input { display: none; visibility: hidden; diff --git a/apps/red-ui/src/app/modules/admin/screens/file-attributes-listing/file-attributes-listing-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/file-attributes-listing/file-attributes-listing-screen.component.ts index 7fc0cb789..e380bfb06 100644 --- a/apps/red-ui/src/app/modules/admin/screens/file-attributes-listing/file-attributes-listing-screen.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/file-attributes-listing/file-attributes-listing-screen.component.ts @@ -83,6 +83,7 @@ export class FileAttributesListingScreenComponent extends ListingComponent { + this.fileAttributesConfig = this._appStateService.getFileAttributeConfig(this.file.dossierTemplateId); + }); } get dossier() { diff --git a/apps/red-ui/src/app/modules/dossier/screens/dossier-overview-screen/dossier-overview-screen.component.ts b/apps/red-ui/src/app/modules/dossier/screens/dossier-overview-screen/dossier-overview-screen.component.ts index dd942e391..4e218d500 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/dossier-overview-screen/dossier-overview-screen.component.ts +++ b/apps/red-ui/src/app/modules/dossier/screens/dossier-overview-screen/dossier-overview-screen.component.ts @@ -136,8 +136,9 @@ export class DossierOverviewScreenComponent extends ListingComponent { + this.fileAttributeConfigs = this._appStateService.getFileAttributeConfig( + this.currentDossier.dossierTemplateId + ).fileAttributeConfigs; + }); + this.addSubscription = this._scrollViewport.scrolledIndexChange .pipe(tap(index => (this._lastScrolledIndex = index))) .subscribe(); diff --git a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.html b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.html index 461d623bb..942cea531 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.html +++ b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.html @@ -157,7 +157,7 @@ (); readonly fileReanalysed$ = new Subject(); readonly dossierChanged$ = new Subject(); + readonly dossierTemplateChanged$ = new Subject(); private _appState: AppState; @@ -63,7 +63,6 @@ export class AppStateService { this._appState = { dossiers: [], dossierTemplates: [], - fileAttributesConfig: {}, activeDossierId: null, activeFileId: null, activeDossierTemplateId: null, @@ -108,12 +107,6 @@ export class AppStateService { return this._appState.dossierTemplates; } - get activeFileAttributesConfig(): FileAttributesConfig { - if (this.activeDossier) { - return this._appState.fileAttributesConfig[this.activeDossier.dossierTemplateId]; - } - } - get activeDictionaryType(): string { return this._appState.activeDictionaryType; } @@ -179,6 +172,11 @@ export class AppStateService { } } + getFileAttributeConfig(dossierTemplateId: string): FileAttributesConfig { + console.log(this.dossierTemplates); + return this.dossierTemplates.find(d => d.dossierTemplateId === dossierTemplateId)?.fileAttributesConfig; + } + getDictionaryColor(type?: string, dossierTemplateId = this.activeDossier?.dossierTemplateId) { if (!dossierTemplateId) { dossierTemplateId = this.dossierTemplates[0]?.dossierTemplateId; @@ -243,12 +241,14 @@ export class AppStateService { return null; } const oldProcessedDate = this.activeFile.lastProcessed; + const dossierTemplateId = this.activeFile.dossierTemplateId; const activeFile = await this._statusControllerService.getFileStatus(this.activeDossierId, this.activeFileId).toPromise(); + activeFile.dossierTemplateId = dossierTemplateId; const activeFileWrapper = new FileStatusWrapper( activeFile, this._userService.getNameForId(activeFile.currentReviewer), - this._appState.fileAttributesConfig[this.activeDossierTemplateId] + this.getFileAttributeConfig(activeFile.dossierTemplateId) ); this.activeDossier.files = this.activeDossier?.files.map(file => file.fileId === activeFileWrapper.fileId ? activeFileWrapper : file @@ -379,16 +379,33 @@ export class AppStateService { async loadAllDossierTemplates() { const dossierTemplates = await this._dossierTemplateControllerService.getAllDossierTemplates().toPromise(); - this._appState.dossierTemplates = dossierTemplates.map(dossierTemplate => new DossierTemplateModelWrapper(dossierTemplate)); - this._appState.fileAttributesConfig = {}; + this._appState.dossierTemplates = dossierTemplates.map(dossierTemplate => new DossierTemplateModelWrapper(dossierTemplate, null)); for (const dossierTemplate of this._appState.dossierTemplates) { - this._appState.fileAttributesConfig[dossierTemplate.dossierTemplateId] = await this._fileAttributesService + dossierTemplate.fileAttributesConfig = await this._fileAttributesService .getFileAttributesConfiguration(dossierTemplate.dossierTemplateId) .pipe(catchError(() => of({}))) .toPromise(); } } + async refreshDossierTemplate(dossierTemplateId: string) { + const dossierTemplate = await this._dossierTemplateControllerService.getDossierTemplate(dossierTemplateId).toPromise(); + + const fileAttributesConfigs = await this._fileAttributesService + .getFileAttributesConfiguration(dossierTemplateId) + .pipe(catchError(() => of({}))) + .toPromise(); + + Object.assign( + this._appState.dossierTemplates.find(d => d.dossierTemplateId === dossierTemplateId), + new DossierTemplateModelWrapper(dossierTemplate, fileAttributesConfigs) + ); + + await this.refreshDossierTemplateDictionaryData(dossierTemplateId); + + this.dossierTemplateChanged$.next(this._appState.dossierTemplates.find(d => d.dossierTemplateId === dossierTemplateId)); + } + async loadDossierTemplatesIfNecessary() { if (!this._appState.dossierTemplates.length) { await this.loadAllDossierTemplates(); @@ -424,7 +441,7 @@ export class AppStateService { this._dictionaryData = dictionaryData; } - async refreshDossierTemplate(dossierTemplateId: string) { + async refreshDossierTemplateDictionaryData(dossierTemplateId: string) { this._dictionaryData[dossierTemplateId] = await this._getDictionaryDataForDossierTemplateObservables(dossierTemplateId).toPromise(); } @@ -683,13 +700,15 @@ export class AppStateService { for (const file of files) { let found = false; + file.dossierTemplateId = dossier.dossierTemplateId; + for (const oldFile of oldFiles) { if (oldFile.fileId === file.fileId) { // emit when analysis count changed const fileStatusWrapper = new FileStatusWrapper( file, this._userService.getNameForId(file.currentReviewer), - this._appState.fileAttributesConfig[dossier.dossierTemplateId] + this.getFileAttributeConfig(file.dossierTemplateId) ); fileStatusWrapper.lastOpened = fileStatusWrapper.fileId === this._userPreferenceService.getLastOpenedFileForDossier(dossier.dossierId); @@ -708,18 +727,18 @@ export class AppStateService { const fsw = new FileStatusWrapper( file, this._userService.getNameForId(file.currentReviewer), - this._appState.fileAttributesConfig[dossier.dossierTemplateId] + this.getFileAttributeConfig(file.dossierTemplateId) ); fileStatusChangedEvent.push(fsw); } } dossier.files = files.map( - f => + file => new FileStatusWrapper( - f, - this._userService.getNameForId(f.currentReviewer), - this._appState.fileAttributesConfig[dossier.dossierTemplateId] + file, + this._userService.getNameForId(file.currentReviewer), + this.getFileAttributeConfig(file.dossierTemplateId) ) ); this._computeStats(); diff --git a/apps/red-ui/src/assets/styles/red-tables.scss b/apps/red-ui/src/assets/styles/red-tables.scss index 2b5122101..0f5896492 100644 --- a/apps/red-ui/src/assets/styles/red-tables.scss +++ b/apps/red-ui/src/assets/styles/red-tables.scss @@ -123,3 +123,13 @@ cdk-virtual-scroll-viewport { } } } + +.attributes-actions-container { + display: flex; + flex: 1; + justify-content: flex-end; + + > *:not(:last-child) { + margin-right: 10px; + } +}