events from app-state for dossier template reload - refactor file status model

This commit is contained in:
Timo Bejan 2021-08-25 10:32:40 +03:00
parent f89a798efb
commit 8280d7c34b
11 changed files with 78 additions and 61 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -83,6 +83,7 @@ export class FileAttributesListingScreenComponent extends ListingComponent<FileA
await this._fileAttributesService
.setFileAttributesConfiguration(newValue, this._appStateService.activeDossierTemplateId)
.toPromise();
await this._appStateService.refreshDossierTemplate(this._appStateService.activeDossierTemplateId);
await this._loadData();
}
);
@ -103,6 +104,7 @@ export class FileAttributesListingScreenComponent extends ListingComponent<FileA
)
.toPromise();
}
await this._appStateService.refreshDossierTemplate(this._appStateService.activeDossierTemplateId);
await this._loadData();
});
}

View File

@ -1,21 +1,31 @@
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { FileAttributesConfig, FileStatus } from '@redaction/red-ui-http';
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { FileAttributesConfig } from '@redaction/red-ui-http';
import { AppStateService } from '@state/app-state.service';
import { DossiersDialogService } from '../../services/dossiers-dialog.service';
import { AutoUnsubscribe } from '@iqser/common-ui';
import { FileStatusWrapper } from '@models/file/file-status.wrapper';
@Component({
selector: 'redaction-document-info',
templateUrl: './document-info.component.html',
styleUrls: ['./document-info.component.scss']
})
export class DocumentInfoComponent {
@Input() file: FileStatus;
export class DocumentInfoComponent extends AutoUnsubscribe implements OnInit {
@Input() file: FileStatusWrapper;
@Output() closeDocumentInfoView = new EventEmitter();
fileAttributesConfig: FileAttributesConfig;
constructor(private readonly _appStateService: AppStateService, private readonly _dialogService: DossiersDialogService) {
this.fileAttributesConfig = this._appStateService.activeFileAttributesConfig;
super();
}
ngOnInit(): void {
this.fileAttributesConfig = this._appStateService.getFileAttributeConfig(this.file.dossierTemplateId);
this.addSubscription = this._appStateService.dossierTemplateChanged$.subscribe(() => {
this.fileAttributesConfig = this._appStateService.getFileAttributeConfig(this.file.dossierTemplateId);
});
}
get dossier() {

View File

@ -136,8 +136,9 @@ export class DossierOverviewScreenComponent extends ListingComponent<FileStatusW
) {
super(_injector);
this._loadEntitiesFromState();
this.fileAttributeConfigs = this._appStateService.activeFileAttributesConfig.fileAttributeConfigs;
this.fileAttributeConfigs = this._appStateService.getFileAttributeConfig(
this.currentDossier.dossierTemplateId
).fileAttributeConfigs;
}
get checkedRequiredFilters() {
@ -164,6 +165,12 @@ export class DossierOverviewScreenComponent extends ListingComponent<FileStatusW
this.calculateData();
});
this.addSubscription = this._appStateService.dossierTemplateChanged$.subscribe(() => {
this.fileAttributeConfigs = this._appStateService.getFileAttributeConfig(
this.currentDossier.dossierTemplateId
).fileAttributeConfigs;
});
this.addSubscription = this._scrollViewport.scrolledIndexChange
.pipe(tap(index => (this._lastScrolledIndex = index)))
.subscribe();

View File

@ -157,7 +157,7 @@
<redaction-document-info
(closeDocumentInfoView)="viewDocumentInfo = false"
*ngIf="viewDocumentInfo"
[file]="fileData.fileStatus.fileStatus"
[file]="fileData.fileStatus"
></redaction-document-info>
<redaction-file-workload

View File

@ -30,7 +30,6 @@ export interface AppState {
activeDossierId: string;
activeFileId: string;
activeDossierTemplateId: string;
fileAttributesConfig: { [key: string]: FileAttributesConfig };
activeDictionaryType: string;
totalAnalysedPages?: number;
totalDocuments?: number;
@ -44,6 +43,7 @@ export class AppStateService {
readonly fileChanged$ = new Subject<FileStatusWrapper>();
readonly fileReanalysed$ = new Subject<FileStatusWrapper>();
readonly dossierChanged$ = new Subject<DossierWrapper>();
readonly dossierTemplateChanged$ = new Subject<DossierTemplateModelWrapper>();
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();

View File

@ -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;
}
}