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

update static version

parent ce04e5d8
......@@ -21,11 +21,9 @@
}
throw error;
}).push(function(sim_json) {
var document_list = JSON.parse(sim_json), result_list = [], i;
if (document.result) {
if (document.result.result_list) {
document_list = document.result.result_list;
}
var result = JSON.parse(sim_json).result, result_list = [], document_list = [], i;
if (result) {
document_list = result.result_list;
}
for (i = 0; i < document_list.length; i += 1) {
result_list.push(RSVP.all([ gadget.whoWantsToDisplayThisResult(gadget.props.jio_key, i), document_list[i].score, document_list[i].key ]));
......
......@@ -192,7 +192,8 @@
_attachment: "simulation.json"
});
}).push(function(sim_json) {
var document_list = JSON.parse(sim_json);
var document_list = JSON.parse(sim_json).result.result_list;
console.log(JSON.parse(sim_json).result);
return document_list[options.result].score + " " + document_list[options.result].key;
});
} else {
......@@ -276,6 +277,7 @@
for (action_id in portal_types.Output) {
if (portal_types.Output.hasOwnProperty(action_id)) {
action_info = portal_types.Output[action_id];
// XXX condition not needed
if (action_info.condition === undefined || action_info.condition(this)) {
action = action_id;
break;
......
......@@ -7,7 +7,7 @@
// Handlebars
/////////////////////////////////////////////////////////////////
// Precompile the templates while loading the first gadget instance
var gadget_klass = rJS(window), source = gadget_klass.__template_element.getElementById("label-template").innerHTML, label_template = Handlebars.compile(source);
var i, 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,6 +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);
queue.push(function() {
// XXX this is incorrect for recursive fieldsets.
// we should use nested fieldset with legend
......@@ -25,6 +26,15 @@
"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");
......@@ -56,8 +66,10 @@
type: "string"
}, node_id);
}
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];
//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") {
......@@ -66,6 +78,8 @@
});
});
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) {
......
......@@ -287,25 +287,94 @@
// jsplumb assigned an id, but we are controlling ids ourselves.
connection.id = edge_id;
}
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++) {
schema = schema[parts[i]];
}
return schema;
}
function expandSchema(class_definition, full_schema) {
// minimal expanding of json schema, supports merging allOf and $ref
// references
// TODO: check for a library that would provide full support
// 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 = {
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) {
expanded_class_definition.oneOf.push(expandSchema(class_definition.oneOf[i], full_schema));
}
}
if (class_definition.allOf) {
for (i = 0; i < class_definition.allOf.length; i += 1) {
referenced = expandSchema(class_definition.allOf[i], full_schema);
if (referenced.properties) {
$.extend(expanded_class_definition.properties, referenced.properties);
delete referenced.properties;
}
$.extend(expanded_class_definition, referenced);
}
}
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 = expandSchema(full_schema.class_definition[// 2 here is for #/
referenced.$ref.substr(2, referenced.$ref.length)], full_schema);
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)) {
if (referenced.properties[property].type) {
//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]);
}
}
}
......@@ -384,6 +453,7 @@
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();
}
......
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