Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
17
Merge Requests
17
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
slapos.core
Commits
b9cb557d
Commit
b9cb557d
authored
Mar 17, 2015
by
Rafael Monnerat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos_web: expand json schema before use it for validation.
parent
640ed520
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
24 deletions
+53
-24
master/bt5/slapos_web/PathTemplateItem/web_page_module/rjs_gadget_slapos_parameter_form_html.xml
...web_page_module/rjs_gadget_slapos_parameter_form_html.xml
+3
-3
master/bt5/slapos_web/PathTemplateItem/web_page_module/rjs_slapos_load_schema_js.xml
...emplateItem/web_page_module/rjs_slapos_load_schema_js.xml
+44
-16
master/bt5/slapos_web/PathTemplateItem/web_page_module/rjs_slapos_parameter_form_js.xml
...lateItem/web_page_module/rjs_slapos_parameter_form_js.xml
+6
-5
No files found.
master/bt5/slapos_web/PathTemplateItem/web_page_module/rjs_gadget_slapos_parameter_form_html.xml
View file @
b9cb557d
...
...
@@ -132,7 +132,7 @@
<fieldset
id=
"parameter-main"
>
</fieldset>
\n
<fieldset
id=
"parameter-optional"
>
</fieldset>
\n
<fieldset
id=
"parameter-xml"
>
\n
<
textarea
name=
"your_parameter_xml"
class=
"parameter_xml_output"
></textarea
>
\n
<
input
type=
hidden
name=
"field_your_instance_xml"
class=
"parameter_xml_output"
></input
>
\n
</fieldset>
\n
\n
</div>
\n
...
...
@@ -278,7 +278,7 @@
</item>
<item>
<key>
<string>
serial
</string>
</key>
<value>
<string>
941.
38608.48931.35464
</string>
</value>
<value>
<string>
941.
46746.34379.16640
</string>
</value>
</item>
<item>
<key>
<string>
state
</string>
</key>
...
...
@@ -296,7 +296,7 @@
</tuple>
<state>
<tuple>
<float>
14265
23723.07
</float>
<float>
14265
86570.59
</float>
<string>
UTC
</string>
</tuple>
</state>
...
...
master/bt5/slapos_web/PathTemplateItem/web_page_module/rjs_slapos_load_schema_js.xml
View file @
b9cb557d
...
...
@@ -102,8 +102,8 @@
<value>
<string
encoding=
"cdata"
>
<![CDATA[
/*jslint nomen: true, maxlen: 200, indent: 2*/\n
/*global window, rJS, console, RSVP, jQuery, jIO, tv4, JSON, $ */\n
(function (window, rJS, $, RSVP) {\n
/*global window, rJS, console, RSVP, jQuery, jIO, tv4,
URI,
JSON, $ */\n
(function (window, rJS, $,
URI,
RSVP) {\n
"use strict";\n
\n
var gk = rJS(window);\n
...
...
@@ -131,7 +131,7 @@
return schema;\n
}\n
\n
function resolveReference(partial_schema, schema) {\n
function resolveReference(partial_schema, schema
, base_url
) {\n
var parts,\n
external_schema,\n
ref = partial_schema.$ref;\n
...
...
@@ -149,6 +149,11 @@
}\n
\n
return RSVP.Queue().push(function () {\n
if (URI(ref).protocol() === "") {\n
if (base_url !== undefined) {\n
ref = base_url + "/" + ref;\n
}\n
}\n
return getJSON(ref);\n
})\n
.push(function (json) {\n
...
...
@@ -164,7 +169,7 @@
}\n
\n
// Inspired from https://github.com/nexedi/dream/blob/master/dream/platform/src/jsplumb/jsplumb.js#L398\n
function expandSchema(json_schema, full_schema) {\n
function expandSchema(json_schema, full_schema
, base_url
) {\n
var i,\n
expanded_json_schema = clone(json_schema) || {};\n
\n
...
...
@@ -176,12 +181,14 @@
if (json_schema.$ref) {\n
return resolveReference(\n
json_schema,\n
full_schema\n
full_schema,\n
base_url\n
)\n
.push(function (remote_schema) {\n
return expandSchema(\n
remote_schema,\n
full_schema\n
full_schema,\n
base_url\n
);\n
}).push(function (referencedx) {\n
$.extend(expanded_json_schema, referencedx);\n
...
...
@@ -197,12 +204,14 @@
function wrapperResolveReference(p) {\n
return resolveReference(\n
json_schema.properties[p],\n
full_schema\n
full_schema,\n
base_url\n
).push(function (external_schema) {\n
// console.log(p);\n
return expandSchema(\n
external_schema,\n
full_schema\n
full_schema,\n
base_url\n
)\n
.push(function (referencedx) {\n
$.extend(expanded_json_schema.properties[p], referencedx);\n
...
...
@@ -231,7 +240,8 @@
function wrapperExpandSchema(p) {\n
return expandSchema(\n
json_schema.allOf[p],\n
full_schema\n
full_schema,\n
base_url\n
).push(function (referencedx) {\n
if (referencedx.properties) {\n
$.extend(\n
...
...
@@ -266,7 +276,7 @@
return getJSON("../../renderjs/slapos_load_meta_schema.json");\n
}\n
\n
function validateJSONSchema(json) {\n
function validateJSONSchema(json
, base_url
) {\n
return getMetaJSONSchema()\n
.then(function (meta_schema) {\n
if (!tv4.validate(json, meta_schema)) {\n
...
...
@@ -275,7 +285,7 @@
return JSON.parse(json);\n
})\n
.then(function (schema) {\n
return expandSchema(schema, schema);\n
return expandSchema(schema, schema
, base_url
);\n
});\n
}\n
\n
...
...
@@ -283,7 +293,14 @@
.declareMethod("loadJSONSchema", function (url) {\n
return getJSON(url)\n
.then(function (json) {\n
return validateJSONSchema(json);\n
var base_url, url_uri;\n
\n
url_uri = URI(url);\n
base_url = url_uri.path().split("/");\n
base_url.pop();\n
base_url = url.split(url_uri.path())[0] + base_url.join("/");\n
\n
return validateJSONSchema(json, base_url);\n
});\n
})\n
\n
...
...
@@ -317,11 +334,22 @@
.declareMethod("validateJSON", function (schema_url, generated_json) {\n
return getJSON(schema_url)\n
.then(function (json) {\n
return tv4.validateMultiple(generated_json, JSON.parse(json));\n
var base_url,\n
url_uri = URI(schema_url),\n
schema = JSON.parse(json);\n
\n
base_url = url_uri.path().split("/");\n
base_url.pop();\n
base_url = schema_url.split(url_uri.path())[0] + base_url.join("/");\n
\n
return expandSchema(schema, schema, base_url)\n
.push(function (loaded_schema) {\n
return tv4.validateMultiple(generated_json, loaded_schema);\n
});\n
});\n
});\n
\n
}(window, rJS, $, RSVP));
}(window, rJS, $, RSVP
, URI
));
]]>
</string>
</value>
</item>
...
...
@@ -458,7 +486,7 @@
</item>
<item>
<key>
<string>
serial
</string>
</key>
<value>
<string>
941.
38337.40987.563
</string>
</value>
<value>
<string>
941.
46927.41646.58504
</string>
</value>
</item>
<item>
<key>
<string>
state
</string>
</key>
...
...
@@ -476,7 +504,7 @@
</tuple>
<state>
<tuple>
<float>
1426
092715.19
</float>
<float>
1426
597461.76
</float>
<string>
UTC
</string>
</tuple>
</state>
...
...
master/bt5/slapos_web/PathTemplateItem/web_page_module/rjs_slapos_parameter_form_js.xml
View file @
b9cb557d
...
...
@@ -246,7 +246,7 @@
return g.validateJSON(json_url, json_dict)\n
.push(function (validation) {\n
var error_index,\n
parameter_
textarea
= g.props.element.querySelectorAll(\'.parameter_xml_output\')[0],\n
parameter_
input
= g.props.element.querySelectorAll(\'.parameter_xml_output\')[0],\n
field_name,\n
div,\n
divm,\n
...
...
@@ -262,7 +262,7 @@
});\n
\n
if (validation.valid) {\n
parameter_
textarea.innerText
= jsonDictToParameterXML(json_dict);\n
parameter_
input.value
= jsonDictToParameterXML(json_dict);\n
} else {\n
for (error_index in validation.errors) {\n
if (validation.errors.hasOwnProperty(error_index)) {\n
...
...
@@ -281,7 +281,7 @@
divm.querySelector("span.error").textContent = validation.missing[missing_index].message;\n
}\n
}\n
parameter_
textarea.innerText
= "ERROR";\n
parameter_
input.value
= "ERROR";\n
}\n
console.log(jsonDictToParameterXML(json_dict));\n
return false;\n
...
...
@@ -472,6 +472,7 @@
);\n
})\n
.fail(function (error) {\n
console.error(error.stack);\n
return g.renderFailoverTextArea(\'\', error.toString());\n
});\n
});\n
...
...
@@ -613,7 +614,7 @@
</item>
<item>
<key>
<string>
serial
</string>
</key>
<value>
<string>
941.4
5697.33456.18551
</string>
</value>
<value>
<string>
941.4
6904.21655.48418
</string>
</value>
</item>
<item>
<key>
<string>
state
</string>
</key>
...
...
@@ -631,7 +632,7 @@
</tuple>
<state>
<tuple>
<float>
14265
23636.72
</float>
<float>
14265
96317.01
</float>
<string>
UTC
</string>
</tuple>
</state>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment