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

WIP

parent 7885b2ba
......@@ -42,17 +42,13 @@
});
return promise.then(function (meta_schema) {
/* Do one actuall validation here is missing */
console.log(tv4.validate(json, meta_schema));
return json;
}, function (error) {
throw error});
};
var validateJSON = function(json, generated_json) {
console.log(tv4.validate(generated_json, json));
return generated_json;
};
gk.declareMethod("loadJSONSchema", function(url) {
return getJSON(url).then(function(json) {
return validateJSONSchema(json);
......@@ -62,7 +58,7 @@
.declareMethod("validateJSON", function(schema_url, generated_json) {
return getJSON(schema_url).then(function(json) {
return validateJSON(json, generated_json);
return tv4.validateMultiple(generated_json, json);
}, function(error) {
throw error});
});
......
......@@ -4,12 +4,15 @@
"user-authorized-key": {
"title": "User Authorized Key",
"description": "SSH public key in order to connect to the SSH server of this runner instance.",
"type": "string"
"type": "string",
"require": true
},
"instance-amount": {
"title": "Partition Amount",
"description": "Number of slappart to deploy inside the runner (default is 10). Needs instance to be restarted.",
"type": "integer",
"minimum": 1,
"maximum": 40,
"optional": true
},
"slapos-software": {
......@@ -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)",
"type": "string",
"format": "uri",
"pattern": "^(http|https|ftp)://",
"optional": true
},
"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 @@
</head>
<body>
<div>
<div class="load-schema"
data-gadget-url="../slapos_load_schema/index.html"
data-gadget-scope="load-schemaparameter" >
</div>
<fieldset id="top">
<label>Software Release URL</label>
<div class="software_release_url"></div>
......
......@@ -59,6 +59,12 @@
if (options.software_release_url === undefined) {
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;
return g.declareGadget(gadget_path_list.connection, {})
......@@ -84,6 +90,9 @@
input.setAttribute("class", "slapos-parameter");
div_input.appendChild(input);
var span_error = document.createElement("span");
span_error.setAttribute("class", "error");
div_input.appendChild(span_error);
div.appendChild(div_input);
if (json.properties[key].optional === true) {
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 @@
throw "undefined software_release_url";
}
var g = this;
var gadget = g.declareGadget(gadget_path_list.parameter, {
software_release_url: options.software_instance_url,
json_url: json_url
})
var gadget = this.getDeclaredGadget('parameter')
.push(function(gadget) {
options[json_url] = json_url;
options[software_type_json_url] = software_type_json_url;
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;
$(this.__element).find(".update-button").click(function(e) {
var json_dict = {};
var input_list = document.getElementsByClassName("slapos-parameter");
for (var key in input_list) {
if (input_list[key].value !== "") {
json_dict[input_list[key].name] = input_list[key].value;
$(".slapos-parameter").each(function(key, input) {
if (input.value !== "") {
if (input.type === 'number') {
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);
} 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