Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit e05c9220 authored by Joze RIHTARSIC's avatar Joze RIHTARSIC
Browse files

[EDELIVERY-13787] fix the UI property dialog not show boolean proeprtues correctly

parent e2fa70a7
No related branches found
No related tags found
No related merge requests found
Pipeline #208292 failed
...@@ -11,13 +11,13 @@ import { ...@@ -11,13 +11,13 @@ import {
} from "@angular/forms"; } from "@angular/forms";
import { import {
AlertMessageService AlertMessageService
} from "../../../common/alert-message/alert-message.service"; } from "../../alert-message/alert-message.service";
import {EntityStatus} from "../../../common/enums/entity-status.enum"; import {EntityStatus} from "../../enums/entity-status.enum";
import {SmpConstants} from "../../../smp.constants"; import {SmpConstants} from "../../../smp.constants";
import {HttpClient} from "@angular/common/http"; import {HttpClient} from "@angular/common/http";
import { import {
HttpErrorHandlerService HttpErrorHandlerService
} from "../../../common/error/http-error-handler.service"; } from "../../error/http-error-handler.service";
import { import {
PropertyRo PropertyRo
} from "../../../system-settings/admin-properties/property-ro.model"; } from "../../../system-settings/admin-properties/property-ro.model";
...@@ -57,7 +57,7 @@ export class PropertyDetailsDialogComponent implements OnInit { ...@@ -57,7 +57,7 @@ export class PropertyDetailsDialogComponent implements OnInit {
this.editMode = data.edit; this.editMode = data.edit;
this.propertyType = data.propertyType; this.propertyType = data.propertyType;
this.propertyType = !data.propertyType ? PropertySourceEnum.SYSTEM : data.propertyType; this.propertyType = !data.propertyType ? PropertySourceEnum.SYSTEM : data.propertyType;
(async () => await this.updateFormTitle()) (); (async () => await this.updateFormTitle())();
this.current = this.editMode this.current = this.editMode
? { ? {
...@@ -80,13 +80,12 @@ export class PropertyDetailsDialogComponent implements OnInit { ...@@ -80,13 +80,12 @@ export class PropertyDetailsDialogComponent implements OnInit {
'value': new UntypedFormControl({value: ''}), 'value': new UntypedFormControl({value: ''}),
'valuePattern': new UntypedFormControl({value: ''}), 'valuePattern': new UntypedFormControl({value: ''}),
'errorMessage': new UntypedFormControl({value: ''}), 'errorMessage': new UntypedFormControl({value: ''}),
'systemDefault': new UntypedFormControl({value: 'true'}), 'systemDefault': new UntypedFormControl({value: false}),
}); });
this.propertyForm.controls['property'].setValue(this.current.property); this.propertyForm.controls['property'].setValue(this.current.property);
this.propertyForm.controls['desc'].setValue(this.current.desc); this.propertyForm.controls['desc'].setValue(this.current.desc);
this.propertyForm.controls['type'].setValue(this.current.type); this.propertyForm.controls['type'].setValue(this.current.type);
this.propertyForm.controls['value'].setValue(this.valueFromPropertyStringValue(this.current.value, this.current.type));
this.propertyForm.controls['valuePattern'].setValue(this.current.valuePattern); this.propertyForm.controls['valuePattern'].setValue(this.current.valuePattern);
this.propertyForm.controls['systemDefault'].setValue(this.current.systemDefault); this.propertyForm.controls['systemDefault'].setValue(this.current.systemDefault);
...@@ -96,8 +95,8 @@ export class PropertyDetailsDialogComponent implements OnInit { ...@@ -96,8 +95,8 @@ export class PropertyDetailsDialogComponent implements OnInit {
async updateFormTitle() { async updateFormTitle() {
this.formTitle = this.editMode this.formTitle = this.editMode
? await lastValueFrom(this.translateService.get("property.details.dialog.title.edit.mode", {type: this.capitalize(this.propertyType)})) ? await lastValueFrom(this.translateService.get("property.details.dialog.title.edit.mode", {type: this.capitalize(this.propertyType)}))
: await lastValueFrom(this.translateService.get("property.details.dialog.title.new.mode", {type: this.capitalize(this.propertyType)})); : await lastValueFrom(this.translateService.get("property.details.dialog.title.new.mode", {type: this.capitalize(this.propertyType)}));
} }
ngOnInit() { ngOnInit() {
...@@ -124,7 +123,6 @@ export class PropertyDetailsDialogComponent implements OnInit { ...@@ -124,7 +123,6 @@ export class PropertyDetailsDialogComponent implements OnInit {
let validationObservable = this.http let validationObservable = this.http
.post<PropertyValidationRo>(SmpConstants.REST_INTERNAL_PROPERTY_VALIDATE, request); .post<PropertyValidationRo>(SmpConstants.REST_INTERNAL_PROPERTY_VALIDATE, request);
this.showSpinner = true; this.showSpinner = true;
try { try {
...@@ -164,25 +162,32 @@ export class PropertyDetailsDialogComponent implements OnInit { ...@@ -164,25 +162,32 @@ export class PropertyDetailsDialogComponent implements OnInit {
/** /**
* Method casts string value to correct property type for dialog component used for editing. * Method casts string value to correct property type for dialog component used for editing.
* @param value * At the moment only BOOLEAN needs to be updated, other types are returned as is.
* @param propertyType * @param value - string value
* @param propertyType - property type
*/ */
public valueFromPropertyStringValue(value: string, propertyType: string) { public valueFromPropertyStringValue(value: any, propertyType: string) {
switch (propertyType) {
case 'BOOLEAN': if (propertyType === 'BOOLEAN') {
return value === 'true'; // make sure that the value is lower case string!
default: const valToString = value?.toString().toLowerCase();
return value; return valToString === 'true' || valToString === '1' || valToString === 'yes';
} }
return value;
} }
/**
* Method casts value to string for property value. At the moment only BOOLEAN needs to be updated.
* @param value - value
* @param propertyType - property type
*/
public valueToPropertyStringValue(value: string, propertyType: string) { public valueToPropertyStringValue(value: string, propertyType: string) {
switch (propertyType) { if (propertyType === 'BOOLEAN') {
case 'BOOLEAN': // make sure that the value is lower case string!
return value === 'true'; const valToString = value?.toString().toLowerCase();
default: return valToString === 'true' || valToString === '1' || valToString === 'yes' ? 'true' : 'false';
return value;
} }
return value;
} }
getInputType(propertyType: string) { getInputType(propertyType: string) {
...@@ -235,7 +240,7 @@ export class PropertyDetailsDialogComponent implements OnInit { ...@@ -235,7 +240,7 @@ export class PropertyDetailsDialogComponent implements OnInit {
public getCurrent(): PropertyRo { public getCurrent(): PropertyRo {
this.current.status = EntityStatus.UPDATED; this.current.status = EntityStatus.UPDATED;
this.current.value = this.propertyForm.value['value']; this.current.value = this.valueToPropertyStringValue(this.propertyForm.value['value'], this.current.type);
this.current.systemDefault = this.propertyForm.value['systemDefault']; this.current.systemDefault = this.propertyForm.value['systemDefault'];
return this.current; return this.current;
} }
...@@ -245,21 +250,22 @@ export class PropertyDetailsDialogComponent implements OnInit { ...@@ -245,21 +250,22 @@ export class PropertyDetailsDialogComponent implements OnInit {
} }
get isSystemDefault(): boolean { get isSystemDefault(): boolean {
let systemDefault = this.propertyForm.value['systemDefault']; return this.propertyForm.value['systemDefault'];
return systemDefault;
} }
/** /**
* Method updates the state of the value field based on the system default checkbox. * Method updates the state of the value field based on the system default checkbox.
*/ */
updateValueState(): void { updateValueState(): void {
let value;
if (!this.isDomainProperty || !this.isSystemDefault) { if (!this.isDomainProperty || !this.isSystemDefault) {
value = this.valueFromPropertyStringValue(this.current.value, this.current.type);
this.propertyForm.controls['value'].enable(); this.propertyForm.controls['value'].enable();
this.propertyForm.controls['value'].setValue(this.current.value);
} else { } else {
this.propertyForm.controls['value'].setValue(this.current.systemDefaultValue); value = this.valueFromPropertyStringValue(this.current.systemDefaultValue, this.current.type);
this.propertyForm.controls['value'].disable(); this.propertyForm.controls['value'].disable();
} }
this.propertyForm.controls['value'].setValue(value);
} }
get isDomainProperty(): boolean { get isDomainProperty(): boolean {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment