diff --git a/apps/red-ui/src/app/modules/shared-dossiers/services/file-assign.service.ts b/apps/red-ui/src/app/modules/shared-dossiers/services/file-assign.service.ts index cd7b5ab51..82269a1f3 100644 --- a/apps/red-ui/src/app/modules/shared-dossiers/services/file-assign.service.ts +++ b/apps/red-ui/src/app/modules/shared-dossiers/services/file-assign.service.ts @@ -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((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 { @@ -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 { $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 { + 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(); } } diff --git a/apps/red-ui/src/assets/config/config.json b/apps/red-ui/src/assets/config/config.json index f9a12cdad..322276d2f 100644 --- a/apps/red-ui/src/assets/config/config.json +++ b/apps/red-ui/src/assets/config/config.json @@ -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" diff --git a/apps/red-ui/src/assets/i18n/de.json b/apps/red-ui/src/assets/i18n/de.json index a067e33ca..2ac69a86c 100644 --- a/apps/red-ui/src/assets/i18n/de.json +++ b/apps/red-ui/src/assets/i18n/de.json @@ -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": "Achtung!

Seitenzahl stimmt nicht überein, aktuelles Dokument hat {currentDocumentPageCount} Seite(n). Das hochgeladene Dokument hat {compareDocumentPageCount} Seite(n).

Möchten Sie fortfahren?", "title": "Vergleichen mit: {fileName}" diff --git a/apps/red-ui/src/assets/i18n/en.json b/apps/red-ui/src/assets/i18n/en.json index 2062802b5..0948840e8 100644 --- a/apps/red-ui/src/assets/i18n/en.json +++ b/apps/red-ui/src/assets/i18n/en.json @@ -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": "Warning!

Number of pages does not match, current document has {currentDocumentPageCount} page(s). Uploaded document has {compareDocumentPageCount} page(s).

Do you wish to proceed?", "title": "Compare with file: {fileName}"