RED-6453: try fix setting file attribute value
This commit is contained in:
parent
7e73d17407
commit
17a74084a8
@ -4,7 +4,7 @@
|
||||
<span class="clamp-3"> {{ fileAttributeValue ? (fileAttributeValue | date : 'd MMM yyyy') : '-' }}</span>
|
||||
</ng-template>
|
||||
|
||||
<ng-container *ngIf="(isEditingFileAttribute$ | async) === false || isInEditMode">
|
||||
<ng-container *ngIf="(fileAttributesService.isEditingFileAttribute$ | async) === false || isInEditMode">
|
||||
<div *ngIf="!isInEditMode; else input" class="edit-button">
|
||||
<iqser-circle-button
|
||||
(action)="editFileAttribute()"
|
||||
@ -35,6 +35,3 @@
|
||||
</ng-template>
|
||||
</ng-container>
|
||||
</div>
|
||||
|
||||
<!-- A hack to avoid subscribing in component -->
|
||||
<ng-container *ngIf="selectedFile$ | async"></ng-container>
|
||||
|
||||
@ -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<boolean>;
|
||||
readonly selectedFile$: Observable<boolean>;
|
||||
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<File>,
|
||||
readonly permissionsService: PermissionsService,
|
||||
private readonly _listingService: ListingService<File>,
|
||||
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();
|
||||
|
||||
@ -24,7 +24,6 @@ import {
|
||||
ListingModes,
|
||||
listingProvidersFactory,
|
||||
LoadingService,
|
||||
log,
|
||||
NestedFilter,
|
||||
OnAttach,
|
||||
shareLast,
|
||||
@ -104,7 +103,7 @@ export class DossierOverviewScreenComponent extends ListingComponent<File> 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();
|
||||
|
||||
@ -15,10 +15,7 @@ export class UserService extends IqserUserService<IIqserUser, User> {
|
||||
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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user