From c343699a3fbeb70abbd3bccd5323697f4e9799fc Mon Sep 17 00:00:00 2001 From: Valentin Date: Mon, 18 Oct 2021 22:23:39 +0300 Subject: [PATCH] automatically assigned reviewer in the Workflow View if there is only one potential Reviewer instead of opening the dialog --- .../shared/services/file-action.service.ts | 48 ++++++++++++++++--- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/apps/red-ui/src/app/modules/dossier/shared/services/file-action.service.ts b/apps/red-ui/src/app/modules/dossier/shared/services/file-action.service.ts index 21ab6dcd3..623ced42f 100644 --- a/apps/red-ui/src/app/modules/dossier/shared/services/file-action.service.ts +++ b/apps/red-ui/src/app/modules/dossier/shared/services/file-action.service.ts @@ -6,7 +6,7 @@ import { PermissionsService } from '@services/permissions.service'; import { DossiersDialogService } from '../../services/dossiers-dialog.service'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { FilesService } from '@services/entity-services/files.service'; -import { ConfirmationDialogInput } from '@iqser/common-ui'; +import { ConfirmationDialogInput, Toaster } from '@iqser/common-ui'; import { DossiersService } from '@services/entity-services/dossiers.service'; import { ReanalysisService } from '@services/reanalysis.service'; @@ -20,6 +20,8 @@ export class FileActionService { private readonly _reanalysisService: ReanalysisService, private readonly _appStateService: AppStateService, private readonly _dossiersService: DossiersService, + private readonly _filesService: FilesService, + private readonly _toaster: Toaster, ) {} reanalyseFile(file = this._appStateService.activeFile) { @@ -91,12 +93,46 @@ export class FileActionService { callback?: Function, ignoreChanged = false, ) { - const data = { mode, files: [file], ignoreChanged }; - this._dialogService.openDialog('assignFile', $event, data, async () => { - if (callback) { - await callback(); + const userIds = + mode === 'approver' ? this._dossiersService.activeDossier.approverIds : this._dossiersService.activeDossier.memberIds; + if (userIds.length === 1) { + this._assignFile(userIds[0], mode, [file]).then(async () => { + if (callback) { + await callback(); + } + }); + } else { + const data = { mode, files: [file], ignoreChanged }; + this._dialogService.openDialog('assignFile', $event, data, async () => { + if (callback) { + await callback(); + } + }); + } + } + + private async _assignFile(userId: string, mode: 'reviewer' | 'approver', files: File[]) { + try { + if (mode === 'reviewer') { + await this._filesService + .setReviewerFor( + files.map(f => f.fileId), + this._dossiersService.activeDossierId, + userId, + ) + .toPromise(); + } else { + await this._filesService + .setUnderApprovalFor( + files.map(f => f.fileId), + this._dossiersService.activeDossierId, + userId, + ) + .toPromise(); } - }); + } catch (error) { + this._toaster.error(_('error.http.generic'), { params: error }); + } } private async _assignReviewerToCurrentUser(files: File[], callback?: Function) {