diff --git a/extension.schema.json b/extension.schema.json index ee5447fed..5f901f199 100644 --- a/extension.schema.json +++ b/extension.schema.json @@ -627,6 +627,16 @@ "type": "array", "items": { "$ref": "#/definitions/settingsGroupParameterRef" }, "minItems": 1 + }, + "rules": { + "description": "Element rules", + "type": "object", + "properties": { + "visible": { + "description": "Rule to evaluate the visibility state", + "type": "string" + } + } } }, "required": ["id", "name", "parameters"] diff --git a/src/app/components/settings/settings.component.ts b/src/app/components/settings/settings.component.ts index bf48908ac..79d488aea 100644 --- a/src/app/components/settings/settings.component.ts +++ b/src/app/components/settings/settings.component.ts @@ -65,7 +65,7 @@ export class SettingsComponent implements OnInit { headerColor$: Observable; get settingGroups(): SettingsGroupRef[] { - return this.appExtensions.settingGroups; + return this.appExtensions.getSettingsGroups(); } constructor( @@ -136,7 +136,9 @@ export class SettingsComponent implements OnInit { } setParamValue(param: SettingsParameterRef, value: any) { - if (param.value !== value) { + const currentValue = this.getStringParamValue(param); + + if (currentValue !== value.toString()) { param.value = value; this.saveToStorage(param); } diff --git a/src/app/extensions/extension.service.ts b/src/app/extensions/extension.service.ts index c189c22b9..ab588c568 100644 --- a/src/app/extensions/extension.service.ts +++ b/src/app/extensions/extension.service.ts @@ -507,6 +507,10 @@ export class AppExtensionService implements RuleContext { .sort(sortByOrder); } + getSettingsGroups(): Array { + return this.settingGroups.filter(group => this.filterVisible(group)); + } + copyAction(action: ContentActionRef): ContentActionRef { return { ...action, @@ -514,7 +518,7 @@ export class AppExtensionService implements RuleContext { }; } - filterVisible(action: ContentActionRef): boolean { + filterVisible(action: ContentActionRef | SettingsGroupRef): boolean { if (action && action.rules && action.rules.visible) { return this.extensions.evaluateRule(action.rules.visible, this); } diff --git a/src/app/types.ts b/src/app/types.ts index 37d291eca..ff0fdfebb 100644 --- a/src/app/types.ts +++ b/src/app/types.ts @@ -27,6 +27,10 @@ export interface SettingsGroupRef { id: string; name: string; parameters: Array; + rules?: { + visible?: string; + [key: string]: string; + }; } export interface SettingsParameterRef { diff --git a/src/assets/app.extensions.json b/src/assets/app.extensions.json index 19771bebf..575e03a4a 100644 --- a/src/assets/app.extensions.json +++ b/src/assets/app.extensions.json @@ -32,7 +32,10 @@ "type": "boolean", "value": false } - ] + ], + "rules": { + "visible": "user.isAdmin" + } }, { "id": "extensions.ps.settings", @@ -44,7 +47,10 @@ "type": "boolean", "value": false } - ] + ], + "rules": { + "visible": "user.isAdmin" + } } ],