remove fileChanged and fileReanalyzed

This commit is contained in:
Dan Percic 2021-11-14 12:10:22 +02:00
parent 29c20edfa7
commit 4f8fa98e65
7 changed files with 51 additions and 75 deletions

View File

@ -1,21 +1,11 @@
import {
ChangeDetectionStrategy,
Component,
EventEmitter,
Input,
OnChanges,
OnDestroy,
OnInit,
Output,
SimpleChanges,
} from '@angular/core';
import { AppStateService } from '@state/app-state.service';
import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnDestroy, Output } from '@angular/core';
import { PermissionsService } from '@services/permissions.service';
import { ConfigService } from '@services/config.service';
import { DossiersService } from '@services/entity-services/dossiers.service';
import { ViewedPagesService } from '../../shared/services/viewed-pages.service';
import { File, IViewedPage } from '@red/domain';
import { AutoUnsubscribe } from '@iqser/common-ui';
import { AutoUnsubscribe, OnChange } from '@iqser/common-ui';
import { FilesMapService } from '@services/entity-services/files-map.service';
@Component({
selector: 'redaction-page-indicator',
@ -23,9 +13,15 @@ import { AutoUnsubscribe } from '@iqser/common-ui';
styleUrls: ['./page-indicator.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class PageIndicatorComponent extends AutoUnsubscribe implements OnChanges, OnInit, OnDestroy {
@Input() file: File;
@Input() active: boolean;
export class PageIndicatorComponent extends AutoUnsubscribe implements OnDestroy {
@Input()
@OnChange<File, PageIndicatorComponent>('handlePageRead')
file: File;
@Input()
@OnChange<boolean, PageIndicatorComponent>('handlePageRead')
active: boolean;
@Input() showDottedIcon = false;
@Input() number: number;
@Input() viewedPages: IViewedPage[];
@ -34,11 +30,10 @@ export class PageIndicatorComponent extends AutoUnsubscribe implements OnChanges
@Output() readonly pageSelected = new EventEmitter<number>();
pageReadTimeout: number = null;
canMarkPagesAsViewed: boolean;
constructor(
private readonly _viewedPagesService: ViewedPagesService,
private readonly _appStateService: AppStateService,
private readonly _filesMapService: FilesMapService,
private readonly _dossiersService: DossiersService,
private readonly _configService: ConfigService,
private readonly _permissionService: PermissionsService,
@ -59,23 +54,8 @@ export class PageIndicatorComponent extends AutoUnsubscribe implements OnChanges
}
}
ngOnInit(): void {
this.addSubscription = this._appStateService.fileChanged$.subscribe(() => {
if (this.canMarkPagesAsViewed !== this._permissionService.canMarkPagesAsViewed(this.file)) {
this.canMarkPagesAsViewed = this._permissionService.canMarkPagesAsViewed(this.file);
this._handlePageRead();
}
});
}
ngOnChanges(changes: SimpleChanges): void {
if (changes.active) {
this._handlePageRead();
}
}
async toggleReadState() {
if (this.canMarkPagesAsViewed) {
if (this._permissionService.canMarkPagesAsViewed(this.file)) {
if (this.read) {
await this._markPageUnread();
} else {
@ -84,8 +64,8 @@ export class PageIndicatorComponent extends AutoUnsubscribe implements OnChanges
}
}
private _handlePageRead() {
if (!this.canMarkPagesAsViewed) {
handlePageRead() {
if (!this._permissionService.canMarkPagesAsViewed(this.file)) {
return;
}

View File

@ -53,6 +53,7 @@ import { UserPreferenceService } from '@services/user-preference.service';
import { saveAsCSV } from '@utils/csv-utils';
import { FilesService } from '@services/entity-services/files.service';
import { FilesMapService } from '@services/entity-services/files-map.service';
import { ReanalysisService } from '@services/reanalysis.service';
@Component({
templateUrl: './dossier-overview-screen.component.html',
@ -91,6 +92,7 @@ export class DossierOverviewScreenComponent extends ListingComponent<File> imple
readonly permissionsService: PermissionsService,
private readonly _loadingService: LoadingService,
private readonly _appStateService: AppStateService,
private readonly _reanalysisService: ReanalysisService,
private readonly _dossiersService: DossiersService,
private readonly _dossierTemplatesService: DossierTemplatesService,
readonly routerHistoryService: RouterHistoryService,
@ -208,7 +210,7 @@ export class DossierOverviewScreenComponent extends ListingComponent<File> imple
async reanalyseDossier() {
try {
await this._appStateService.reanalyzeDossier();
await this._reanalysisService.reanalyzeDossier(this.dossierId, true).toPromise();
await this.reloadFiles();
this._toaster.success(_('dossier-overview.reanalyse-dossier.success'));
} catch (e) {
@ -223,10 +225,6 @@ export class DossierOverviewScreenComponent extends ListingComponent<File> imple
}
async calculateData(): Promise<void> {
if (!this.dossierId) {
return;
}
await this._loadEntitiesFromState();
this._computeAllFilters();

View File

@ -10,7 +10,7 @@
></iqser-circle-button>
<iqser-circle-button
(action)="reanalyseDossier($event, dossier)"
(action)="reanalyseDossier($event, dossier.dossierId)"
*ngIf="permissionsService.displayReanalyseBtn(dossier) && analysisForced"
[tooltip]="'dossier-listing.reanalyse.action' | translate"
[type]="circleButtonTypes.dark"

View File

@ -8,6 +8,8 @@ import { DossiersDialogService } from '../../../../services/dossiers-dialog.serv
import { LongPressEvent } from '@shared/directives/long-press.directive';
import { UserPreferenceService } from '@services/user-preference.service';
import { FilesMapService } from '@services/entity-services/files-map.service';
import { ReanalysisService } from '@services/reanalysis.service';
import { switchMapTo, tap } from 'rxjs/operators';
@Component({
selector: 'redaction-dossiers-listing-actions',
@ -26,6 +28,7 @@ export class DossiersListingActionsComponent {
constructor(
readonly appStateService: AppStateService,
private readonly _reanalysisService: ReanalysisService,
private readonly _userService: UserService,
readonly permissionsService: PermissionsService,
readonly filesMapService: FilesMapService,
@ -50,10 +53,9 @@ export class DossiersListingActionsComponent {
});
}
reanalyseDossier($event: MouseEvent, dossier: Dossier): void {
async reanalyseDossier($event: MouseEvent, id: string): Promise<void> {
$event.stopPropagation();
this.appStateService.reanalyzeDossier(dossier).then(() => {
this.appStateService.loadAllDossiers().then(() => this.actionPerformed.emit());
});
const reanalysis$ = this._reanalysisService.reanalyzeDossier(id).pipe(switchMapTo(this.appStateService.loadAllDossiers()));
await reanalysis$.pipe(tap(() => this.actionPerformed.emit())).toPromise();
}
}

View File

@ -358,7 +358,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
response.manualRedactionEntryWrapper.rectId,
);
this._instance.Core.annotationManager.deleteAnnotation(annotation);
this.fileData.file = await this.appStateService.reloadActiveFile();
this.fileData.file = await this.appStateService.reloadFile(this.dossierId, this.fileId);
const distinctPages = entryWrapper.manualRedactionEntry.positions
.map(p => p.page)
.filter((item, pos, self) => self.indexOf(item) === pos);
@ -499,7 +499,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
async assignToMe() {
await this._fileActionService.assignToMe([this.fileData.file], async () => {
await this.appStateService.reloadActiveFile();
await this.appStateService.reloadFile(this.dossierId, this.fileId);
this._updateCanPerformActions();
});
}
@ -512,7 +512,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
await this._filesService.setReviewerFor([fileId], dossierId, reviewerId).toPromise();
this._toaster.info(_('assignment.reviewer'), { params: { reviewerName, filename } });
await this.appStateService.reloadActiveFile();
await this.appStateService.reloadFile(this.dossierId, this.fileId);
this._updateCanPerformActions();
this.editingReviewer = false;
}
@ -585,8 +585,10 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
}
private _subscribeToFileUpdates(): void {
this.addSubscription = timer(0, 10000).pipe(switchMapTo(this.appStateService.reloadActiveFile())).subscribe();
this.addSubscription = this.appStateService.fileReanalysed$
this.addSubscription = timer(0, 10000)
.pipe(switchMapTo(this.appStateService.reloadFile(this.dossierId, this.fileId)))
.subscribe();
this.addSubscription = this._filesMapService.fileReanalysed$
.pipe(filter(file => file.fileId === this.fileId))
.subscribe(async () => {
await this._loadFileData(!this._reloadFileOnReanalysis);
@ -645,7 +647,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
const currentPageAnnotations = this.annotations.filter(a => a.pageNumber === page);
const currentPageAnnotationIds = currentPageAnnotations.map(a => a.id);
this.fileData.file = await this.appStateService.reloadActiveFile();
this.fileData.file = await this.appStateService.reloadFile(this.dossierId, this.fileId);
this.fileData.redactionLog = await this._fileDownloadService.loadRedactionLogFor(this.dossierId, this.fileId).toPromise();
this.rebuildFilters();

View File

@ -40,7 +40,7 @@ export class FilesMapService {
const newEntities = entities.map(newEntity => {
const oldEntity = this.get(key, newEntity.id);
if (oldEntity.lastProcessed !== newEntity.lastProcessed) {
if (oldEntity?.lastProcessed !== newEntity.lastProcessed) {
this.fileReanalysed$.next(newEntity);
}
@ -55,6 +55,11 @@ export class FilesMapService {
this._map.get(key).next(newEntities);
}
replace(entity: File) {
const all = this.get(entity.dossierId).filter(file => file.fileId !== entity.fileId);
this.set(entity.dossierId, [...all, entity]);
}
watch$(key: string, entityId: string): Observable<File> {
return this._entityChanged$.pipe(
filter(entity => entity.id === entityId),

View File

@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
import { Dictionary, Dossier, DossierTemplate, File, IColors, IDossier } from '@red/domain';
import { ActivationEnd, Router } from '@angular/router';
import { UserService } from '@services/user.service';
import { forkJoin, Observable, of, Subject } from 'rxjs';
import { forkJoin, Observable, of } from 'rxjs';
import { catchError, filter, first, map, tap } from 'rxjs/operators';
import { currentComponentRoute, FALLBACK_COLOR, hexToRgb } from '@utils/functions';
import { DossiersService } from '@services/entity-services/dossiers.service';
@ -11,7 +11,6 @@ import { FilesService } from '@services/entity-services/files.service';
import { DictionaryService } from '@shared/services/dictionary.service';
import { DossierTemplatesService } from '@services/entity-services/dossier-templates.service';
import { FileAttributesService } from '@services/entity-services/file-attributes.service';
import { ReanalysisService } from '@services/reanalysis.service';
import { DossierStatsService } from '@services/entity-services/dossier-stats.service';
import { FilesMapService } from '@services/entity-services/files-map.service';
@ -24,9 +23,6 @@ export interface AppState {
providedIn: 'root',
})
export class AppStateService {
readonly fileChanged$ = new Subject<File>();
readonly fileReanalysed$ = new Subject<File>();
private _appState: AppState = {};
constructor(
@ -34,7 +30,6 @@ export class AppStateService {
private readonly _userService: UserService,
private readonly _dossiersService: DossiersService,
private readonly _filesService: FilesService,
private readonly _reanalysisService: ReanalysisService,
private readonly _dictionaryService: DictionaryService,
private readonly _dossierTemplatesService: DossierTemplatesService,
private readonly _dossierStatsService: DossierStatsService,
@ -143,26 +138,24 @@ export class AppStateService {
return Promise.all(mappedDossiers$);
}
async reloadActiveFile() {
const activeDossier = this._dossiersService.activeDossier;
async reloadFile(dossierId: string, fileId: string) {
const dossier = this._dossiersService.find(dossierId);
const oldFile = this._filesMapService.get(dossierId, fileId);
if (!this.activeFile || !activeDossier) {
if (!oldFile || !dossier) {
return null;
}
const oldProcessedDate = this.activeFile.lastProcessed;
const iFile = await this._filesService.get(activeDossier.dossierId, this.activeFileId).toPromise();
const activeFile = new File(
const iFile = await this._filesService.get(dossierId, fileId).toPromise();
const newFile = new File(
iFile,
this._userService.getNameForId(iFile.currentReviewer),
this._fileAttributesService.getFileAttributeConfig(activeDossier.dossierTemplateId),
this._fileAttributesService.getFileAttributeConfig(dossier.dossierTemplateId),
);
if (activeFile.lastProcessed !== oldProcessedDate) {
this.fileReanalysed$.next(activeFile);
}
this.fileChanged$.next(activeFile);
return activeFile;
this._filesMapService.replace(newFile);
return newFile;
}
async getFiles(dossier = this._dossiersService.activeDossier) {
@ -178,10 +171,6 @@ export class AppStateService {
return newFiles;
}
async reanalyzeDossier({ id } = this._dossiersService.activeDossier) {
await this._reanalysisService.reanalyzeDossier(id, true).toPromise();
}
async activateFile(dossierId: string, fileId: string) {
if (this._dossiersService.activeDossierId === dossierId && this.activeFileId === fileId) {
return;