Skip to content

Commit

Permalink
add plugin config validation functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
bwp91 committed Oct 23, 2024
1 parent e0cf975 commit 673afc8
Show file tree
Hide file tree
Showing 38 changed files with 206 additions and 110 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ All notable changes to `homebridge-config-ui-x` will be documented in this file.

- implement and allow switching to scoped plugins
- fix widget config saving on dashboard
- add plugin config validation functionality

### Other Changes

Expand Down
102 changes: 40 additions & 62 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@
"@homebridge/hap-client": "1.10.2",
"@homebridge/node-pty-prebuilt-multiarch": "0.11.14",
"@nestjs/axios": "3.1.0",
"@nestjs/common": "10.4.5",
"@nestjs/core": "10.4.5",
"@nestjs/common": "10.4.6",
"@nestjs/core": "10.4.6",
"@nestjs/jwt": "10.2.0",
"@nestjs/passport": "10.0.3",
"@nestjs/platform-fastify": "10.4.5",
"@nestjs/platform-socket.io": "10.4.5",
"@nestjs/platform-fastify": "10.4.6",
"@nestjs/platform-socket.io": "10.4.6",
"@nestjs/swagger": "7.4.2",
"@nestjs/websockets": "10.4.5",
"@nestjs/websockets": "10.4.6",
"axios": "1.7.7",
"bash-color": "0.0.4",
"buffer-shims": "1.0.0",
Expand Down Expand Up @@ -122,7 +122,7 @@
},
"devDependencies": {
"@antfu/eslint-config": "^3.8.0",
"@nestjs/testing": "^10.4.5",
"@nestjs/testing": "^10.4.6",
"@types/fs-extra": "^11.0.4",
"@types/lodash": "^4.17.12",
"@types/node": "^22.7.9",
Expand Down
6 changes: 3 additions & 3 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ <h5 class="modal-title">
[configSchema]="schema"
[(data)]="pluginConfig[0]"
(dataChanged)="schemaFormUpdatedSubject.next($event)"
(isValid)="onIsValid($event)"
>
</app-schema-form>
</div>
Expand Down Expand Up @@ -79,25 +80,23 @@ <h5 class="modal-title">
</button>
</div>
<div class="text-center"></div>
<div class="text-right">
<button
*ngIf="plugin.name !== 'homebridge-config-ui-x'"
class="btn btn-danger"
[ngbTooltip]="'form.button_delete' | translate"
<div class="text-right d-flex align-items-center justify-content-end">
<i
*ngIf="showSchemaForm"
class="fa fa-fw fa-xl"
[ngClass]="formIsValid ? 'fa-circle-check green-text' : (strictValidation ? 'fa-circle-exclamation red-text' : 'fa-circle-exclamation orange-text')"
[ngbTooltip]="(formIsValid ? 'form.label_valid' : (strictValidation ? 'form.label_invalid_strict' : 'form.label_invalid')) | translate"
container="modal"
placement="top"
openDelay="150"
triggers="hover"
[disabled]="saveInProgress"
(click)="deletePluginConfig()"
>
<i class="fa fa-fw fa-trash"></i>
</button>
></i>
<button
type="button"
class="btn btn-primary"
data-dismiss="modal"
(click)="savePluginConfig(true)"
[disabled]="saveInProgress"
[disabled]="saveInProgress || !showSchemaForm || (showSchemaForm && strictValidation && !formIsValid)"
>
<span *ngIf="!saveInProgress">{{ 'form.button_save' | translate }}</span>
<i *ngIf="saveInProgress" class="fas fa-fw fa-spinner fa-pulse"></i>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export class CustomPluginsComponent implements OnInit, OnDestroy {
public formActionSubject = new Subject()
public childBridges: any[] = []
public isFirstSave = false
public formIsValid = true
public strictValidation = false

private io: IoNamespace
private basePath: string
Expand All @@ -63,6 +65,7 @@ export class CustomPluginsComponent implements OnInit, OnDestroy {
this.io = this.$ws.connectToNamespace('plugins/settings-ui')
this.pluginAlias = this.schema.pluginAlias
this.pluginType = this.schema.pluginType
this.strictValidation = this.schema.strictValidation

if (this.pluginConfig.length === 0) {
this.isFirstSave = true
Expand Down Expand Up @@ -481,9 +484,8 @@ export class CustomPluginsComponent implements OnInit, OnDestroy {
}
}

deletePluginConfig() {
this.updateConfigBlocks([])
this.savePluginConfig(true)
onIsValid($event: boolean) {
this.formIsValid = $event
}

ngOnDestroy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ <h4 class="mt-2">
</div>

<div class="mt-3" *ngIf="gshConfig && gshConfig.token">
<markdown class="plugin-md" [data]="schema.footerDisplay" *ngIf="schema.footerDisplay"> </markdown>
<markdown class="plugin-md" [data]="schema.footerDisplay" *ngIf="schema.footerDisplay"></markdown>
</div>

<div *ngIf="gshConfig && gshConfig.token" class="card p-2 pt-3 mt-4">
Expand Down
Loading

0 comments on commit 673afc8

Please sign in to comment.