RED-3949: fix assigning under approval file to me
This commit is contained in:
parent
e73f8e7950
commit
a6ab0b6f7d
@ -1,44 +1,44 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { UserService } from '@services/user.service';
|
||||
import { Dossier, File } from '@red/domain';
|
||||
import { Dossier, File, User } from '@red/domain';
|
||||
import { DossiersDialogService } from './dossiers-dialog.service';
|
||||
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
||||
import { FilesService } from '@services/files/files.service';
|
||||
import { ConfirmationDialogInput, LoadingService, Toaster } from '@iqser/common-ui';
|
||||
import { ActiveDossiersService } from '@services/dossiers/active-dossiers.service';
|
||||
import { firstValueFrom, Observable } from 'rxjs';
|
||||
import { tap } from 'rxjs/operators';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
|
||||
const changeReviewerDialogInput = new ConfirmationDialogInput({
|
||||
title: _('confirmation-dialog.assign-file-to-me.title'),
|
||||
question: _('confirmation-dialog.assign-file-to-me.question'),
|
||||
});
|
||||
|
||||
const changeApproverDialogInput = new ConfirmationDialogInput({
|
||||
title: _('confirmation-dialog.assign-me-as-approver.title'),
|
||||
question: _('confirmation-dialog.assign-me-as-approver.question'),
|
||||
});
|
||||
|
||||
const atLeastOneAssignee = (files: File[]) => files.reduce((acc, fs) => acc || !!fs.assignee, false);
|
||||
|
||||
@Injectable()
|
||||
export class FileAssignService {
|
||||
readonly currentUser: User;
|
||||
|
||||
constructor(
|
||||
private readonly _dialogService: DossiersDialogService,
|
||||
private readonly _userService: UserService,
|
||||
private readonly _filesService: FilesService,
|
||||
private readonly _activeDossiersService: ActiveDossiersService,
|
||||
private readonly _loadingService: LoadingService,
|
||||
userService: UserService,
|
||||
private readonly _toaster: Toaster,
|
||||
) {}
|
||||
private readonly _filesService: FilesService,
|
||||
private readonly _loadingService: LoadingService,
|
||||
private readonly _dialogService: DossiersDialogService,
|
||||
private readonly _activeDossiersService: ActiveDossiersService,
|
||||
) {
|
||||
this.currentUser = userService.currentUser;
|
||||
}
|
||||
|
||||
async assignToMe(files: File[]) {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
const atLeastOneFileHasReviewer = files.reduce((acc, fs) => acc || !!fs.assignee, false);
|
||||
if (atLeastOneFileHasReviewer) {
|
||||
const data = new ConfirmationDialogInput({
|
||||
title: _('confirmation-dialog.assign-file-to-me.title'),
|
||||
question: _('confirmation-dialog.assign-file-to-me.question'),
|
||||
});
|
||||
this._dialogService.openDialog('confirm', null, data, () => {
|
||||
firstValueFrom(this._assignReviewerToCurrentUser(files))
|
||||
.then(() => resolve())
|
||||
.catch(() => reject());
|
||||
});
|
||||
} else {
|
||||
firstValueFrom(this._assignReviewerToCurrentUser(files))
|
||||
.then(() => resolve())
|
||||
.catch(() => reject());
|
||||
}
|
||||
});
|
||||
const filesAreUnderApproval = files.reduce((acc, fs) => acc && fs.isUnderApproval, true);
|
||||
|
||||
return filesAreUnderApproval ? this.#assignMeAsApprover(files) : this.#assignMeAsReviewer(files);
|
||||
}
|
||||
|
||||
async assignReviewer($event: MouseEvent, file: File, ignoreChanged = false): Promise<void> {
|
||||
@ -49,10 +49,32 @@ export class FileAssignService {
|
||||
await this._assignFile('approver', $event, file, ignoreChanged);
|
||||
}
|
||||
|
||||
#assignMeAsReviewer(files: File[]) {
|
||||
if (atLeastOneAssignee(files)) {
|
||||
const cb = () => this.#assignReviewerToCurrentUser(files);
|
||||
const ref = this._dialogService.openDialog('confirm', null, changeReviewerDialogInput, cb);
|
||||
|
||||
return firstValueFrom(ref.afterClosed());
|
||||
}
|
||||
|
||||
return this.#assignReviewerToCurrentUser(files);
|
||||
}
|
||||
|
||||
#assignMeAsApprover(files: File[]) {
|
||||
if (atLeastOneAssignee(files)) {
|
||||
const cb = () => this.#assignApproverToCurrentUser(files);
|
||||
const ref = this._dialogService.openDialog('confirm', null, changeApproverDialogInput, cb);
|
||||
|
||||
return firstValueFrom(ref.afterClosed());
|
||||
}
|
||||
|
||||
return this.#assignApproverToCurrentUser(files);
|
||||
}
|
||||
|
||||
private async _assignFile(mode: 'reviewer' | 'approver', $event: MouseEvent, file: File, ignoreChanged = false): Promise<void> {
|
||||
$event?.stopPropagation();
|
||||
|
||||
const currentUserId = this._userService.currentUser.id;
|
||||
const currentUserId = this.currentUser.id;
|
||||
const currentDossier = this._activeDossiersService.find(file.dossierId);
|
||||
const eligibleUsersIds = this._getUserIds(mode, currentDossier);
|
||||
|
||||
@ -97,10 +119,17 @@ export class FileAssignService {
|
||||
return mode === 'approver' ? dossier.approverIds : dossier.memberIds;
|
||||
}
|
||||
|
||||
private _assignReviewerToCurrentUser(files: File[]): Observable<any> {
|
||||
async #assignReviewerToCurrentUser(files: File[]) {
|
||||
this._loadingService.start();
|
||||
return this._filesService
|
||||
.setReviewerFor(files, files[0].dossierId, this._userService.currentUser.id)
|
||||
.pipe(tap(() => this._loadingService.stop()));
|
||||
const reviewer$ = this._filesService.setReviewerFor(files, files[0].dossierId, this.currentUser.id);
|
||||
await firstValueFrom(reviewer$);
|
||||
this._loadingService.stop();
|
||||
}
|
||||
|
||||
async #assignApproverToCurrentUser(files: File[]) {
|
||||
this._loadingService.start();
|
||||
const approver$ = this._filesService.setUnderApprovalFor(files, files[0].dossierId, this.currentUser.id);
|
||||
await firstValueFrom(approver$);
|
||||
this._loadingService.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{
|
||||
"ADMIN_CONTACT_NAME": null,
|
||||
"ADMIN_CONTACT_URL": null,
|
||||
"API_URL": "https://dev-05.iqser.cloud/redaction-gateway-v1",
|
||||
"API_URL": "https://dev-08.iqser.cloud/redaction-gateway-v1",
|
||||
"APP_NAME": "RedactManager",
|
||||
"AUTO_READ_TIME": 3,
|
||||
"BACKEND_APP_VERSION": "4.4.40",
|
||||
@ -16,7 +16,7 @@
|
||||
"MAX_RETRIES_ON_SERVER_ERROR": 3,
|
||||
"OAUTH_CLIENT_ID": "redaction",
|
||||
"OAUTH_IDP_HINT": null,
|
||||
"OAUTH_URL": "https://dev-05.iqser.cloud/auth/realms/redaction",
|
||||
"OAUTH_URL": "https://dev-08.iqser.cloud/auth/realms/redaction",
|
||||
"RECENT_PERIOD_IN_HOURS": 24,
|
||||
"SELECTION_MODE": "structural",
|
||||
"MANUAL_BASE_URL": "https://docs.redactmanager.com/preview"
|
||||
|
||||
@ -554,6 +554,10 @@
|
||||
"question": "Dieses Dokument wird gerade von einer anderen Person geprüft. Möchten Sie Reviewer werden und sich selbst dem Dokument zuweisen?",
|
||||
"title": "Neuen Reviewer zuweisen"
|
||||
},
|
||||
"assign-me-as-approver": {
|
||||
"question": "",
|
||||
"title": ""
|
||||
},
|
||||
"compare-file": {
|
||||
"question": "<strong>Achtung!</strong> <br><br> Seitenzahl stimmt nicht überein, aktuelles Dokument hat <strong>{currentDocumentPageCount} Seite(n)</strong>. Das hochgeladene Dokument hat <strong>{compareDocumentPageCount} Seite(n)</strong>. <br><br> Möchten Sie fortfahren?",
|
||||
"title": "Vergleichen mit: {fileName}"
|
||||
|
||||
@ -554,6 +554,10 @@
|
||||
"question": "This document is currently reviewed by someone else. Do you want to become the reviewer and assign yourself to this document?",
|
||||
"title": "Re-assign user"
|
||||
},
|
||||
"assign-me-as-approver": {
|
||||
"question": "This document is currently under approval by someone else. Do you want to become the approver and assign yourself to this document?",
|
||||
"title": "Re-assign approver"
|
||||
},
|
||||
"compare-file": {
|
||||
"question": "<strong>Warning!</strong> <br><br> Number of pages does not match, current document has <strong>{currentDocumentPageCount} page(s)</strong>. Uploaded document has <strong>{compareDocumentPageCount} page(s)</strong>. <br><br> Do you wish to proceed?",
|
||||
"title": "Compare with file: {fileName}"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user