RED-3827: System managed entities disabled fields

This commit is contained in:
Adina Țeudan 2022-04-13 12:12:12 +03:00
parent 0ccb68726e
commit 5aa2c4a355
3 changed files with 24 additions and 7 deletions

View File

@ -13,6 +13,7 @@ const routes = [
{
path: 'info',
component: InfoComponent,
canDeactivate: [PendingChangesGuard],
},
{
path: 'dictionary',

View File

@ -52,6 +52,10 @@ export class InfoComponent {
this._addEditEntityComponent.revert();
}
get changed(): boolean {
return this._addEditEntityComponent.changed;
}
@HostListener('window:keydown.Enter', ['$event'])
async onEnter(event: KeyboardEvent): Promise<void> {
event?.stopImmediatePropagation();

View File

@ -42,23 +42,35 @@ export class AddEditEntityComponent extends BaseFormComponent implements OnInit
this.form.patchValue(this.initialFormValue);
}
get #caseSensitiveControl() {
return { value: this.entity ? !this.entity.caseInsensitive : false, disabled: this.#isSystemManaged };
}
#addToDictionaryActionControl() {
return { value: this.entity?.addToDictionaryAction, disabled: this.#isSystemManaged };
}
get #isSystemManaged(): boolean {
return !!this.entity?.systemManaged;
}
private _initializeForm(): void {
const controlsConfig = {
type: [this.entity?.type],
label: [this.entity?.label, [Validators.required, Validators.minLength(3)]],
description: [this.entity?.description],
rank: [this.entity?.rank, Validators.required],
rank: [{ value: this.entity?.rank, disabled: this.#isSystemManaged }, Validators.required],
hexColor: [this.entity?.hexColor, [Validators.required, Validators.minLength(7)]],
recommendationHexColor: [this.entity?.recommendationHexColor, [Validators.required, Validators.minLength(7)]],
hint: [!!this.entity?.hint],
hasDictionary: [!!this.entity?.hasDictionary],
hint: [{ value: !!this.entity?.hint, disabled: this.#isSystemManaged }],
hasDictionary: [{ value: !!this.entity?.hasDictionary, disabled: this.#isSystemManaged }],
};
if (!this.entity?.hint) {
Object.assign(controlsConfig, {
defaultReason: [{ value: null, disabled: true }],
caseSensitive: [this.entity ? !this.entity.caseInsensitive : false],
addToDictionaryAction: [this.entity?.addToDictionaryAction],
caseSensitive: [this.#caseSensitiveControl],
addToDictionaryAction: [this.#addToDictionaryActionControl],
});
}
const form = this._formBuilder.group(controlsConfig);
@ -71,9 +83,9 @@ export class AddEditEntityComponent extends BaseFormComponent implements OnInit
if (isHint) {
REDACTION_FIELDS.forEach(field => form.removeControl(field));
} else {
form.addControl('addToDictionaryAction', new FormControl(this.entity?.addToDictionaryAction));
form.addControl('caseSensitive', new FormControl(!this.entity?.caseInsensitive));
form.addControl('defaultReason', new FormControl({ value: null, disabled: true }));
form.addControl('caseSensitive', new FormControl(this.#caseSensitiveControl));
form.addControl('addToDictionaryAction', new FormControl(this.#addToDictionaryActionControl));
}
});