RED-5976: Fixed download button disabling and treated errors.

This commit is contained in:
Nicoleta Panaghiu 2023-02-02 15:33:30 +02:00
parent a13f2da9f5
commit 7206564543
10 changed files with 41 additions and 26 deletions

View File

@ -1,6 +1,6 @@
import { ChangeDetectionStrategy, Component, Input, OnChanges } from '@angular/core';
import { PermissionsService } from '@services/permissions.service';
import { Action, ActionTypes, Dossier, File } from '@red/domain';
import { Action, ActionTypes, Dossier, File, ProcessingFileStatuses } from '@red/domain';
import { CircleButtonType, CircleButtonTypes, ListingModes } from '@iqser/common-ui';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { LongPressEvent } from '@shared/directives/long-press.directive';
@ -94,7 +94,7 @@ export class DossierOverviewBulkActionsComponent implements OnChanges {
},
{
type: ActionTypes.downloadBtn,
show: true,
show: !this.selectedFiles.some(file => file.processingStatus === ProcessingFileStatuses.ERROR),
files: this.selectedFiles,
dossier: this.dossier,
},

View File

@ -11,7 +11,7 @@ import {
ViewChild,
} from '@angular/core';
import { PermissionsService } from '@services/permissions.service';
import { Action, ActionTypes, Dossier, File, User } from '@red/domain';
import { Action, ActionTypes, Dossier, File, ProcessingFileStatuses, User } from '@red/domain';
import { DossiersDialogService } from '../../services/dossiers-dialog.service';
import {
CircleButtonType,
@ -165,6 +165,7 @@ export class FileActionsComponent implements OnChanges {
dossier: this.dossier,
tooltipClass: 'small',
show: this._permissionsService.canDownloadRedactedFile(),
disabled: this.file.processingStatus === ProcessingFileStatuses.ERROR,
},
{
type: ActionTypes.circleBtn,

View File

@ -1,9 +1,9 @@
<iqser-circle-button
(action)="downloadFiles($event)"
[disabled]="disabled || !canDownloadFiles"
[disabled]="disabled || !canDownloadFiles || invalidDownload"
[tooltipClass]="tooltipClass"
[tooltipPosition]="tooltipPosition"
[tooltip]="tooltip | translate: { count: this.files.length }"
[tooltip]="tooltip | translate : { count: this.files.length }"
[type]="type"
icon="iqser:download"
></iqser-circle-button>

View File

@ -1,6 +1,6 @@
import { ChangeDetectionStrategy, Component, Input, OnChanges } from '@angular/core';
import { PermissionsService } from '@services/permissions.service';
import { Dossier, File } from '@red/domain';
import { Dossier, File, ProcessingFileStatuses } from '@red/domain';
import { FileDownloadService } from '@upload-download/services/file-download.service';
import { CircleButtonType, CircleButtonTypes, defaultDialogConfig, Toaster } from '@iqser/common-ui';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
@ -35,6 +35,10 @@ export class FileDownloadBtnComponent implements OnChanges {
private readonly _toaster: Toaster,
) {}
get invalidDownload() {
return this.files.some(file => file.processingStatus === ProcessingFileStatuses.ERROR);
}
ngOnChanges(): void {
this.canDownloadFiles = this._permissionsService.canDownloadFiles(this.files, this.dossier);
this.tooltip = this.canDownloadFiles ? _('dossier-overview.download-file') : _('dossier-overview.download-file-disabled');
@ -44,18 +48,20 @@ export class FileDownloadBtnComponent implements OnChanges {
$event.stopPropagation();
const ref = this._dialog.open<DownloadDialogComponent, DownloadDialogData, DownloadDialogResult>(DownloadDialogComponent, {
...defaultDialogConfig,
data: { dossier: this.dossier, hasUnapprovedDocuments: this.files.some(file => !file.isApproved) },
data: { dossier: this.dossier, files: this.files },
});
const result = await firstValueFrom(ref.afterClosed());
if (!result) {
return;
}
await this._fileDownloadService.downloadFiles({
dossierId: this.dossier.id,
fileIds: this.files.map(f => f.id),
...result,
});
this._toaster.info(_('download-status.queued'));
await this._fileDownloadService
.downloadFiles({
dossierId: this.dossier.id,
fileIds: this.files.map(f => f.id),
...result,
})
.then(() => this._toaster.info(_('download-status.queued')))
.catch(() => this._toaster.error(_('download-status.error')));
}
}

View File

@ -21,6 +21,7 @@
[tooltipClass]="btn.tooltipClass"
[tooltipPosition]="tooltipPosition"
[type]="buttonType"
[disabled]="btn.disabled"
></redaction-file-download-btn>
<!-- exclude from redaction -->

View File

@ -84,7 +84,7 @@ export class ExpandableFileActionsComponent implements OnChanges {
$event.stopPropagation();
const ref = this._dialog.open<DownloadDialogComponent, DownloadDialogData, DownloadDialogResult>(DownloadDialogComponent, {
...defaultDialogConfig,
data: { dossier, hasUnapprovedDocuments: files.some(file => !file.isApproved) },
data: { dossier, files },
});
const result = await firstValueFrom(ref.afterClosed());
if (!result) {

View File

@ -2,7 +2,7 @@
<form *ngIf="form" [formGroup]="form">
<div [translate]="'download-dialog.header'" class="dialog-header heading-l"></div>
<div *ngIf="data.hasUnapprovedDocuments" class="inline-dialog-toast toast-warning">
<div *ngIf="hasUnapprovedFiles" class="inline-dialog-toast toast-warning">
<div [translate]="'download-dialog.unapproved-files-warning'"></div>
</div>

View File

@ -1,5 +1,5 @@
import { Component, Inject } from '@angular/core';
import { Dossier, DownloadFileType, DownloadFileTypes, IReportTemplate } from '@red/domain';
import { Dossier, DownloadFileType, DownloadFileTypes, IReportTemplate, File, WorkflowFileStatuses } from '@red/domain';
import { downloadTypesForDownloadTranslations } from '@translations/download-types-translations';
import { ReportTemplateService } from '@services/report-template.service';
import { AbstractControl, FormBuilder } from '@angular/forms';
@ -9,7 +9,7 @@ import { IconButtonTypes, List } from '@iqser/common-ui';
export interface DownloadDialogData {
readonly dossier: Dossier;
readonly hasUnapprovedDocuments: boolean;
readonly files: File[];
}
export interface DownloadDialogResult {
@ -50,6 +50,18 @@ export class DownloadDialogComponent {
return this.form.controls.downloadFileTypes?.value?.length || 0;
}
get hasUnapprovedFiles() {
return this.data.files.some(file => !file.isApproved);
}
get invalidDownload() {
return (
!!this.form.controls.downloadFileTypes.value.length &&
this.form.controls.downloadFileTypes.value.every(type => type === DownloadFileTypes.REDACTED) &&
!this.data.files.some(file => file.workflowStatus === WorkflowFileStatuses.APPROVED)
);
}
private get _availableReportTypes() {
const dossierTemplateId = this.data.dossier.dossierTemplateId;
const result = this._reportTemplateController.getAvailableReportTemplates(dossierTemplateId);
@ -72,13 +84,6 @@ export class DownloadDialogComponent {
this._dialogRef.close();
}
get invalidDownload() {
return (
this.form.controls.downloadFileTypes.value.every(type => type === DownloadFileTypes.REDACTED) &&
this.data.hasUnapprovedDocuments
);
}
private _hasReportTemplateOrDownloadType(control: AbstractControl) {
const atLeastAReportSelected = control.get('reportTemplateIds')?.value.length > 0;
const atLeastATypeSelected = control.get('downloadFileTypes')?.value.length > 0;

View File

@ -1053,7 +1053,8 @@
},
"download-includes": "Wählen Sie die Dokumente für Ihr Download-Paket aus",
"download-status": {
"queued": "Ihr Download wurde zur Warteschlange hinzugefügt. Hier finden Sie alle angeforderten Downloads: <a href='/main/downloads'>My Downloads<a/>."
"queued": "Ihr Download wurde zur Warteschlange hinzugefügt. Hier finden Sie alle angeforderten Downloads: <a href='/main/downloads'>My Downloads<a/>.",
"error": ""
},
"download-type": {
"annotated": "PDF mit Anmerkungen",

View File

@ -1053,7 +1053,8 @@
},
"download-includes": "Choose what is included at download:",
"download-status": {
"queued": "Your download has been queued, you can see all your requested downloads here: <a href='/ui/main/downloads'>My Downloads<a/>."
"queued": "Your download has been queued, you can see all your requested downloads here: <a href='/ui/main/downloads'>My Downloads<a/>.",
"error": "The download preparation failed, please recheck the selected files and download option settings."
},
"download-type": {
"annotated": "Annotated PDF",