improved settings api (#1408)

This commit is contained in:
Denys Vuika 2020-04-09 20:06:18 +01:00 committed by GitHub
parent 3ee61c3d29
commit 785b7abb8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 5 deletions

View File

@ -627,6 +627,16 @@
"type": "array", "type": "array",
"items": { "$ref": "#/definitions/settingsGroupParameterRef" }, "items": { "$ref": "#/definitions/settingsGroupParameterRef" },
"minItems": 1 "minItems": 1
},
"rules": {
"description": "Element rules",
"type": "object",
"properties": {
"visible": {
"description": "Rule to evaluate the visibility state",
"type": "string"
}
}
} }
}, },
"required": ["id", "name", "parameters"] "required": ["id", "name", "parameters"]

View File

@ -65,7 +65,7 @@ export class SettingsComponent implements OnInit {
headerColor$: Observable<string>; headerColor$: Observable<string>;
get settingGroups(): SettingsGroupRef[] { get settingGroups(): SettingsGroupRef[] {
return this.appExtensions.settingGroups; return this.appExtensions.getSettingsGroups();
} }
constructor( constructor(
@ -136,7 +136,9 @@ export class SettingsComponent implements OnInit {
} }
setParamValue(param: SettingsParameterRef, value: any) { setParamValue(param: SettingsParameterRef, value: any) {
if (param.value !== value) { const currentValue = this.getStringParamValue(param);
if (currentValue !== value.toString()) {
param.value = value; param.value = value;
this.saveToStorage(param); this.saveToStorage(param);
} }

View File

@ -507,6 +507,10 @@ export class AppExtensionService implements RuleContext {
.sort(sortByOrder); .sort(sortByOrder);
} }
getSettingsGroups(): Array<SettingsGroupRef> {
return this.settingGroups.filter(group => this.filterVisible(group));
}
copyAction(action: ContentActionRef): ContentActionRef { copyAction(action: ContentActionRef): ContentActionRef {
return { return {
...action, ...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) { if (action && action.rules && action.rules.visible) {
return this.extensions.evaluateRule(action.rules.visible, this); return this.extensions.evaluateRule(action.rules.visible, this);
} }

View File

@ -27,6 +27,10 @@ export interface SettingsGroupRef {
id: string; id: string;
name: string; name: string;
parameters: Array<SettingsParameterRef>; parameters: Array<SettingsParameterRef>;
rules?: {
visible?: string;
[key: string]: string;
};
} }
export interface SettingsParameterRef { export interface SettingsParameterRef {

View File

@ -32,7 +32,10 @@
"type": "boolean", "type": "boolean",
"value": false "value": false
} }
] ],
"rules": {
"visible": "user.isAdmin"
}
}, },
{ {
"id": "extensions.ps.settings", "id": "extensions.ps.settings",
@ -44,7 +47,10 @@
"type": "boolean", "type": "boolean",
"value": false "value": false
} }
] ],
"rules": {
"visible": "user.isAdmin"
}
} }
], ],