diff --git a/master/bt5/slapos_jio/PathTemplateItem/web_page_module/rjs_gadget_erp5_page_slap_parameter_form_js.js b/master/bt5/slapos_jio/PathTemplateItem/web_page_module/rjs_gadget_erp5_page_slap_parameter_form_js.js index 8316c83a0702b9a5c6fdd1ed6de669f34820c5c1..94bb0983c1a5bfa5f0ae1c664367cb812f2a875e 100644 --- a/master/bt5/slapos_jio/PathTemplateItem/web_page_module/rjs_gadget_erp5_page_slap_parameter_form_js.js +++ b/master/bt5/slapos_jio/PathTemplateItem/web_page_module/rjs_gadget_erp5_page_slap_parameter_form_js.js @@ -46,26 +46,40 @@ selected: (default_value === undefined) })], option_index, + selected, + is_selected = (default_value === undefined), data_format = "string"; if (json_field.type === "integer" || json_field.type === "number") { data_format = "number"; + } else if (json_field.type === "boolean") { + data_format = "boolean"; } if (default_value === undefined) { - default_value = "" + default_value = ""; } for (option_index in json_field['enum']) { if (json_field['enum'].hasOwnProperty(option_index)) { + selected = (json_field['enum'][option_index].toString() === default_value.toString()); + is_selected = (is_selected || selected); option_list.push(domsugar('option', { value: json_field['enum'][option_index], text: json_field['enum'][option_index], "data-format": data_format, - selected: ( - json_field['enum'][option_index].toString() === default_value.toString() - ) + selected: true })); } } + if (!is_selected) { + // The default value should be included even if it is + // outside the enum. + option_list.push(domsugar('option', { + value: default_value, + text: default_value, + "data-format": data_format, + selected: selected + })); + } return domsugar('select', { size: 1, "data-format": data_format @@ -344,20 +358,16 @@ entry_list, multi_level_dict = {}; $(element.querySelectorAll(".slapos-parameter")).each(function (key, input) { - var index_e; + var index_e, data_format = input.getAttribute("data-format"); if (input.value !== "") { if (input.type === 'number') { json_dict[input.name] = parseFloat(input.value); - } else if (input.value === "true") { - json_dict[input.name] = true; - } else if (input.value === "false") { - json_dict[input.name] = false; } else if (input.tagName === "TEXTAREA") { - if (input.getAttribute("data-format") === "string") { + if (data_format === "string") { json_dict[input.name] = input.value; - } else if (input.getAttribute("data-format") === "array") { + } else if (data_format === "array") { json_dict[input.name] = input.value.split('\n'); - } else if (input.getAttribute("data-format") === "array-number") { + } else if (data_format === "array-number") { json_dict[input.name] = []; entry_list = input.value.split("\n"); for (index_e in entry_list) { @@ -373,12 +383,20 @@ json_dict[input.name] = input.value.split('\n'); } } else if (input.tagName === "SELECT") { - if (input.getAttribute("data-format") === "number") { - json_dict[input.name] = parseFloat(input.value); - } else if (input.getAttribute("data-format") === "integer") { - // Don't use parseInt since it will round the value, modifing the - // use input. So we keep it the value. - json_dict[input.name] = parseFloat(input.value); + if (data_format === "number" || data_format === "integer") { + // Integer must use parseFloat, otherwise the value is rounded + // loosing user's input. + if (isNaN(parseFloat(input.value))) { + json_dict[input.name] = input.value; + } else { + json_dict[input.name] = parseFloat(input.value); + } + } else if (input.getAttribute("data-format") === "boolean") { + if (input.value === "true" || input.value === "false") { + json_dict[input.name] = Boolean(input.value); + } else { + json_dict[input.name] = input.value; + } } else { json_dict[input.name] = input.value; } @@ -585,10 +603,10 @@ for (error_index in validation.errors) { if (validation.errors.hasOwnProperty(error_index)) { field_name = validation.errors[error_index].dataPath; - input_field = g.element.querySelector(".slapos-parameter[name='/" + field_name + "']") + input_field = g.element.querySelector(".slapos-parameter[name='/" + field_name + "']"); if (input_field === null) { - field_name = field_name.split("/").slice(0, -1).join("/") - input_field = g.element.querySelector(".slapos-parameter[name='/" + field_name + "']") + field_name = field_name.split("/").slice(0, -1).join("/"); + input_field = g.element.querySelector(".slapos-parameter[name='/" + field_name + "']"); } div = input_field.parentNode; div.setAttribute("class", "slapos-parameter error-input"); @@ -599,17 +617,17 @@ for (missing_index in validation.missing) { if (validation.missing.hasOwnProperty(missing_index)) { missing_field_name = validation.missing[missing_index].dataPath; - input_field = g.element.querySelector(".slapos-parameter[name='/" + missing_field_name + "']") + input_field = g.element.querySelector(".slapos-parameter[name='/" + missing_field_name + "']"); if (input_field === null) { - missing_field_name = field_name.split("/").slice(0, -1).join("/") - input_field = g.element.querySelector(".slapos-parameter[name='/" + missing_field_name + "']") + missing_field_name = field_name.split("/").slice(0, -1).join("/"); + input_field = g.element.querySelector(".slapos-parameter[name='/" + missing_field_name + "']"); } divm = input_field.parentNode; divm.setAttribute("class", "error-input"); divm.querySelector("span.error").textContent = validation.missing[missing_index].message; } } - return "ERROR"; + return xml_output; }); } @@ -1058,6 +1076,11 @@ content_dict.shared = 1; } if (text_content !== null) { + // Don't provide blank string since the parameter will not able to load + // itself. If the user removed the values, provide an empty parameter default. + if (text_content.value === "") { + return '<?xml version="1.0" encoding="utf-8" ?><instance></instance>'; + } return text_content.value; } return checkValidity(gadget); diff --git a/master/bt5/slapos_jio/PathTemplateItem/web_page_module/rjs_gadget_erp5_page_slap_parameter_form_js.xml b/master/bt5/slapos_jio/PathTemplateItem/web_page_module/rjs_gadget_erp5_page_slap_parameter_form_js.xml index 322aeb10ec2354a98a4b85654e750f994d3ce629..cd9c179655fde730c465c485dc20f5aa2982f279 100644 --- a/master/bt5/slapos_jio/PathTemplateItem/web_page_module/rjs_gadget_erp5_page_slap_parameter_form_js.xml +++ b/master/bt5/slapos_jio/PathTemplateItem/web_page_module/rjs_gadget_erp5_page_slap_parameter_form_js.xml @@ -280,7 +280,7 @@ </item> <item> <key> <string>serial</string> </key> - <value> <string>1000.9806.10724.60689</string> </value> + <value> <string>1000.14042.12571.63982</string> </value> </item> <item> <key> <string>state</string> </key> @@ -298,7 +298,7 @@ </tuple> <state> <tuple> - <float>1652220502.37</float> + <float>1652712920.56</float> <string>UTC</string> </tuple> </state> diff --git a/master/bt5/slapos_jio/SkinTemplateItem/portal_skins/slapos_hal_json_style/sample-software-schema/simplebaddemo.xml b/master/bt5/slapos_jio/SkinTemplateItem/portal_skins/slapos_hal_json_style/sample-software-schema/simplebaddemo.xml new file mode 100644 index 0000000000000000000000000000000000000000..c880985d524352848b21d8a3736d1c8dd45cda54 --- /dev/null +++ b/master/bt5/slapos_jio/SkinTemplateItem/portal_skins/slapos_hal_json_style/sample-software-schema/simplebaddemo.xml @@ -0,0 +1,26 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <global name="Folder" module="OFS.Folder"/> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>_objects</string> </key> + <value> + <tuple/> + </value> + </item> + <item> + <key> <string>id</string> </key> + <value> <string>simplebaddemo</string> </value> + </item> + <item> + <key> <string>title</string> </key> + <value> <string></string> </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/master/bt5/slapos_jio/SkinTemplateItem/portal_skins/slapos_hal_json_style/sample-software-schema/simplebaddemo/instance-input-schema.json.json b/master/bt5/slapos_jio/SkinTemplateItem/portal_skins/slapos_hal_json_style/sample-software-schema/simplebaddemo/instance-input-schema.json.json new file mode 100644 index 0000000000000000000000000000000000000000..9576456f55d2f9b4dfc4719101aa84ee00b46770 --- /dev/null +++ b/master/bt5/slapos_jio/SkinTemplateItem/portal_skins/slapos_hal_json_style/sample-software-schema/simplebaddemo/instance-input-schema.json.json @@ -0,0 +1,24 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "description": "Sample paremeters for a Simple Demo with broken or bad standards", + "additionalProperties": false, + "properties": { + "simple-boolean-as-string": { + "title": "Example of Boolean defined as String (WORKS BUT BAD PATTERN)", + "description": "Example of Boolean defined as String (WORKS BUT BAD PATTERN)", + "enum": [ + "false", + "true" + ], + "type": "string" + }, + "simple-boolean": { + "title": "Correct Boolean definition", + "description": "Correct Boolean definition", + "type": "boolean", + "default": true + } + } +} + diff --git a/master/bt5/slapos_jio/SkinTemplateItem/portal_skins/slapos_hal_json_style/sample-software-schema/simplebaddemo/instance-input-schema.json.xml b/master/bt5/slapos_jio/SkinTemplateItem/portal_skins/slapos_hal_json_style/sample-software-schema/simplebaddemo/instance-input-schema.json.xml new file mode 100644 index 0000000000000000000000000000000000000000..7c0e31042793106304aa4f76ad164472bf85cc9f --- /dev/null +++ b/master/bt5/slapos_jio/SkinTemplateItem/portal_skins/slapos_hal_json_style/sample-software-schema/simplebaddemo/instance-input-schema.json.xml @@ -0,0 +1,28 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <global name="File" module="OFS.Image"/> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>__name__</string> </key> + <value> <string>instance-input-schema.json</string> </value> + </item> + <item> + <key> <string>content_type</string> </key> + <value> <string>text/x-json</string> </value> + </item> + <item> + <key> <string>precondition</string> </key> + <value> <string></string> </value> + </item> + <item> + <key> <string>title</string> </key> + <value> <string></string> </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/master/bt5/slapos_jio/SkinTemplateItem/portal_skins/slapos_hal_json_style/sample-software-schema/simplebaddemo/software.cfg.json.json b/master/bt5/slapos_jio/SkinTemplateItem/portal_skins/slapos_hal_json_style/sample-software-schema/simplebaddemo/software.cfg.json.json new file mode 100644 index 0000000000000000000000000000000000000000..4a2e34f29f2cab84876ec406ed308ab28007bbca --- /dev/null +++ b/master/bt5/slapos_jio/SkinTemplateItem/portal_skins/slapos_hal_json_style/sample-software-schema/simplebaddemo/software.cfg.json.json @@ -0,0 +1,14 @@ +{ + "name": "Simple Demo following bad parameters", + "description": "Demo Simple following bad parameters", + "serialisation": "xml", + "software-type": { + "default": { + "title": "Default", + "description": "Default reference parameters", + "request": "instance-input-schema.json", + "response": "instance-output-schema.json", + "index": 0 + } + } +} diff --git a/master/bt5/slapos_jio/SkinTemplateItem/portal_skins/slapos_hal_json_style/sample-software-schema/simplebaddemo/software.cfg.json.xml b/master/bt5/slapos_jio/SkinTemplateItem/portal_skins/slapos_hal_json_style/sample-software-schema/simplebaddemo/software.cfg.json.xml new file mode 100644 index 0000000000000000000000000000000000000000..d65dea69c4ec63bb59f53392ddb2465553935447 --- /dev/null +++ b/master/bt5/slapos_jio/SkinTemplateItem/portal_skins/slapos_hal_json_style/sample-software-schema/simplebaddemo/software.cfg.json.xml @@ -0,0 +1,28 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <global name="File" module="OFS.Image"/> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>__name__</string> </key> + <value> <string>software.cfg.json</string> </value> + </item> + <item> + <key> <string>content_type</string> </key> + <value> <string>text/x-json</string> </value> + </item> + <item> + <key> <string>precondition</string> </key> + <value> <string></string> </value> + </item> + <item> + <key> <string>title</string> </key> + <value> <string></string> </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/master/bt5/slapos_jio/SkinTemplateItem/portal_skins/slapos_hal_json_style/sample-software-schema/simplebaddemo/software.cfg.txt b/master/bt5/slapos_jio/SkinTemplateItem/portal_skins/slapos_hal_json_style/sample-software-schema/simplebaddemo/software.cfg.txt new file mode 100644 index 0000000000000000000000000000000000000000..4d5519c204f28119795cbcaef2ddd476cccecd00 --- /dev/null +++ b/master/bt5/slapos_jio/SkinTemplateItem/portal_skins/slapos_hal_json_style/sample-software-schema/simplebaddemo/software.cfg.txt @@ -0,0 +1 @@ +# Required to mimic software releases \ No newline at end of file diff --git a/master/bt5/slapos_jio/SkinTemplateItem/portal_skins/slapos_hal_json_style/sample-software-schema/simplebaddemo/software.cfg.xml b/master/bt5/slapos_jio/SkinTemplateItem/portal_skins/slapos_hal_json_style/sample-software-schema/simplebaddemo/software.cfg.xml new file mode 100644 index 0000000000000000000000000000000000000000..8de0d7401ab1bc9e74973ecf1ca12ea9b4abc0a9 --- /dev/null +++ b/master/bt5/slapos_jio/SkinTemplateItem/portal_skins/slapos_hal_json_style/sample-software-schema/simplebaddemo/software.cfg.xml @@ -0,0 +1,28 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <global name="File" module="OFS.Image"/> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>__name__</string> </key> + <value> <string>software.cfg</string> </value> + </item> + <item> + <key> <string>content_type</string> </key> + <value> <string>text/plain</string> </value> + </item> + <item> + <key> <string>precondition</string> </key> + <value> <string></string> </value> + </item> + <item> + <key> <string>title</string> </key> + <value> <string></string> </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/master/bt5/slapos_jio/SkinTemplateItem/portal_skins/slapos_hal_json_style/sample-software-schema/simpledemo/instance-input-json-in-xml-schema.json.json b/master/bt5/slapos_jio/SkinTemplateItem/portal_skins/slapos_hal_json_style/sample-software-schema/simpledemo/instance-input-json-in-xml-schema.json.json index 5c2ede19668ac57873fcda96ca88989ed0361999..c705fd6b4b556e06fb942adcb2d48b813848b243 100644 --- a/master/bt5/slapos_jio/SkinTemplateItem/portal_skins/slapos_hal_json_style/sample-software-schema/simpledemo/instance-input-json-in-xml-schema.json.json +++ b/master/bt5/slapos_jio/SkinTemplateItem/portal_skins/slapos_hal_json_style/sample-software-schema/simpledemo/instance-input-json-in-xml-schema.json.json @@ -26,6 +26,62 @@ "description": "Example of Array of Numbers", "type": "array", "items": {"type": "number"} + }, + "simple-object": { + "title": "Example of Single Object", + "description": "Example of Single Object", + "type": "object", + "properties": { + "sample-object-string": { + "title": "Example of Simple String on an object", + "description": "Example of Simple String", + "type": "string", + "default": "Simple string " + }, + "simple-object-with-integer": { + "title": "Example of Simple Integer", + "description": "Example of Simple Integer", + "type": "integer", + "default": 1 + }, + "simple-object-with-integer-with-enum": { + "title": "Example of Simple Integer with enum", + "description": "Example of Simple Integer with enum", + "type": "integer", + "default": 1, + "enum": [ + 1, + 2 + ] + } + } + }, + "simple-object-dict": { + "title": "Example of multi objects as a Dict", + "description": "Example of multi objects as a Dict", + "type": "object", + "patternProperties": { + ".*": { + "properties": { + "simple-object-dict-string-example": { + "title": "Example of the String as part of Object", + "description": "Example of the String as part of Object", + "type": "string", + "default": "" + }, + "simple-object-dict-string-with-enum": { + "title": "Example of the String as part of Object with Enum", + "description": "Example of the String as part of Object with Enum", + "type": "string", + "default": "String Sample A", + "enum": [ + "String Sample A", + "String Sample B" + ] + } + } + } + } } } } diff --git a/master/bt5/slapos_jio/SkinTemplateItem/portal_skins/slapos_hal_json_style/sample-software-schema/simpledemo/instance-input-schema.json.json b/master/bt5/slapos_jio/SkinTemplateItem/portal_skins/slapos_hal_json_style/sample-software-schema/simpledemo/instance-input-schema.json.json index f0e98c2378d984da290a80c57178a7570cfae39d..f368653e36d3c879834f74d198f7e1d54da71ad7 100644 --- a/master/bt5/slapos_jio/SkinTemplateItem/portal_skins/slapos_hal_json_style/sample-software-schema/simpledemo/instance-input-schema.json.json +++ b/master/bt5/slapos_jio/SkinTemplateItem/portal_skins/slapos_hal_json_style/sample-software-schema/simpledemo/instance-input-schema.json.json @@ -21,6 +21,12 @@ ], "default": "simple string A" }, + "simple-boolean": { + "title": "Example of Simple String", + "description": "Example of Simple String", + "type": "boolean", + "default": true + }, "simple-string-with-text-area": { "title": "Example of Simple String with textarea", "description": "Example of Simple String with text area",