automatically assigned reviewer in the Workflow View if there is only one potential Reviewer instead of opening the dialog

This commit is contained in:
Valentin 2021-10-18 22:23:39 +03:00
parent b43c788d4d
commit c343699a3f

View File

@ -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) {