Commit 6edd92c8 authored by Sebastien Robin's avatar Sebastien Robin

erp5_test_result: simplify performance graph gadget code by using renderjs recent features

parent 349b9a44
/*jslint indent: 2, nomen: true */ /*jslint indent: 2, nomen: true */
/*global window, rJS, RSVP, console, loopEventListener */ /*global window, rJS, RSVP, console */
(function (window, rJS, RSVP, loopEventListener) { (function (window, rJS, RSVP) {
"use strict"; "use strict";
var WIDGET_GRAPH_URL = "../gadget_officejs_widget_graph_chart.html"; var WIDGET_GRAPH_URL = "../gadget_officejs_widget_graph_chart.html";
...@@ -23,8 +23,8 @@ ...@@ -23,8 +23,8 @@
function getCheckDateAndRefreshGraphFunction(gadget) { function getCheckDateAndRefreshGraphFunction(gadget) {
return function checkDateAndRefreshGraph() { return function checkDateAndRefreshGraph() {
var from_date, at_date, i; var from_date, at_date, i;
from_date = gadget.property_dict.element.querySelector('[name="from_date"]').value; from_date = gadget.element.querySelector('[name="from_date"]').value;
at_date = gadget.property_dict.element.querySelector('[name="at_date"]').value; at_date = gadget.element.querySelector('[name="at_date"]').value;
if (at_date !== "" && from_date !== "") { if (at_date !== "" && from_date !== "") {
console.log("will need to get data"); console.log("will need to get data");
return gadget.jio_allDocs({ return gadget.jio_allDocs({
...@@ -70,12 +70,8 @@ ...@@ -70,12 +70,8 @@
rJS(window) rJS(window)
.ready(function (gadget) { .ready(function (gadget) {
gadget.property_dict = {}; gadget.property_dict = {
return gadget.getElement() };
.push(function (element) {
gadget.property_dict.element = element;
gadget.property_dict.deferred = RSVP.defer();
});
}) })
////////////////////////////////////////////// //////////////////////////////////////////////
...@@ -90,35 +86,22 @@ ...@@ -90,35 +86,22 @@
console.log("gadget_erp5_test_result_performance_graph, render, options", option_dict); console.log("gadget_erp5_test_result_performance_graph, render, options", option_dict);
var gadget = this; var gadget = this;
gadget.property_dict.option_dict = option_dict.value; gadget.property_dict.option_dict = option_dict.value;
return new RSVP.Queue() gadget.renderGraph(); //Launch as a service, not blocking, we could run other job if we wish.
.push(function () {
return gadget.property_dict.deferred.resolve();
});
}) })
///////////////////////////////////////// /////////////////////////////////////////
// Render text content gadget // Render text content gadget
///////////////////////////////////////// /////////////////////////////////////////
.declareService(function () { .declareJob("renderGraph", function () {
var gadget = this, var gadget = this,
graph_gadget = null; graph_gadget = null;
return new RSVP.Queue() return gadget.declareGadget(
.push(function () {
return gadget.property_dict.deferred.promise;
})
.push(function () {
return RSVP.all([
gadget.declareGadget(
WIDGET_GRAPH_URL, WIDGET_GRAPH_URL,
{ {
scope: "graph", scope: "graph",
element: gadget.property_dict.element.querySelector(".document-content") element: gadget.element.querySelector(".document-content")
})
]);
}) })
.push(function (graph_gadget) {
.push(function (result) {
graph_gadget = result[0];
gadget.property_dict.graph_widget = graph_gadget; gadget.property_dict.graph_widget = graph_gadget;
gadget.property_dict.graph_data_dict = {data: [{ gadget.property_dict.graph_data_dict = {data: [{
value_dict: {0: [], value_dict: {0: [],
...@@ -138,31 +121,18 @@ ...@@ -138,31 +121,18 @@
var now = new Date(), last_month, tomorrow; var now = new Date(), last_month, tomorrow;
last_month = new Date(now.valueOf() - 86400 * 1000 * 30); // - 30 days last_month = new Date(now.valueOf() - 86400 * 1000 * 30); // - 30 days
tomorrow = new Date(now.valueOf() + 86400 * 1000 * 1); // + 1 day tomorrow = new Date(now.valueOf() + 86400 * 1000 * 1); // + 1 day
gadget.property_dict.element.querySelector('[name="from_date"]').value = getDateAsString(last_month); gadget.element.querySelector('[name="from_date"]').value = getDateAsString(last_month);
gadget.property_dict.element.querySelector('[name="at_date"]').value = getDateAsString(tomorrow); gadget.element.querySelector('[name="at_date"]').value = getDateAsString(tomorrow);
}) })
.push(function () { .push(function () {
getCheckDateAndRefreshGraphFunction(gadget)(); return getCheckDateAndRefreshGraphFunction(gadget)();
});
})
.declareService(function () {
var gadget = this;
return loopEventListener(
gadget.property_dict.element.querySelector('[name="from_date"]'),
'change',
false,
function () {
getCheckDateAndRefreshGraphFunction(gadget)();
}); });
}) })
.declareService(function () { .onEvent('change', function (evt) {
var gadget = this; if (evt.target === this.element.querySelector('[name="from_date"]')) {
return loopEventListener( return getCheckDateAndRefreshGraphFunction(this)();
gadget.property_dict.element.querySelector('[name="at_date"]'), } else if (evt.target === this.element.querySelector('[name="at_date"]')) {
'change', return getCheckDateAndRefreshGraphFunction(this)();
false, }
function () {
getCheckDateAndRefreshGraphFunction(gadget)();
});
}); });
}(window, rJS, RSVP, loopEventListener)); }(window, rJS, RSVP));
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