From f6e9e170111f495af65f1616575b7fc81f67f65f Mon Sep 17 00:00:00 2001 From: Timo Date: Mon, 24 May 2021 14:48:27 +0300 Subject: [PATCH] fixed RED-1541 --- ...project-overview-bulk-actions.component.ts | 8 ++-- .../projects/services/file-action.service.ts | 42 +++++++++++-------- .../services/projects-dialog.service.ts | 2 +- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/apps/red-ui/src/app/modules/projects/components/bulk-actions/project-overview-bulk-actions.component.ts b/apps/red-ui/src/app/modules/projects/components/bulk-actions/project-overview-bulk-actions.component.ts index c73ed40bf..83b7a9287 100644 --- a/apps/red-ui/src/app/modules/projects/components/bulk-actions/project-overview-bulk-actions.component.ts +++ b/apps/red-ui/src/app/modules/projects/components/bulk-actions/project-overview-bulk-actions.component.ts @@ -8,7 +8,7 @@ import { import { PermissionsService } from '@services/permissions.service'; import { FileStatusWrapper } from '@models/file/file-status.wrapper'; import { FileActionService } from '../../services/file-action.service'; -import { Observable } from 'rxjs'; +import { from, Observable } from 'rxjs'; import { StatusOverlayService } from '@upload-download/services/status-overlay.service'; import { ProjectsDialogService } from '../../services/projects-dialog.service'; @@ -236,6 +236,10 @@ export class ProjectOverviewBulkActionsComponent { this._performBulkAction(this._fileActionService.setFileApproved(this.selectedFiles)); } + assignToMe() { + this._performBulkAction(from(this._fileActionService.assignToMe(this.selectedFiles))); + } + private _performBulkAction(obs: Observable) { this.loading = true; obs.subscribe().add(() => { @@ -257,6 +261,4 @@ export class ProjectOverviewBulkActionsComponent { this.loading = false; }); } - - assignToMe() {} } diff --git a/apps/red-ui/src/app/modules/projects/services/file-action.service.ts b/apps/red-ui/src/app/modules/projects/services/file-action.service.ts index b0a995631..a99666298 100644 --- a/apps/red-ui/src/app/modules/projects/services/file-action.service.ts +++ b/apps/red-ui/src/app/modules/projects/services/file-action.service.ts @@ -1,11 +1,7 @@ import { Injectable } from '@angular/core'; import { AppStateService } from '@state/app-state.service'; import { UserService } from '@services/user.service'; -import { - FileStatus, - ReanalysisControllerService, - StatusControllerService -} from '@redaction/red-ui-http'; +import { ReanalysisControllerService, StatusControllerService } from '@redaction/red-ui-http'; import { FileStatusWrapper } from '@models/file/file-status.wrapper'; import { PermissionsService } from '@services/permissions.service'; import { isArray } from 'rxjs/internal-compatibility'; @@ -88,16 +84,21 @@ export class FileActionService { ); } - async assignToMe(file?: FileStatusWrapper, callback?: Function) { - if (!file.currentReviewer) { - await this._assignReviewerToCurrentUser(file, callback); + async assignToMe(fileStatus?: FileStatusWrapper | FileStatusWrapper[], callback?: Function) { + if (!isArray(fileStatus)) { + fileStatus = [fileStatus]; + } + + const atLeastOneFileHasReviewer = fileStatus.reduce( + (acc, fs) => acc || !!fs.currentReviewer, + false + ); + if (atLeastOneFileHasReviewer) { + this._dialogService.openAssignFileToMeDialog(async () => { + await this._assignReviewerToCurrentUser(fileStatus, callback); + }); } else { - this._dialogService.openAssignFileToMeDialog( - file ? file : this._appStateService.activeFile, - async () => { - await this._assignReviewerToCurrentUser(file, callback); - } - ); + await this._assignReviewerToCurrentUser(fileStatus, callback); } } @@ -160,12 +161,17 @@ export class FileActionService { ); } - private async _assignReviewerToCurrentUser(file?: FileStatus, callback?: Function) { - console.log('assign here'); + private async _assignReviewerToCurrentUser( + fileStatus: FileStatusWrapper | FileStatusWrapper[], + callback?: Function + ) { + if (!isArray(fileStatus)) { + fileStatus = [fileStatus]; + } await this._statusControllerService - .setFileReviewer( + .setFileReviewerForList( + fileStatus.map((f) => f.fileId), this._appStateService.activeProjectId, - file.fileId, this._userService.userId ) .toPromise(); diff --git a/apps/red-ui/src/app/modules/projects/services/projects-dialog.service.ts b/apps/red-ui/src/app/modules/projects/services/projects-dialog.service.ts index eebd4cbfd..5fa72f5e5 100644 --- a/apps/red-ui/src/app/modules/projects/services/projects-dialog.service.ts +++ b/apps/red-ui/src/app/modules/projects/services/projects-dialog.service.ts @@ -248,7 +248,7 @@ export class ProjectsDialogService { return ref; } - openAssignFileToMeDialog(file: FileStatus, cb?: Function) { + openAssignFileToMeDialog(cb?: Function) { const ref = this._dialog.open(ConfirmationDialogComponent, { ...dialogConfig, data: new ConfirmationDialogInput({