Commit 3e9f4a0d authored by Jérome Perrin's avatar Jérome Perrin

Input_viewResultComparison: New widget to show results and compare order lateness

parent e4980345
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Result List</title>
<script src="../<%= copy.rsvp.relative_dest %>" type="text/javascript"></script>
<script src="../<%= copy.renderjs.relative_dest %>" type="text/javascript"></script>
<script src="../<%= copy.handlebars.relative_dest %>" type="text/javascript"></script>
<script src="mixin_gadget.js" type="text/javascript"></script>
<script src="Input_viewResultComparison.js" type="text/javascript"></script>
</head>
<body>
<div data-gadget-url="../handsontable/index.html"
data-gadget-scope="tableeditor"></div>
</body>
</html>
/*global rJS, RSVP, initGadgetMixin, jQuery */
/*jslint loopfunc: true */
/*jslint nomen: true */
(function (window, rJS, RSVP, initGadgetMixin, $) {
"use strict";
var gadget_klass = rJS(window);
initGadgetMixin(gadget_klass);
gadget_klass
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("aq_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("whoWantsToDisplayThisResult",
"whoWantsToDisplayThisResult")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("render", function (options) {
var gadget = this, order_lateness = {};
this.props.jio_key = options.id;
return gadget.aq_getAttachment({
"_id": gadget.props.jio_key,
"_attachment": "body.json"
})
.push(undefined, function (error) {
if (error.status_code === 404) {
// Simulation not yet generated
return JSON.stringify([]);
}
throw error;
})
.push(function (sim_json) {
var result = JSON.parse(sim_json).result,
result_list = [],
document_list = [],
i;
if (result && result.result_list) {
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]
]));
}
return RSVP.all(result_list);
})
.push(function (result_list) {
var i, link, result,
calculateOrderLateness = function(order_id) {
var order = result.order_lateness[order_id];
order.link = link;
if (!order_lateness[order_id]){
order_lateness[order_id] = [];
}
order_lateness[order_id].push(order);
};
for (i=0; i<result_list.length; i++) {
link = result_list[i][0];
result = result_list[i][1];
Object.keys(result.order_lateness).forEach(calculateOrderLateness);
}
return gadget.getDeclaredGadget("tableeditor");
})
.push(function(tableeditor) {
var i,
data = [],
colHeaders = ["Project"],
columns = [{data: 0}];
Object.keys(order_lateness).forEach(function(order_id) {
var order = order_lateness[order_id];
order.unshift(order_id);
data.push(order);
});
function orderHtmlRenderer(instance, td, row, col, prop, value, cellProperties) {
var a, color = "yellow";
if (value.delay < .5) {
color = "green";
}
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;
}
for (i=1; i < data[0].length; i+=1) {
colHeaders.push("Solution #" + i);
columns.push({data: i, renderer: orderHtmlRenderer})
}
return tableeditor.render(
JSON.stringify(data),
{
colHeaders: colHeaders,
columns: columns,
readOnly: true
}
);
});
})
.declareMethod("startService", function () {
var gadget = this;
return this.getDeclaredGadget("tableeditor")
.push(function (tableeditor) {
return tableeditor.startService();
});
});
}(window, rJS, RSVP, initGadgetMixin, jQuery));
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