1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00

fixing settings value change detection

This commit is contained in:
Patrik J. Braun 2022-02-05 10:58:24 +01:00
parent b4df99b5ce
commit a749ba3a58
3 changed files with 57 additions and 38 deletions

View File

@ -16,7 +16,7 @@
<app-gallery-search-field
*ngIf="!IsEnumType && Type === 'searchQuery'"
*ngIf="Type === 'searchQuery'"
[(ngModel)]="state.value"
[id]="idName"
[name]="idName"
@ -28,7 +28,7 @@
</app-gallery-search-field>
<input
*ngIf="!IsEnumType && Type !== 'boolean' && Type !== 'searchQuery'"
*ngIf="!state.isEnumType && !state.isEnumArrayType && Type !== 'boolean' && Type !== 'searchQuery'"
[type]="type" [min]="state.min" [max]="state.max" class="form-control"
[placeholder]="PlaceHolder"
[title]="title"
@ -39,40 +39,53 @@
[id]="idName"
required="required">
<ng-container *ngIf="IsEnumType || Type === 'boolean'">
<ng-container *ngFor="let _ of Values; let i=index">
<select
*ngIf="state.isEnumType"
[id]="idName"
[name]="idName"
[title]="title"
(ngModelChange)="onChange($event)"
[disabled]="state.readonly || disabled"
class="form-control" [(ngModel)]="state.value">
<option *ngFor="let opt of optionsView" [ngValue]="opt.key">{{opt.value}}
</option>
</select>
<bSwitch
*ngIf="Type === 'boolean'"
class="switch"
[id]="idName"
[name]="idName"
[title]="title"
[disabled]="state.readonly || disabled"
switch-on-color="primary"
switch-inverse="true"
switch-off-text="Disabled"
switch-on-text="Enabled"
i18n-switch-off-text
i18n-switch-on-text
switch-handle-width="100"
switch-label-width="20"
(ngModelChange)="onChange($event)"
[(ngModel)]="state.value">
</bSwitch>
<ng-container *ngIf="state.isEnumArrayType">
<ng-container *ngFor="let _ of state.value; let i=index">
<div class="row col-12 mt-1 m-0 p-0">
<div class="col p-0">
<select
*ngIf="IsEnumType"
[id]="'list_'+idName+i"
[name]="'list_'+idName+i"
[title]="title"
(ngModelChange)="onChange($event)"
[disabled]="state.readonly || disabled"
class="form-control" [(ngModel)]="Values[i]">
class="form-control" [(ngModel)]="state.value[i]">
<option *ngFor="let opt of optionsView" [ngValue]="opt.key">{{opt.value}}
</option>
</select>
<bSwitch
*ngIf="Type === 'boolean'"
class="switch"
[id]="'list_'+idName+i"
[name]="'list_'+idName+i"
[title]="title"
[disabled]="state.readonly || disabled"
switch-on-color="primary"
switch-inverse="true"
switch-off-text="Disabled"
switch-on-text="Enabled"
i18n-switch-off-text
i18n-switch-on-text
switch-handle-width="100"
switch-label-width="20"
(ngModelChange)="onChange($event)"
[(ngModel)]="Values[i]">
</bSwitch>
</div>
<ng-container *ngIf="state.type === 'array'">

View File

@ -58,6 +58,7 @@ export class SettingsEntryComponent implements ControlValueAccessor, Validator,
idName: string;
disabled: boolean;
private readonly GUID = Utils.GUID();
private singleValueWrapper: { set: (value: any) => void; get: () => any };
constructor(private searchQueryParserService: SearchQueryParserService) {
@ -67,9 +68,6 @@ export class SettingsEntryComponent implements ControlValueAccessor, Validator,
if (this.disabled) {
return false;
}
if (this.state.type === 'array') {
return !Utils.equalsFilter(this.state.value, this.state.default);
}
return !Utils.equalsFilter(this.state.value, this.state.default);
}
@ -101,21 +99,10 @@ export class SettingsEntryComponent implements ControlValueAccessor, Validator,
}
get Values(): any[] {
if (Array.isArray(this.state.value)) {
return this.state.value;
}
return [this.state.value];
}
get Type(): any {
return this.typeOverride || this.state.type;
}
get IsEnumType(): boolean {
return this.state.isEnumType === true || this.state.isEnumArrayType === true;
}
get StringValue(): any {
if (this.state.type === 'array' &&
(this.state.arrayType === 'string' || this.isNumberArray)) {

View File

@ -34,4 +34,23 @@ describe('Utils', () => {
expect(Utils.findClosestinSorted(10, [3, 20])).to.be.equal(3);
expect(Utils.findClosestinSorted(10, [20])).to.be.equal(20);
});
it('should equal', () => {
expect(Utils.equalsFilter('abc', 'abc')).to.be.equal(true);
expect(Utils.equalsFilter('abc', 'abcd')).to.be.equal(false);
expect(Utils.equalsFilter(10, 10)).to.be.equal(true);
expect(Utils.equalsFilter(10, 11)).to.be.equal(false);
expect(Utils.equalsFilter(true, true)).to.be.equal(true);
expect(Utils.equalsFilter(false, false)).to.be.equal(true);
expect(Utils.equalsFilter(false, true)).to.be.equal(false);
expect(Utils.equalsFilter(true, false)).to.be.equal(false);
expect(Utils.equalsFilter(0, false)).to.be.equal(false);
expect(Utils.equalsFilter(0, 0)).to.be.equal(true);
expect(Utils.equalsFilter(false, 0)).to.be.equal(false);
expect(Utils.equalsFilter(null, null)).to.be.equal(true);
expect(Utils.equalsFilter(null, false)).to.be.equal(false);
expect(Utils.equalsFilter(false, null)).to.be.equal(false);
expect(Utils.equalsFilter({a: 0}, {b: 0})).to.be.equal(false);
expect(Utils.equalsFilter({a: 0}, {a: 0})).to.be.equal(true);
});
});