Commit 114d59fa authored by Rafael Monnerat's avatar Rafael Monnerat

Fixup for Parameter Editor

See merge request !385
parents 41cbe596 a3651c60
Pipeline #21518 failed with stage
in 0 seconds
......@@ -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);
......
......@@ -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>
......
<?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>
{
"$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
}
}
}
<?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>
{
"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
}
}
}
<?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>
<?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>
......@@ -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"
]
}
}
}
}
}
}
}
......
......@@ -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",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment