Commit 8400195a authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_jio: Implement proper array of numbers

  Include more sample data.
parent a468149b
...@@ -116,6 +116,7 @@ ...@@ -116,6 +116,7 @@
} }
function render_field(json_field, default_value) { function render_field(json_field, default_value) {
var data_format, domsugar_input_dict = {};
if (json_field['enum'] !== undefined) { if (json_field['enum'] !== undefined) {
return render_selection(json_field, default_value); return render_selection(json_field, default_value);
} }
...@@ -136,15 +137,19 @@ ...@@ -136,15 +137,19 @@
} }
if (json_field.type === "array") { if (json_field.type === "array") {
return render_textarea(json_field, default_value, "array"); data_format = json_field.type;
if (json_field.items !== undefined) {
if (json_field.items.type === "number" || json_field.items.type === "integer") {
data_format = "array-number";
}
}
return render_textarea(json_field, default_value, data_format);
} }
if (json_field.type === "string" && json_field.textarea === true) { if (json_field.type === "string" && json_field.textarea === true) {
return render_textarea(json_field, default_value, "string"); return render_textarea(json_field, default_value, "string");
} }
var domsugar_input_dict = {};
if (default_value !== undefined) { if (default_value !== undefined) {
domsugar_input_dict.value = default_value; domsugar_input_dict.value = default_value;
} }
...@@ -336,8 +341,10 @@ ...@@ -336,8 +341,10 @@
function getFormValuesAsJSONDict(element) { function getFormValuesAsJSONDict(element) {
var json_dict = {}, var json_dict = {},
entry, entry,
entry_list,
multi_level_dict = {}; multi_level_dict = {};
$(element.querySelectorAll(".slapos-parameter")).each(function (key, input) { $(element.querySelectorAll(".slapos-parameter")).each(function (key, input) {
var index_e;
if (input.value !== "") { if (input.value !== "") {
if (input.type === 'number') { if (input.type === 'number') {
json_dict[input.name] = parseFloat(input.value); json_dict[input.name] = parseFloat(input.value);
...@@ -348,6 +355,20 @@ ...@@ -348,6 +355,20 @@
} else if (input.tagName === "TEXTAREA") { } else if (input.tagName === "TEXTAREA") {
if (input.getAttribute("data-format") === "string") { if (input.getAttribute("data-format") === "string") {
json_dict[input.name] = input.value; json_dict[input.name] = input.value;
} else if (input.getAttribute("data-format") === "array") {
json_dict[input.name] = input.value.split('\n');
} else if (input.getAttribute("data-format") === "array-number") {
json_dict[input.name] = [];
entry_list = input.value.split("\n");
for (index_e in entry_list) {
if (entry_list.hasOwnProperty(index_e)) {
if (isNaN(parseFloat(entry_list[index_e]))) {
json_dict[input.name].push(entry_list[index_e]);
} else {
json_dict[input.name].push(parseFloat(entry_list[index_e]));
}
}
}
} else { } else {
json_dict[input.name] = input.value.split('\n'); json_dict[input.name] = input.value.split('\n');
} }
...@@ -539,7 +560,8 @@ ...@@ -539,7 +560,8 @@
divm, divm,
missing_index, missing_index,
missing_field_name, missing_field_name,
xml_output; xml_output,
input_field;
$(g.element.querySelectorAll("span.error")).each(function (i, span) { $(g.element.querySelectorAll("span.error")).each(function (i, span) {
span.textContent = ""; span.textContent = "";
...@@ -563,7 +585,12 @@ ...@@ -563,7 +585,12 @@
for (error_index in validation.errors) { for (error_index in validation.errors) {
if (validation.errors.hasOwnProperty(error_index)) { if (validation.errors.hasOwnProperty(error_index)) {
field_name = validation.errors[error_index].dataPath; field_name = validation.errors[error_index].dataPath;
div = $(".slapos-parameter[name='/" + field_name + "']")[0].parentNode; 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 + "']")
}
div = input_field.parentNode;
div.setAttribute("class", "slapos-parameter error-input"); div.setAttribute("class", "slapos-parameter error-input");
div.querySelector("span.error").textContent = validation.errors[error_index].message; div.querySelector("span.error").textContent = validation.errors[error_index].message;
} }
...@@ -572,7 +599,12 @@ ...@@ -572,7 +599,12 @@
for (missing_index in validation.missing) { for (missing_index in validation.missing) {
if (validation.missing.hasOwnProperty(missing_index)) { if (validation.missing.hasOwnProperty(missing_index)) {
missing_field_name = validation.missing[missing_index].dataPath; missing_field_name = validation.missing[missing_index].dataPath;
divm = $('.slapos-parameter[name=/' + missing_field_name + "']")[0].parentNode; 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 + "']")
}
divm = input_field.parentNode;
divm.setAttribute("class", "error-input"); divm.setAttribute("class", "error-input");
divm.querySelector("span.error").textContent = validation.missing[missing_index].message; divm.querySelector("span.error").textContent = validation.missing[missing_index].message;
} }
......
...@@ -280,7 +280,7 @@ ...@@ -280,7 +280,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1000.9503.46381.7543</string> </value> <value> <string>1000.9806.10724.60689</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -298,7 +298,7 @@ ...@@ -298,7 +298,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1652204027.96</float> <float>1652220502.37</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"description": "Extend simple parameter extension with extra only supported on json-in-xml",
"additionalProperties": false,
"allOf": [
{
"$ref": "instance-input-schema.json#/"
},
{
"properties": {
"simple-array-of-string": {
"title": "Example of Simple array of String",
"description": "Example of Array of String",
"type": "array",
"items": {"type": "string"}
},
"simple-array-of-integer": {
"title": "Example of Simple array of Integer",
"description": "Example of Array of Interger",
"type": "array",
"items": {"type": "integer"}
}
}
}
]
}
\ No newline at end of file
<?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-json-in-xml-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>
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
"software-type": { "software-type": {
"default": { "default": {
"title": "Default", "title": "Default",
"description": "Default", "description": "Default reference parameters",
"request": "instance-input-schema.json", "request": "instance-input-schema.json",
"response": "instance-output-schema.json", "response": "instance-output-schema.json",
"index": 0 "index": 0
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
"jsondefault": { "jsondefault": {
"title": "JSON in XML", "title": "JSON in XML",
"serialisation": "json-in-xml", "serialisation": "json-in-xml",
"description": "Default", "description": "Default reference parameters under json-in-xml",
"request": "instance-input-schema.json", "request": "instance-input-json-in-xml-schema.json",
"response": "instance-output-schema.json", "response": "instance-output-schema.json",
"index": 1 "index": 1
} }
......
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