DM-313 remove document version for rss

This commit is contained in:
Dan Percic 2023-06-26 15:29:30 +03:00
parent 15aacabd62
commit e7924dcce0
8 changed files with 92 additions and 94 deletions

View File

@ -75,20 +75,22 @@
</mat-checkbox>
</div>
<p class="heading download-includes">{{ 'download-includes' | translate }}</p>
<div class="flex">
<redaction-select
[label]="
'download-type.label'
| translate
: {
length: form.controls['downloadFileTypes'].value.length
}
"
[options]="downloadTypes"
formControlName="downloadFileTypes"
></redaction-select>
</div>
<ng-container *deny="roles.getRss">
<p class="heading download-includes">{{ 'download-includes' | translate }}</p>
<div class="flex">
<redaction-select
[label]="
'download-type.label'
| translate
: {
length: form.controls['downloadFileTypes'].value.length
}
"
[options]="downloadTypes"
formControlName="downloadFileTypes"
></redaction-select>
</div>
</ng-container>
<p class="heading download-includes">{{ 'add-edit-clone-dossier-template.form.hidden-text.heading' | translate }}</p>
<div class="hidden-elements">

View File

@ -1,18 +1,20 @@
<form *ngIf="form && componentContext$ | async as ctx" [formGroup]="form">
<div>
<redaction-select
[disabled]="!canEditDossier"
[label]="'report-type.label' | translate : { length: reportTypesLength }"
[optionTemplate]="reportTemplateOptionTemplate"
[options]="availableReportTypes"
[valueMapper]="reportTemplateValueMapper"
[disabled]="!canEditDossier"
class="mr-16"
formControlName="reportTemplateIds"
></redaction-select>
<redaction-select
*deny="roles.getRss"
[disabled]="!canEditDossier"
[label]="'download-type.label' | translate : { length: downloadFileTypesLength }"
[options]="downloadTypes"
[disabled]="!canEditDossier"
formControlName="downloadFileTypes"
></redaction-select>
</div>
@ -37,7 +39,7 @@
</ng-container>
<ng-template #noWatermarks>
<p class="no-watermark" [innerHTML]="'dossier-watermark-selector.no-watermark' | translate"></p>
<p [innerHTML]="'dossier-watermark-selector.no-watermark' | translate" class="no-watermark"></p>
</ng-template>
</form>

View File

@ -1,16 +1,15 @@
import { Component, Input, OnInit } from '@angular/core';
import { Dossier, DossierTemplate, DownloadFileType, IDossierTemplate, IReportTemplate } from '@red/domain';
import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
import { Dossier, DownloadFileType, IReportTemplate } from '@red/domain';
import { FormBuilder, FormGroup } from '@angular/forms';
import { EditDossierSaveResult, EditDossierSectionInterface } from '../edit-dossier-section.interface';
import { downloadTypesTranslations } from '@translations/download-types-translations';
import { ReportTemplateService } from '@services/report-template.service';
import { PermissionsService } from '@services/permissions.service';
import { firstValueFrom, forkJoin, Observable } from 'rxjs';
import { firstValueFrom, Observable } from 'rxjs';
import { DossiersService } from '@services/dossiers/dossiers.service';
import { WatermarksMapService } from '@services/entity-services/watermarks-map.service';
import { ContextComponent, shareLast } from '@iqser/common-ui';
import { tap } from 'rxjs/operators';
import { DossierTemplatesService } from '@services/dossier-templates/dossier-templates.service';
import { Roles } from '@users/roles';
interface EditDossierDownloadPackageContext {
existsWatermarks: boolean;
@ -25,7 +24,7 @@ export class EditDossierDownloadPackageComponent
extends ContextComponent<EditDossierDownloadPackageContext>
implements OnInit, EditDossierSectionInterface
{
form: UntypedFormGroup;
form: FormGroup;
downloadTypes: { key: DownloadFileType; label: string }[] = ['ORIGINAL', 'PREVIEW', 'DELTA_PREVIEW', 'REDACTED'].map(
(type: DownloadFileType) => ({
key: type,
@ -34,14 +33,14 @@ export class EditDossierDownloadPackageComponent
);
availableReportTypes: IReportTemplate[] = [];
#existsWatermarks$: Observable<boolean>;
readonly roles = Roles;
@Input() dossier: Dossier;
#existsWatermarks$: Observable<boolean>;
constructor(
private readonly _dossiersService: DossiersService,
private readonly _reportTemplateController: ReportTemplateService,
private readonly _formBuilder: UntypedFormBuilder,
private readonly _formBuilder: FormBuilder,
private readonly _permissionsService: PermissionsService,
private readonly _watermarksMapService: WatermarksMapService,
) {
@ -109,7 +108,7 @@ export class EditDossierDownloadPackageComponent
this.availableReportTypes = (await this._reportTemplateController.getAvailableReportTemplates(dossierTemplateId)) || [];
this.form = this._getForm();
this.form = this.#getForm();
if (!this.canEditDossier) {
this.form.disable();
}
@ -137,7 +136,7 @@ export class EditDossierDownloadPackageComponent
});
}
private _getForm(): UntypedFormGroup {
#getForm() {
return this._formBuilder.group(
{
reportTemplateIds: [this.dossier.reportTemplateIds],

View File

@ -2,15 +2,9 @@ import { Component, Input, OnChanges } from '@angular/core';
import { PermissionsService } from '@services/permissions.service';
import { Dossier, File, ProcessingFileStatuses } from '@red/domain';
import { FileDownloadService } from '@upload-download/services/file-download.service';
import { CircleButtonType, CircleButtonTypes, defaultDialogConfig, TenantsService, Toaster } from '@iqser/common-ui';
import { CircleButtonType, CircleButtonTypes, IqserDialog, TenantsService, Toaster } from '@iqser/common-ui';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { MatDialog } from '@angular/material/dialog';
import {
DownloadDialogComponent,
DownloadDialogData,
DownloadDialogResult,
} from '@shared/dialogs/download-dialog/download-dialog.component';
import { firstValueFrom } from 'rxjs';
import { DownloadDialogComponent } from '@shared/dialogs/download-dialog/download-dialog.component';
@Component({
selector: 'redaction-file-download-btn',
@ -33,7 +27,7 @@ export class FileDownloadBtnComponent implements OnChanges {
private readonly _permissionsService: PermissionsService,
private readonly _tenantsService: TenantsService,
private readonly _fileDownloadService: FileDownloadService,
private readonly _dialog: MatDialog,
private readonly _dialog: IqserDialog,
private readonly _toaster: Toaster,
) {}
@ -44,11 +38,10 @@ export class FileDownloadBtnComponent implements OnChanges {
}
async downloadFiles() {
const ref = this._dialog.open<DownloadDialogComponent, DownloadDialogData, DownloadDialogResult>(DownloadDialogComponent, {
...defaultDialogConfig,
const ref = this._dialog.open(DownloadDialogComponent, {
data: { dossier: this.dossier, files: this.files },
});
const result = await firstValueFrom(ref.afterClosed());
const result = await ref.result();
if (!result) {
return;
}

View File

@ -1,17 +1,11 @@
import { Component, Input, OnChanges, SimpleChanges, ViewChild } from '@angular/core';
import { Action, ActionTypes, Dossier, File } from '@red/domain';
import { CircleButtonType, defaultDialogConfig, IqserTooltipPosition, TenantsService, Toaster, trackByFactory } from '@iqser/common-ui';
import { CircleButtonType, IqserDialog, IqserTooltipPosition, TenantsService, Toaster, trackByFactory } from '@iqser/common-ui';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { FileDownloadService } from '@upload-download/services/file-download.service';
import { PermissionsService } from '@services/permissions.service';
import { firstValueFrom } from 'rxjs';
import { MatMenuTrigger } from '@angular/material/menu';
import {
DownloadDialogComponent,
DownloadDialogData,
DownloadDialogResult,
} from '@shared/dialogs/download-dialog/download-dialog.component';
import { MatDialog } from '@angular/material/dialog';
import { DownloadDialogComponent } from '@shared/dialogs/download-dialog/download-dialog.component';
@Component({
selector: 'redaction-expandable-file-actions',
@ -37,7 +31,7 @@ export class ExpandableFileActionsComponent implements OnChanges {
private readonly _tenantsService: TenantsService,
private readonly _toaster: Toaster,
private readonly _permissionsService: PermissionsService,
private readonly _dialog: MatDialog,
private readonly _dialog: IqserDialog,
) {}
ngOnChanges(changes: SimpleChanges) {
@ -71,7 +65,7 @@ export class ExpandableFileActionsComponent implements OnChanges {
// Patch download button
const downloadBtn = this.actions.find(btn => btn.type === ActionTypes.downloadBtn);
if (downloadBtn) {
downloadBtn.action = () => this._downloadFiles(downloadBtn.files, downloadBtn.dossier);
downloadBtn.action = () => this.#downloadFiles(downloadBtn.files, downloadBtn.dossier);
downloadBtn.disabled = !this._permissionsService.canDownloadFiles(downloadBtn.files, downloadBtn.dossier);
}
}
@ -82,13 +76,11 @@ export class ExpandableFileActionsComponent implements OnChanges {
this.matMenu.closeMenu();
}
// TODO: this doesn't look like its called
private async _downloadFiles(files: File[], dossier: Dossier) {
const ref = this._dialog.open<DownloadDialogComponent, DownloadDialogData, DownloadDialogResult>(DownloadDialogComponent, {
...defaultDialogConfig,
async #downloadFiles(files: File[], dossier: Dossier) {
const ref = this._dialog.open(DownloadDialogComponent, {
data: { dossier, files },
});
const result = await firstValueFrom(ref.afterClosed());
const result = await ref.result();
if (!result) {
return;
}

View File

@ -88,7 +88,9 @@
class="mr-16"
formControlName="reportTemplateIds"
></redaction-select>
<redaction-select
*deny="roles.getRss"
[height]="165"
[label]="'download-type.label' | translate : { length: downloadFileTypesLength }"
[options]="downloadTypes"

View File

@ -1,11 +1,11 @@
<section class="dialog">
<div [translate]="'download-dialog.header'" class="dialog-header heading-l"></div>
<div *ngIf="hasUnapprovedFiles" class="inline-dialog-toast toast-warning">
<div [translate]="'download-dialog.unapproved-files-warning'"></div>
</div>
<form *ngIf="form" [formGroup]="form">
<div [translate]="'download-dialog.header'" class="dialog-header heading-l"></div>
<div *ngIf="hasUnapprovedFiles" class="inline-dialog-toast toast-warning">
<div [translate]="'download-dialog.unapproved-files-warning'"></div>
</div>
<div class="dialog-content">
<redaction-select
*ngIf="availableReportTypes | async as reportTypes"
@ -18,6 +18,7 @@
></redaction-select>
<redaction-select
*deny="roles.getRss"
[label]="'download-type.label' | translate : { length: downloadFileTypesLength }"
[options]="downloadTypes"
formControlName="downloadFileTypes"
@ -46,18 +47,18 @@
</div>
</div>
</div>
<div class="dialog-actions">
<iqser-icon-button
(action)="save()"
[disabled]="form.invalid || invalidDownload"
(action)="close()"
[disabled]="!valid"
[label]="'download-dialog.actions.save' | translate"
[submit]="true"
[type]="iconButtonTypes.primary"
></iqser-icon-button>
</div>
<iqser-circle-button (action)="close()" class="dialog-close" icon="iqser:close"></iqser-circle-button>
</form>
<iqser-circle-button (action)="close()" class="dialog-close" icon="iqser:close"></iqser-circle-button>
</section>
<ng-template #reportTemplateOptionTemplate let-option="option">

View File

@ -1,11 +1,11 @@
import { Component, Inject } from '@angular/core';
import { Dossier, DownloadFileType, DownloadFileTypes, IReportTemplate, File, WorkflowFileStatuses } from '@red/domain';
import { Component } from '@angular/core';
import { Dossier, DownloadFileType, DownloadFileTypes, File, IReportTemplate, WorkflowFileStatuses } from '@red/domain';
import { downloadTypesForDownloadTranslations } from '@translations/download-types-translations';
import { ReportTemplateService } from '@services/report-template.service';
import { AbstractControl } from '@angular/forms';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { AbstractControl, FormBuilder } from '@angular/forms';
import { DefaultColorsService } from '@services/entity-services/default-colors.service';
import { BaseDialogComponent, IconButtonTypes, List } from '@iqser/common-ui';
import { IconButtonTypes, IqserDialogComponent, List } from '@iqser/common-ui';
import { Roles } from '@users/roles';
export interface DownloadDialogData {
readonly dossier: Dossier;
@ -19,24 +19,23 @@ export interface DownloadDialogResult {
}
@Component({
selector: 'redaction-download-dialog',
templateUrl: './download-dialog.component.html',
styleUrls: ['./download-dialog.component.scss'],
})
export class DownloadDialogComponent extends BaseDialogComponent {
export class DownloadDialogComponent extends IqserDialogComponent<DownloadDialogComponent, DownloadDialogData, DownloadDialogResult> {
readonly iconButtonTypes = IconButtonTypes;
readonly downloadTypes: { key: DownloadFileType; label: string }[] = this._formDownloadTypes;
readonly availableReportTypes = this._availableReportTypes;
readonly downloadTypes: { key: DownloadFileType; label: string }[] = this.#formDownloadTypes;
readonly availableReportTypes = this.#availableReportTypes;
readonly form = this.#getForm();
initialFormValue = this.form.getRawValue();
readonly roles = Roles;
constructor(
private readonly _defaultColorsService: DefaultColorsService,
private readonly _reportTemplateController: ReportTemplateService,
protected readonly _dialogRef: MatDialogRef<DownloadDialogComponent, DownloadDialogResult>,
@Inject(MAT_DIALOG_DATA) readonly data: DownloadDialogData,
private readonly _formBuilder: FormBuilder,
) {
super(_dialogRef);
this.form = this._getForm();
super();
}
get reportTypesLength() {
@ -60,13 +59,17 @@ export class DownloadDialogComponent extends BaseDialogComponent {
);
}
private get _availableReportTypes() {
override get valid() {
return this.form.valid && !this.invalidDownload;
}
get #availableReportTypes() {
const dossierTemplateId = this.data.dossier.dossierTemplateId;
const result = this._reportTemplateController.getAvailableReportTemplates(dossierTemplateId);
return result.then(values => values ?? []);
}
private get _formDownloadTypes() {
get #formDownloadTypes() {
return ['ORIGINAL', 'PREVIEW', 'DELTA_PREVIEW', 'REDACTED']
.map((type: DownloadFileType) => ({
key: type,
@ -80,7 +83,7 @@ export class DownloadDialogComponent extends BaseDialogComponent {
});
}
private get _selectedDownloadTypes() {
get #selectedDownloadTypes() {
return this.data.dossier.downloadFileTypes.filter(type => {
if (!this.data.files.some(file => file.workflowStatus === WorkflowFileStatuses.APPROVED)) {
return type !== DownloadFileTypes.REDACTED;
@ -89,44 +92,48 @@ export class DownloadDialogComponent extends BaseDialogComponent {
});
}
override onEnterValidator() {
return this.valid;
}
reportTemplateValueMapper = (reportTemplate: IReportTemplate) => reportTemplate.templateId;
async save() {
close() {
const result: DownloadDialogResult = {
reportTemplateIds: this.form.controls.reportTemplateIds.value,
downloadFileTypes: this.form.controls.downloadFileTypes.value,
redactionPreviewColor: this.form.controls.redactionPreviewColor.value,
};
this._dialogRef.close(result);
if (result.reportTemplateIds.length === 0) {
return this.dialogRef.close();
}
this.dialogRef.close(result);
}
close() {
this._dialogRef.close();
}
private _hasReportTemplateOrDownloadType(control: AbstractControl) {
#hasReportTemplateOrDownloadType(control: AbstractControl) {
const atLeastAReportSelected = control.get('reportTemplateIds')?.value.length > 0;
const atLeastATypeSelected = control.get('downloadFileTypes')?.value.length > 0;
return atLeastATypeSelected || atLeastAReportSelected ? null : { reportTemplateIds: true, downloadFileTypes: true };
}
private _getForm() {
#getForm() {
const previewColor = this._defaultColorsService.getColor(this.data.dossier.dossierTemplateId, 'previewColor');
return this._formBuilder.group(
{
reportTemplateIds: [this.data.dossier.reportTemplateIds],
downloadFileTypes: [this._selectedDownloadTypes],
downloadFileTypes: [this.#selectedDownloadTypes],
redactionPreviewColor: [previewColor],
},
{
validators: [control => this._hasReportTemplateOrDownloadType(control), control => this._isHexColor(control)],
validators: [control => this.#hasReportTemplateOrDownloadType(control), control => this.#isHexColor(control)],
},
);
}
private _isHexColor(control: AbstractControl) {
#isHexColor(control: AbstractControl) {
const color = control.get('redactionPreviewColor')?.value;
const isHexColor = /^#[0-9A-F]{6}$/i.test(color);
return isHexColor ? null : { redactionPreviewColor: true };