Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gpii 4207 Updates to default values and some settings that were missing #824

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
107 changes: 107 additions & 0 deletions gpii/node_modules/solutionsRegistry/src/js/SolutionsUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* GPII Solutions Utils - Independent helper functions and utilities for working with
* solutions and their schemas.
*
* Copyright 2019 Raising the Floor - US
*
* Licensed under the New BSD license. You may not use this file except in
* compliance with this License.
*
* The research leading to these results has received funding from the European Union's
* Seventh Framework Programme (FP7/2007-2013)
* under grant agreement no. 289016.
*
* You may obtain a copy of the License at
* https://github.com/GPII/universal/blob/master/LICENSE.txt
*/
"use strict";
var fluid = require("infusion");
var gpii = fluid.registerNamespace("gpii");

fluid.registerNamespace("gpii.universal.solutionsRegistry");

/**
* This function will take a schema from a supported setting in the solutions
* registry and return metadata on it's default value, including the type of
* the default value. The function will always return a block of json in order
* to avoid any ambiguities for a situation where the default value is perhaps
* `null`. A key `hasDefault` will be `true` or `false` to communicate this.
* If the schema does have a default value, then the properties `type` and
* `default` can also be included. Note that there may not always be a `type`
* that can be included, the inclusion of this in the return if optional and
* will be included if a `type` is declared.
*
* This is NOT meant to be an exhaustive coverage of all the possible ways
* default values can be set for any JSON Schema. We merely want to cover the
* cases in use in the solutions registry, focussing on single primitive values,
* and situations where we next one level deep due to a requirement of having a
* `properties` entry in the schema.
*
* @param {Object} schema - Schema to search for a default value. This is what
* would be in the solutions registry under `supportedSettings` and a
* configuration. An example from the Windows Mouse Keys MaxSpeed setting is:
* ```json
* {
* "title": "Mouse keys speed",
* "description": "Speed of mouse keys",
* "type": "number",
* "multipleOf": 10,
* "default": 80
* }
* ```
* @return {Object} Always returns a json block. For the example above the
* return value would be:
* ```json
* {
* "hasDefault": true,
* "type": "number",
* "default": 80
* }
* ```
* If a default value cannot be detected the return payload will be:
* ```json
* {
* "hasDefault": false
* }
* ```
*/
gpii.universal.solutionsRegistry.findDefaultValue = function (schema) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's helpful, but it is not used by anything in the codebase - does it belong in the capture tool instead?
Also note that the one place where we do fetch setting defaults, we do not use this approach - https://github.com/GPII/universal/blob/master/gpii/node_modules/flowManager/src/PSPChannel.js#L139 - instead, we read the value from build/schemas/solution-schema-codex.json . What do you think, @cindyli , @the-t-in-rtf ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was confused as to where and why you'd use this, but then I looked at some of the deeper structures like the SPI settings here:

// TODO: Discuss somehow simplifying the structure of SPI settings for easier UI input.

I guess my questions are, what do you expect to do with this potential "deep default" and why do you preserve the "type" but not anything else? If you're putting up controls or anything else, you don't have enough information to create controls. You don't know the range any longer, you don't know if the field is required, et cetera. If you're getting that info somewhere else, why not get the type from there as well?

Also, your code is focused on the value property, there are others, like this object that has RGB properties. How do you plan to handle those?

It seems to me like you need proper handling for nested properties, and this type of recursion should be possible in both javascript and handlebars templates. But maybe I just don't get what you're doing, and an example of what you're feeding into this and where you use it would help. Apologies if you've already covered that in the longer conversation.

I also am not sure this belongs in this particular part of the Solutions Registry. The use case would help confirm, but if it's truly about UI generation, it seems like this would be an early utility that would make up part of the "presentation registry" instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amb26 Well, it's first use is the capture tool (and I've already temporarily duplicated it there), but it will all need to be used in the PPT, Morphic Vaults and other user facing applications build on top of universal. Quite a number of our UX specs at some point highlight what the default value of a particular setting is.

Also, regardless of the input, whether it's from win32.json or from solution-schema-codex.json, I believe we have the same problems. (and this impl I believe should still work if you pass in the corresponding property/schema either way. Here is a section from my locally generated solution-schema-codex.json:

       "SlowKeysInterval": {
        "title": "Slow keys interval",
        "description": "Slow keys interval time in milliseconds",
        "properties": {
          "path": {
            "type": "string",
            "required": true
          },
          "value": {
            "required": true,
            "type": "integer",
            "minimum": 0,
            "maximum": 20000,
            "default": 1000
          }
        }
      },
      "BounceKeysInterval": {
        "title": "Bounce keys interval",
        "description": "Bounce keys interval time in milliseconds",
        "type": "integer",
        "default": 0
      }

Here, you can see that the default is at the top level for BounceKeysInterval, and then for SlowKeysInterval you need to drill down a level to get the default value.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@the-t-in-rtf An example of what I'm doing with the default value (regardless of whether it's in the top level of the items schema, or further down), is here in the capture tool where you can filter values on and off, depending if they match the default:

image

In the PPT, on the tables that show settings for each solution there is a column for the default.

Current I'm just preserving type because it's the amount of information I need to build these UI's (maybe not a great answer, but the truth). I just need the default, and it's type so I can compare them. I've haven't yet dealt with RGB values or anything, as the comments on the method allude to, I'm trying to knock out the largest number of settings at the moment that show up on these UI's with the simplest solution so far.

I'm ok with it being anywhere in universal, but it would be nice to have it in at least one of our most central repos... at the moment every one of our user facing projects still includes universal. Also, I can imagine a time soon where this default value information would be needed to create some time of data feed endpoint in universal.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't understand why you can't just use the schema in its entirety. We should discuss in the meeting today.

var togo;

// 1. The most simple, and hopefull case is that there is a top level
// default value.
if (schema["default"] !== undefined) {
togo = {
hasDefault: true,
default: schema["default"]
};
if (schema.type) {
togo.type = schema.type;
}
}
// 2. Sometimes we have a properties structure that can be interogated, example:
// "properties": {
// "path": { "type": "string"},
// "value": {
// "type": "string",
// "default": "%SystemRoot%\\Web\\Wallpaper\\Windows\\img0.jpg"
// }
// }
else if (schema.properties && schema.properties.value && schema.properties.value["default"] !== undefined) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a great place to use fluid.get.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, updated to use fluid.get

togo = {
hasDefault: true,
default: schema.properties.value["default"]
};
if (schema.properties.value.type) {
togo.type = schema.properties.value.type;
}
}
// We cannot find a default value for our simplified usage of json schema...
else {
togo = {
hasDefault: false
};
}

return togo;
};
153 changes: 153 additions & 0 deletions gpii/node_modules/solutionsRegistry/test/SolutionsUtilsTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
* Tests for GPII Solutions Utils
*
* Copyright 2019 Raising the Floor - US
*
* Licensed under the New BSD license. You may not use this file except in
* compliance with this License.
*
* The research leading to these results has received funding from the European Union's
* Seventh Framework Programme (FP7/2007-2013)
* under grant agreement no. 289016.
*
* You may obtain a copy of the License at
* https://github.com/GPII/universal/blob/master/LICENSE.txt
*/

"use strict";
var fluid = require("infusion");
var gpii = fluid.registerNamespace("gpii");
var jqUnit = require("node-jqunit");

require("../src/js/SolutionsUtils");

jqUnit.module("Tests for Solutions Registry Utility functions.");

fluid.registerNamespace("gpii.tests.universal.solutionsRegistry.solutionsUtils");

gpii.tests.universal.solutionsRegistry.solutionsUtils.defaultValueTests = [
{
schema: {
"title": "Attribute Rotation Delay",
"description": "When in Attribute...",
"type": "integer",
"default": 1000
},
result: {
hasDefault: true,
type: "integer",
default: 1000
}
},
{
schema: {
"title": "Attribute Rotation Delay",
"description": "When in Attribute...",
"default": 1000
},
result: {
hasDefault: true,
default: 1000
}
},
{
schema: {
"title": "Attribute Rotation Delay With No Default...",
"description": "When in Attribute...",
"type": "integer"
},
result: {
hasDefault: false
}
},
{
schema: {
"title": "Desktop background wallpaper",
"description": "The path to the image to be set as the new desktop wallpaper.",
"properties": {
"path": { "type": "string"},
"value": {
"type": "string",
"default": "%SystemRoot%\\Web\\Wallpaper\\Windows\\img0.jpg"
}
}
},
result: {
hasDefault: true,
type: "string",
default: "%SystemRoot%\\Web\\Wallpaper\\Windows\\img0.jpg"
}
},
{
schema: {
"title": "Desktop background wallpaper",
"description": "The path to the image to be set as the new desktop wallpaper.",
"properties": {
"path": { "type": "string"},
"value": {
"default": "%SystemRoot%\\Web\\Wallpaper\\Windows\\img0.jpg"
}
}
},
result: {
hasDefault: true,
default: "%SystemRoot%\\Web\\Wallpaper\\Windows\\img0.jpg"
}
},
{
schema: {
"title": "Desktop background wallpaper",
"description": "The path to the image to be set as the new desktop wallpaper.",
"properties": {
"path": { "type": "string", "required": true},
"value": {
"type": "string",
"required": true,
"default": ""
}
}
},
result: {
hasDefault: true,
type: "string",
default: ""
}
},
{
schema: {
"title": "Screen mirroring",
"description": "Mirrors the primary screen into a secondary screen.",
"type": "boolean",
"default": false
},
result: {
hasDefault: true,
type: "boolean",
default: false
}
}
];

gpii.tests.universal.solutionsRegistry.solutionsUtils.findDefaultValueTest = function (schema, expectedResult) {
var result = gpii.universal.solutionsRegistry.findDefaultValue(schema);
jqUnit.assertDeepEq("Checking default value for: " + schema.title, expectedResult, result);
};

gpii.tests.universal.solutionsRegistry.solutionsUtils.findDefaultValueTests = function () {
jqUnit.test("Testing my empty stubs...", function () {
fluid.each(gpii.tests.universal.solutionsRegistry.solutionsUtils.defaultValueTests, function (item) {
gpii.tests.universal.solutionsRegistry.solutionsUtils.findDefaultValueTest(item.schema, item.result);
});
});
};

fluid.defaults("gpii.tests.universal.solutionsRegistry.solutionsUtils", {
gradeNames: ["fluid.component"],
listeners: {
"onCreate.findDefaultValueTest": {
funcName: "gpii.tests.universal.solutionsRegistry.solutionsUtils.findDefaultValueTests"
}
}
});

gpii.tests.universal.solutionsRegistry.solutionsUtils();
1 change: 1 addition & 0 deletions gpii/node_modules/solutionsRegistry/test/all-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ require("./FilteredSettingsMiddlewareTests.js");
require("./GenericTermsTests.js");
require("./SettingsPayloadTests.js");
require("./SolutionsRegistryFileTests.js");
require("./SolutionsUtilsTests.js");
Loading