Commit fd10e401 authored by Jérome Perrin's avatar Jérome Perrin

update static version

parent ebc77d04
...@@ -24,7 +24,9 @@ ...@@ -24,7 +24,9 @@
name = file.name; name = file.name;
return promiseReadAsText(file); return promiseReadAsText(file);
}).push(function(json) { }).push(function(json) {
json_data = json; var data = JSON.parse(json);
data.general.name = name;
json_data = JSON.stringify(data);
return createDocument(gadget, name); return createDocument(gadget, name);
}).push(function(jio_document) { }).push(function(jio_document) {
// Add JSON as attachment // Add JSON as attachment
......
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Debug JSON</title>
<script src="../lib/rsvp.min.js" type="text/javascript"></script>
<script src="../lib/renderjs.min.js" type="text/javascript"></script>
<script src="mixin_gadget.js" type="text/javascript"></script>
<script src="Input_viewDebugJson.js" type="text/javascript"></script>
</head>
<body>
<div xdata-gadget-url="https://softinst52398.node.vifib.com/gadget_codemirror.html"
data-gadget-scope="editor"
data-gadget-sandbox="iframe"></div>
<label for="json">JSON</label>
<textarea spellcheck="false" rows="20" name="json" class="json"></textarea>
</body>
</html>
/*global rJS, initGadgetMixin */
(function(window, rJS, initGadgetMixin) {
"use strict";
var gadget_klass = rJS(window);
initGadgetMixin(gadget_klass);
gadget_klass.declareAcquiredMethod("aq_getAttachment", "jio_getAttachment").declareMethod("render", function(options) {
var gadget = this;
this.props.jio_key = options.id;
this.props.result = options.result;
return gadget.aq_getAttachment({
_id: gadget.props.jio_key,
_attachment: "body.json"
}).push(function(result_json) {
var document = JSON.parse(result_json);
gadget.props.element.querySelector(".json").textContent = JSON.stringify(document, undefined, " ");
});
});
})(window, rJS, initGadgetMixin);
\ No newline at end of file
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
_id: gadget.props.jio_key, _id: gadget.props.jio_key,
_attachment: "simulation.json" _attachment: "simulation.json"
}).push(undefined, function(error) { }).push(undefined, function(error) {
if (error.status === 404) { if (error.status_code === 404) {
// Simulation not yet generated // Simulation not yet generated
return JSON.stringify([]); return JSON.stringify([]);
} }
......
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
/*jslint unparam: true */ /*jslint unparam: true */
(function(window, rJS, $, initGadgetMixin) { (function(window, rJS, $, initGadgetMixin) {
"use strict"; "use strict";
function station_utilisation_graph_widget(output_data) { function station_utilisation_graph_widget(data, result_id) {
var blockage_data = [], waiting_data = [], failure_data = [], working_data = [], ticks = [], counter = 1, series, options; var blockage_data = [], waiting_data = [], failure_data = [], working_data = [], ticks = [], counter = 1, series, options;
// XXX output is still elementList ??? // XXX output is still elementList ???
$.each(output_data.elementList.sort(function(a, b) { $.each(data.result.result_list[result_id].elementList.sort(function(a, b) {
return a.id < b.id ? -1 : 1; return a.id < b.id ? -1 : 1;
}), function(idx, obj) { }), function(idx, obj) {
// add each object that has a working ratio // add each object that has a working ratio
...@@ -106,7 +106,7 @@ ...@@ -106,7 +106,7 @@
_id: gadget.props.jio_key, _id: gadget.props.jio_key,
_attachment: "simulation.json" _attachment: "simulation.json"
}).push(function(simulation_json) { }).push(function(simulation_json) {
gadget.props.result_list = station_utilisation_graph_widget(JSON.parse(simulation_json).result.result_list[gadget.props.result]); gadget.props.result_list = station_utilisation_graph_widget(JSON.parse(simulation_json), gadget.props.result);
}); });
}).declareMethod("startService", function() { }).declareMethod("startService", function() {
// XXX Manually calculate width and height when resizing // XXX Manually calculate width and height when resizing
......
@media (min-width:110em){.jqm-navmenu-panel.ui-panel-closed{visibility:visible!important;width:17em;-webkit-transition:none!important;-moz-transition:none!important;transition:none!important;-webkit-transform:none!important;-moz-transform:none!important;transform:none!important;-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none;height:100%;position:absolute;display:block}.ui-panel-page-content-open{width:auto}.ui-panel-page-content-open.ui-panel-page-content-position-left{margin-right:17em}.ui-panel-dismiss,.menu_link{display:none!important}.gadget_container,header,nav{margin-left:17em}.close-entry{display:none!important}.gadget_container{padding:1em}}[data-gadget-scope=productionline_toolbox]{position:relative;width:19.5%;float:left}[data-gadget-scope=productionline_graph]{position:relative;width:79.5%;float:right}form.save_form{display:none} @media (min-width:100em){.jqm-navmenu-panel.ui-panel-closed{visibility:visible!important;width:17em;-webkit-transition:none!important;-moz-transition:none!important;transition:none!important;-webkit-transform:none!important;-moz-transform:none!important;transform:none!important;-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none;height:100%;position:absolute;display:block}.ui-panel-page-content-open{width:auto}.ui-panel-page-content-open.ui-panel-page-content-position-left{margin-right:17em}.ui-panel-dismiss,.menu_link{display:none!important}.gadget_container,header,nav{margin-left:17em}.close-entry{display:none!important}.gadget_container{padding:1em}}[data-gadget-scope=productionline_toolbox]{position:relative;width:19.5%;float:left}[data-gadget-scope=productionline_graph]{position:relative;width:79.5%;float:right}form.save_form{display:none}
\ No newline at end of file \ No newline at end of file
...@@ -314,9 +314,14 @@ ...@@ -314,9 +314,14 @@
}).ready(function(g) { }).ready(function(g) {
return g.getDeclaredGadget("jio").push(function(gadget) { return g.getDeclaredGadget("jio").push(function(gadget) {
return gadget.createJio({ return gadget.createJio({
type: "local", type: "query",
username: "dream", sub_storage: {
applicationname: "dream" type: "document",
document_id: "/",
sub_storage: {
type: "local"
}
}
}); });
}); });
}).declareMethod("render", function(options) { }).declareMethod("render", function(options) {
...@@ -398,7 +403,7 @@ ...@@ -398,7 +403,7 @@
if (error instanceof RSVP.CancellationError) { if (error instanceof RSVP.CancellationError) {
throw error; throw error;
} }
console.error(error); console.error(error.stack);
document.querySelector("article[class='gadget_container']").innerHTML = error_template({ document.querySelector("article[class='gadget_container']").innerHTML = error_template({
error: error error: error
}); });
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
// Handlebars // Handlebars
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Precompile the templates while loading the first gadget instance // Precompile the templates while loading the first gadget instance
var i, gadget_klass = rJS(window), source = gadget_klass.__template_element.getElementById("label-template").innerHTML, label_template = Handlebars.compile(source); var gadget_klass = rJS(window), source = gadget_klass.__template_element.getElementById("label-template").innerHTML, label_template = Handlebars.compile(source);
initGadgetMixin(gadget_klass); initGadgetMixin(gadget_klass);
gadget_klass.declareMethod("render", function(options, node_id) { gadget_klass.declareMethod("render", function(options, node_id) {
// XXX node_id is added like a property so that one can change the node // XXX node_id is added like a property so that one can change the node
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
gadget.props.field_gadget_list = []; gadget.props.field_gadget_list = [];
function addField(property_id, property_definition, value) { function addField(property_id, property_definition, value) {
var sub_gadget; var sub_gadget;
console.log("addField", property_id, property_definition, value); //console.log("addField", property_id, property_definition, value);
queue.push(function() { queue.push(function() {
// XXX this is incorrect for recursive fieldsets. // XXX this is incorrect for recursive fieldsets.
// we should use nested fieldset with legend // we should use nested fieldset with legend
...@@ -26,15 +26,6 @@ ...@@ -26,15 +26,6 @@
"for": property_id, "for": property_id,
name: property_definition.name || property_definition.description || property_id name: property_definition.name || property_definition.description || property_id
})); }));
//console.log("PD", property_definition);
if (property_definition.oneOf) {
// if we got a oneOf, then we use the first one that matches our
// data.
console.log(value);
for (i = 0; i < property_definition.oneOf.length; i += 1) {
console.log(property_definition.oneOf[i]);
}
}
if (property_definition.type === "object") { if (property_definition.type === "object") {
// Create a recursive fieldset for this key. // Create a recursive fieldset for this key.
return gadget.declareGadget("../fieldset/index.html"); return gadget.declareGadget("../fieldset/index.html");
...@@ -66,20 +57,18 @@ ...@@ -66,20 +57,18 @@
type: "string" type: "string"
}, node_id); }, node_id);
} }
console.log(options.property_definition); //console.log(options.property_definition);
Object.keys(options.property_definition.properties).forEach(function(property_name) { Object.keys(options.property_definition.properties).forEach(function(property_name) {
var property_definition = options.property_definition.properties[property_name], value = (options.value || {})[property_name] === undefined ? property_definition._default : options.value[property_name]; var property_definition = options.property_definition.properties[property_name], value = (options.value || {})[property_name] === undefined ? property_definition.default : options.value[property_name];
//console.log(property_name, property_definition); //console.log(property_name, property_definition);
// XXX some properties are not editable // XXX some properties are not editable
// XXX should not be defined here // XXX should not be defined here
if (property_name !== "coordinate" && property_name !== "_class") { if (property_name !== "coordinate" && property_name !== "_class" && property_name !== "id") {
addField(property_name, property_definition, value); addField(property_name, property_definition, value);
} }
}); });
}); });
return queue; return queue;
}).declareMethod("notifyDataChanged", function() {
console.log("content changed");
}).declareMethod("getContent", function() { }).declareMethod("getContent", function() {
var i, promise_list = [], gadget = this; var i, promise_list = [], gadget = this;
for (i = 0; i < this.props.field_gadget_list.length; i += 1) { for (i = 0; i < this.props.field_gadget_list.length; i += 1) {
......
...@@ -13,23 +13,36 @@ ...@@ -13,23 +13,36 @@
return storage.allDocs.apply(storage, arguments); return storage.allDocs.apply(storage, arguments);
}).declareMethod("get", function() { }).declareMethod("get", function() {
var storage = this.state_parameter_dict.jio_storage; var storage = this.state_parameter_dict.jio_storage;
return storage.get.apply(storage, arguments); return storage.get.apply(storage, arguments).push(function(result) {
return {
data: result
};
});
}).declareMethod("remove", function() { }).declareMethod("remove", function() {
var storage = this.state_parameter_dict.jio_storage; var storage = this.state_parameter_dict.jio_storage;
return storage.remove.apply(storage, arguments); return storage.remove.apply(storage, arguments);
}).declareMethod("getAttachment", function() { }).declareMethod("getAttachment", function() {
var storage = this.state_parameter_dict.jio_storage; var storage = this.state_parameter_dict.jio_storage;
return storage.getAttachment.apply(storage, arguments).then(function(response) { return storage.getAttachment.apply(storage, arguments).then(function(response) {
return jIO.util.readBlobAsText(response.data); return jIO.util.readBlobAsText(response);
}).then(function(lala) { }).then(function(lala) {
return lala.target.result; return lala.target.result;
}); });
}).declareMethod("putAttachment", function() { }).declareMethod("putAttachment", function() {
var storage = this.state_parameter_dict.jio_storage; var storage = this.state_parameter_dict.jio_storage, argument_list = arguments;
return storage.putAttachment.apply(storage, arguments); return storage.putAttachment.apply(storage, arguments).push(function() {
return {
id: argument_list[0]._id,
attachment: argument_list[0]._attachment
};
});
}).declareMethod("post", function() { }).declareMethod("post", function() {
// XXX set modified value // XXX set modified value
var storage = this.state_parameter_dict.jio_storage; var storage = this.state_parameter_dict.jio_storage;
return storage.post.apply(storage, arguments); return storage.post.apply(storage, arguments).push(function(id) {
return {
id: id
};
});
}); });
})(rJS, jIO); })(rJS, jIO);
\ No newline at end of file
...@@ -14,6 +14,10 @@ ...@@ -14,6 +14,10 @@
<script src="../lib/jquery.jsplumb.js"></script> <script src="../lib/jquery.jsplumb.js"></script>
<script src="../lib/handlebars.min.js"></script> <script src="../lib/handlebars.min.js"></script>
<script src="../dream/mixin_gadget.js"></script>
<script src="../dream/mixin_promise.js"></script>
<script src="jsplumb.js"></script>
<script id="node-template" type="text/x-handlebars-template"> <script id="node-template" type="text/x-handlebars-template">
<div class="window {{class}}" <div class="window {{class}}"
id="{{element_id}}" id="{{element_id}}"
...@@ -22,8 +26,7 @@ ...@@ -22,8 +26,7 @@
<div class="ep"></div> <div class="ep"></div>
</div> </div>
</script> </script>
<script id="popup-edit-template" type="text/x-handlebars-template">
<template id="popup-edit-template">
<div id="edit-popup" data-position-to="origin"> <div id="edit-popup" data-position-to="origin">
<div data-role="header" data-theme="a"> <div data-role="header" data-theme="a">
<h1 class="node_class">Edit properties</h1> <h1 class="node_class">Edit properties</h1>
...@@ -36,12 +39,7 @@ ...@@ -36,12 +39,7 @@
<input type="submit" value="Validate"> <input type="submit" value="Validate">
</form> </form>
</div> </div>
</template> </script>
<script src="../dream/mixin_gadget.js"></script>
<script src="../dream/mixin_promise.js"></script>
<script src="jsplumb.js"></script>
</head> </head>
<body> <body>
<div id="main"></div> <div id="main"></div>
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
* factorize node & edge popup edition * factorize node & edge popup edition
*/ */
/*jslint nomen: true */ /*jslint nomen: true */
var gadget_klass = rJS(window), node_template_source = gadget_klass.__template_element.getElementById("node-template").innerHTML, node_template = Handlebars.compile(node_template_source), popup_edit_template = gadget_klass.__template_element.getElementById("popup-edit-template"), domParser = new DOMParser(); var gadget_klass = rJS(window), node_template_source = gadget_klass.__template_element.getElementById("node-template").innerHTML, node_template = Handlebars.compile(node_template_source), popup_edit_template = gadget_klass.__template_element.getElementById("popup-edit-template").innerHTML, domParser = new DOMParser();
function loopJsplumbBind(gadget, type, callback) { function loopJsplumbBind(gadget, type, callback) {
////////////////////////// //////////////////////////
// Infinite event listener (promise is never resolved) // Infinite event listener (promise is never resolved)
...@@ -290,7 +290,7 @@ ...@@ -290,7 +290,7 @@
function resolveReference(ref, schema) { function resolveReference(ref, schema) {
// 2 here is for #/ // 2 here is for #/
var i, ref_path = ref.substr(2, ref.length), parts = ref_path.split("/"); var i, ref_path = ref.substr(2, ref.length), parts = ref_path.split("/");
for (i = 0; i < parts.length; i++) { for (i = 0; i < parts.length; i += 1) {
schema = schema[parts[i]]; schema = schema[parts[i]];
} }
return schema; return schema;
...@@ -300,37 +300,17 @@ ...@@ -300,37 +300,17 @@
// references // references
// XXX this should probably be moved to fieldset ( and not handle // XXX this should probably be moved to fieldset ( and not handle
// class_definition here) // class_definition here)
// XXX known limitation: we do not expand refs inside oneOf var referenced, i, expanded_class_definition = {
var property, referenced, i, expanded_class_definition = {
properties: class_definition.properties || {} properties: class_definition.properties || {}
}; };
console.log("expandSchema", class_definition);
// expand direct ref // expand direct ref
if (class_definition.$ref) { if (class_definition.$ref) {
console.log("DI", class_definition.$ref);
referenced = expandSchema(resolveReference(class_definition.$ref, full_schema.class_definition), full_schema); referenced = expandSchema(resolveReference(class_definition.$ref, full_schema.class_definition), full_schema);
if (referenced.properties) { if (referenced.properties) {
delete referenced.properties; delete referenced.properties;
} }
$.extend(expanded_class_definition, referenced); $.extend(expanded_class_definition, referenced);
console.log("after direct expand", Object.create(referenced));
} }
/*
// expand refs inside properties
for (property in expanded_class_definition.properties) {
if (expanded_class_definition.properties.hasOwnProperty(property)) {
referenced = expanded_class_definition.properties[property];
if (referenced.$ref) {
if (!expanded_class_definition.properties[property]){
expanded_class_definition.properties[property] = {};
}
$.extend(expanded_class_definition.properties[property], expandSchema(
resolveReference(referenced.$ref, full_schema.class_definition),
full_schema));
}
}
}
*/
if (class_definition.oneOf) { if (class_definition.oneOf) {
expanded_class_definition.oneOf = []; expanded_class_definition.oneOf = [];
for (i = 0; i < class_definition.oneOf.length; i += 1) { for (i = 0; i < class_definition.oneOf.length; i += 1) {
...@@ -350,38 +330,7 @@ ...@@ -350,38 +330,7 @@
if (expanded_class_definition.$ref) { if (expanded_class_definition.$ref) {
delete expanded_class_definition.$ref; delete expanded_class_definition.$ref;
} }
console.log("R", expanded_class_definition);
return Object.create(expanded_class_definition); return Object.create(expanded_class_definition);
// expand refs directly in allOf
if (class_definition.xallOf) {
for (i = 0; i < class_definition.allOf.length; i += 1) {
referenced = class_definition.allOf[i];
if (referenced.$ref) {
referenced = Object.create(referenced);
$.extend(referenced, expandSchema(resolveReference(referenced.$ref, full_schema.class_definition), full_schema));
}
if (referenced.properties) {
for (property in referenced.properties) {
if (referenced.properties.hasOwnProperty(property)) {
//console.log('property2', property, referenced.properties[property]);
// and in allOf references. XXX I guess this can be merged with
// "expand ref inside properties"
if (referenced.properties[property].$ref) {
expanded_class_definition.properties[property] = referenced.properties[property];
$.extend(expanded_class_definition.properties[property], expandSchema(resolveReference(referenced.properties[property].$ref, full_schema.class_definition), full_schema));
}
if (referenced.properties[property].type) {
if (!expanded_class_definition.properties[property]) {
expanded_class_definition.properties[property] = {};
}
$.extend(expanded_class_definition.properties[property], referenced.properties[property]);
}
}
}
}
}
}
return expanded_class_definition;
} }
function openEdgeEditionDialog(gadget, connection) { function openEdgeEditionDialog(gadget, connection) {
var edge_id = connection.id, edge_data = gadget.props.data.graph.edge[edge_id], edit_popup = $(gadget.props.element).find("#popup-edit-template"), schema, fieldset_element, delete_promise; var edge_id = connection.id, edge_data = gadget.props.data.graph.edge[edge_id], edit_popup = $(gadget.props.element).find("#popup-edit-template"), schema, fieldset_element, delete_promise;
...@@ -389,7 +338,7 @@ ...@@ -389,7 +338,7 @@
// We do not edit source & destination on edge this way. // We do not edit source & destination on edge this way.
delete schema.properties.source; delete schema.properties.source;
delete schema.properties.destination; delete schema.properties.destination;
gadget.props.element.appendChild(document.importNode(popup_edit_template.content, true).children[0]); gadget.props.element.insertAdjacentHTML("beforeend", popup_edit_template);
edit_popup = $(gadget.props.element).find("#edit-popup"); edit_popup = $(gadget.props.element).find("#edit-popup");
edit_popup.find(".node_class").text(connection._class); edit_popup.find(".node_class").text(connection._class);
fieldset_element = edit_popup.find("fieldset")[0]; fieldset_element = edit_popup.find("fieldset")[0];
...@@ -449,15 +398,16 @@ ...@@ -449,15 +398,16 @@
function openNodeEditionDialog(gadget, element) { function openNodeEditionDialog(gadget, element) {
var node_id = getNodeId(gadget, element.id), node_data = gadget.props.data.graph.node[node_id], node_edit_popup = $(gadget.props.element).find("#popup-edit-template"), schema, fieldset_element, delete_promise; var node_id = getNodeId(gadget, element.id), node_data = gadget.props.data.graph.node[node_id], node_edit_popup = $(gadget.props.element).find("#popup-edit-template"), schema, fieldset_element, delete_promise;
// If we have no definition for this, we do not allow edition. // If we have no definition for this, we do not allow edition.
// XXX incorrect, we need to display this dialog to be able
// to delete a node
if (gadget.props.data.class_definition[node_data._class] === undefined) { if (gadget.props.data.class_definition[node_data._class] === undefined) {
return; return;
} }
schema = expandSchema(gadget.props.data.class_definition[node_data._class], gadget.props.data); schema = expandSchema(gadget.props.data.class_definition[node_data._class], gadget.props.data);
console.log("editing node with", schema);
if (node_edit_popup.length !== 0) { if (node_edit_popup.length !== 0) {
node_edit_popup.remove(); node_edit_popup.remove();
} }
gadget.props.element.appendChild(document.importNode(popup_edit_template.content, true).children[0]); gadget.props.element.insertAdjacentHTML("beforeend", popup_edit_template);
node_edit_popup = $(gadget.props.element).find("#edit-popup"); node_edit_popup = $(gadget.props.element).find("#edit-popup");
// Set the name of the popup to the node class // Set the name of the popup to the node class
node_edit_popup.find(".node_class").text(node_data._class); node_edit_popup.find(".node_class").text(node_data._class);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
var input = this.element.querySelector("input"); var input = this.element.querySelector("input");
input.setAttribute("value", options.value); input.setAttribute("value", options.value);
input.setAttribute("name", options.key); input.setAttribute("name", options.key);
input.setAttribute("title", options.title || options.key); input.setAttribute("title", options.property_definition.description);
}).declareMethod("getContent", function() { }).declareMethod("getContent", function() {
var input = this.element.querySelector("input"), result = {}; var input = this.element.querySelector("input"), result = {};
if (input.value !== "") { if (input.value !== "") {
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
var input = this.element.querySelector("input"); var input = this.element.querySelector("input");
input.setAttribute("value", options.value || ""); input.setAttribute("value", options.value || "");
input.setAttribute("name", options.key); input.setAttribute("name", options.key);
input.setAttribute("title", options.title || options.key); input.setAttribute("title", options.property_definition.description);
}).declareMethod("getContent", function() { }).declareMethod("getContent", function() {
var input = this.element.querySelector("input"), result = {}; var input = this.element.querySelector("input"), result = {};
result[input.getAttribute("name")] = input.value; result[input.getAttribute("name")] = input.value;
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
tools_container.className = "tools-container"; tools_container.className = "tools-container";
Object.keys(data.class_definition).forEach(function(key) { Object.keys(data.class_definition).forEach(function(key) {
var _class = data.class_definition[key], tool; var _class = data.class_definition[key], tool;
// XXX "expand" the json schema "allOF" etc // XXX "expand" the json schema "allOf" etc
if (_class._class === "node") { if (_class._class === "node") {
tool = document.createElement("div"); tool = document.createElement("div");
// XXX maybe allow to configure the class name ? // XXX maybe allow to configure the class name ?
...@@ -39,6 +39,9 @@ ...@@ -39,6 +39,9 @@
tool.textContent = _class.name || key; tool.textContent = _class.name || key;
tool.draggable = true; tool.draggable = true;
tool.dataset.class_name = JSON.stringify(key); tool.dataset.class_name = JSON.stringify(key);
if (_class.description) {
tool.title = _class.description;
}
Object.keys(_class.css || {}).forEach(function(k) { Object.keys(_class.css || {}).forEach(function(k) {
tool.style[k] = _class.css[k]; tool.style[k] = _class.css[k];
}); });
......
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