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

GUI: new gadget to compare spreadsheet using daff

parent 70f7552f
/*global jQuery, rJS, window, JSON, daff */
(function (window, $, rJS, JSON, daff) {
"use strict";
rJS(window)
.declareMethod('render', function (content) {
var flags, highlighter, diff2html, table_diff, table_diff_html,
data_diff = [],
data = JSON.parse(content),
table1 = new daff.TableView(data[0]),
table2 = new daff.TableView(data[1]),
alignment = daff.compareTables(table1,table2).align();
table_diff = new daff.TableView(data_diff);
flags = new daff.CompareFlags();
highlighter = new daff.TableDiff(alignment,flags);
highlighter.hilite(table_diff);
diff2html = new daff.DiffRender();
diff2html.render(table_diff);
table_diff_html = diff2html.html();
return this.getElement()
.push(function (element) {
$(element).html(table_diff_html);
});
});
}(window, jQuery, rJS, JSON, daff));
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script src="../<%= curl.jquery.relative_dest %>"></script>
<script src="../<%= copy.rsvp.relative_dest %>"></script>
<script src="../<%= copy.renderjs.relative_dest %>"></script>
<script src="../<%= curl.daff.relative_dest %>"></script>
<script src="daff.js"></script>
</head>
<body>
<div class="table-diff"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Compare Spreadsheet</title>
<script src="../<%= copy.rsvp.relative_dest %>" type="text/javascript"></script>
<script src="../<%= copy.renderjs.relative_dest %>" type="text/javascript"></script>
<script src="../<%= curl.jquery.relative_dest %>" type="text/javascript"></script>
<script src="../<%= curl.jquerymobilejs.relative_dest %>" type="text/javascript"></script>
<script src="mixin_gadget.js" type="text/javascript"></script>
<script src="mixin_promise.js" type="text/javascript"></script>
<script src="Output_viewSpreadsheetComparison.js" type="text/javascript"></script>
</head>
<body>
<div data-gadget-url="../daff/index.html"
data-gadget-scope="tablediff"></div>
<a class="set_reference_schedule_button ui-btn ui-btn-b ui-btn-inline
ui-icon-refresh ui-btn-icon-right">Set current schedule as reference</a>
</body>
</html>
/*global rJS, RSVP, initGadgetMixin, promiseEventListener, $, setTimeout */
(function (window, rJS, RSVP, initGadgetMixin, promiseEventListener, $) {
"use strict";
var gadget_klass = rJS(window);
initGadgetMixin(gadget_klass);
gadget_klass
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("aq_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("aq_putAttachment", "jio_putAttachment")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("render", function (options) {
var jio_key = options.id,
gadget = this;
gadget.props.jio_key = jio_key;
return new RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.aq_getAttachment({
"_id": jio_key,
"_attachment": "body.json"
}),
gadget.getDeclaredGadget("tablediff")
]);
})
.push(function (result_list){
var reference_spreadsheet = JSON.parse(result_list[0]).input.reference_spreadsheet || [],
new_spreadsheet = JSON.parse(result_list[0]).result.result_list[options.result][options.action_definition.configuration.output_id];
gadget.props.new_spreadsheet = new_spreadsheet;
return result_list[1].render(JSON.stringify([reference_spreadsheet, new_spreadsheet]));
});
})
.declareMethod("startService", function () {
var gadget = this;
return new RSVP.Queue()
.push(function () {
return promiseEventListener(
gadget.props.element.querySelector(".set_reference_schedule_button"),
'click',
false
);
}).push(function() {
return gadget.aq_getAttachment({
_id: gadget.props.jio_key,
_attachment: "body.json"
});
}).push(function (data) {
var object_data = JSON.parse(data);
// XXX option for that
object_data.input.reference_spreadsheet = gadget.props.new_spreadsheet;
return gadget.aq_putAttachment({
"_id": gadget.props.jio_key,
"_attachment": "body.json",
"_data": JSON.stringify(object_data)
}).push(function (){
// XXX quick way to get a popup message
$.mobile.loading( 'show', { text: "Current schedule set as reference", textVisible: true, textonly: true });
setTimeout(function () { $.mobile.loading( "hide" ); }, 1000);
});
});
});
}(window, rJS, RSVP, initGadgetMixin, promiseEventListener, $));
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