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

update static version

parent ebc77d04
......@@ -24,7 +24,9 @@
name = file.name;
return promiseReadAsText(file);
}).push(function(json) {
json_data = json;
var data = JSON.parse(json);
data.general.name = name;
json_data = JSON.stringify(data);
return createDocument(gadget, name);
}).push(function(jio_document) {
// 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 @@
_id: gadget.props.jio_key,
_attachment: "simulation.json"
}).push(undefined, function(error) {
if (error.status === 404) {
if (error.status_code === 404) {
// Simulation not yet generated
return JSON.stringify([]);
}
......
......@@ -2,10 +2,10 @@
/*jslint unparam: true */
(function(window, rJS, $, initGadgetMixin) {
"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;
// 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;
}), function(idx, obj) {
// add each object that has a working ratio
......@@ -106,7 +106,7 @@
_id: gadget.props.jio_key,
_attachment: "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() {
// 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}
\ No newline at end of file
@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
......@@ -314,9 +314,14 @@
}).ready(function(g) {
return g.getDeclaredGadget("jio").push(function(gadget) {
return gadget.createJio({
type: "local",
username: "dream",
applicationname: "dream"
type: "query",
sub_storage: {
type: "document",
document_id: "/",
sub_storage: {
type: "local"
}
}
});
});
}).declareMethod("render", function(options) {
......@@ -398,7 +403,7 @@
if (error instanceof RSVP.CancellationError) {
throw error;
}
console.error(error);
console.error(error.stack);
document.querySelector("article[class='gadget_container']").innerHTML = error_template({
error: error
});
......
......@@ -7,7 +7,7 @@
// Handlebars
/////////////////////////////////////////////////////////////////
// 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);
gadget_klass.declareMethod("render", function(options, node_id) {
// XXX node_id is added like a property so that one can change the node
......@@ -18,7 +18,7 @@
gadget.props.field_gadget_list = [];
function addField(property_id, property_definition, value) {
var sub_gadget;
console.log("addField", property_id, property_definition, value);
//console.log("addField", property_id, property_definition, value);
queue.push(function() {
// XXX this is incorrect for recursive fieldsets.
// we should use nested fieldset with legend
......@@ -26,15 +26,6 @@
"for": 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") {
// Create a recursive fieldset for this key.
return gadget.declareGadget("../fieldset/index.html");
......@@ -66,20 +57,18 @@
type: "string"
}, node_id);
}
console.log(options.property_definition);
//console.log(options.property_definition);
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);
// XXX some properties are not editable
// 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);
}
});
});
return queue;
}).declareMethod("notifyDataChanged", function() {
console.log("content changed");
}).declareMethod("getContent", function() {
var i, promise_list = [], gadget = this;
for (i = 0; i < this.props.field_gadget_list.length; i += 1) {
......
......@@ -13,23 +13,36 @@
return storage.allDocs.apply(storage, arguments);
}).declareMethod("get", function() {
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() {
var storage = this.state_parameter_dict.jio_storage;
return storage.remove.apply(storage, arguments);
}).declareMethod("getAttachment", function() {
var storage = this.state_parameter_dict.jio_storage;
return storage.getAttachment.apply(storage, arguments).then(function(response) {
return jIO.util.readBlobAsText(response.data);
return jIO.util.readBlobAsText(response);
}).then(function(lala) {
return lala.target.result;
});
}).declareMethod("putAttachment", function() {
var storage = this.state_parameter_dict.jio_storage;
return storage.putAttachment.apply(storage, arguments);
var storage = this.state_parameter_dict.jio_storage, argument_list = arguments;
return storage.putAttachment.apply(storage, arguments).push(function() {
return {
id: argument_list[0]._id,
attachment: argument_list[0]._attachment
};
});
}).declareMethod("post", function() {
// XXX set modified value
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);
\ No newline at end of file
......@@ -14,6 +14,10 @@
<script src="../lib/jquery.jsplumb.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">
<div class="window {{class}}"
id="{{element_id}}"
......@@ -22,8 +26,7 @@
<div class="ep"></div>
</div>
</script>
<template id="popup-edit-template">
<script id="popup-edit-template" type="text/x-handlebars-template">
<div id="edit-popup" data-position-to="origin">
<div data-role="header" data-theme="a">
<h1 class="node_class">Edit properties</h1>
......@@ -36,12 +39,7 @@
<input type="submit" value="Validate">
</form>
</div>
</template>
<script src="../dream/mixin_gadget.js"></script>
<script src="../dream/mixin_promise.js"></script>
<script src="jsplumb.js"></script>
</script>
</head>
<body>
<div id="main"></div>
......
......@@ -35,7 +35,7 @@
* factorize node & edge popup edition
*/
/*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) {
//////////////////////////
// Infinite event listener (promise is never resolved)
......@@ -290,7 +290,7 @@
function resolveReference(ref, schema) {
// 2 here is for #/
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]];
}
return schema;
......@@ -300,37 +300,17 @@
// references
// XXX this should probably be moved to fieldset ( and not handle
// class_definition here)
// XXX known limitation: we do not expand refs inside oneOf
var property, referenced, i, expanded_class_definition = {
var referenced, i, expanded_class_definition = {
properties: class_definition.properties || {}
};
console.log("expandSchema", class_definition);
// expand direct ref
if (class_definition.$ref) {
console.log("DI", class_definition.$ref);
referenced = expandSchema(resolveReference(class_definition.$ref, full_schema.class_definition), full_schema);
if (referenced.properties) {
delete referenced.properties;
}
$.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) {
expanded_class_definition.oneOf = [];
for (i = 0; i < class_definition.oneOf.length; i += 1) {
......@@ -350,38 +330,7 @@
if (expanded_class_definition.$ref) {
delete expanded_class_definition.$ref;
}
console.log("R", 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) {
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 @@
// We do not edit source & destination on edge this way.
delete schema.properties.source;
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.find(".node_class").text(connection._class);
fieldset_element = edit_popup.find("fieldset")[0];
......@@ -449,15 +398,16 @@
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;
// 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) {
return;
}
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) {
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");
// Set the name of the popup to the node class
node_edit_popup.find(".node_class").text(node_data._class);
......
......@@ -9,7 +9,7 @@
var input = this.element.querySelector("input");
input.setAttribute("value", options.value);
input.setAttribute("name", options.key);
input.setAttribute("title", options.title || options.key);
input.setAttribute("title", options.property_definition.description);
}).declareMethod("getContent", function() {
var input = this.element.querySelector("input"), result = {};
if (input.value !== "") {
......
......@@ -9,7 +9,7 @@
var input = this.element.querySelector("input");
input.setAttribute("value", options.value || "");
input.setAttribute("name", options.key);
input.setAttribute("title", options.title || options.key);
input.setAttribute("title", options.property_definition.description);
}).declareMethod("getContent", function() {
var input = this.element.querySelector("input"), result = {};
result[input.getAttribute("name")] = input.value;
......
......@@ -31,7 +31,7 @@
tools_container.className = "tools-container";
Object.keys(data.class_definition).forEach(function(key) {
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") {
tool = document.createElement("div");
// XXX maybe allow to configure the class name ?
......@@ -39,6 +39,9 @@
tool.textContent = _class.name || key;
tool.draggable = true;
tool.dataset.class_name = JSON.stringify(key);
if (_class.description) {
tool.title = _class.description;
}
Object.keys(_class.css || {}).forEach(function(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