RED-5330: download button always available & use new prepare endpoint
This commit is contained in:
parent
06515cd610
commit
cff0d4f01b
@ -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'));
|
||||
}
|
||||
}
|
||||
|
||||
@ -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'));
|
||||
}
|
||||
|
||||
|
||||
@ -29,11 +29,9 @@ export class FileDownloadService extends EntitiesService<IDownloadStatus, Downlo
|
||||
super();
|
||||
}
|
||||
|
||||
downloadFiles(fileIds: List, dossierId: string): Observable<DownloadStatus[]> {
|
||||
return this.prepareDownload({
|
||||
fileIds,
|
||||
dossierId,
|
||||
}).pipe(switchMap(() => this.loadAll()));
|
||||
downloadFiles(request: IPrepareDownloadRequest): Promise<DownloadStatus[]> {
|
||||
const prepare = this.prepareDownload(request).pipe(switchMap(() => this.loadAll()));
|
||||
return firstValueFrom(prepare);
|
||||
}
|
||||
|
||||
loadAll(): Observable<DownloadStatus[]> {
|
||||
@ -61,7 +59,7 @@ export class FileDownloadService extends EntitiesService<IDownloadStatus, Downlo
|
||||
|
||||
@Validate()
|
||||
prepareDownload(@RequiredParam() body: IPrepareDownloadRequest): Observable<IDownloadResponse> {
|
||||
return this._post(body, `${this._defaultModelPath}/prepare`);
|
||||
return this._post(body, `${this._defaultModelPath}/prepare-option`);
|
||||
}
|
||||
|
||||
@Validate()
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -13,7 +13,7 @@ export class RedRoleGuard extends IqserRoleGuard {
|
||||
async canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean> {
|
||||
const currentUser = this._userService.currentUser;
|
||||
|
||||
if (!currentUser.hasAnyRole) {
|
||||
if (!currentUser?.hasAnyRole) {
|
||||
await this._router.navigate(['/auth-error']);
|
||||
this._loadingService.stop();
|
||||
return false;
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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<DownloadFileType>;
|
||||
readonly redactionPreviewColor: string;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user