From f3190cc68f7adf76825783b36d9488488e5ff088 Mon Sep 17 00:00:00 2001 From: Drew Ansbacher Date: Thu, 19 Aug 2021 11:40:52 -0600 Subject: [PATCH] fixes --- .../components/form-object/form-error.component.html | 3 +++ .../components/form-object/form-object.component.ts | 5 +++-- .../apps-routes/app-interfaces/app-interfaces.page.ts | 8 ++++---- ui/src/app/services/form.service.ts | 10 ++++++++++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/ui/src/app/components/form-object/form-error.component.html b/ui/src/app/components/form-object/form-error.component.html index d8a3a8681..05a4bf84c 100644 --- a/ui/src/app/components/form-object/form-error.component.html +++ b/ui/src/app/components/form-object/form-error.component.html @@ -17,6 +17,9 @@

Number not in range

+

+ Invalid Number +

diff --git a/ui/src/app/components/form-object/form-object.component.ts b/ui/src/app/components/form-object/form-object.component.ts index efce9ab09..f613f78a5 100644 --- a/ui/src/app/components/form-object/form-object.component.ts +++ b/ui/src/app/components/form-object/form-object.component.ts @@ -88,6 +88,7 @@ export class FormObjectComponent { const newItem = this.formService.getListItem(listSpec, val) newItem.markAllAsTouched() arr.insert(0, newItem) + console.log('new Item', newItem) if (['object', 'union'].includes(listSpec.subtype)) { const displayAs = (listSpec.spec as ListValueSpecOf<'object'>)['display-as'] this.objectListInfo[key].push({ @@ -163,11 +164,11 @@ export class FormObjectComponent { } private deleteListItem (key: string, index: number, markDirty = true): void { - this.objectListInfo[key][index].height = '0px' + if (this.objectListInfo[key]) this.objectListInfo[key][index].height = '0px' const arr = this.formGroup.get(key) as FormArray if (markDirty) arr.markAsDirty() pauseFor(500).then(() => { - this.objectListInfo[key].splice(index, 1) + if (this.objectListInfo[key]) this.objectListInfo[key].splice(index, 1) arr.removeAt(index) }) } diff --git a/ui/src/app/pages/apps-routes/app-interfaces/app-interfaces.page.ts b/ui/src/app/pages/apps-routes/app-interfaces/app-interfaces.page.ts index 2667985cc..148da0880 100644 --- a/ui/src/app/pages/apps-routes/app-interfaces/app-interfaces.page.ts +++ b/ui/src/app/pages/apps-routes/app-interfaces/app-interfaces.page.ts @@ -29,11 +29,11 @@ export class AppInterfacesPage { const pkgId = this.route.snapshot.paramMap.get('pkgId') const pkg = this.patch.data['package-data'][pkgId] const interfaces = pkg.manifest.interfaces - const addressesMap = pkg.installed['interface-addresses'] + const addressesMap = pkg.installed['interface-addresses'] || { } const ui = interfaces['ui'] if (ui) { - const uiAddresses = addressesMap['ui'] + const uiAddresses = addressesMap['ui'] || { } this.ui = { def: ui, addresses: { @@ -50,8 +50,8 @@ export class AppInterfacesPage { return { def: interfaces[key], addresses: { - 'lan-address': addresses['lan-address'] ? 'https://' + addresses['lan-address'] : null, - 'tor-address': addresses['tor-address'] ? 'http://' + addresses['tor-address'] : null, + 'lan-address': addresses && addresses['lan-address'] ? 'https://' + addresses['lan-address'] : null, + 'tor-address': addresses && addresses['tor-address'] ? 'http://' + addresses['tor-address'] : null, }, } }) diff --git a/ui/src/app/services/form.service.ts b/ui/src/app/services/form.service.ts index 5d4bdf77a..4b5146a4b 100644 --- a/ui/src/app/services/form.service.ts +++ b/ui/src/app/services/form.service.ts @@ -119,6 +119,8 @@ export class FormService { private numberValidators (spec: ValueSpecNumber | ListValueSpecNumber): ValidatorFn[] { const validators: ValidatorFn[] = [] + validators.push(isNumber()) + if (!(spec as ValueSpecNumber).nullable) { validators.push(Validators.required) } @@ -160,6 +162,14 @@ export function numberInRange (stringRange: string): ValidatorFn { } } +export function isNumber (): ValidatorFn { + return (control: AbstractControl): ValidationErrors | null => { + return control.value == Number(control.value) ? + null : + { invalidNumber: { value: control.value } } + } +} + export function isInteger (): ValidatorFn { return (control: AbstractControl): ValidationErrors | null => { return control.value == Math.trunc(control.value) ?