diff --git a/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dictionary-dialog/add-edit-dictionary-dialog.component.html b/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dictionary-dialog/add-edit-dictionary-dialog.component.html index 459ff3d45..88843ac2c 100644 --- a/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dictionary-dialog/add-edit-dictionary-dialog.component.html +++ b/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dictionary-dialog/add-edit-dictionary-dialog.component.html @@ -1,19 +1,14 @@
- {{ - (dictionary ? 'add-edit-dictionary.title.edit' : 'add-edit-dictionary.title.new') - | translate: { name: dictionary?.type | humanize } - }} + {{ dialogHeader }}
- -
- - {{ dictionary.label }} -
-
+
+ + {{ dictionary.label }} +
@@ -53,13 +48,7 @@ [style.background]="dictionaryForm.get('hexColor').value" class="input-icon" > - +
@@ -81,11 +70,11 @@
- {{ 'add-edit-dictionary.form.redaction' | translate }} + {{ 'add-edit-dictionary.form.redaction' | translate }} + - {{ 'add-edit-dictionary.form.hint' | translate }} + {{ 'add-edit-dictionary.form.hint' | translate }} +
diff --git a/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dictionary-dialog/add-edit-dictionary-dialog.component.ts b/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dictionary-dialog/add-edit-dictionary-dialog.component.ts index e435c3a0f..9f3c732e1 100644 --- a/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dictionary-dialog/add-edit-dictionary-dialog.component.ts +++ b/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dictionary-dialog/add-edit-dictionary-dialog.component.ts @@ -1,5 +1,4 @@ import { Component, Inject } from '@angular/core'; -import { AppStateService } from '@state/app-state.service'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { DictionaryControllerService, TypeValue } from '@redaction/red-ui-http'; @@ -7,6 +6,7 @@ import { Observable } from 'rxjs'; import { NotificationService, NotificationType } from '@services/notification.service'; import { TranslateService } from '@ngx-translate/core'; import { TypeValueWrapper } from '../../../../models/file/type-value.wrapper'; +import { humanize } from '../../../../utils/functions'; @Component({ selector: 'redaction-add-edit-dictionary-dialog', @@ -20,17 +20,16 @@ export class AddEditDictionaryDialogComponent { constructor( private readonly _dictionaryControllerService: DictionaryControllerService, - private readonly _appStateService: AppStateService, private readonly _formBuilder: FormBuilder, private readonly _notificationService: NotificationService, private readonly _translateService: TranslateService, - public dialogRef: MatDialogRef, + private readonly _dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) - public data: { dictionary: TypeValueWrapper; dossierTemplateId: string } + private readonly _data: { dictionary: TypeValueWrapper; dossierTemplateId: string } ) { - this.dictionary = data.dictionary; - this._dossierTemplateId = data.dossierTemplateId; - this.dictionaryForm = this._formBuilder.group({ + this.dictionary = _data.dictionary; + this._dossierTemplateId = _data.dossierTemplateId; + this.dictionaryForm = _formBuilder.group({ type: [this.dictionary?.type, [Validators.required, Validators.minLength(3)]], description: [this.dictionary?.description], rank: [this.dictionary?.rank, Validators.required], @@ -41,7 +40,19 @@ export class AddEditDictionaryDialogComponent { }); } - get dictCaseSensitive() { + get dialogHeader(): string { + const i18nString = 'add-edit-dictionary.title.' + (this.dictionary ? 'edit' : 'new'); + return this._translateService.instant(i18nString, { + name: humanize(this.dictionary?.type) + }); + } + + get hasColor(): boolean { + const hexColorValue = this.dictionaryForm.get('hexColor').value; + return !hexColorValue || hexColorValue?.length === 0; + } + + get dictCaseSensitive(): boolean { return this.dictionary ? !this.dictionary.caseInsensitive : false; } @@ -63,14 +74,14 @@ export class AddEditDictionaryDialogComponent { async saveDictionary() { const typeValue: TypeValue = this._formToObject(); - let observable: Observable; + if (this.dictionary) { // edit mode observable = this._dictionaryControllerService.updateType( typeValue, - typeValue.type, - this._dossierTemplateId + this._dossierTemplateId, + typeValue.type ); } else { // create mode @@ -79,9 +90,7 @@ export class AddEditDictionaryDialogComponent { } observable.subscribe( - () => { - this.dialogRef.close({ dictionary: this.dictionary ? null : typeValue }); - }, + () => this._dialogRef.close(this.dictionary ? null : typeValue), error => { if (error.status === 409) { this._notifyError('add-edit-dictionary.error.dictionary-already-exists');