RED-6082: hide download button when selected files are not processed

This commit is contained in:
Dan Percic 2023-02-08 20:51:10 +02:00
parent b46c24321a
commit 5310f4dae4

View File

@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, Component, Input, OnChanges } from '@angular/core';
import { Component, Input, OnChanges } from '@angular/core';
import { PermissionsService } from '@services/permissions.service';
import { Action, ActionTypes, Dossier, File, ProcessingFileStatuses } from '@red/domain';
import { CircleButtonType, CircleButtonTypes, ListingModes } from '@iqser/common-ui';
@ -12,7 +12,6 @@ import { ConfigService } from '../../config.service';
selector: 'redaction-dossier-overview-bulk-actions [dossier] [selectedFiles]',
templateUrl: './dossier-overview-bulk-actions.component.html',
styleUrls: ['./dossier-overview-bulk-actions.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class DossierOverviewBulkActionsComponent implements OnChanges {
@Input() dossier: Dossier;
@ -94,7 +93,7 @@ export class DossierOverviewBulkActionsComponent implements OnChanges {
},
{
type: ActionTypes.downloadBtn,
show: !this.selectedFiles.some(file => file.processingStatus === ProcessingFileStatuses.ERROR),
show: !this.selectedFiles.some(file => file.processingStatus === ProcessingFileStatuses.ERROR || !file.lastProcessed),
files: this.selectedFiles,
dossier: this.dossier,
},
@ -162,59 +161,61 @@ export class DossierOverviewBulkActionsComponent implements OnChanges {
}
private _setup() {
if (this.selectedFiles.length) {
const isWorkflow = this._configService.listingMode === ListingModes.workflow;
if (!this.selectedFiles.length) {
return;
}
const allFilesAreUnderReviewOrUnassigned = this.selectedFiles.reduce(
(acc, file) => acc && (file.isUnderReview || file.isNew),
const isWorkflow = this._configService.listingMode === ListingModes.workflow;
const allFilesAreUnderReviewOrUnassigned = this.selectedFiles.reduce(
(acc, file) => acc && (file.isUnderReview || file.isNew),
true,
);
const allFilesAreUnderApproval = this.selectedFiles.reduce((acc, file) => acc && file.isUnderApproval, true);
const allFilesAreApproved = this.selectedFiles.reduce((acc, file) => acc && file.isApproved, true);
this.#allFilesAreExcluded = this.selectedFiles.reduce((acc, file) => acc && file.excluded, true);
this.#canMoveToSameState = allFilesAreUnderReviewOrUnassigned || allFilesAreUnderApproval || allFilesAreApproved;
this.#canAssign =
this.#canMoveToSameState &&
this.selectedFiles.reduce(
(acc, file) =>
(acc && this._permissionsService.canAssignUser(file, this.dossier)) ||
this._permissionsService.canUnassignUser(file, this.dossier),
true,
);
const allFilesAreUnderApproval = this.selectedFiles.reduce((acc, file) => acc && file.isUnderApproval, true);
const allFilesAreApproved = this.selectedFiles.reduce((acc, file) => acc && file.isApproved, true);
this.#allFilesAreExcluded = this.selectedFiles.reduce((acc, file) => acc && file.excluded, true);
this.#canMoveToSameState = allFilesAreUnderReviewOrUnassigned || allFilesAreUnderApproval || allFilesAreApproved;
this.#canAssignToSelf = this.#canMoveToSameState && this._permissionsService.canAssignToSelf(this.selectedFiles, this.dossier);
this.#canAssign =
this.#canMoveToSameState &&
this.selectedFiles.reduce(
(acc, file) =>
(acc && this._permissionsService.canAssignUser(file, this.dossier)) ||
this._permissionsService.canUnassignUser(file, this.dossier),
true,
);
this.#canAssignToSelf = this.#canMoveToSameState && this._permissionsService.canAssignToSelf(this.selectedFiles, this.dossier);
this.#canDelete = this._permissionsService.canSoftDeleteFile(this.selectedFiles, this.dossier);
this.#canDelete = this._permissionsService.canSoftDeleteFile(this.selectedFiles, this.dossier);
this.#canReanalyse = this._permissionsService.canReanalyseFile(this.selectedFiles, this.dossier);
this.#canReanalyse = this._permissionsService.canReanalyseFile(this.selectedFiles, this.dossier);
this.#canDisableAutoAnalysis = this._permissionsService.canDisableAutoAnalysis(this.selectedFiles, this.dossier);
this.#canDisableAutoAnalysis = this._permissionsService.canDisableAutoAnalysis(this.selectedFiles, this.dossier);
this.#canEnableAutoAnalysis = this._permissionsService.canEnableAutoAnalysis(this.selectedFiles, this.dossier);
this.#canEnableAutoAnalysis = this._permissionsService.canEnableAutoAnalysis(this.selectedFiles, this.dossier);
this.#canToggleAnalysis = this._permissionsService.canToggleAnalysis(this.selectedFiles, this.dossier);
this.#canToggleAnalysis = this._permissionsService.canToggleAnalysis(this.selectedFiles, this.dossier);
this.#canOcr = this._permissionsService.canOcrFile(this.selectedFiles, this.dossier);
this.#canOcr = this._permissionsService.canOcrFile(this.selectedFiles, this.dossier);
this.#canSetToNew = this._permissionsService.canSetToNew(this.selectedFiles, this.dossier) && !isWorkflow;
this.#canSetToNew = this._permissionsService.canSetToNew(this.selectedFiles, this.dossier) && !isWorkflow;
this.#canSetToUnderReview = this._permissionsService.canSetUnderReview(this.selectedFiles, this.dossier) && !isWorkflow;
this.#canSetToUnderReview = this._permissionsService.canSetUnderReview(this.selectedFiles, this.dossier) && !isWorkflow;
this.#canSetToUnderApproval = this._permissionsService.canSetUnderApproval(this.selectedFiles, this.dossier) && !isWorkflow;
this.#canSetToUnderApproval = this._permissionsService.canSetUnderApproval(this.selectedFiles, this.dossier) && !isWorkflow;
this.#isReadyForApproval = this._permissionsService.isReadyForApproval(this.selectedFiles, this.dossier) && !isWorkflow;
this.#isReadyForApproval = this._permissionsService.isReadyForApproval(this.selectedFiles, this.dossier) && !isWorkflow;
this.#canApprove = this._permissionsService.canBeApproved(this.selectedFiles, this.dossier) && !isWorkflow;
this.#canApprove = this._permissionsService.canBeApproved(this.selectedFiles, this.dossier) && !isWorkflow;
this.#canUndoApproval = this._permissionsService.canUndoApproval(this.selectedFiles, this.dossier) && !isWorkflow;
this.#canUndoApproval = this._permissionsService.canUndoApproval(this.selectedFiles, this.dossier) && !isWorkflow;
this.#assignTooltip = allFilesAreUnderApproval ? _('dossier-overview.assign-approver') : _('dossier-overview.assign-reviewer');
this.#assignTooltip = allFilesAreUnderApproval ? _('dossier-overview.assign-approver') : _('dossier-overview.assign-reviewer');
this.#toggleAnalysisTooltip = this.#allFilesAreExcluded
? _('file-preview.toggle-analysis.enable')
: _('file-preview.toggle-analysis.disable');
this.#toggleAnalysisTooltip = this.#allFilesAreExcluded
? _('file-preview.toggle-analysis.enable')
: _('file-preview.toggle-analysis.disable');
this.buttons = this._buttons;
}
this.buttons = this._buttons;
}
}