Commit 5c6100c0 authored by Alain Takoudjou's avatar Alain Takoudjou

[erp5_web_monitoring] load graph using declareJob to prevent slowing down the page rendering

parent 807afa79
...@@ -114,7 +114,7 @@ ...@@ -114,7 +114,7 @@
"portal_type": [], "portal_type": [],
"search_column_list": column_list, "search_column_list": column_list,
"sort_column_list": column_list, "sort_column_list": column_list,
"sort": [["title", "ascending"], ["status", "ascending"]], "sort": [["status", "ascending"]],
"title": "Software Instances", "title": "Software Instances",
"type": "ListBox" "type": "ListBox"
} }
......
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>964.14466.37435.3993</string> </value> <value> <string>964.14467.38710.51797</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1513620695.39</float> <float>1514302362.58</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
</head> </head>
<body> <body>
<div data-gadget-url="gadget_officejs_monitoring_jio.html" data-gadget-scope="jio_gadget" data-gadget-sandbox="public"></div>
<form> <form>
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline <button type="submit" class="ui-btn ui-btn-b ui-btn-inline
ui-icon-edit ui-btn-icon-right ui-screen-hidden"></button> ui-icon-edit ui-btn-icon-right ui-screen-hidden"></button>
......
...@@ -250,7 +250,7 @@ ...@@ -250,7 +250,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.33703.32471.53657</string> </value> <value> <string>963.33703.45054.40584</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -268,7 +268,7 @@ ...@@ -268,7 +268,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1510929101.2</float> <float>1514370578.19</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -10,18 +10,11 @@ ...@@ -10,18 +10,11 @@
link_template = Handlebars.compile(source); link_template = Handlebars.compile(source);
gadget_klass gadget_klass
.setState({ .setState({
jio_gadget: "",
instance: "", instance: "",
opml: "", opml: "",
opml_outline: "", opml_outline: "",
graph_value: {} graph_value: {}
}) })
.ready(function (gadget) {
return gadget.getDeclaredGadget("jio_gadget")
.push(function (jio_gadget) {
return gadget.changeState({"jio_gadget": jio_gadget});
});
})
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Acquired methods // Acquired methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
...@@ -30,7 +23,6 @@ ...@@ -30,7 +23,6 @@
.declareAcquiredMethod("getUrlFor", "getUrlFor") .declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("jio_get", "jio_get") .declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs") .declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
.declareAcquiredMethod("translateHtml", "translateHtml") .declareAcquiredMethod("translateHtml", "translateHtml")
.declareAcquiredMethod("redirect", "redirect") .declareAcquiredMethod("redirect", "redirect")
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
...@@ -61,16 +53,6 @@ ...@@ -61,16 +53,6 @@
opml: opml_doc opml: opml_doc
}); });
}) })
.push(function () {
return gadget.state.jio_gadget.createJio({
type: "webhttp",
// XXX fix of url
url: gadget.state.instance._links.private_url.href
.replace("jio_private", "private") +
'documents/',
basic_login: gadget.state.opml.basic_login
});
})
.push(function () { .push(function () {
return gadget.getUrlFor({command: 'push_history', options: { return gadget.getUrlFor({command: 'push_history', options: {
jio_key: options.doc.reference, jio_key: options.doc.reference,
...@@ -197,82 +179,78 @@ ...@@ -197,82 +179,78 @@
}) })
.onStateChange(function () { .onStateChange(function () {
var gadget = this, var gadget = this,
graph_value = {}; graph_data;
if (!gadget.state.hasOwnProperty('status') && if (!gadget.state.hasOwnProperty('status') &&
!gadget.state.hasOwnProperty('title')) { !gadget.state.hasOwnProperty('title')) {
return; return;
} }
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
// Move this to not slow down the page rendering... var graph_options = {
return gadget.state.jio_gadget.get( data_url: gadget.state.instance._links.private_url.href +
gadget.state.instance.data.state 'documents/',
) data_filename: gadget.state.instance.data.state,
.push(undefined, function (error) { basic_login: gadget.state.opml.basic_login
return gadget.notifySubmitted({ };
message: "Warning: Failed to download monitoring state history file!\n " +
error.message || "",
status: "error"
})
.push(function () {
return {};
});
})
.push(function (element_dict) {
var promise_data = [
"Date, Success, Error, Warning",
new Date() + ",0,0,0"
],
data = element_dict.data || promise_data,
data_list = [],
line_list,
i;
data_list.push({ graph_options.extract_method = function (element_dict) {
value_dict: {"0": [], "1": []}, var promise_data = [
type: "scatter", "Date, Success, Error",
axis_mapping_id_dict: {"1": "1_1"}, new Date() + ",0,0"
title: "promises success" ],
}); data = element_dict.data || promise_data,
data_list.push({ data_list = [],
value_dict: {"0": [], "1": []}, line_list,
type: "scatter", i;
axis_mapping_id_dict: {"1": "1_2"},
title: "promises error"
});
for (i = 1; i < data.length; i += 1) {
line_list = data[i].split(',');
data_list[0].value_dict["0"].push(line_list[0]);
data_list[0].value_dict["1"].push(line_list[1]);
// XXX repeating date entry data_list.push({
data_list[1].value_dict["0"].push(line_list[0]); value_dict: {"0": [], "1": []},
data_list[1].value_dict["1"].push(line_list[2]); type: "scatter",
} axis_mapping_id_dict: {"1": "1_1"},
graph_value = { title: "promises success"
data: data_list,
layout: {
axis_dict : {
"0": {
"title": "Success/Failure Progression",
"scale_type": "linear",
"value_type": "date"
},
"1_1": {
"title": "Promises success",
"position": "right"
},
"1_2": {
"title": "Promises error",
"position": "right"
}
},
title: "Success/Failure Progression"
}
};
}); });
data_list.push({
value_dict: {"0": [], "1": []},
type: "scatter",
axis_mapping_id_dict: {"1": "1_2"},
title: "promises error"
});
for (i = 1; i < data.length; i += 1) {
line_list = data[i].split(',');
data_list[0].value_dict["0"].push(line_list[0]);
data_list[0].value_dict["1"].push(line_list[1]);
// XXX repeating date entry
data_list[1].value_dict["0"].push(line_list[0]);
data_list[1].value_dict["1"].push(line_list[2]);
}
return data_list;
};
graph_options.data_dict = {
data: {},
layout: {
axis_dict : {
"0": {
"title": "Promises Failure Progression",
"scale_type": "linear",
"value_type": "date"
},
"1_1": {
"title": "Promises success",
"position": "right"
},
"1_2": {
"title": "Promises error",
"position": "right"
}
},
title: "Promises Failure Progression"
}
};
return graph_options;
}) })
.push(function () { .push(function (g) {
graph_data = g;
//gadget.element.querySelector('.template-view').innerHTML = html; //gadget.element.querySelector('.template-view').innerHTML = html;
return gadget.getDeclaredGadget('form_view'); return gadget.getDeclaredGadget('form_view');
}) })
...@@ -486,9 +464,9 @@ ...@@ -486,9 +464,9 @@
css_class: "no_label", css_class: "no_label",
description: "The Graph Status", description: "The Graph Status",
hidden: 0, hidden: 0,
"default": graph_value || {}, "default": graph_data,
key: "graph_status", key: "graph_status",
url: "gadget_field_graph_dygraph.html", url: "gadget_ojsm_graph_field.html",
title: "", title: "",
type: "GadgetField" type: "GadgetField"
} }
......
...@@ -250,7 +250,7 @@ ...@@ -250,7 +250,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.33702.55453.15257</string> </value> <value> <string>964.26968.43905.35072</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -268,7 +268,7 @@ ...@@ -268,7 +268,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1510929159.97</float> <float>1514370868.02</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -108,7 +108,7 @@ ...@@ -108,7 +108,7 @@
<item> <item>
<key> <string>text_content</string> </key> <key> <string>text_content</string> </key>
<value> <string>CACHE MANIFEST\n <value> <string>CACHE MANIFEST\n
# generated on Fri, 15 Nov 2017 15:47:33 +0000\n # generated on Fri, 27 Dec 2017 11:48:33 +0000\n
# XXX + fonts\n # XXX + fonts\n
# images/ajax-loader.gif\n # images/ajax-loader.gif\n
CACHE:\n CACHE:\n
...@@ -224,6 +224,7 @@ gadget_erp5_page_ojsm_erp5_configurator.html\n ...@@ -224,6 +224,7 @@ gadget_erp5_page_ojsm_erp5_configurator.html\n
gadget_erp5_page_ojsm_jump.html\n gadget_erp5_page_ojsm_jump.html\n
gadget_officejs_monitoring_opml_edit.html\n gadget_officejs_monitoring_opml_edit.html\n
gadget_erp5_page_ojsm_dispatch.html\n gadget_erp5_page_ojsm_dispatch.html\n
gadget_ojsm_graph_field.html\n
\n \n
# monitoring js\n # monitoring js\n
gadget_officejs_monitoring_jio.js\n gadget_officejs_monitoring_jio.js\n
...@@ -251,6 +252,7 @@ gadget_erp5_page_ojsm_jump.js\n ...@@ -251,6 +252,7 @@ gadget_erp5_page_ojsm_jump.js\n
gadget_erp5_page_ojsm_erp5_configurator.js\n gadget_erp5_page_ojsm_erp5_configurator.js\n
gadget_officejs_monitoring_opml_edit.js\n gadget_officejs_monitoring_opml_edit.js\n
gadget_erp5_page_ojsm_dispatch.js\n gadget_erp5_page_ojsm_dispatch.js\n
gadget_ojsm_graph_field.js\n
\n \n
# erp5_web_renderjs_ui\n # erp5_web_renderjs_ui\n
gadget_erp5_editor_panel.html\n gadget_erp5_editor_panel.html\n
...@@ -385,7 +387,7 @@ NETWORK:\n ...@@ -385,7 +387,7 @@ NETWORK:\n
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.40590.4483.37222</string> </value> <value> <string>964.26988.39431.42120</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -403,7 +405,7 @@ NETWORK:\n ...@@ -403,7 +405,7 @@ NETWORK:\n
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1511342469.81</float> <float>1514371963.04</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>ERP5 Gadget Graph</title>
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<!-- custom script -->
<script src="gadget_ojsm_graph_field.js" type="text/javascript"></script>
</head>
<body>
<div data-gadget-url="gadget_officejs_monitoring_jio.html" data-gadget-scope="jio_gadget" data-gadget-sandbox="public"></div>
<div data-gadget-url="gadget_field_graph_dygraph.html" data-gadget-scope="graph_gadget" data-gadget-sandbox="public"></div>
</body>
</html>
\ No newline at end of file
/*global window, rJS, RSVP */
/*jslint indent: 2, maxerr: 3 */
(function (window, rJS, RSVP) {
"use strict";
function displayGraph(gadget, data) {
return gadget.getDeclaredGadget('graph_gadget')
.push(function (graph_gadget) {
return graph_gadget.render({value: data});
});
}
rJS(window)
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
.declareMethod('render', function (options) {
var field_json = options || {},
state_dict = {
data_dict: field_json.value.data_dict,
data_url: field_json.value.data_url,
data_filename: field_json.value.data_filename,
extract_method: field_json.value.extract_method,
basic_login: field_json.value.basic_login
};
return this.changeState(state_dict);
})
.onStateChange(function () {
return this.renderGraph();
})
.declareJob('renderGraph', function () {
var gadget = this,
jio_gadget;
if (gadget.state.data_url !== undefined &&
gadget.state.data_filename !== undefined) {
return gadget.getDeclaredGadget("jio_gadget")
.push(function (g) {
jio_gadget = g;
return jio_gadget.createJio({
type: "webhttp",
// XXX fix of url
url: gadget.state.data_url.replace("jio_private", "private"),
basic_login: gadget.state.basic_login
});
})
.push(function () {
return jio_gadget.get(
gadget.state.data_filename
);
})
.push(undefined, function (error) {
gadget.state.data_dict.data = {};
return gadget.notifySubmitted({
message: "Warning: Failed to download graph data file '" +
gadget.state.data_filename + "'!\n " + error.message || "",
status: "error"
})
.push(function () {
return undefined;
});
})
.push(function (data_result) {
if (data_result !== undefined &&
gadget.state.extract_method !== undefined) {
return new RSVP.Queue()
.push(function () {
return gadget.state.extract_method(
data_result,
gadget.state.data_filename
);
})
.push(function (result) {
gadget.state.data_dict.data = result;
return displayGraph(gadget, gadget.state.data_dict);
});
}
return displayGraph(gadget, gadget.state.data_dict);
});
}
return displayGraph(gadget, gadget.state.data_dict);
});
}(window, rJS, RSVP));
\ No newline at end of file
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
<!-- renderjs --> <!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script> <script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script> <script src="renderjs.js" type="text/javascript"></script>
<script src="handlebars.js"></script>
<!-- custom script --> <!-- custom script -->
<script src="gadget_erp5_field_status.js" type="text/javascript"></script> <script src="gadget_erp5_field_status.js" type="text/javascript"></script>
<script id="template-status-field" type="text/x-handlebars-template"> <script id="template-status-field" type="text/x-handlebars-template">
......
...@@ -111,7 +111,7 @@ ...@@ -111,7 +111,7 @@
</item> </item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
<value> <string>passwordGadget ERP5 Statusfield</string> </value> <value> <string>Gadget ERP5 Statusfield</string> </value>
</item> </item>
<item> <item>
<key> <string>version</string> </key> <key> <string>version</string> </key>
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.8986.63671.20514</string> </value> <value> <string>964.25935.32773.12561</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1509446386.76</float> <float>1514308778.96</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
web_page_module/gadget_erp5_field_status_* web_page_module/gadget_erp5_field_status_*
web_page_module/gadget_erp5_page_ojsm_* web_page_module/gadget_erp5_page_ojsm_*
web_page_module/gadget_ojsm_*
web_page_module/gadget_erp5_page_settings_configurator_* web_page_module/gadget_erp5_page_settings_configurator_*
web_page_module/gadget_officejs_jio_software_instance_view_html web_page_module/gadget_officejs_jio_software_instance_view_html
web_page_module/gadget_officejs_jio_software_instance_view_js web_page_module/gadget_officejs_jio_software_instance_view_js
......
web_page_module/gadget_erp5_field_status_* web_page_module/gadget_erp5_field_status_*
web_page_module/gadget_erp5_page_ojsm_* web_page_module/gadget_erp5_page_ojsm_*
web_page_module/gadget_ojsm_*
web_page_module/gadget_erp5_page_settings_configurator_* web_page_module/gadget_erp5_page_settings_configurator_*
web_page_module/gadget_officejs_jio_software_instance_view_html web_page_module/gadget_officejs_jio_software_instance_view_html
web_page_module/gadget_officejs_jio_software_instance_view_js web_page_module/gadget_officejs_jio_software_instance_view_js
......
...@@ -8,6 +8,7 @@ web_page_module/gadget_officejs_jio_promise_view_js ...@@ -8,6 +8,7 @@ web_page_module/gadget_officejs_jio_promise_view_js
web_page_module/gadget_officejs_jio_software_instance_view_html web_page_module/gadget_officejs_jio_software_instance_view_html
web_page_module/gadget_officejs_jio_software_instance_view_js web_page_module/gadget_officejs_jio_software_instance_view_js
web_page_module/gadget_officejs_monitoring_* web_page_module/gadget_officejs_monitoring_*
web_page_module/gadget_ojsm_*
web_page_module/jsen_json_validator_js web_page_module/jsen_json_validator_js
web_page_module/monitoring_jio_storage_js web_page_module/monitoring_jio_storage_js
web_page_module/monitoring_jio_web_storage_js web_page_module/monitoring_jio_web_storage_js
......
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