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

update static version

parent 62a9d57f
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
var gadget_klass = rJS(window); var gadget_klass = rJS(window);
initGadgetMixin(gadget_klass); initGadgetMixin(gadget_klass);
gadget_klass.declareAcquiredMethod("aq_getAttachment", "jio_getAttachment").declareAcquiredMethod("whoWantsToDisplayThisResult", "whoWantsToDisplayThisResult").declareMethod("render", function(options) { gadget_klass.declareAcquiredMethod("aq_getAttachment", "jio_getAttachment").declareAcquiredMethod("whoWantsToDisplayThisResult", "whoWantsToDisplayThisResult").declareMethod("render", function(options) {
var gadget = this, order_lateness = {}; var gadget = this, order_lateness = {}, general_json;
this.props.jio_key = options.id; this.props.jio_key = options.id;
return gadget.aq_getAttachment({ return gadget.aq_getAttachment({
_id: gadget.props.jio_key, _id: gadget.props.jio_key,
...@@ -17,7 +17,8 @@ ...@@ -17,7 +17,8 @@
} }
throw error; throw error;
}).push(function(sim_json) { }).push(function(sim_json) {
var result = JSON.parse(sim_json).result, result_list = [], document_list = [], i; var json = JSON.parse(sim_json), result = json.result, result_list = [], document_list = [], i;
general_json = result;
if (result && result.result_list) { if (result && result.result_list) {
document_list = result.result_list; document_list = result.result_list;
} }
...@@ -26,56 +27,62 @@ ...@@ -26,56 +27,62 @@
} }
return RSVP.all(result_list); return RSVP.all(result_list);
}).push(function(result_list) { }).push(function(result_list) {
var i, link, result, calculateOrderLateness = function(order_id) { var i, link, result, scenario_id, calculateOrderLateness = function(order_id) {
var order = result.order_lateness[order_id]; var order = result.order_lateness[order_id];
order.link = link; order.link = link;
if (!order_lateness[order_id]) { if (!order_lateness[order_id]) {
order_lateness[order_id] = []; order_lateness[order_id] = {};
} }
order_lateness[order_id].push(order); order_lateness[order_id][scenario_id] = order;
}; };
for (i = 0; i < result_list.length; i += 1) { for (i = 0; i < result_list.length; i += 1) {
scenario_id = result_list[i][1].name || i;
link = result_list[i][0]; link = result_list[i][0];
result = result_list[i][1]; result = result_list[i][1];
Object.keys(result.order_lateness).forEach(calculateOrderLateness); Object.keys(result.order_lateness).forEach(calculateOrderLateness);
} }
return gadget.getDeclaredGadget("tableeditor"); return gadget.getDeclaredGadget("tableeditor");
}).push(function(tableeditor) { }).push(function(tableeditor) {
var i, data = [], colHeaders = [ "Project" ], columns = [ { var i, data = {}, data_list = [], colHeaders = [ "Project" ], columns = [ {
data: 0 data: "id"
} ]; } ];
Object.keys(order_lateness).forEach(function(order_id) { Object.keys(order_lateness).forEach(function(order_id) {
var order = order_lateness[order_id]; var order = order_lateness[order_id];
order.unshift(order_id); order.id = order_id;
data.push(order); data[order_id] = order;
}); });
/*jslint unparam: true */ /*jslint unparam: true */
function orderHtmlRenderer(instance, td, row, col, prop, value, cellProperties) { function orderHtmlRenderer(instance, td, row, col, prop, value, cellProperties) {
var a, color = "yellow"; var a, color = "yellow";
if (value.delay < .5) { if (value) {
color = "green"; if (value.delay < .5) {
color = "green";
}
if (value.delay > .5) {
color = "red";
}
$(td).text("").css({
"background-color": color
});
a = $("<a>").attr("href", value.link).text(value.completionDate + "\n" + (value.delay || 0).toFixed(0)).css({
color: "black",
"text-shadow": "none"
});
a.appendTo(td);
} }
if (value.delay > .5) {
color = "red";
}
$(td).css({
"background-color": color
});
a = $("<a>").attr("href", value.link).text(value.completionDate + "\n" + (value.delay || 0).toFixed(0)).css({
color: "black",
"text-shadow": "none"
});
a.appendTo(td);
return td; return td;
} }
for (i = 1; i < data[0].length; i += 1) { for (i = 0; i < general_json.result_list.length; i += 1) {
colHeaders.push("Solution #" + i); colHeaders.push(general_json.result_list[i].name || "Solution #" + (i + 1));
columns.push({ columns.push({
data: i, data: general_json.result_list[i].name || i,
renderer: orderHtmlRenderer renderer: orderHtmlRenderer
}); });
} }
return tableeditor.render(JSON.stringify(data), { Object.keys(data).forEach(function(order_id) {
data_list.push(order_lateness[order_id]);
});
return tableeditor.render(JSON.stringify(data_list), {
colHeaders: colHeaders, colHeaders: colHeaders,
columns: columns, columns: columns,
readOnly: true readOnly: true
......
...@@ -2,25 +2,10 @@ ...@@ -2,25 +2,10 @@
(function(window, $, rJS, JSON, RSVP) { (function(window, $, rJS, JSON, RSVP) {
"use strict"; "use strict";
rJS(window).declareMethod("render", function(content, options) { rJS(window).declareMethod("render", function(content, options) {
var data = JSON.parse(content), i, ctrlflag = true, def = []; var data = JSON.parse(content);
// if the content is not an array of arrays then create one
// from the content
for (i = 0; i <= data.length - 1; i += 1) {
if (!(data[i].constructor === Array)) {
def.push(data[i].name);
} else {
// otherwise do not modify anything
def = data;
ctrlflag = false;
break;
}
}
if (ctrlflag) {
def = [ def ];
}
return this.getElement().push(function(element) { return this.getElement().push(function(element) {
$(element).find(".table-container").handsontable($.extend({ $(element).find(".table-container").handsontable($.extend({
data: def, data: data,
stretchH: "all" stretchH: "all"
}, options || {})); }, options || {}));
}); });
......
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