From 17a74084a82d9267738ca66b4f5374bc88f82cb6 Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Mon, 20 Mar 2023 20:11:59 +0200 Subject: [PATCH] RED-6453: try fix setting file attribute value --- .../file-attribute.component.html | 5 +-- .../file-attribute.component.ts | 39 +++++++++---------- .../dossier-overview-screen.component.ts | 3 +- apps/red-ui/src/app/users/user.service.ts | 5 +-- 4 files changed, 22 insertions(+), 30 deletions(-) diff --git a/apps/red-ui/src/app/modules/dossier-overview/components/table-item/file-attribute/file-attribute.component.html b/apps/red-ui/src/app/modules/dossier-overview/components/table-item/file-attribute/file-attribute.component.html index 34220fd87..602e751e4 100644 --- a/apps/red-ui/src/app/modules/dossier-overview/components/table-item/file-attribute/file-attribute.component.html +++ b/apps/red-ui/src/app/modules/dossier-overview/components/table-item/file-attribute/file-attribute.component.html @@ -4,7 +4,7 @@ {{ fileAttributeValue ? (fileAttributeValue | date : 'd MMM yyyy') : '-' }} - +
- - - diff --git a/apps/red-ui/src/app/modules/dossier-overview/components/table-item/file-attribute/file-attribute.component.ts b/apps/red-ui/src/app/modules/dossier-overview/components/table-item/file-attribute/file-attribute.component.ts index 799e2e426..863ee9353 100644 --- a/apps/red-ui/src/app/modules/dossier-overview/components/table-item/file-attribute/file-attribute.component.ts +++ b/apps/red-ui/src/app/modules/dossier-overview/components/table-item/file-attribute/file-attribute.component.ts @@ -1,10 +1,10 @@ -import { ChangeDetectionStrategy, Component, HostListener, Input, OnInit } from '@angular/core'; +import { Component, HostListener, Input, OnDestroy, OnInit } from '@angular/core'; import { Dossier, File, FileAttributeConfigTypes, IFileAttributeConfig } from '@red/domain'; import { BaseFormComponent, ListingService, Toaster } from '@iqser/common-ui'; import { PermissionsService } from '@services/permissions.service'; import { FormBuilder, UntypedFormGroup } from '@angular/forms'; import { FileAttributesService } from '@services/entity-services/file-attributes.service'; -import { BehaviorSubject, firstValueFrom, Observable } from 'rxjs'; +import { firstValueFrom, Subscription } from 'rxjs'; import { FilesService } from '@services/files/files.service'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import dayjs from 'dayjs'; @@ -15,39 +15,34 @@ import { filter, map, tap } from 'rxjs/operators'; selector: 'redaction-file-attribute [fileAttribute] [file] [dossier]', templateUrl: './file-attribute.component.html', styleUrls: ['./file-attribute.component.scss'], - changeDetection: ChangeDetectionStrategy.OnPush, }) -export class FileAttributeComponent extends BaseFormComponent implements OnInit { +export class FileAttributeComponent extends BaseFormComponent implements OnInit, OnDestroy { @Input() fileAttribute!: IFileAttributeConfig; - @Input() file!: File; - @Input() dossier!: Dossier; + isInEditMode = false; closedDatepicker = true; - readonly isEditingFileAttribute$: BehaviorSubject; - readonly selectedFile$: Observable; + readonly #subscriptions = new Subscription(); constructor( - private readonly _fileAttributesService: FileAttributesService, + router: Router, private readonly _toaster: Toaster, private readonly _formBuilder: FormBuilder, private readonly _filesService: FilesService, - private readonly _router: Router, - private readonly _listingService: ListingService, readonly permissionsService: PermissionsService, + private readonly _listingService: ListingService, + readonly fileAttributesService: FileAttributesService, ) { super(); - this.isEditingFileAttribute$ = this._fileAttributesService.isEditingFileAttribute$; + const sub = router.events.pipe(filter(event => event instanceof NavigationEnd)).subscribe(() => this.close()); + this.#subscriptions.add(sub); - _router.events.pipe(filter(event => event instanceof NavigationEnd)).subscribe(() => { - this.close(); - }); - - this.selectedFile$ = this._listingService.selectedLength$.pipe( + const sub2 = this._listingService.selectedLength$.pipe( map(selectedLength => !!selectedLength), tap(() => this.close()), ); + this.#subscriptions.add(sub2.subscribe()); } get isDate(): boolean { @@ -62,6 +57,10 @@ export class FileAttributeComponent extends BaseFormComponent implements OnInit return JSON.stringify(this.file.fileAttributes.attributeIdToValue) === '{}'; } + ngOnDestroy() { + this.#subscriptions.unsubscribe(); + } + ngOnInit(): void { if (this.#noFileAttributes) { this.#initFileAttributes(); @@ -84,7 +83,7 @@ export class FileAttributeComponent extends BaseFormComponent implements OnInit }; try { await firstValueFrom( - this._fileAttributesService.setFileAttributes({ attributeIdToValue }, this.file.dossierId, this.file.fileId), + this.fileAttributesService.setFileAttributes({ attributeIdToValue }, this.file.dossierId, this.file.fileId), ); await firstValueFrom(this._filesService.reload(this.file.dossierId, this.file)); this.initialFormValue = rawFormValue; @@ -111,7 +110,7 @@ export class FileAttributeComponent extends BaseFormComponent implements OnInit } #initFileAttributes() { - const configs = this._fileAttributesService.getFileAttributeConfig(this.file.dossierTemplateId).fileAttributeConfigs; + const configs = this.fileAttributesService.getFileAttributeConfig(this.file.dossierTemplateId).fileAttributeConfigs; configs.forEach(config => (this.file.fileAttributes.attributeIdToValue[config.id] = null)); } @@ -131,7 +130,7 @@ export class FileAttributeComponent extends BaseFormComponent implements OnInit #toggleEdit(): void { this.isInEditMode = !this.isInEditMode; - this.isEditingFileAttribute$.next(this.isInEditMode); + this.fileAttributesService.isEditingFileAttribute$.next(this.isInEditMode); if (this.isInEditMode) { this.#focusOnEditInput(); diff --git a/apps/red-ui/src/app/modules/dossier-overview/screen/dossier-overview-screen.component.ts b/apps/red-ui/src/app/modules/dossier-overview/screen/dossier-overview-screen.component.ts index a9876a93b..780b993f8 100644 --- a/apps/red-ui/src/app/modules/dossier-overview/screen/dossier-overview-screen.component.ts +++ b/apps/red-ui/src/app/modules/dossier-overview/screen/dossier-overview-screen.component.ts @@ -24,7 +24,6 @@ import { ListingModes, listingProvidersFactory, LoadingService, - log, NestedFilter, OnAttach, shareLast, @@ -104,7 +103,7 @@ export class DossierOverviewScreenComponent extends ListingComponent imple this.#currentDossier = _dossiersService.find(this.dossierId); this.workflowConfig = configService.workflowConfig(); this.dossierTemplateId = this.#currentDossier.dossierTemplateId; - this.files$ = merge(this.#files$, this.#dossierFilesChange$).pipe(log('Files'), shareLast()); + this.files$ = merge(this.#files$, this.#dossierFilesChange$).pipe(shareLast()); this._updateFileAttributes(); _router.events.pipe(filter(event => event instanceof NavigationEnd)).subscribe(() => { this._fileDropOverlayService.cleanupFileDropHandling(); diff --git a/apps/red-ui/src/app/users/user.service.ts b/apps/red-ui/src/app/users/user.service.ts index 337528063..55bbec07e 100644 --- a/apps/red-ui/src/app/users/user.service.ts +++ b/apps/red-ui/src/app/users/user.service.ts @@ -15,10 +15,7 @@ export class UserService extends IqserUserService { const currentUser = await super.loadCurrentUser(); this._permissionsService.add({ - [ROLES.any]: (permission, all) => { - console.log('all roles: ', Object.keys(all)); - return Object.keys(all).some(key => this._permissionsFilter(key)); - }, + [ROLES.any]: (permission, all) => Object.keys(all).some(key => this._permissionsFilter(key)), }); return currentUser;