refactoring && update common

This commit is contained in:
Edi Cziszter 2022-01-26 20:48:15 +02:00
parent b0d088fc7a
commit 46cec7e6b8
2 changed files with 29 additions and 27 deletions

View File

@ -1,13 +1,6 @@
<section class="dialog">
<div class="dialog-header heading-l">
{{
'confirm-delete-file-attribute.title'
| translate
: {
type: type,
name: data.attribute?.label
}
}}
{{ 'confirm-delete-file-attribute.title' | translate: translateArgs }}
</div>
<div *ngIf="showToast" class="inline-dialog-toast toast-error">
@ -32,7 +25,7 @@
{{ 'confirm-delete-file-attribute.delete' | translate: { type: type } }}
</button>
<div
(click)="cancel()"
(click)="this.dialogRef.close()"
[translateParams]="{ type: type }"
[translate]="'confirm-delete-file-attribute.cancel'"
class="all-caps-label cancel"

View File

@ -27,25 +27,14 @@ export class ConfirmDeleteAttributeDialogComponent {
constructor(
private readonly _translateService: TranslateService,
public dialogRef: MatDialogRef<ConfirmDeleteAttributeDialogComponent>,
readonly dialogRef: MatDialogRef<ConfirmDeleteAttributeDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: DialogData,
) {
this.checkboxes = this.checkBoxConfig;
}
get checkBoxConfig(): CheckBox[] {
const checkBoxes = isFileAttributeConfig(this.data.attribute)
? [
{
value: false,
label: this._translateService.instant('confirm-delete-file-attribute.file-impacted-documents', { type: this.type }),
},
{ value: false, label: this._translateService.instant('confirm-delete-file-attribute.file-lost-details') },
]
: [
{ value: false, label: this._translateService.instant('confirm-delete-file-attribute.dossier-impacted-documents') },
{ value: false, label: this._translateService.instant('confirm-delete-file-attribute.dossier-lost-details') },
];
const checkBoxes = isFileAttributeConfig(this.data.attribute) ? this._fileAttributeCheckboxes : this._dossierAttributeCheckboxes;
if (this.data.count !== 0) {
checkBoxes.push({
value: false,
@ -57,13 +46,37 @@ export class ConfirmDeleteAttributeDialogComponent {
}
get valid() {
return this.checkboxes.reduce((initialValue, currentValue) => initialValue && currentValue.value, true);
return this.checkboxes.reduce((acc, currentValue) => acc && currentValue.value, true);
}
get type(): 'bulk' | 'single' {
return this.data.attribute ? 'single' : 'bulk';
}
get translateArgs() {
return {
type: this.type,
name: this.data.attribute?.label,
};
}
private get _fileAttributeCheckboxes(): CheckBox[] {
return [
{
value: false,
label: this._translateService.instant('confirm-delete-file-attribute.file-impacted-documents', { type: this.type }),
},
{ value: false, label: this._translateService.instant('confirm-delete-file-attribute.file-lost-details') },
];
}
private get _dossierAttributeCheckboxes(): CheckBox[] {
return [
{ value: false, label: this._translateService.instant('confirm-delete-file-attribute.dossier-impacted-documents') },
{ value: false, label: this._translateService.instant('confirm-delete-file-attribute.dossier-lost-details') },
];
}
deleteFileAttribute() {
if (this.valid) {
this.dialogRef.close(true);
@ -71,8 +84,4 @@ export class ConfirmDeleteAttributeDialogComponent {
this.showToast = true;
}
}
cancel() {
this.dialogRef.close();
}
}