Commit 059cfb4f authored by Rafael Monnerat's avatar Rafael Monnerat

WIP

parent 7885b2ba
...@@ -42,17 +42,13 @@ ...@@ -42,17 +42,13 @@
}); });
return promise.then(function (meta_schema) { return promise.then(function (meta_schema) {
/* Do one actuall validation here is missing */
console.log(tv4.validate(json, meta_schema)); console.log(tv4.validate(json, meta_schema));
return json; return json;
}, function (error) { }, function (error) {
throw error}); throw error});
}; };
var validateJSON = function(json, generated_json) {
console.log(tv4.validate(generated_json, json));
return generated_json;
};
gk.declareMethod("loadJSONSchema", function(url) { gk.declareMethod("loadJSONSchema", function(url) {
return getJSON(url).then(function(json) { return getJSON(url).then(function(json) {
return validateJSONSchema(json); return validateJSONSchema(json);
...@@ -62,7 +58,7 @@ ...@@ -62,7 +58,7 @@
.declareMethod("validateJSON", function(schema_url, generated_json) { .declareMethod("validateJSON", function(schema_url, generated_json) {
return getJSON(schema_url).then(function(json) { return getJSON(schema_url).then(function(json) {
return validateJSON(json, generated_json); return tv4.validateMultiple(generated_json, json);
}, function(error) { }, function(error) {
throw error}); throw error});
}); });
......
...@@ -4,12 +4,15 @@ ...@@ -4,12 +4,15 @@
"user-authorized-key": { "user-authorized-key": {
"title": "User Authorized Key", "title": "User Authorized Key",
"description": "SSH public key in order to connect to the SSH server of this runner instance.", "description": "SSH public key in order to connect to the SSH server of this runner instance.",
"type": "string" "type": "string",
"require": true
}, },
"instance-amount": { "instance-amount": {
"title": "Partition Amount", "title": "Partition Amount",
"description": "Number of slappart to deploy inside the runner (default is 10). Needs instance to be restarted.", "description": "Number of slappart to deploy inside the runner (default is 10). Needs instance to be restarted.",
"type": "integer", "type": "integer",
"minimum": 1,
"maximum": 40,
"optional": true "optional": true
}, },
"slapos-software": { "slapos-software": {
...@@ -29,6 +32,7 @@ ...@@ -29,6 +32,7 @@
"description": "url of the default git repository that will be download by the runner while its instanciation. Will be cloned in a directory named 'slapos' (default is http://git.erp5.org/repos/slapos.git)", "description": "url of the default git repository that will be download by the runner while its instanciation. Will be cloned in a directory named 'slapos' (default is http://git.erp5.org/repos/slapos.git)",
"type": "string", "type": "string",
"format": "uri", "format": "uri",
"pattern": "^(http|https|ftp)://",
"optional": true "optional": true
}, },
"slapos-reference": { "slapos-reference": {
......
{
"$schema": "http://json-schema.org/draft-04/schema#",
"properties": {
"software-type": {
"title": "Software Type",
"description": "Instance Software Type",
"type": "string",
"enum": ["default", "resilient"]
}
},
"required": ["software-type"]
}
\ No newline at end of file
...@@ -11,6 +11,10 @@ ...@@ -11,6 +11,10 @@
</head> </head>
<body> <body>
<div> <div>
<div class="load-schema"
data-gadget-url="../slapos_load_schema/index.html"
data-gadget-scope="load-schemaparameter" >
</div>
<fieldset id="top"> <fieldset id="top">
<label>Software Release URL</label> <label>Software Release URL</label>
<div class="software_release_url"></div> <div class="software_release_url"></div>
......
...@@ -59,6 +59,12 @@ ...@@ -59,6 +59,12 @@
if (options.software_release_url === undefined) { if (options.software_release_url === undefined) {
throw "undefined software_release_url"; throw "undefined software_release_url";
} }
if (options.json_url === undefined) {
throw "undefined software_release_url";
}
if (options.software_release_json_url === undefined) {
throw "undefined software_release_url";
}
var g = this; var g = this;
return g.declareGadget(gadget_path_list.connection, {}) return g.declareGadget(gadget_path_list.connection, {})
...@@ -84,6 +90,9 @@ ...@@ -84,6 +90,9 @@
input.setAttribute("class", "slapos-parameter"); input.setAttribute("class", "slapos-parameter");
div_input.appendChild(input); div_input.appendChild(input);
var span_error = document.createElement("span");
span_error.setAttribute("class", "error");
div_input.appendChild(span_error);
div.appendChild(div_input); div.appendChild(div_input);
if (json.properties[key].optional === true) { if (json.properties[key].optional === true) {
fieldset_optional.appendChild(div); fieldset_optional.appendChild(div);
......
.error-input {
border:1px red solid;
}
.error-input span {
color: red;
}
\ No newline at end of file
...@@ -15,31 +15,67 @@ ...@@ -15,31 +15,67 @@
throw "undefined software_release_url"; throw "undefined software_release_url";
} }
var g = this; var g = this;
var gadget = g.declareGadget(gadget_path_list.parameter, { var gadget = this.getDeclaredGadget('parameter')
software_release_url: options.software_instance_url,
json_url: json_url
})
.push(function(gadget) { .push(function(gadget) {
options[json_url] = json_url;
options[software_type_json_url] = software_type_json_url;
return gadget.render(options); return gadget.render(options);
}); });
var connection_gadget = g.declareGadget(gadget_path_list.connection, {}) var gadget_promise = g.declareGadget(gadget_path_list.connection, {});
g.__element.querySelector("div.software_release_url").innerHTML = options.software_release_url; g.__element.querySelector("div.software_release_url").innerHTML = options.software_release_url;
$(this.__element).find(".update-button").click(function(e) { $(this.__element).find(".update-button").click(function(e) {
var json_dict = {}; var json_dict = {};
var input_list = document.getElementsByClassName("slapos-parameter"); $(".slapos-parameter").each(function(key, input) {
for (var key in input_list) { if (input.value !== "") {
if (input_list[key].value !== "") { if (input.type === 'number') {
json_dict[input_list[key].name] = input_list[key].value; json_dict[input.name] = parseInt(input.value);
} else if (input.value === "true") {
json_dict[input.name] = true;
} else if (input.value === "false") {
json_dict[input.name] = false;
} else {
json_dict[input.name] = input.value;
} }
} }
});
$("span.error").each(function(i, span) {
span.textContent = "";
});
$("div.error-input").each(function(i, div) {
div.setAttribute("class", "");
});
json = connection_gadget.validateJSON(json_url, json_dict);
gadget_promise.then(function(gadget) {
return gadget.validateJSON(json_url, json_dict)
.push(function(validation) {
if (validation.valid) {
$('div.debug')[0].innerHTML = JSON.stringify(json_dict); $('div.debug')[0].innerHTML = JSON.stringify(json_dict);
} else {
for (var error_index in validation.errors) {
var field_name = validation.errors[error_index].dataPath.slice(1);
var div = $('.slapos-parameter[name=' + field_name + "]")[0].parentNode;
div.setAttribute("class", "slapos-parameter error-input");
div.querySelector("span.error").textContent = validation.errors[error_index].message;
}
for (var missing_index in validation.missing) {
var missing_field_name = validation.missing[missing_index].dataPath.slice(1);
var divm = $('.slapos-parameter[name=' + missing_field_name + "]")[0].parentNode;
divm.setAttribute("class", "error-input");
divm.querySelector("span.error").textContent = validation.errors[missing_index].message;
}
}
});
});
}); });
}); });
......
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