fix form display for services with no config

This commit is contained in:
Matt Hill
2021-09-09 08:55:13 -06:00
parent 8ac20b3894
commit ffc920bf53
2 changed files with 11 additions and 8 deletions

View File

@@ -6,7 +6,7 @@
</ion-button> </ion-button>
</ion-buttons> </ion-buttons>
<ion-title>Config</ion-title> <ion-title>Config</ion-title>
<ion-buttons slot="end" class="ion-padding-end"> <ion-buttons *ngIf="hasConfig" slot="end" class="ion-padding-end">
<ion-button fill="clear" [disabled]="loadingText" (click)="resetDefaults()"> <ion-button fill="clear" [disabled]="loadingText" (click)="resetDefaults()">
<ion-icon slot="start" name="refresh"></ion-icon> <ion-icon slot="start" name="refresh"></ion-icon>
Reset Defaults Reset Defaults
@@ -24,7 +24,7 @@
<ng-template #loaded> <ng-template #loaded>
<ng-container *ngIf="patch.data['package-data'][pkgId] as pkg"> <ng-container *ngIf="patch.data['package-data'][pkgId] as pkg">
<ion-item> <ion-item *ngIf="hasConfig && !pkg.installed.status.configured && !configForm.dirty">
<ion-label> <ion-label>
<ion-text color="success">To use the default config for {{ pkg.manifest.title }}, click "Save" below.</ion-text> <ion-text color="success">To use the default config for {{ pkg.manifest.title }}, click "Save" below.</ion-text>
</ion-label> </ion-label>
@@ -66,7 +66,7 @@
</ion-item> </ion-item>
<!-- has config --> <!-- has config -->
<form [formGroup]="configForm" (ngSubmit)="save(pkg)" novalidate> <form *ngIf="hasConfig" [formGroup]="configForm" (ngSubmit)="save(pkg)" novalidate>
<form-object <form-object
[objectSpec]="configSpec" [objectSpec]="configSpec"
[formGroup]="configForm" [formGroup]="configForm"
@@ -81,9 +81,12 @@
<ion-footer> <ion-footer>
<ion-toolbar *ngIf="patch.data['package-data'][pkgId] as pkg"> <ion-toolbar *ngIf="patch.data['package-data'][pkgId] as pkg">
<ion-buttons slot="end" class="ion-padding-end"> <ion-buttons slot="end" class="ion-padding-end">
<ion-button fill="outline" [disabled]="saving" (click)="save(pkg)" class="enter-click" [class.no-click]="saving"> <ion-button *ngIf="hasConfig" fill="outline" [disabled]="saving" (click)="save(pkg)" class="enter-click" [class.no-click]="saving">
Save Save
</ion-button> </ion-button>
<ion-button *ngIf="!loadingText && !hasConfig" fill="outline" (click)="dismiss()" class="enter-click">
Close
</ion-button>
</ion-buttons> </ion-buttons>
</ion-toolbar> </ion-toolbar>
</ion-footer> </ion-footer>

View File

@@ -72,18 +72,18 @@ export class AppConfigPage {
this.configForm.markAllAsTouched() this.configForm.markAllAsTouched()
if (depConfig) { if (depConfig) {
this.markDirtyRecursive(this.configForm, depConfig) this.alterConfigRecursive(this.configForm, depConfig)
} }
} }
markDirtyRecursive (group: FormGroup, config: object) { alterConfigRecursive (group: FormGroup, config: object) {
Object.keys(config).forEach(key => { Object.keys(config).forEach(key => {
const next = group.get(key) const next = group.get(key)
if (!next) throw new Error('Dependency config not compatible with service version. Please contact support') if (!next) throw new Error('Dependency config not compatible with service version. Please contact support')
const newVal = config[key] const newVal = config[key]
// check if val is an object // check if val is an object
if (newVal && typeof newVal === 'object' && !Array.isArray(newVal)) { if (newVal && typeof newVal === 'object' && !Array.isArray(newVal)) {
this.markDirtyRecursive(next as FormGroup, newVal) this.alterConfigRecursive(next as FormGroup, newVal)
} else { } else {
let val1 = group.get(key).value let val1 = group.get(key).value
let val2 = config[key] let val2 = config[key]
@@ -98,7 +98,7 @@ export class AppConfigPage {
resetDefaults () { resetDefaults () {
this.configForm = this.formService.createForm(this.configSpec) this.configForm = this.formService.createForm(this.configSpec)
this.markDirtyRecursive(this.configForm, this.current) this.alterConfigRecursive(this.configForm, this.current)
} }
dismissRec () { dismissRec () {