fix dictionary update

This commit is contained in:
Dan Percic 2021-06-23 20:19:02 +03:00
parent b70a06cc5f
commit b556c0f982
2 changed files with 33 additions and 35 deletions

View File

@ -1,19 +1,14 @@
<section class="dialog">
<div class="dialog-header heading-l">
{{
(dictionary ? 'add-edit-dictionary.title.edit' : 'add-edit-dictionary.title.new')
| translate: { name: dictionary?.type | humanize }
}}
{{ dialogHeader }}
</div>
<form (submit)="saveDictionary()" [formGroup]="dictionaryForm">
<div class="dialog-content">
<ng-container *ngIf="!!dictionary">
<div class="red-input-group mb-14">
<label translate="add-edit-dictionary.form.name"></label>
{{ dictionary.label }}
</div>
</ng-container>
<div class="red-input-group mb-14" *ngIf="!!dictionary">
<label translate="add-edit-dictionary.form.name"></label>
{{ dictionary.label }}
</div>
<div class="first-row">
<div *ngIf="!dictionary" class="red-input-group required">
@ -53,13 +48,7 @@
[style.background]="dictionaryForm.get('hexColor').value"
class="input-icon"
>
<mat-icon
*ngIf="
!dictionaryForm.get('hexColor').value ||
dictionaryForm.get('hexColor').value?.length === 0
"
svgIcon="red:color-picker"
></mat-icon>
<mat-icon *ngIf="hasColor" svgIcon="red:color-picker"></mat-icon>
</div>
</div>
</div>
@ -81,11 +70,11 @@
<div class="red-input-group slider-row">
<mat-button-toggle-group appearance="legacy" formControlName="hint" name="hint">
<mat-button-toggle [value]="false">
{{ 'add-edit-dictionary.form.redaction' | translate }}</mat-button-toggle
>
{{ 'add-edit-dictionary.form.redaction' | translate }}
</mat-button-toggle>
<mat-button-toggle [value]="true">
{{ 'add-edit-dictionary.form.hint' | translate }}</mat-button-toggle
>
{{ 'add-edit-dictionary.form.hint' | translate }}
</mat-button-toggle>
</mat-button-toggle-group>
</div>

View File

@ -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<AddEditDictionaryDialogComponent>,
private readonly _dialogRef: MatDialogRef<AddEditDictionaryDialogComponent>,
@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<any>;
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');