Commit c113c5ef authored by Rafael Monnerat's avatar Rafael Monnerat

Support schemas more accurately based on serialisation

See merge request nexedi/slapos.core!375
parents 2d374bc9 e837fd71
......@@ -196,7 +196,7 @@ url_list = [
"gadget_slapos_network_status.js",
"gadget_slapos_panel.html",
"gadget_slapos_panel.js",
"gadget_slapos_panel.png?format=",
"gadget_slapos_panel.png?format=png",
"gadget_slapos_invoice_logo.png?format=",
"gadget_slapos_payment_result.js",
"gadget_slapos_project_status.html",
......@@ -210,6 +210,11 @@ url_list = [
"leaflet.js",
"tv4.min.js",
"vkbeautify.js",
"jquery.js",
"URI.js",
"slapos_load_software_schema.json",
"slapos_load_meta_schema_xml.json",
"slapos_load_meta_schema_json_in_xml.json",
"gadget_erp5_page_slap_language_view.js",
"gadget_erp5_page_slap_language_view.html"
]
......
/*jslint nomen: true, maxlen: 200, indent: 2*/
/*global window, rJS, console, RSVP, jQuery, jIO, tv4, URI, JSON, $, btoa */
(function (window, rJS, $, RSVP, btoa) {
(function (window, rJS, $, RSVP, btoa, URI, tv4) {
"use strict";
var gk = rJS(window);
......@@ -57,12 +57,12 @@
}
if (ref.substr(0, 1) === "#") {
return RSVP.Queue().push(function () {
return new RSVP.Queue().push(function () {
return resolveLocalReference(ref, schema);
});
}
return RSVP.Queue().push(function () {
return new RSVP.Queue().push(function () {
if (URI(ref).protocol() === "") {
if (base_url !== undefined) {
ref = base_url + "/" + ref;
......@@ -91,7 +91,7 @@
expanded_json_schema.properties = {};
}
return RSVP.Queue().push(function () {
return new RSVP.Queue().push(function () {
if (json_schema.$ref) {
return resolveReference(
json_schema,
......@@ -113,7 +113,7 @@
return true;
}).push(function () {
var property, queue = RSVP.Queue();
var property, queue = new RSVP.Queue();
function wrapperResolveReference(p) {
return resolveReference(
......@@ -149,7 +149,7 @@
})
.push(function () {
var zqueue = RSVP.Queue();
var zqueue = new RSVP.Queue();
function wrapperExpandSchema(p) {
return expandSchema(
......@@ -187,12 +187,18 @@
});
}
function getMetaJSONSchema() {
function getMetaJSONSchema(serialisation) {
if (serialisation === "xml") {
return getJSON("slapos_load_meta_schema_xml.json");
}
if (serialisation === "json-in-xml") {
return getJSON("slapos_load_meta_schema_json_in_xml.json");
}
return getJSON("slapos_load_meta_schema.json");
}
function validateJSONSchema(json, base_url) {
return getMetaJSONSchema()
function validateJSONSchema(json, base_url, serialisation) {
return getMetaJSONSchema(serialisation)
.push(function (meta_schema) {
if (!tv4.validate(json, meta_schema)) {
throw new Error("Non valid JSON schema " + json);
......@@ -204,8 +210,17 @@
});
}
gk
function validateSoftwareJSONSchema(json) {
return getJSON("slapos_load_software_schema.json")
.push(function (schema) {
if (!tv4.validate(json, schema)) {
throw new Error("Non valid JSON for software.cfg.json:" + json);
}
return JSON.parse(json);
});
}
gk
.declareMethod("getBaseUrl", function (url) {
var base_url, url_uri = URI(url);
base_url = url_uri.path().split("/");
......@@ -213,13 +228,13 @@
base_url = url.split(url_uri.path())[0] + base_url.join("/");
return base_url;
})
.declareMethod("loadJSONSchema", function (url) {
.declareMethod("loadJSONSchema", function (url, serialisation) {
var gadget = this;
return getJSON(url)
.push(function (json) {
return gadget.getBaseUrl(url)
.push(function (base_url) {
return validateJSONSchema(json, base_url);
return validateJSONSchema(json, base_url, serialisation);
});
});
})
......@@ -227,7 +242,7 @@
.declareMethod("loadSoftwareJSON", function (url) {
return getJSON(url)
.push(function (json) {
return JSON.parse(json);
return validateSoftwareJSONSchema(json);
});
})
......@@ -249,4 +264,4 @@
});
});
});
}(window, rJS, $, RSVP, btoa));
}(window, rJS, $, RSVP, btoa, URI, tv4));
......@@ -553,10 +553,10 @@
return "";
}
gk.declareMethod("loadJSONSchema", function (url) {
gk.declareMethod("loadJSONSchema", function (url, serialisation) {
return this.getDeclaredGadget('loadschema')
.push(function (gadget) {
return gadget.loadJSONSchema(url);
return gadget.loadJSONSchema(url, serialisation);
});
})
......@@ -648,10 +648,10 @@
});
})
.declareMethod('renderParameterForm', function (json_url, default_dict, restricted_parameter) {
.declareMethod('renderParameterForm', function (json_url, default_dict, restricted_parameter, serialisation) {
var g = this;
return g.loadJSONSchema(json_url)
return g.loadJSONSchema(json_url, serialisation)
.push(function (json) {
var fieldset_list = g.element.querySelectorAll('fieldset'),
fieldset = document.createElement("fieldset");
......@@ -944,7 +944,8 @@
parameter_json_schema_url = prefix + "/" + parameter_json_schema_url;
}
return gadget.renderParameterForm(parameter_json_schema_url,
parameter_dict, restricted_parameter);
parameter_dict, restricted_parameter,
options.serialisation);
})
.push(function () {
var i, div_list = gadget.element.querySelectorAll('.slapos-parameter-dict-key > div'),
......
......@@ -280,7 +280,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>999.21924.60509.42444</string> </value>
<value> <string>999.23324.48841.24558</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -298,7 +298,7 @@
</tuple>
<state>
<tuple>
<float>1649185724.55</float>
<float>1649686520.32</float>
<string>UTC</string>
</tuple>
</state>
......
{
"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": {}
}
\ No newline at end of file
{
"id": "http://json-schema.org/draft-04/schema#",
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Meta-schema for XML serialisaton schemas",
"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
},
"customProperties": {
"definitions": {
"simpleTypes": {
"enum": [ "array", "boolean", "integer", "null", "number", "string" ]
}
},
"type": "object",
"properties": {
"default": {},
"multipleOf": {
"type": "number",
"minimum": 0,
"exclusiveMinimum": true
},
"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": {}
},
"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/customProperties/definitions/simpleTypes" },
{
"type": "array",
"items": { "$ref": "#/definitions/customProperties/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": {}
}
},
"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": "#/definitions/customProperties" },
"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": {}
}
\ No newline at end of file
{
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Slapos Software Release instantiation descriptor",
"additionalProperties": false,
"required": [
"software-type"
],
"properties": {
"name": {
"description": "A short human-friendly name for the sofware release",
"default": "",
"type": "string"
},
"description": {
"description": "A short description of the sofware release",
"default": "",
"type": "string"
},
"serialisation": {
"description": "How the parameters and results are serialised",
"enum": [
"xml",
"json-in-xml"
],
"type": "string"
},
"software-type": {
"description": "Existing software types",
"patternProperties": {
".*": {
"description": "Software type declaration",
"additionalProperties": false,
"required": [
"request",
"response"
],
"properties": {
"title": {
"description": "A human-friendly title of the software type",
"default": "",
"type": "string"
},
"description": {
"description": "A human-friendly description of the software type",
"default": "",
"type": "string"
},
"serialisation": {
"description": "How the parameters and results are serialised, if different from global setting, required if global setting is not provided",
"enum": [
"xml",
"json-in-xml"
],
"type": "string"
},
"request": {
"description": "URL, relative to Software Release base path, of a json schema for values expected by instance of current software type",
"type": "string"
},
"response": {
"description": "URL, relative to Software Release base path, of a json schema for values published by instance of current software type",
"type": "string"
},
"software-type": {
"description": "Value to be used as software type instead of the software type id (in order to use multiple diferent forms for the same software type).",
"type": "string"
},
"shared": {
"description": "Define if the request will request a Slave or Software Instance.",
"default": "false",
"type": "boolean"
},
"index": {
"description": "Value to use instead of software type id to sort them (in order to display most relevant software types earlier in a list, for example)",
"default": 0,
"type": "number"
}
},
"type": "object"
}
},
"type": "object"
}
},
"type": "object"
}
\ No newline at end of file
......@@ -209,6 +209,10 @@ web_page_module/rjs_gadget_trial_panel_js
web_page_module/rjs_gadget_slapos_utils_js
web_page_module/rjs_leaflet_css
web_page_module/rjs_leaflet_js
web_page_module/rjs_slapos_load_meta_schema_json
web_page_module/rjs_slapos_load_meta_schema_xml_in_json_json
web_page_module/rjs_slapos_load_meta_schema_xml_json
web_page_module/rjs_slapos_load_software_schema_json
web_page_module/rjs_tv4_min_js
web_page_module/rjs_vkbeautify_js
web_site_module/hostingjs
......
......@@ -211,6 +211,10 @@ web_page_module/rjs_gadget_trial_panel_html
web_page_module/rjs_gadget_trial_panel_js
web_page_module/rjs_leaflet_css
web_page_module/rjs_leaflet_js
web_page_module/rjs_slapos_load_meta_schema_json
web_page_module/rjs_slapos_load_meta_schema_xml_in_json_json
web_page_module/rjs_slapos_load_meta_schema_xml_json
web_page_module/rjs_slapos_load_software_schema_json
web_page_module/rjs_tv4_min_js
web_page_module/rjs_vkbeautify_js
web_site_module/hostingjs
......
<!DOCTYPE html>
<html manifest="gadget_erp5.appcache">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ERP5</title>
<link rel="shortcut icon" href="favicon.ico">
<script src="rsvp.js" type="text/javascript"></script>
<script src="../renderjs.js" type="text/javascript"></script>
<script src="URI.js" type="text/javascript"></script>
<script src="jquery.js" type="text/javascript"></script>
<script src="tv4.min.js" type="text/javascript"></script>
<script src="URI.js" type="text/javascript"></script>
<script src="jio.js" type="text/javascript"></script>
<script src="slapos_load_schema.js" type="text/javascript"></script>
</head>
<body>
<div />
</body>
</html>
\ No newline at end of file
/*jslint nomen: true, maxlen: 200, indent: 2*/
/*global window, rJS, console, RSVP, jQuery, jIO, tv4, URI, JSON, $ */
(function (window, rJS, $, RSVP) {
"use strict";
var gk = rJS(window);
function getJSON(url) {
var protocol = URI(url).protocol();
if ( protocol === "http" || protocol === "https" ) {
if (URI(window.location).protocol() !== protocol) {
throw new Error("You cannot mixed http and https calls");
}
}
return RSVP.Queue()
.push(function () {
return jIO.util.ajax({
url: url
})
.then(function (evt) {
return evt.target.responseText;
});
});
}
function resolveLocalReference(ref, schema) {
// 2 here is for #/
var i, ref_path = ref.substr(2, ref.length),
parts = ref_path.split("/");
if (parts.length === 1 && parts[0] === "") {
// It was uses #/ to reference the entire json so just return it.
return schema;
}
for (i = 0; i < parts.length; i += 1) {
schema = schema[parts[i]];
}
return schema;
}
function resolveReference(partial_schema, schema, base_url) {
var parts,
external_schema,
ref = partial_schema.$ref;
if (ref === undefined) {
return RSVP.Queue().push(function () {
return partial_schema;
});
}
if (ref.substr(0, 1) === "#") {
return RSVP.Queue().push(function () {
return resolveLocalReference(ref, schema);
});
}
return RSVP.Queue().push(function () {
if (URI(ref).protocol() === "") {
if (base_url !== undefined) {
ref = base_url + "/" + ref;
}
}
return getJSON(ref);
})
.push(function (json) {
external_schema = JSON.parse(json);
parts = ref.split("#");
ref = "#" + parts[1];
return resolveLocalReference(ref, external_schema);
});
}
function clone(obj) {
return JSON.parse(JSON.stringify(obj));
}
// Inspired from https://github.com/nexedi/dream/blob/master/dream/platform/src/jsplumb/jsplumb.js#L398
function expandSchema(json_schema, full_schema, base_url) {
var i,
expanded_json_schema = clone(json_schema) || {};
if (!expanded_json_schema.properties) {
expanded_json_schema.properties = {};
}
return RSVP.Queue().push(function () {
if (json_schema.$ref) {
return resolveReference(
json_schema,
full_schema,
base_url
)
.push(function (remote_schema) {
return expandSchema(
remote_schema,
full_schema,
base_url
);
}).push(function (referencedx) {
$.extend(expanded_json_schema, referencedx);
delete expanded_json_schema.$ref;
return true;
});
}
return true;
}).push(function () {
var property, queue = RSVP.Queue();
function wrapperResolveReference(p) {
return resolveReference(
json_schema.properties[p],
full_schema,
base_url
).push(function (external_schema) {
// console.log(p);
return expandSchema(
external_schema,
full_schema,
base_url
)
.push(function (referencedx) {
$.extend(expanded_json_schema.properties[p], referencedx);
if (json_schema.properties[p].$ref) {
delete expanded_json_schema.properties[p].$ref;
}
return referencedx;
});
});
}
// expand ref in properties
for (property in json_schema.properties) {
if (json_schema.properties.hasOwnProperty(property)) {
queue.push(
wrapperResolveReference.bind(this, property)
);
}
}
return queue;
})
.push(function () {
var zqueue = RSVP.Queue();
function wrapperExpandSchema(p) {
return expandSchema(
json_schema.allOf[p],
full_schema,
base_url
).push(function (referencedx) {
if (referencedx.properties) {
$.extend(
expanded_json_schema.properties,
referencedx.properties
);
delete referencedx.properties;
}
$.extend(expanded_json_schema, referencedx);
});
}
if (json_schema.allOf) {
for (i = 0; i < json_schema.allOf.length; i += 1) {
zqueue.push(wrapperExpandSchema.bind(this, i));
}
}
return zqueue;
})
.push(function () {
if (expanded_json_schema.allOf) {
delete expanded_json_schema.allOf;
}
if (expanded_json_schema.$ref) {
delete expanded_json_schema.$ref;
}
// console.log(expanded_json_schema);
return clone(expanded_json_schema);
});
}
function getMetaJSONSchema() {
return getJSON("../../renderjs/slapos_load_meta_schema.json");
}
function validateJSONSchema(json, base_url) {
return getMetaJSONSchema()
.push(function (meta_schema) {
if (!tv4.validate(json, meta_schema)) {
throw new Error("Non valid JSON schema " + json);
}
return JSON.parse(json);
})
.push(function (schema) {
return expandSchema(schema, schema, base_url);
});
}
gk
.declareMethod("loadJSONSchema", function (url) {
return getJSON(url)
.push(function (json) {
var base_url, url_uri;
url_uri = URI(url);
base_url = url_uri.path().split("/");
base_url.pop();
base_url = url.split(url_uri.path())[0] + base_url.join("/");
return validateJSONSchema(json, base_url);
});
})
.declareMethod("loadSoftwareJSON", function (url) {
return getJSON(url)
.push(function (json) {
return JSON.parse(json);
});
})
.declareMethod("validateJSONForSoftwareType", function (schema_url, software_type, generated_json) {
return getJSON(schema_url)
.push(function (json) {
return JSON.parse(json);
})
.push(function (json_object) {
var parameter_schema_url,
st,
base_url,
url_uri = URI(schema_url);
for (st in json_object["software-type"]) {
if (json_object["software-type"].hasOwnProperty(st)) {
if (st === software_type) {
parameter_schema_url = json_object["software-type"][st].request;
}
}
}
if (URI(parameter_schema_url).protocol() === "") {
base_url = url_uri.path().split("/");
base_url.pop();
base_url = schema_url.split(url_uri.path())[0] + base_url.join("/");
if (base_url !== undefined) {
parameter_schema_url = base_url + "/" + parameter_schema_url;
}
}
return getJSON(parameter_schema_url)
.push(function (json) {
var schema = JSON.parse(json);
return expandSchema(schema, schema, base_url)
.push(function (loaded_json) {
return tv4.validateMultiple(generated_json, loaded_json);
});
});
});
})
.declareMethod("validateJSON", function (schema_url, generated_json) {
return getJSON(schema_url)
.push(function (json) {
var base_url,
url_uri = URI(schema_url),
schema = JSON.parse(json);
base_url = url_uri.path().split("/");
base_url.pop();
base_url = schema_url.split(url_uri.path())[0] + base_url.join("/");
return expandSchema(schema, schema, base_url)
.push(function (loaded_schema) {
return tv4.validateMultiple(generated_json, loaded_schema);
});
});
});
}(window, rJS, $, RSVP));
\ No newline at end of file
/*jslint nomen: true, maxlen: 200, indent: 2*/
/*global window, rJS, console, jQuery, jIO, tv4, JSON */
(function (window, rJS) {
"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_meta_schema.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("loadSoftwareJSON", function (url) {
return getJSON(url)
.then(function (json) {
return JSON.parse(json);
});
})
.declareMethod("validateJSON", function (schema_url, generated_json) {
return getJSON(schema_url)
.then(function (json) {
return tv4.validateMultiple(generated_json, json);
});
});
}(window, rJS, jQuery));
\ No newline at end of file
/*jslint nomen: true, maxlen: 200, indent: 2*/
/*global window, rJS , $ , console */
(function (window, rJS, $) {
"use strict";
var gk = rJS(window),
json_url = "sample_schema.json",
parameter_gadget_url = "gadget_slapos_parameter_form.html";
gk.declareMethod('getContent', function () {
var g = this;
return g.getDeclaredGadget("parameter")
.push(function(gadget) {
var field_your_instance_xml = gadget.__element.querySelector('textarea[name=field_your_instance_xml]');
if (field_your_instance_xml !== null) {
return "SKIP";
}
return gadget.processValidation(g.options.json_url);
})
.push(function (xml_result) {
if (xml_result === "SKIP") {
/* The raw parameters are already on the request */
return {};
}
return {"field_your_instance_xml": xml_result};
})
.fail(function (e) {
return {};
});
});
gk.declareMethod('render', function (options) {
var g = this;
options.json_url = "../../renderjs/slapos_load_schema_software_type.json";
options.parameter = {};
g.options = options;
if (options.value !== undefined) {
// A JSON where provided via gadgetfield
$.extend(options, JSON.parse(options.value));
delete options.value;
}
if (options.parameter.parameter_hash !== undefined) {
// A JSON where provided via gadgetfield
options.parameter.parameter_xml = atob(options.parameter.parameter_hash);
}
if (options.parameter.json_url !== undefined) {
// A JSON where provided via gadgetfield
options.json_url = options.parameter.json_url;
}
return g.declareGadget(parameter_gadget_url, {'scope': 'parameter'})
.push(function (gadget) {
return gadget.render(options);
}).push(function (gadget) {
var div = g.__element.querySelector(".parameter");
$(div).replaceWith(gadget.__element);
return gadget;
});
});
}(window, rJS, $));
\ No newline at end of file
web_page_module/rjs_gadget_slapos_load_schema_html
web_page_module/rjs_gadget_slapos_parameter_form_html
web_page_module/rjs_gadget_slapos_load_schema_html
web_page_module/rjs_slapos_sample_schema_json
web_page_module/rjs_gadget_slapos_parameter_form_html
web_page_module/rjs_slapos_sample_schema_with_remote_json
web_page_module/rjs_gadget_slapos_request_form_html
web_page_module/rjs_slapos_load_meta_schema_json
web_page_module/rjs_slapos_load_schema_js
web_page_module/rjs_slapos_load_schema_js_backup
web_page_module/rjs_slapos_parameter_form_js
web_page_module/rjs_slapos_request_form_js
web_page_module/slapos-free-trial-*
image_module/vifib.cloud
image_module/vifib.rack
......
......@@ -2,6 +2,7 @@ portal_caches/facebook_server_auth_token_cache_factory
portal_caches/facebook_server_auth_token_cache_factory/persistent_cache_plugin
portal_caches/google_server_auth_token_cache_factory
portal_caches/google_server_auth_token_cache_factory/persistent_cache_plugin
web_page_module/rjs_slapos_load_meta_schema_json
web_page_module/rjs_tv4_min_js
web_page_module/rjs_vkbeautify_js
portal_types/Certificate Authority Tool
......
image_module/vifib.cloud
image_module/vifib.kvm
image_module/vifib.rack
web_page_module/rjs_gadget_slapos_load_schema_html
web_page_module/rjs_gadget_slapos_load_schema_html
web_page_module/rjs_gadget_slapos_parameter_form_html
web_page_module/rjs_gadget_slapos_parameter_form_html
web_page_module/rjs_gadget_slapos_request_form_html
web_page_module/rjs_slapos_load_meta_schema_json
web_page_module/rjs_slapos_load_schema_js
web_page_module/rjs_slapos_load_schema_js_backup
web_page_module/rjs_slapos_parameter_form_js
web_page_module/rjs_slapos_request_form_js
web_page_module/rjs_slapos_sample_schema_json
web_page_module/rjs_slapos_sample_schema_with_remote_json
web_page_module/slapos-free-trial-*
\ No newline at end of file
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