From e15884f037368d8ad6d8642cba1a5fbd5edde0ce Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Sat, 6 Nov 2021 15:56:12 +0200 Subject: [PATCH] use custom share operators, update data streams --- .../base-screen/base-screen.component.ts | 5 +- .../file-workload.component.html | 6 +- .../file-workload/file-workload.component.ts | 2 +- .../page-indicator.component.ts | 55 ++++++++------ .../file-preview-screen.component.html | 12 +-- .../file-preview-screen.component.ts | 75 +++++++++---------- .../app/modules/dossier/services/injector.ts | 16 ---- .../services/file-download.service.ts | 22 +++--- .../app/utils/configuration.initializer.ts | 4 +- libs/common-ui | 2 +- 10 files changed, 97 insertions(+), 102 deletions(-) delete mode 100644 apps/red-ui/src/app/modules/dossier/services/injector.ts diff --git a/apps/red-ui/src/app/components/base-screen/base-screen.component.ts b/apps/red-ui/src/app/components/base-screen/base-screen.component.ts index e51e82711..80e31da53 100644 --- a/apps/red-ui/src/app/components/base-screen/base-screen.component.ts +++ b/apps/red-ui/src/app/components/base-screen/base-screen.component.ts @@ -8,8 +8,9 @@ import { FileDownloadService } from '@upload-download/services/file-download.ser import { TranslateService } from '@ngx-translate/core'; import { SpotlightSearchAction } from '@components/spotlight-search/spotlight-search-action'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; -import { distinctUntilChanged, filter, map, startWith } from 'rxjs/operators'; +import { filter, map, startWith } from 'rxjs/operators'; import { DossiersService } from '@services/entity-services/dossiers.service'; +import { shareDistinctLast } from '@iqser/common-ui'; interface MenuItem { readonly name: string; @@ -73,7 +74,7 @@ export class BaseScreenComponent { filter(isNavigationStart), map((event: NavigationStart) => event.url), startWith(this._router.url), - distinctUntilChanged(), + shareDistinctLast(), ); readonly isDossiersView$ = this._navigationStart$.pipe(map(isDossiersView)); readonly isSearchScreen$ = this._navigationStart$.pipe(map(isSearchScreen)); diff --git a/apps/red-ui/src/app/modules/dossier/components/file-workload/file-workload.component.html b/apps/red-ui/src/app/modules/dossier/components/file-workload/file-workload.component.html index 7ee814bf5..02872ba00 100644 --- a/apps/red-ui/src/app/modules/dossier/components/file-workload/file-workload.component.html +++ b/apps/red-ui/src/app/modules/dossier/components/file-workload/file-workload.component.html @@ -105,11 +105,11 @@
-
+
- + {{ 'file-preview.tabs.annotations.page-is' | translate }} . diff --git a/apps/red-ui/src/app/modules/dossier/components/file-workload/file-workload.component.ts b/apps/red-ui/src/app/modules/dossier/components/file-workload/file-workload.component.ts index 6f7328ee1..4dfe8b247 100644 --- a/apps/red-ui/src/app/modules/dossier/components/file-workload/file-workload.component.ts +++ b/apps/red-ui/src/app/modules/dossier/components/file-workload/file-workload.component.ts @@ -90,7 +90,7 @@ export class FileWorkloadComponent { return !this._permissionsService.canPerformAnnotationActions(); } - get isExcluded(): boolean { + get currentPageIsExcluded(): boolean { return this.fileData?.file?.excludedPages?.includes(this.activeViewerPage); } diff --git a/apps/red-ui/src/app/modules/dossier/components/page-indicator/page-indicator.component.ts b/apps/red-ui/src/app/modules/dossier/components/page-indicator/page-indicator.component.ts index b99b2bad1..743b86fd5 100644 --- a/apps/red-ui/src/app/modules/dossier/components/page-indicator/page-indicator.component.ts +++ b/apps/red-ui/src/app/modules/dossier/components/page-indicator/page-indicator.component.ts @@ -1,4 +1,14 @@ -import { Component, EventEmitter, Input, OnChanges, OnDestroy, OnInit, Output, SimpleChanges } from '@angular/core'; +import { + ChangeDetectionStrategy, + Component, + EventEmitter, + Input, + OnChanges, + OnDestroy, + OnInit, + Output, + SimpleChanges, +} from '@angular/core'; import { AppStateService } from '@state/app-state.service'; import { PermissionsService } from '@services/permissions.service'; import { ConfigService } from '@services/config.service'; @@ -11,6 +21,7 @@ import { AutoUnsubscribe } from '@iqser/common-ui'; selector: 'redaction-page-indicator', templateUrl: './page-indicator.component.html', styleUrls: ['./page-indicator.component.scss'], + changeDetection: ChangeDetectionStrategy.OnPush, }) export class PageIndicatorComponent extends AutoUnsubscribe implements OnChanges, OnInit, OnDestroy { @Input() active: boolean; @@ -62,12 +73,12 @@ export class PageIndicatorComponent extends AutoUnsubscribe implements OnChanges } } - toggleReadState() { + async toggleReadState() { if (this.canMarkPagesAsViewed) { if (this.read) { - this._markPageUnread(); + await this._markPageUnread(); } else { - this._markPageRead(); + await this._markPageRead(); } } } @@ -82,9 +93,9 @@ export class PageIndicatorComponent extends AutoUnsubscribe implements OnChanges } if (this.active && !this.read) { - this.pageReadTimeout = window.setTimeout(() => { + this.pageReadTimeout = window.setTimeout(async () => { if (this.active && !this.read) { - this._markPageRead(); + await this._markPageRead(); } }, this._configService.values.AUTO_READ_TIME * 1000); } @@ -107,26 +118,24 @@ export class PageIndicatorComponent extends AutoUnsubscribe implements OnChanges // } // } - private _markPageRead() { - this.addSubscription = this._viewedPagesService + private async _markPageRead() { + await this._viewedPagesService .addPage({ page: this.number }, this._dossiersService.activeDossierId, this._appStateService.activeFileId) - .subscribe(() => { - if (this.activePage) { - this.activePage.hasChanges = false; - } else { - this.viewedPages?.push({ page: this.number, fileId: this._appStateService.activeFileId }); - } - }); + .toPromise(); + if (this.activePage) { + this.activePage.hasChanges = false; + } else { + this.viewedPages?.push({ page: this.number, fileId: this._appStateService.activeFileId }); + } } - private _markPageUnread() { - this.addSubscription = this._viewedPagesService + private async _markPageUnread() { + await this._viewedPagesService .removePage(this._dossiersService.activeDossierId, this._appStateService.activeFileId, this.number) - .subscribe(() => { - this.viewedPages?.splice( - this.viewedPages?.findIndex(p => p.page === this.number), - 1, - ); - }); + .toPromise(); + this.viewedPages?.splice( + this.viewedPages?.findIndex(p => p.page === this.number), + 1, + ); } } 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 f46c6c24b..62229d1a4 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 @@ -1,4 +1,4 @@ -
+