From cff0d4f01be24104cd365ea95e1285aba5ed1bab Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Fri, 9 Dec 2022 13:24:50 +0200 Subject: [PATCH] RED-5330: download button always available & use new prepare endpoint --- .../file-download-btn.component.ts | 10 +++++++--- .../expandable-file-actions.component.ts | 15 ++++++++++----- .../services/file-download.service.ts | 10 ++++------ .../src/app/services/permissions.service.ts | 2 +- apps/red-ui/src/app/users/red-role.guard.ts | 2 +- apps/red-ui/src/assets/i18n/redact/en.json | 2 +- apps/red-ui/src/assets/i18n/scm/en.json | 2 +- .../src/lib/downloads/prepare-download.request.ts | 8 ++++++-- 8 files changed, 31 insertions(+), 20 deletions(-) diff --git a/apps/red-ui/src/app/modules/shared/components/buttons/file-download-btn/file-download-btn.component.ts b/apps/red-ui/src/app/modules/shared/components/buttons/file-download-btn/file-download-btn.component.ts index 0c9f3f8d9..a36f4e61c 100644 --- a/apps/red-ui/src/app/modules/shared/components/buttons/file-download-btn/file-download-btn.component.ts +++ b/apps/red-ui/src/app/modules/shared/components/buttons/file-download-btn/file-download-btn.component.ts @@ -4,7 +4,6 @@ import { Dossier, File } from '@red/domain'; import { FileDownloadService } from '@upload-download/services/file-download.service'; import { CircleButtonType, CircleButtonTypes, Toaster } from '@iqser/common-ui'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; -import { firstValueFrom } from 'rxjs'; @Component({ selector: 'redaction-file-download-btn [files] [dossier]', @@ -35,9 +34,14 @@ export class FileDownloadBtnComponent implements OnChanges { async downloadFiles($event: MouseEvent) { $event.stopPropagation(); - const dossierId = this.files[0].dossierId; const filesIds = this.files.map(f => f.id); - await firstValueFrom(this._fileDownloadService.downloadFiles(filesIds, dossierId)); + await this._fileDownloadService.downloadFiles({ + dossierId: this.dossier.id, + fileIds: filesIds, + reportTemplateIds: this.dossier.reportTemplateIds, + downloadFileTypes: this.dossier.downloadFileTypes, + redactionPreviewColor: undefined, + }); this._toaster.info(_('download-status.queued')); } } diff --git a/apps/red-ui/src/app/modules/shared/components/expandable-file-actions/expandable-file-actions.component.ts b/apps/red-ui/src/app/modules/shared/components/expandable-file-actions/expandable-file-actions.component.ts index 7dc7730c1..395038fdd 100644 --- a/apps/red-ui/src/app/modules/shared/components/expandable-file-actions/expandable-file-actions.component.ts +++ b/apps/red-ui/src/app/modules/shared/components/expandable-file-actions/expandable-file-actions.component.ts @@ -1,5 +1,5 @@ import { ChangeDetectionStrategy, Component, Input, OnChanges, SimpleChanges, ViewChild } from '@angular/core'; -import { Action, ActionTypes, File } from '@red/domain'; +import { Action, ActionTypes, Dossier, File } from '@red/domain'; import { CircleButtonType, IqserTooltipPosition, @@ -72,7 +72,7 @@ export class ExpandableFileActionsComponent implements OnChanges { // Patch download button const downloadBtn = this.actions.find(btn => btn.type === ActionTypes.downloadBtn); if (downloadBtn) { - downloadBtn.action = ($event: MouseEvent) => this._downloadFiles($event, downloadBtn.files); + downloadBtn.action = ($event: MouseEvent) => this._downloadFiles($event, downloadBtn.files, downloadBtn.dossier); downloadBtn.disabled = !this._permissionsService.canDownloadFiles(downloadBtn.files, downloadBtn.dossier); } } @@ -83,11 +83,16 @@ export class ExpandableFileActionsComponent implements OnChanges { } } - private async _downloadFiles($event: MouseEvent, files: File[]) { + private async _downloadFiles($event: MouseEvent, files: File[], dossier: Dossier) { $event.stopPropagation(); - const dossierId = files[0].dossierId; const filesIds = files.map(f => f.id); - await firstValueFrom(this._fileDownloadService.downloadFiles(filesIds, dossierId)); + await this._fileDownloadService.downloadFiles({ + dossierId: dossier.id, + fileIds: filesIds, + reportTemplateIds: dossier.reportTemplateIds, + downloadFileTypes: dossier.downloadFileTypes, + redactionPreviewColor: undefined, + }); this._toaster.info(_('download-status.queued')); } diff --git a/apps/red-ui/src/app/modules/upload-download/services/file-download.service.ts b/apps/red-ui/src/app/modules/upload-download/services/file-download.service.ts index 18a766f97..7bb2ea402 100644 --- a/apps/red-ui/src/app/modules/upload-download/services/file-download.service.ts +++ b/apps/red-ui/src/app/modules/upload-download/services/file-download.service.ts @@ -29,11 +29,9 @@ export class FileDownloadService extends EntitiesService { - return this.prepareDownload({ - fileIds, - dossierId, - }).pipe(switchMap(() => this.loadAll())); + downloadFiles(request: IPrepareDownloadRequest): Promise { + const prepare = this.prepareDownload(request).pipe(switchMap(() => this.loadAll())); + return firstValueFrom(prepare); } loadAll(): Observable { @@ -61,7 +59,7 @@ export class FileDownloadService extends EntitiesService { - return this._post(body, `${this._defaultModelPath}/prepare`); + return this._post(body, `${this._defaultModelPath}/prepare-option`); } @Validate() diff --git a/apps/red-ui/src/app/services/permissions.service.ts b/apps/red-ui/src/app/services/permissions.service.ts index 86d6a4964..f82d8483e 100644 --- a/apps/red-ui/src/app/services/permissions.service.ts +++ b/apps/red-ui/src/app/services/permissions.service.ts @@ -261,7 +261,7 @@ export class PermissionsService { if (files.length === 0) { return false; } - return this.isApprover(dossier) && files.reduce((prev, file) => prev && file.isApproved, true); + return this.isApprover(dossier) && files.reduce((prev, file) => prev && !file.isInitialProcessing, true); } canSoftDeleteDossier(dossier: IDossier): boolean { diff --git a/apps/red-ui/src/app/users/red-role.guard.ts b/apps/red-ui/src/app/users/red-role.guard.ts index 2d7dfc9b5..7a5b156ec 100644 --- a/apps/red-ui/src/app/users/red-role.guard.ts +++ b/apps/red-ui/src/app/users/red-role.guard.ts @@ -13,7 +13,7 @@ export class RedRoleGuard extends IqserRoleGuard { async canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise { const currentUser = this._userService.currentUser; - if (!currentUser.hasAnyRole) { + if (!currentUser?.hasAnyRole) { await this._router.navigate(['/auth-error']); this._loadingService.stop(); return false; diff --git a/apps/red-ui/src/assets/i18n/redact/en.json b/apps/red-ui/src/assets/i18n/redact/en.json index 79bb30582..7cebea594 100644 --- a/apps/red-ui/src/assets/i18n/redact/en.json +++ b/apps/red-ui/src/assets/i18n/redact/en.json @@ -849,7 +849,7 @@ } }, "download-file": "Download", - "download-file-disabled": "You need to be approver in the dossier and the {count, plural, one{file needs} other{files need}} to be approved in order to download.", + "download-file-disabled": "You need to be approver in the dossier and the {count, plural, one{file needs} other{files need}} to be initially processed in order to download.", "file-listing": { "file-entry": { "file-error": "Re-processing required", diff --git a/apps/red-ui/src/assets/i18n/scm/en.json b/apps/red-ui/src/assets/i18n/scm/en.json index d3360d811..985cd343f 100644 --- a/apps/red-ui/src/assets/i18n/scm/en.json +++ b/apps/red-ui/src/assets/i18n/scm/en.json @@ -849,7 +849,7 @@ } }, "download-file": "Download", - "download-file-disabled": "You need to be approver in the dossier and the {count, plural, one{file needs} other{files need}} to be approved in order to download.", + "download-file-disabled": "You need to be approver in the dossier and the {count, plural, one{file needs} other{files need}} to be initially processed in order to download.", "file-listing": { "file-entry": { "file-error": "Re-processing required", diff --git a/libs/red-domain/src/lib/downloads/prepare-download.request.ts b/libs/red-domain/src/lib/downloads/prepare-download.request.ts index cade875c9..22f7295ef 100644 --- a/libs/red-domain/src/lib/downloads/prepare-download.request.ts +++ b/libs/red-domain/src/lib/downloads/prepare-download.request.ts @@ -2,8 +2,12 @@ * Object containing information on which file and report types should be included in the download. */ import { List } from '@iqser/common-ui'; +import { DownloadFileType } from '../shared'; export interface IPrepareDownloadRequest { - readonly dossierId?: string; - readonly fileIds?: List; + readonly dossierId: string; + readonly fileIds: List; + readonly reportTemplateIds: List; + readonly downloadFileTypes: List; + readonly redactionPreviewColor: string; }