Commit 0ab7b995 authored by Romain Courteaud's avatar Romain Courteaud

WIP rewrite of Rafael work

parent 553c22c9
<html>
<head>
<title>Simple Text Editor Gadget</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="../lib/rsvp.min.js" type="text/javascript"></script>
<script src="../lib/renderjs.min.js" type="text/javascript"></script>
<script src="../lib/jquery.js"></script>
<script src="../<%= copy.uritemplate.relative_dest %>" type="text/javascript"></script>
<script src="../<%= copy.uri.relative_dest %>" type="text/javascript"></script>
<script src="../<%= concat.jio.relative_dest %>" type="text/javascript"></script>
<script src="../lib/tv4.min.js"></script>
<script src="load_schema.js" type="text/javascript"></script>
<link rel="http://www.renderjs.org/rel/interface"
href="http://www.renderjs.org/interface/editor"/>
</head>
<body>
<div id="editor"></div>
</body>
</html>
/*jslint nomen: true, maxlen: 200*/
/*global window, rJS, RSVP, console, jQuery, jIO, tv4, JSON */
(function (window, rJS, RSVP) {
"use strict";
var gk = rJS(window);
function getJSON(url) {
return jIO.util.ajax({
url: url
})
.then(function (evt) {
return evt.target.responseText;
});
}
function getMetaJSONSchema() {
return getJSON("../slapos_load_schema/meta.json");
}
function validateJSONSchema(json) {
return getMetaJSONSchema()
.then(function (meta_schema) {
if (!tv4.validate(json, meta_schema)) {
throw new Error("Non valid JSON schema " + json);
}
return JSON.parse(json);
});
}
gk
.declareMethod("loadJSONSchema", function (url) {
return getJSON(url)
.then(function (json) {
return validateJSONSchema(json);
});
})
.declareMethod("validateJSON", function (schema_url, generated_json) {
return getJSON(schema_url)
.then(function (json) {
return tv4.validateMultiple(generated_json, json);
});
});
}(window, rJS, RSVP, jQuery));
{
"id": "http://json-schema.org/draft-04/schema#",
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Core schema meta-schema",
"definitions": {
"schemaArray": {
"type": "array",
"minItems": 1,
"items": { "$ref": "#" }
},
"positiveInteger": {
"type": "integer",
"minimum": 0
},
"positiveIntegerDefault0": {
"allOf": [ { "$ref": "#/definitions/positiveInteger" }, { "default": 0 } ]
},
"simpleTypes": {
"enum": [ "array", "boolean", "integer", "null", "number", "object", "string" ]
},
"stringArray": {
"type": "array",
"items": { "type": "string" },
"minItems": 1,
"uniqueItems": true
}
},
"type": "object",
"properties": {
"id": {
"type": "string",
"format": "uri"
},
"$schema": {
"type": "string",
"format": "uri"
},
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"default": {},
"multipleOf": {
"type": "number",
"minimum": 0,
"exclusiveMinimum": true
},
"maximum": {
"type": "number"
},
"exclusiveMaximum": {
"type": "boolean",
"default": false
},
"minimum": {
"type": "number"
},
"exclusiveMinimum": {
"type": "boolean",
"default": false
},
"maxLength": { "$ref": "#/definitions/positiveInteger" },
"minLength": { "$ref": "#/definitions/positiveIntegerDefault0" },
"pattern": {
"type": "string",
"format": "regex"
},
"additionalItems": {
"anyOf": [
{ "type": "boolean" },
{ "$ref": "#" }
],
"default": {}
},
"items": {
"anyOf": [
{ "$ref": "#" },
{ "$ref": "#/definitions/schemaArray" }
],
"default": {}
},
"maxItems": { "$ref": "#/definitions/positiveInteger" },
"minItems": { "$ref": "#/definitions/positiveIntegerDefault0" },
"uniqueItems": {
"type": "boolean",
"default": false
},
"maxProperties": { "$ref": "#/definitions/positiveInteger" },
"minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
"required": { "$ref": "#/definitions/stringArray" },
"additionalProperties": {
"anyOf": [
{ "type": "boolean" },
{ "$ref": "#" }
],
"default": {}
},
"definitions": {
"type": "object",
"additionalProperties": { "$ref": "#" },
"default": {}
},
"properties": {
"type": "object",
"additionalProperties": { "$ref": "#" },
"default": {}
},
"patternProperties": {
"type": "object",
"additionalProperties": { "$ref": "#" },
"default": {}
},
"dependencies": {
"type": "object",
"additionalProperties": {
"anyOf": [
{ "$ref": "#" },
{ "$ref": "#/definitions/stringArray" }
]
}
},
"enum": {
"type": "array",
"minItems": 1,
"uniqueItems": true
},
"type": {
"anyOf": [
{ "$ref": "#/definitions/simpleTypes" },
{
"type": "array",
"items": { "$ref": "#/definitions/simpleTypes" },
"minItems": 1,
"uniqueItems": true
}
]
},
"allOf": { "$ref": "#/definitions/schemaArray" },
"anyOf": { "$ref": "#/definitions/schemaArray" },
"oneOf": { "$ref": "#/definitions/schemaArray" },
"not": { "$ref": "#" }
},
"dependencies": {
"exclusiveMaximum": [ "maximum" ],
"exclusiveMinimum": [ "minimum" ]
},
"default": {}
}
{
"$schema": "http://json-schema.org/draft-04/schema#",
"properties": {
"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",
"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": {
"title": "Pre-selected Software Release",
"description": "a relative path from the slapos git repo to a folder containing a software release, which will be automaticaly deployed while the runner instanciation, and only if the parameter auto-deploy is set to 'true'. For example: 'software/helloworld",
"type": "string",
"optional": true
},
"auto-deploy": {
"title": "Automatically Deploy Software",
"description": "Authorizes the software declared with 'slapos-software' to be automatically deployed, or not. Needs instance to be restarted. (default is false)",
"type": "boolean",
"optional": true
},
"slapos-repository": {
"title": "SlapOS Git Repository URL",
"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": {
"title": "SlapOS Git Branch Name",
"description": "Branch or hash on which the default repository will checkout (default is master)",
"type": "string",
"optional": true
},
"auto-deploy-instance": {
"title": "Automatically Deploy Instances",
"description": "Prevent the runner from deploying and starting instances. Needs instance to be restarted. It is set to false for instances of type 'import' in resiliency in any case (default is false)",
"type": "boolean",
"optional": true
},
"autorun": {
"title": "Automatically Run Sofware/Instance",
"description": "Let automaticaly build and run a declared software with 'slapos-software'. Only works if 'slapos-software' is set, and 'auto-deploy' is true. Needs instance to be restarted. (default is false)",
"type": "boolean",
"optional": true
},
"slapos-software-type": {
"title": "Deployed Instance Software Type" ,
"description": "Software type of your instance inside the runner",
"type": "string",
"optional": true
},
"parameter-*": {
"title": "Parameter-* This I dont know",
"description": "'*' is a parameter which will be used to configure the instance inside the runner.",
"type": "string",
"optional": true
},
"custom-frontend-backend-url": {
"title": "Custom Frontend Backend URL",
"description": "return an ipv4 frontend of the given ipv6(+optional port)",
"type": "string",
"format": "uri",
"optional": true
},
"custom-frontend-backend-type": {
"title": "Custom Frontend Backend Type",
"description": "The type of the frontend slave instance to ask",
"type": "string",
"enum": ["zope"],
"optional": true
},
"custom-frontend-basic-auth": {
"title": "Custom Frontend Basic Auth",
"description": "if the ip given with 'custom-frontend-backend-url' is secure, set it to true for the promise do not fail",
"type": "boolean",
"optional": true
},
"custom-frontend-instance-guid": {
"title": "Custom Frontend Instance GUID",
"description": "Instance guid of the frontend you whish to use",
"type": "string",
"optional": true
},
"custom-frontend-software-type": {
"title": "Custom Frontend Software Type",
"description": "SoftwareType of the frontend you request (default is RootSoftwareInstance)",
"type": "string",
"enum": ["RootSoftwareInstance", "default"],
"optional": true
},
"custom-frontend-software-url": {
"title": "Custom Frontend Software URL",
"description": "Software Url of the frontend you request (ie.: http://git.erp5.org/gitweb/slapos.git/blob_plain/HEAD:/software/apache-frontend/software.cfg)",
"type": "string",
"format": "uri",
"optional": true
},
"monitor-port": {
"title": "Monitor Port",
"description": "Allow to manually change the port on wich the apache server running monitoring interface is listening. The default value for the webrunner is different from the default value of the standalone stack-monitor server (default 9684)",
"type": "integer",
"minimum": 9683,
"exclusiveMinimum": true,
"optional": true
},
"resilient-clone-number": {
"title": "Number of Resilient Clones",
"description": "Number of clones to be deployed when a resilient runner, if missing a single clone is provided. Its value can be 1 or 2",
"type": "integer",
"enum": [1, 2],
"optional": true
}
}
}
{
"$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
<html>
<head>
<title>Simple Text Editor Gadget</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="../lib/rsvp.min.js" type="text/javascript"></script>
<script src="../lib/renderjs.min.js" type="text/javascript"></script>
<script src="parameter_editor.js" type="text/javascript"></script>
<link rel="stylesheet" href="./slapos_parameter.css" media="screen" ></link>
<link rel="http://www.renderjs.org/rel/interface"
href="http://www.renderjs.org/interface/editor"/>
</head>
<body>
<div>
<fieldset id="top">
<label>Software Release URL</label>
<div class="software_release_url"></div>
</fieldset>
<fieldset id="main"> </fieldset>
<fieldset id="optional"> </fieldset>
</div>
</body>
</html>
/*jslint nomen: true, maxlen: 200*/
/*global rJS, console */
(function (window, document, rJS) {
"use strict";
var gk = rJS(window);
// var gadget_path_list = {
// connection: "../slapos_load_schema/index.html"
// };
function render_selection(json_field) {
var input = document.createElement("select"),
option = document.createElement("option"),
option_index,
optionz;
input.size = 1;
option.selected = "selected";
option.value = "";
input.appendChild(option);
for (option_index in json_field.enum) {
if (json_field.enum.hasOwnProperty(option_index)) {
optionz = document.createElement("option");
optionz.value = json_field.enum[option_index];
optionz.textContent = json_field.enum[option_index];
input.appendChild(optionz);
}
}
return input;
}
function render_field(json_field) {
if (json_field.enum !== undefined) {
return render_selection(json_field);
}
if (json_field.type === "boolean") {
json_field.enum = [true, false];
return render_selection(json_field);
}
var input = document.createElement("input");
if (json_field.default !== undefined) {
input.value = json_field.default;
}
switch (json_field.type) {
case "integer":
input.type = "number";
break;
default:
input.type = "text";
}
return input;
}
gk
.ready(function (g) {
g.props = {};
return g.getElement()
.push(function (element) {
g.props.element = element;
});
})
.declareAcquiredMethod("aq_loadJSONSchema", "loadJSONSchema")
// gk.declareMethod("getJSON", function() {
// for (var key in document.getElementByTagName("input")) {
// console.log(input.value);
// }
// })
.declareMethod('render', function (options) {
if (options.software_release_url === undefined) {
throw new Error("undefined software_release_url");
}
if (options.json_url === undefined) {
throw new Error("undefined json_url");
}
var g = this,
json_url = options.json_url;
return g.aq_loadJSONSchema(json_url)
.push(function (json) {
var fieldset_list = g.props.element.querySelectorAll('fieldset'),
key,
div,
label,
input,
div_input,
span_error,
fieldset = fieldset_list[1],
fieldset_optional = fieldset_list[2];
for (key in json.properties) {
if (json.properties.hasOwnProperty(key)) {
div = document.createElement("div");
div.setAttribute("class", "field");
div.title = json.properties[key].description;
/* console.log(key); */
label = document.createElement("label");
label.textContent = json.properties[key].title;
div.appendChild(label);
div_input = document.createElement("div");
div.setAttribute("class", "input");
input = render_field(json.properties[key]);
input.name = key;
input.setAttribute("class", "slapos-parameter");
div_input.appendChild(input);
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);
} else {
fieldset.appendChild(div);
}
}
}
});
});
}(window, document, rJS));
{
"$schema": "http://json-schema.org/draft-04/schema#",
"properties": {
"user-authorized-key": {
"description" : "SSH public key in order to connect to the SSH server of this runner instance",
"type": "string"
},
"instance-amount": {
"description": "number of slappart to deploy inside the runner. Needs instance to be restarted.",
"type": "integer",
"default": 10
},
"slapos-software": {
"description": "a relative path from the slapos git repo to a folder containing a software release, which will be automaticaly deployed while the runner instanciation, and only if the parameter auto-deploy is set to 'true'. For example: 'software/helloworld",
"type": "string"
},
"auto-deploy": { "description": "authorizes the software declared with 'slapos-software' to be automatically deployed, or not. Needs instance to be restarted.",
"type": "boolean",
"default": "false"
},
"slapos-repository": {
"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'",
"type": "string",
"default": "http://git.erp5.org/repos/slapos.git"
},
"slapos-reference": {
"description": "commit reference on which the default repository will checkout",
"type": "string",
"default": "master"
},
"auto-deploy-instance": {
"description": "prevent the runner from deploying and starting instances. Needs instance to be restarted.",
"type": "boolean",
"default": "true, but is set to false for instances of type 'import' in resiliency"
},
"autorun": {
"description": "let automaticaly build and run a declared software with 'slapos-software'. Only works if 'slapos-software' is set, and 'auto-deploy' is true. Needs instance to be restarted.",
"type": "boolean",
"default": "false"
},
"slapos-software-type": {
"description": "Software type of your instance inside the runner",
"type": "string"
},
"parameter-*": {
"description": "'*' is a parameter which will be used to configure the instance inside the runner.",
"type": "string"
},
"custom-frontend-backend-url": {
"description": "return an ipv4 frontend of the given ipv6(+optional port)",
"type": "string"
},
"custom-frontend-backend-type": {
"description": "The type of the frontend slave instance to ask",
"type": "string"
},
"custom-frontend-basic-auth": {
"description": "if the ip given with 'custom-frontend-backend-url' is secure, set it to true for the promise do not fail",
"type": "boolean",
"default": "false"
},
"custom-frontend-instance-guid": {
"description": "Instance guid of the frontend you whish to use",
"type": "string",
"default": "none"
},
"custom-frontend-software-type": {
"description": "SoftwareType of the frontend you request",
"default": "RootSoftwareInstance",
"type": "string"
},
"custom-frontend-software-url": {
"description": "Software Url of the frontend you request",
"default": "http://git.erp5.org/gitweb/slapos.git/blob_plain/HEAD:/software/apache-frontend/software.cfg"
"type": "string"
},
"monitor-port": {
"description": "allow to manually change the port on wich the apache server running monitoring interface is listening. The default value for the webrunner is different from the default value of the standalone stack-monitor server",
"type": "integer",
"default": 9684
}
"resilient-clone-number": {
"description": "is the number of clones to be deployed when a resilient runner is ordered. Its value can be 1 or 2",
"type": "integer",
"default" : 1
}
}
}
label {
float: left;
width: 300px;
}
<html>
<head>
<title>SlapOS request Gadget</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="../<%= copy.rsvp.relative_dest %>" type="text/javascript"></script>
<script src="../<%= copy.renderjs.relative_dest %>" type="text/javascript"></script>
<script src="../<%= curl.jquery.relative_dest %>" type="text/javascript"></script>
<script src="slapos_request.js" type="text/javascript"></script>
<link rel="stylesheet" href="./slapos_request.css" media="screen" ></link>
<link rel="http://www.renderjs.org/rel/interface"
href="http://www.renderjs.org/interface/editor"/>
</head>
<body>
Couscous
<div>
<div class="software-type"
data-gadget-url="../slapos_parameter/index.html"
data-gadget-scope="software-type" >
</div>
<div class="parameter"
data-gadget-url="../slapos_parameter/index.html"
data-gadget-scope="parameter" >
</div>
<button class="update-button" > Update </button>
<div class="debug"> </div>
<div
data-gadget-url="../slapos_load_schema/index.html"
data-gadget-scope="loadschema" >
</div>
</div>
</body>
</html>
.error-input {
border:1px red solid;
}
.error-input span {
color: red;
}
\ No newline at end of file
/*jslint nomen: true, maxlen: 200*/
/*global rJS, console, jQuery, RSVP */
(function (window, document, $, rJS) {
"use strict";
var gk = rJS(window),
json_url = "../slapos_load_schema/schema.json";
// gadget_path_list = {
// connection: "../slapos_load_schema/index.html"
// };
// Temporary hack to make it works
gk.ready(function (gadget) {
console.log("before couscous");
return gadget.render({software_release_url: "couscous"})
.push(function (result) {
console.log(result);
})
.push(undefined, function (error) {
console.error(error.stack);
console.error(error);
});
});
gk.allowPublicAcquisition("loadJSONSchema", function (param_list) {
return this.getDeclaredGadget('loadschema')
.push(function (gadget) {
return gadget.loadJSONSchema.apply(gadget, param_list);
});
});
gk.declareMethod('render', function (options) {
if (options.software_release_url === undefined) {
throw new Error("undefined software_release_url");
}
var g = this;
return g.getDeclaredGadget('software-type')
.push(function (gadget) {
options.json_url = "../slapos_load_schema/software_type.json";
return gadget.render(options);
})
.push(function () {
return g.getDeclaredGadget('parameter');
})
.push(function (gadget) {
options.json_url = json_url;
return gadget.render(options);
})
// XXX Custom code for great students
.push(function () {
return g.getDeclaredGadget('loadschema');
})
.push(function (gadget) {
return gadget.validateJSON(json_url, {});
});
//
//
//
//
// 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 = {};
// $(".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", "");
// });
//
//
// 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;
// }
//
//
// }
// });
// });
//
// });
});
}(window, document, jQuery, rJS));
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