- split check for can disable or enable auto analysis in two different methods

- split request method for toggle auto analysis in two methods, one for a single file and another for bulk
This commit is contained in:
Valentin Mihai 2022-02-07 13:31:01 +02:00
parent a33be9aadc
commit fb3cc7fc5b
5 changed files with 30 additions and 18 deletions

View File

@ -165,9 +165,9 @@ export class DossierOverviewBulkActionsComponent implements OnChanges {
this.canReanalyse = this._permissionsService.canReanalyseFile(this.selectedFiles);
this.canDisableAutoAnalysis = this._permissionsService.canEnableDisableAutoAnalysis(this.selectedFiles, 'disable');
this.canDisableAutoAnalysis = this._permissionsService.canDisableAutoAnalysis(this.selectedFiles);
this.canEnableAutoAnalysis = this._permissionsService.canEnableDisableAutoAnalysis(this.selectedFiles, 'enable');
this.canEnableAutoAnalysis = this._permissionsService.canEnableAutoAnalysis(this.selectedFiles);
this.canOcr = this.selectedFiles.reduce((acc, file) => acc && file.canBeOCRed, true);

View File

@ -88,7 +88,7 @@ export class BulkActionsService {
async toggleAutomaticAnalysis(files: File[], excluded?: boolean) {
this._loadingService.start();
const fileIds = files.map(file => file.fileId);
await firstValueFrom(this._reanalysisService.toggleAutomaticAnalysis(files[0].dossierId, fileIds, excluded));
await firstValueFrom(this._reanalysisService.toggleAutomaticAnalysisBulk(files[0].dossierId, fileIds, excluded));
this._loadingService.stop();
}

View File

@ -326,7 +326,7 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnDestroy,
await firstValueFrom(
this._reanalysisService.toggleAutomaticAnalysis(
this.file.dossierId,
[this.file.fileId],
this.file.fileId,
!this.file.excludedFromAutomaticAnalysis,
),
);
@ -376,8 +376,8 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnDestroy,
this.showDelete = this._permissionsService.canDeleteFile(this.file);
this.showOCR = this.file.canBeOCRed;
this.canReanalyse = this._permissionsService.canReanalyseFile(this.file);
this.canDisableAutoAnalysis = this._permissionsService.canEnableDisableAutoAnalysis(this.file, 'disable');
this.canEnableAutoAnalysis = this._permissionsService.canEnableDisableAutoAnalysis(this.file, 'enable');
this.canDisableAutoAnalysis = this._permissionsService.canDisableAutoAnalysis([this.file]);
this.canEnableAutoAnalysis = this._permissionsService.canEnableAutoAnalysis([this.file]);
this.showStatusBar = !this.file.isError && !this.file.isPending && this.isDossierOverviewList;

View File

@ -32,9 +32,12 @@ export class PermissionsService {
return files.reduce((acc, _file) => this._canReanalyseFile(_file) && acc, true);
}
canEnableDisableAutoAnalysis(file: File | File[], value: 'enable' | 'disable'): boolean {
const files = file instanceof File ? [file] : file;
return files.reduce((acc, _file) => this._canEnableDisableAutoAnalysis(_file, value) && acc, true);
canEnableAutoAnalysis(files: File[]): boolean {
return files.reduce((acc, _file) => this._canEnableAutoAnalysis(_file) && acc, true);
}
canDisableAutoAnalysis(files: File[]): boolean {
return files.reduce((acc, _file) => this._canDisableAutoAnalysis(_file) && acc, true);
}
isFileAssignee(file: File): boolean {
@ -163,9 +166,12 @@ export class PermissionsService {
return this.isReviewerOrApprover(file) || file.isNew || (file.isError && file.isNew);
}
private _canEnableDisableAutoAnalysis(file: File, value: 'enable' | 'disable'): boolean {
const enableOrDisable = value === 'enable' ? file.excludedFromAutomaticAnalysis : !file.excludedFromAutomaticAnalysis;
return enableOrDisable && file.assignee === this._userService.currentUser.id;
private _canEnableAutoAnalysis(file: File): boolean {
return file.excludedFromAutomaticAnalysis && file.assignee === this._userService.currentUser.id;
}
private _canDisableAutoAnalysis(file: File): boolean {
return !file.excludedFromAutomaticAnalysis && file.assignee === this._userService.currentUser.id;
}
private _canAssignToSelf(file: File, dossier: Dossier): boolean {

View File

@ -53,13 +53,19 @@ export class ReanalysisService extends GenericService<unknown> {
}
@Validate()
toggleAutomaticAnalysis(@RequiredParam() dossierId: string, @RequiredParam() fileIds: string[], excluded?: boolean) {
toggleAutomaticAnalysis(@RequiredParam() dossierId: string, @RequiredParam() fileId: string, excluded?: boolean) {
const queryParams: QueryParam[] = [{ key: 'excluded', value: !!excluded }];
return this._post(
fileIds.length > 1 ? fileIds : {},
`toggle-automatic-analysis/${dossierId}/${fileIds.length > 1 ? 'bulk' : fileIds[0]}`,
queryParams,
).pipe(switchMap(() => this._filesService.loadAll(dossierId)));
return this._post({}, `toggle-automatic-analysis/${dossierId}/${fileId}`, queryParams).pipe(
switchMap(() => this._filesService.loadAll(dossierId)),
);
}
@Validate()
toggleAutomaticAnalysisBulk(@RequiredParam() dossierId: string, @RequiredParam() fileIds: string[], excluded?: boolean) {
const queryParams: QueryParam[] = [{ key: 'excluded', value: !!excluded }];
return this._post(fileIds, 'toggle-automatic-analysis/bulk', queryParams).pipe(
switchMap(() => this._filesService.loadAll(dossierId)),
);
}
@Validate()