Commit abdd8a67 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_jio: Fix boolean and values outsite enum for parameter editor

   Boolean should be handled as boolean not as strings.
   Selection should include default value even if they are outside the enum list.
parent 8477ed06
...@@ -46,26 +46,40 @@ ...@@ -46,26 +46,40 @@
selected: (default_value === undefined) selected: (default_value === undefined)
})], })],
option_index, option_index,
selected,
is_selected = (default_value === undefined),
data_format = "string"; data_format = "string";
if (json_field.type === "integer" || json_field.type === "number") { if (json_field.type === "integer" || json_field.type === "number") {
data_format = "number"; data_format = "number";
} else if (json_field.type === "boolean") {
data_format = "boolean";
} }
if (default_value === undefined) { if (default_value === undefined) {
default_value = "" default_value = "";
} }
for (option_index in json_field['enum']) { for (option_index in json_field['enum']) {
if (json_field['enum'].hasOwnProperty(option_index)) { 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', { option_list.push(domsugar('option', {
value: json_field['enum'][option_index], value: json_field['enum'][option_index],
text: json_field['enum'][option_index], text: json_field['enum'][option_index],
"data-format": data_format, "data-format": data_format,
selected: ( selected: true
json_field['enum'][option_index].toString() === default_value.toString()
)
})); }));
} }
} }
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', { return domsugar('select', {
size: 1, size: 1,
"data-format": data_format "data-format": data_format
...@@ -344,20 +358,16 @@ ...@@ -344,20 +358,16 @@
entry_list, 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; var index_e, data_format = input.getAttribute("data-format");
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);
} 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") { } else if (input.tagName === "TEXTAREA") {
if (input.getAttribute("data-format") === "string") { if (data_format === "string") {
json_dict[input.name] = input.value; 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'); 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] = []; json_dict[input.name] = [];
entry_list = input.value.split("\n"); entry_list = input.value.split("\n");
for (index_e in entry_list) { for (index_e in entry_list) {
...@@ -373,12 +383,20 @@ ...@@ -373,12 +383,20 @@
json_dict[input.name] = input.value.split('\n'); json_dict[input.name] = input.value.split('\n');
} }
} else if (input.tagName === "SELECT") { } else if (input.tagName === "SELECT") {
if (input.getAttribute("data-format") === "number") { if (data_format === "number" || data_format === "integer") {
json_dict[input.name] = parseFloat(input.value); // Integer must use parseFloat, otherwise the value is rounded
} else if (input.getAttribute("data-format") === "integer") { // loosing user's input.
// Don't use parseInt since it will round the value, modifing the if (isNaN(parseFloat(input.value))) {
// use input. So we keep it the value. json_dict[input.name] = input.value;
json_dict[input.name] = parseFloat(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 { } else {
json_dict[input.name] = input.value; json_dict[input.name] = input.value;
} }
......
...@@ -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.13719.19212.614</string> </value> <value> <string>1000.14042.12571.63982</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>1652455568.82</float> <float>1652712920.56</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
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