Commit 76584479 authored by Alain Takoudjou's avatar Alain Takoudjou

[erp5_web_monitoring] fix jslint, remove useless code and use more renderjs and RSVP methods

make all javascript code compliant with jslint
use renderjs declarejob instead of rsvp defer
use RSVP.delay in replacement of setTimeout for background sync
factorise opml add/view gadget and remove global OPMLManage
parent 65570efd
/*global window, rJS, RSVP, Handlebars */
/*global window, rJS, Handlebars */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, Handlebars) {
(function (window, rJS, Handlebars) {
"use strict";
var gadget_klass = rJS(window),
......@@ -32,7 +32,6 @@
page_title: "Jump to Object"
});
});
});
}(window, rJS, RSVP, Handlebars));
\ No newline at end of file
}(window, rJS, Handlebars));
\ No newline at end of file
......@@ -238,7 +238,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.3579.43071.5205</string> </value>
<value> <string>963.29379.61141.36334</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -256,7 +256,7 @@
</tuple>
<state>
<tuple>
<float>1509121711.67</float>
<float>1510669689.61</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -104,7 +104,8 @@
var gadget = this;
return getHostingData(gadget, param_list[0])
.push(function (result) {
var i, value, len = result.data.total_rows;
var i,
len = result.data.total_rows;
for (i = 0; i < len; i += 1) {
if (result.data.rows[i].value.hasOwnProperty("date")) {
result.data.rows[i].value.date = {
......@@ -171,7 +172,7 @@
lines_limit;
return new RSVP.Queue()
.push(function () {
return gadget.getSetting("listbox_lines_limit", 100);
return gadget.getSetting("listbox_lines_limit", 20);
})
.push(function (listbox_lines_limit) {
lines_limit = listbox_lines_limit;
......@@ -224,7 +225,7 @@
}
});
})
.push(function (result) {
.push(function () {
return gadget.updateHeader({
page_title: "Hosting Subscriptions Status",
filter_action: true
......
......@@ -239,7 +239,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.19077.52757.17169</string> </value>
<value> <string>963.27984.14453.52343</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -257,7 +257,7 @@
</tuple>
<state>
<tuple>
<float>1510052055.87</float>
<float>1510766156.1</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, document, Handlebars, Rusha */
/*global window, rJS, document, RSVP, Rusha, escape */
/*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, document, Handlebars, Rusha) {
(function (window, rJS, document, RSVP, Rusha, escape) {
"use strict";
var gadget_klass = rJS(window),
templater = gadget_klass.__template_element,
rusha = new Rusha();
function generateHash(str) {
......@@ -41,7 +40,9 @@
})
.push(function () {
var result = gadget.state.instance_dict,
i, value, len = result.data.total_rows;
i,
value,
len = result.data.total_rows;
for (i = 0; i < len; i += 1) {
if (result.data.rows[i].value.hasOwnProperty("date")) {
value = new Date(result.data.rows[i].value.date);
......@@ -91,8 +92,8 @@
.declareMethod("render", function (options) {
var gadget = this;
return gadget.updateHeader({
title: 'Hosting Subscriptions View'
})
title: 'Hosting Subscriptions View'
})
.push(function () {
return gadget.jio_get(options.opml_key);
})
......@@ -101,8 +102,8 @@
})
.push(function () {
return gadget.jio_allDocs({
query: '(portal_type:"opml-outline") AND (parent_id:"' +
generateHash(options.opml_key) + '")'
query: '(portal_type:"opml-outline") AND (parent_id:"' +
generateHash(options.opml_key) + '")'
});
})
.push(function (ouline_list) {
......@@ -122,28 +123,28 @@
return RSVP.all(promise_list);
})
.push(function (result_list) {
var i,
var j,
ok_to_save = true,
promise_list = [];
for (i = 0; i < result_list.length; i += 1) {
if (result_list[i].status !== 'OK') {
return_list = [];
for (j = 0; j < result_list.length; j += 1) {
if (result_list[j].status !== 'OK') {
ok_to_save = false;
break;
}
promise_list.push(gadget.props.parameter_form_list[i].saveContent());
return_list.push(gadget.props.parameter_form_list[j].saveContent());
}
if (ok_to_save) {
return RSVP.all(promise_list);
return RSVP.all(return_list);
}
// One of storage failed, cancel save to be consistent
return result_list;
})
.push(function (result_list) {
var msg_list = [],
i;
for (i = 0; i < result_list.length; i += 1) {
if (result_list[i].status !== "OK") {
msg_list.push(result_list[i].stage + " from " + result_list[i].url);
j;
for (j = 0; j < result_list.length; j += 1) {
if (result_list[j].status !== "OK") {
msg_list.push(result_list[j].stage + " from " + result_list[j].url);
}
}
if (msg_list.length > 0) {
......@@ -172,7 +173,6 @@
}
if (modification_dict.hasOwnProperty('instance_dict')) {
// render parameter form
return new RSVP.Queue()
.push(function () {
var promise_list = [],
......@@ -190,12 +190,10 @@
element.appendChild(gadget_element);
promise_list.push(
gadget.declareGadget("gadget_officejs_monitoring_parameter_view.html",
{
element: gadget_element,
{element: gadget_element,
scope: 'p_' + gadget.state.instance_dict.data.rows[i].id,
sandbox: "public"
}
)
sandbox: "public"}
)
);
}
return RSVP.all(promise_list);
......@@ -224,13 +222,13 @@
})
.push(function (form_list) {
var column_list = [
['title', 'Instance Title'],
['date', 'Status Date'],
['status', 'Status']
],
j,
key_list = [],
instance_query = '(portal_type:"global")';
['title', 'Instance Title'],
['date', 'Status Date'],
['status', 'Status']
],
j,
key_list = [],
instance_query = '(portal_type:"global")';
if (gadget.state.ouline_list.length === 0) {
return;
......@@ -309,4 +307,4 @@
});
});
}(window, rJS, document, Handlebars, Rusha));
\ No newline at end of file
}(window, rJS, document, RSVP, Rusha, escape));
\ No newline at end of file
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.20929.61143.52155</string> </value>
<value> <string>963.27984.14453.52343</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1510216762.18</float>
<float>1510586789.54</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, RSVP, jsen, Rusha, Handlebars, atob, btoa, DOMParser,
/*global window, rJS, RSVP, jsen, Handlebars, atob, btoa, DOMParser,
URLSearchParams */
/*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, RSVP, jsen, Rusha, Handlebars, atob, btoa, DOMParser,
(function (window, rJS, RSVP, jsen, Handlebars, atob, btoa, DOMParser,
URLSearchParams) {
"use strict";
......@@ -22,14 +22,14 @@
select_list: ["basic_login", "url", "title", "active"],
query: '(portal_type:"opml")'
})
.push(function (opml_result) {
var i,
opml_dict = {opml_description_list: []};
for (i = 0; i < opml_result.data.total_rows; i += 1) {
opml_dict.opml_description_list.push(opml_result.data.rows[i].value);
}
return opml_dict;
});
.push(function (opml_result) {
var i,
opml_dict = {opml_description_list: []};
for (i = 0; i < opml_result.data.total_rows; i += 1) {
opml_dict.opml_description_list.push(opml_result.data.rows[i].value);
}
return opml_dict;
});
}
function validateJsonConfiguration(json_value, uses_old_schema) {
......@@ -139,7 +139,7 @@
var is_old_schema = false;
gadget.state.message.textContent = "";
return new RSVP.Queue()
.push(function (form_doc) {
.push(function () {
var configuration_dict;
if (typeof config === 'string') {
try {
......@@ -231,14 +231,13 @@
}
return true;
});
} else {
gadget.state.message
.innerHTML = notify_msg_template({
status: 'error',
message: 'Error: Content is not a valid Monitoring Json configuration!'
});
return false;
}
gadget.state.message
.innerHTML = notify_msg_template({
status: 'error',
message: 'Error: Content is not a valid Monitoring Json configuration!'
});
return false;
})
.push(function (status) {
if (status) {
......@@ -297,13 +296,13 @@
limit = 100;
}
return gadget.state.erp5_gadget.allDocs({
query: '(portal_type:"Hosting Subscription") AND (validation_state:"validated")',
select_list: ['title', 'default_predecessor_uid', 'uid'],
limit: [0, limit],
sort_on: [
["creation_date", "descending"]
]
})
query: '(portal_type:"Hosting Subscription") AND (validation_state:"validated")',
select_list: ['title', 'default_predecessor_uid', 'uid'],
limit: [0, limit],
sort_on: [
["creation_date", "descending"]
]
})
.push(function (result) {
var i,
uid_search_list = [];
......@@ -530,9 +529,7 @@
});
})
.push(function () {
var hosting_subscription_list = [],
has_failed = false,
uid_dict = {};
var has_failed = false;
if (gadget.state.sync === "erp5" && gadget.state.storage_url) {
// start import from erp5 now
return gadget.notifySubmitting()
......@@ -548,8 +545,7 @@
.push(function (select_limit) {
return getInstanceOPMLListFromMaster(gadget, select_limit);
})
.push(undefined, function (error) {
console.log(error);
.push(undefined, function () {
gadget.state.message
.innerHTML = notify_msg_template({
status: 'error',
......@@ -593,12 +589,11 @@
message: "Failed to import Configurations",
status: "error"
});
} else {
return gadget.notifySubmitted({
message: "Configuration Saved!",
status: "success"
});
}
return gadget.notifySubmitted({
message: "Configuration Saved!",
status: "success"
});
})
.push(function () {
if (!has_failed) {
......@@ -611,5 +606,4 @@
}
});
});
}(window, rJS, RSVP, jsen, Rusha, Handlebars, atob, btoa, DOMParser,
URLSearchParams));
}(window, rJS, RSVP, jsen, Handlebars, atob, btoa, DOMParser, URLSearchParams));
......@@ -250,7 +250,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.21850.42337.9796</string> </value>
<value> <string>963.27920.40078.20411</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -268,7 +268,7 @@
</tuple>
<state>
<tuple>
<float>1510219191.94</float>
<float>1510582176.99</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -40,8 +40,7 @@
return RSVP.all(promise_list);
})
.push(function (result_list) {
var i,
tab_list = [];
var tab_list = [];
tab_list.push({
title: options.view_title || options.jio_key,
......
......@@ -238,7 +238,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.1691.38549.3618</string> </value>
<value> <string>963.27666.8050.30907</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -256,7 +256,7 @@
</tuple>
<state>
<tuple>
<float>1509095381.18</float>
<float>1510581537.14</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -9,20 +9,15 @@
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="handlebars.js"></script>
<script src="gadget_officejs_monitoring_global.js"></script>
<script src="gadget_erp5_page_ojsm_opml_add.js"></script>
<script id="template-message-error" type="text/x-handlebars-template">
<p><span class='ui-text-{{status}}'>{{message}}</span></p>
</script>
</head>
<body>
<div data-gadget-url="gadget_officejs_monitoring_jio.html" data-gadget-scope="jio_gadget" data-gadget-sandbox="public"></div>
<form class="save_form ui-body-c" novalidate>
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline
ui-icon-edit ui-btn-icon-right ui-screen-hidden"></button>
<div class="ui-message-alert"></div>
<div data-gadget-url="gadget_officejs_monitoring_opml_edit.html"
data-gadget-scope="opml_gadget" data-gadget-sandbox="public"></div>
<div data-gadget-url="gadget_erp5_form.html"
data-gadget-scope="form_view"
data-gadget-sandbox="public">
......
......@@ -250,7 +250,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.1898.2167.63078</string> </value>
<value> <string>963.27666.8050.30907</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -268,7 +268,7 @@
</tuple>
<state>
<tuple>
<float>1509020790.01</float>
<float>1510675648.98</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, RSVP, Handlebars, OPMLManage */
/*global window, rJS, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, Handlebars, OPMLManage) {
(function (window, rJS, RSVP) {
"use strict";
var gadget_klass = rJS(window),
templater = gadget_klass.__template_element,
notify_msg_template = Handlebars.compile(
templater.getElementById("template-message-error").innerHTML
),
opml_global = OPMLManage;
rJS(window)
gadget_klass
/////////////////////////////
// state
/////////////////////////////
.setState({
message: "",
redirect: true
})
/////////////////////////////
// ready
/////////////////////////////
.ready(function (gadget) {
return opml_global.init(gadget, notify_msg_template);
})
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
......@@ -31,7 +12,6 @@
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
......@@ -40,49 +20,29 @@
/////////////////////////////////////////////////////////////////
.onEvent('submit', function () {
var gadget = this,
opml_gadget,
doc;
return new RSVP.Queue()
.push(function () {
return gadget.getDeclaredGadget('form_view');
return gadget.getDeclaredGadget('opml_gadget');
})
.push(function (g) {
opml_gadget = g;
return gadget.getDeclaredGadget('form_view');
})
.push(function (form_gadget) {
return form_gadget.getContent();
})
.push(function (form_doc) {
doc = form_doc;
if (!opml_global.validateHttpUrl(form_doc.url)) {
gadget.state.message
.innerHTML = notify_msg_template({
status: 'error',
message: "'" + form_doc.url + "' is not a valid OPML URL"
});
return false;
}
if (!form_doc.username || !form_doc.password) {
gadget.state.message
.innerHTML = notify_msg_template({
status: 'error',
message: 'Username and password fields are required!'
});
return false;
}
if (form_doc.new_password &&
form_doc.new_password !== form_doc.confirm_new_password) {
gadget.state.message
.innerHTML = notify_msg_template({
status: 'error',
message: 'The new password and it confirmation are differents!'
});
return false;
}
return true;
return opml_gadget.checkOPMLForm(doc);
})
.push(function (state) {
if (state) {
return gadget.notifySubmitting()
.push(function () {
doc.title = "";
return opml_global.saveOPML(doc, true);
return opml_gadget.saveOPML(doc, true);
})
.push(function (status) {
var msg = {message: 'OPML document added', status: 'success'};
......@@ -95,10 +55,10 @@
]);
})
.push(function (result_list) {
if (result_list[1] && gadget.state.redirect) {
if (result_list[1]) {
return gadget.redirect({
"command": "change",
"options": {"page": "ojsm_status_list"}
"command": "display",
"options": {"page": "settings_configurator"}
});
}
});
......@@ -169,13 +129,13 @@
},
"my_active": {
"description": "Sync this opml or not",
"title": "Active (Auto Sync)",
"title": "Active (Enable Sync)",
"default": 1,
"css_class": "",
"required": 1,
"editable": 1,
"key": "active",
"hidden": 1,
"hidden": 0,
"type": "CheckBoxField"
},
"my_new_password": {
......@@ -199,7 +159,7 @@
"key": "confirm_new_password",
"hidden": (options.chg_passwd || '' === true) ? 0 : 1,
"type": "PasswordField"
},
}
}},
"_links": {
"type": {
......@@ -236,4 +196,4 @@
});
});
});
}(window, rJS, RSVP, Handlebars, OPMLManage));
}(window, rJS, RSVP));
......@@ -250,7 +250,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.21318.32760.12475</string> </value>
<value> <string>963.29486.6222.37785</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -268,7 +268,7 @@
</tuple>
<state>
<tuple>
<float>1510217057.28</float>
<float>1510676454.74</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, RSVP, Handlebars */
/*global window, rJS */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, Handlebars) {
(function (window, rJS) {
"use strict";
rJS(window)
......@@ -29,4 +29,4 @@
}});
});
});
}(window, rJS, RSVP, Handlebars));
}(window, rJS));
......@@ -250,7 +250,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.20929.61143.52155</string> </value>
<value> <string>963.27666.8050.30907</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -268,7 +268,7 @@
</tuple>
<state>
<tuple>
<float>1510231849.59</float>
<float>1510581396.39</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -10,6 +10,7 @@
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="handlebars.js"></script>
<script id="infobox-widget-template" type="text/x-handlebars-template">
{{#each resource_list}}
......
......@@ -243,7 +243,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.22427.36654.49664</string> </value>
<value> <string>963.27666.8050.30907</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -261,7 +261,7 @@
</tuple>
<state>
<tuple>
<float>1510327379.3</float>
<float>1510669287.69</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -56,9 +56,7 @@
});
})
.push(function () {
var key,
promise_list = [];
gadget.property_dict.jio_gadget.createJio({
return gadget.property_dict.jio_gadget.createJio({
type: "webhttp",
// XXX fix URL
url: (gadget.state.opml_outline.url
......@@ -66,14 +64,16 @@
'documents/'),
basic_login: gadget.state.opml.basic_login
});
})
.push(function () {
return gadget.property_dict.jio_gadget
.get(gadget.property_dict.monitor_process_state);
})
.push(undefined, function (error) {
.push(undefined, function () {
return gadget.notifySubmitted({
message: "Error: Failed to download data files!",
status: "error"
})
message: "Error: Failed to download data files!",
status: "error"
})
.push(function () {
return undefined;
});
......@@ -91,7 +91,7 @@
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
.allowPublicAcquisition("jio_allDocs", function (param_list) {
.allowPublicAcquisition("jio_allDocs", function () {
var gadget = this,
result = {data: {total_rows: 0, rows: []}};
return gadget.property_dict.jio_gadget.get(gadget.property_dict.process_state)
......@@ -222,16 +222,22 @@
return gadget.property_dict.jio_gadget
.get(gadget.property_dict.monitor_process_state)
.push(undefined, function () {
return undefined;
.push(undefined, function () {
return gadget.notifySubmitted({
message: "Error: Failed to download data files!",
status: "error"
})
.push(function (average_result) {
if (average_result !== undefined) {
return gadget.changeState({
average_state: average_result
});
}
});
.push(function () {
return undefined;
});
})
.push(function (average_result) {
if (average_result !== undefined) {
return gadget.changeState({
average_state: average_result
});
}
});
}, 65000);
}(window, rJS, RSVP, Handlebars));
\ No newline at end of file
......@@ -239,7 +239,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.22187.48632.58282</string> </value>
<value> <string>963.29300.23681.7082</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -257,7 +257,7 @@
</tuple>
<state>
<tuple>
<float>1510239168.21</float>
<float>1510669789.68</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, RSVP, console */
/*global window, rJS, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, RSVP, console) {
(function (window, rJS, RSVP) {
"use strict";
var gadget_klass = rJS(window);
function getDateWindow(data) {
var max_date,
begin_date,
end_date,
date_window = [];
if (data.length > 0) {
max_date = data[data.length - 1].split(',')[0];
begin_date = new Date(max_date);
end_date = new Date(max_date);
begin_date.setHours(begin_date.getHours() - 2);
date_window = [Date.parse(begin_date), Date.parse(end_date)];
}
return date_window;
}
function loadGraphData(gadget, key) {
var resource_key = gadget.property_dict.ressource_dict[key];
var resource_key = gadget.property_dict.resource_dict[key];
return gadget.property_dict.jio_gadget.get(resource_key)
.push(undefined, function () {
return gadget.notifySubmitted({
message: "Error: Failed to download resource file '" + resource_key +
"' from URL: " + gadget.state.opml_outline.url,
status: "error"
})
message: "Error: Failed to download resource file '" + resource_key +
"' from URL: " + gadget.state.opml_outline.url,
status: "error"
})
.push(function () {
return {data: []};
});
......@@ -103,28 +117,15 @@
};
}
function getDateWindow(data) {
var max_date,
begin_date,
end_date,
date_window = [];
if (data.length > 0) {
max_date = data[data.length - 1].split(',')[0];
begin_date = new Date(max_date);
end_date = new Date(max_date);
begin_date.setHours(begin_date.getHours() - 2);
date_window = [Date.parse(begin_date), Date.parse(end_date)];
}
return date_window;
}
function updateGraph(gadget) {
return new RSVP.Queue()
.push(function () {
var key,
promise_list = [];
for (key in gadget.property_dict.ressource_dict) {
promise_list.push(loadGraphData(gadget, key));
for (key in gadget.property_dict.resource_dict) {
if (gadget.property_dict.resource_dict.hasOwnProperty(key)) {
promise_list.push(loadGraphData(gadget, key));
}
}
return RSVP.all(promise_list);
})
......@@ -136,8 +137,7 @@
var data_list = [],
axis_dict = {},
line_list,
i,
j;
i;
axis_dict = {
"0": {
......@@ -259,8 +259,7 @@
})
.ready(function (gadget) {
gadget.property_dict = {};
gadget.property_dict.render_deferred = RSVP.defer();
gadget.property_dict.ressource_dict = {
gadget.property_dict.resource_dict = {
memory_resource: "monitor_resource_memory.data",
cpu_resource: "monitor_resource_process.data",
io_resource: "monitor_resource_io.data"
......@@ -276,7 +275,6 @@
return gadget.getDeclaredGadget("graph_cpu")
.push(function (graph_cpu) {
gadget.property_dict.graph_cpu = graph_cpu;
gadget.property_dict.graph_cpu_label_list = [];
});
})
.ready(function (gadget) {
......@@ -333,7 +331,7 @@
gadget.property_dict.mem_data = {data: []};
gadget.property_dict.process_data = {data: []};
gadget.property_dict.io_data = {data: []};
return gadget.property_dict.render_deferred.resolve();
return gadget.deferUpdateGraph();
});
})
......@@ -349,9 +347,9 @@
/////////////////////////////////////////////////////////////////
// declared service
/////////////////////////////////////////////////////////////////
.declareService(function () {
var gadget = this,
date_window = [];
.declareJob("deferUpdateGraph", function () {
return updateGraph(this);
/*function toggleSerieVisibility(evt) {
var checkbox = evt.target.nextSibling,
......@@ -367,10 +365,6 @@
});
}*/
return new RSVP.Queue()
.push(function () {
return gadget.property_dict.render_deferred.promise;
})
/**.push(function () {
return gadget.property_dict.graph_cpu.render(
gadget.property_dict.process_data.data.join('\n'),
......@@ -434,9 +428,6 @@
RSVP.all(promise_list);
return updateGraphTimer();
})**/
.push(function () {
return updateGraph(gadget);
});
});
}(window, rJS, RSVP, console));
\ No newline at end of file
}(window, rJS, RSVP));
\ No newline at end of file
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.22199.29933.17390</string> </value>
<value> <string>963.27984.14453.52343</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1510239154.52</float>
<float>1510651329.34</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -86,7 +86,7 @@
return new RSVP.Queue()
.push(function () {
return gadget.getSetting("listbox_lines_limit", 100);
return gadget.getSetting("listbox_lines_limit", 20);
})
.push(function (listbox_lines_limit) {
lines_limit = listbox_lines_limit;
......@@ -136,7 +136,7 @@
}
});
})
.push(function (result) {
.push(function () {
return gadget.updateHeader({
page_title: "Software Instances Status",
filter_action: true
......@@ -147,7 +147,6 @@
.onLoop(function () {
var gadget = this;
console.log("ONloop...");
return gadget.getSetting('latest_sync_time')
.push(function (latest_sync_time) {
if (latest_sync_time > gadget.state.latest_reload_time) {
......
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.19079.34809.6058</string> </value>
<value> <string>963.27984.14453.52343</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1510051687.96</float>
<float>1510766173.29</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -108,7 +108,7 @@
}
})
.push(function () {
return gadget.getSetting("listbox_lines_limit", 50);
return gadget.getSetting("listbox_lines_limit", 20);
})
.push(function (listbox_lines_limit) {
lines_limit = listbox_lines_limit;
......@@ -160,7 +160,7 @@
}
});
})
.push(function (result) {
.push(function () {
return gadget.updateHeader({
page_title: "Monitoring Promises Status",
filter_action: true
......
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.16563.15280.46899</string> </value>
<value> <string>963.27984.14453.52343</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1510052474.13</float>
<float>1510766112.11</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -13,17 +13,20 @@
.declareMethod("render", function () {
var gadget = this;
return this.updateHeader({
page_title: "Monitoring Synchronization"
})
page_title: "Monitoring Synchronization"
})
.push(function () {
return gadget.getDeclaredGadget('sync_gadget')
.push(function (sync_gadget) {
// start synchronization now if possible (not running already)
return sync_gadget.registerSync({now: true});
return sync_gadget.register({now: true});
});
})
.push(function () {
gadget.redirect({command: "change", options: {page: "ojsm_status_list"}});
return gadget.redirect({
command: "change",
options: {page: "ojsm_status_list"}
});
});
});
}(window, rJS));
......@@ -250,7 +250,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>962.53085.48571.55790</string> </value>
<value> <string>963.29336.22296.43468</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -268,7 +268,7 @@
</tuple>
<state>
<tuple>
<float>1508159965.22</float>
<float>1510668189.54</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -9,22 +9,17 @@
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="handlebars.js"></script>
<script src="gadget_officejs_monitoring_global.js"></script>
<script src="gadget_officejs_jio_opml_view.js"></script>
<script id="template-message-error" type="text/x-handlebars-template">
<p><span class='ui-text-{{status}}'>{{message}}</span></p>
</script>
</head>
<body>
<div data-gadget-url="gadget_officejs_monitoring_jio.html" data-gadget-scope="jio_gadget" data-gadget-sandbox="public"></div>
<div class="template-view"></div>
<form class="save_form ui-body-c" novalidate>
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline
ui-icon-edit ui-btn-icon-right ui-screen-hidden"></button>
<div class="ui-message-alert"></div>
<div data-gadget-url="gadget_officejs_monitoring_opml_edit.html"
data-gadget-scope="opml_gadget" data-gadget-sandbox="public"></div>
<div data-gadget-url="gadget_erp5_form.html"
data-gadget-scope="form_view"
data-gadget-sandbox="public">
......
......@@ -250,7 +250,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.1858.13217.15684</string> </value>
<value> <string>963.29465.32349.33501</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -268,7 +268,7 @@
</tuple>
<state>
<tuple>
<float>1509018559.06</float>
<float>1510675412.13</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, RSVP, Handlebars, OPMLManage */
/*global window, rJS, RSVP, Handlebars */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, Handlebars, OPMLManage) {
(function (window, rJS, RSVP) {
"use strict";
var gadget_klass = rJS(window),
templater = gadget_klass.__template_element,
notify_msg_template = Handlebars.compile(
templater.getElementById("template-message-error").innerHTML
),
opml_global = OPMLManage;
gadget_klass
/////////////////////////////
// state
/////////////////////////////
.setState({
message: "",
redirect: false
})
/////////////////////////////
// ready
/////////////////////////////
.ready(function (gadget) {
return opml_global.init(gadget, notify_msg_template);
})
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
......@@ -40,47 +18,39 @@
/////////////////////////////////////////////////////////////////
.onEvent('submit', function () {
var gadget = this,
doc;
doc,
opml_gadget;
return new RSVP.Queue()
.push(function () {
return gadget.getDeclaredGadget('form_view');
return gadget.getDeclaredGadget('opml_gadget');
})
.push(function (g) {
opml_gadget = g;
return gadget.getDeclaredGadget('form_view');
})
.push(function (form_gadget) {
return form_gadget.getContent();
})
.push(function (form_doc) {
doc = form_doc;
if (!opml_global.validateHttpUrl(form_doc.url)) {
gadget.state.message
.innerHTML = notify_msg_template({
status: 'error',
message: "'" + form_doc.url + "' is not a valid OPML URL"
});
return false;
}
if (!form_doc.username || !form_doc.password) {
gadget.state.message
.innerHTML = notify_msg_template({
status: 'error',
message: 'Username and password fields are required!'
});
return false;
}
if (doc.password !== gadget.state.password) {
// password was modified, update on backend
doc.new_password = doc.password;
doc.confirm_new_password = doc.new_password;
doc.password = gadget.state.password;
doc.verify_password = 1;
}
return true;
return opml_gadget.checkOPMLForm(doc);
})
.push(function (state) {
if (state) {
return gadget.notifySubmitting()
.push(function () {
doc.title = gadget.state.opml_title;
return opml_global.saveOPML(doc,
doc.title === "" || doc.title === undefined || doc.verify_password === 1);
return opml_gadget.saveOPML(
doc,
doc.title === "" || doc.title === undefined || doc.verify_password === 1
);
})
.push(function (status) {
var msg = {message: 'Document Updated', status: 'success'};
......@@ -92,11 +62,10 @@
status
]);
})
.push(function (result_list) {
if (result_list[1] && gadget.state.redirect) {
return gadget.redirect({
"command": "change",
"options": {"page": "ojsm_status_list"}
.push(function (result) {
if (result[1]) {
return gadget.changeState({
"password": doc.password
});
}
});
......@@ -224,7 +193,7 @@
});
})
.push(function () {
return gadget.changeState({redirect: false})
return new RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getUrlFor({command: 'history_previous'}),
......@@ -258,4 +227,4 @@
});
});
});
}(window, rJS, RSVP, Handlebars, OPMLManage));
}(window, rJS, RSVP));
......@@ -250,7 +250,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.21293.17700.853</string> </value>
<value> <string>963.29546.42896.22118</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -268,7 +268,7 @@
</tuple>
<state>
<tuple>
<float>1510185606.72</float>
<float>1510680193.17</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, RSVP, Handlebars, RegExp */
/*global window, rJS, RSVP, Handlebars, RegExp, document, atob */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, Handlebars, RegExp) {
(function (window, rJS, RSVP, Handlebars, RegExp, document, atob) {
"use strict";
var gadget_klass = rJS(window),
......@@ -10,20 +10,22 @@
link_template = Handlebars.compile(source);
function getPromiseTextContent(content, private_url) {
/*jslint regexp: true*/
var regex = /(https?:\/\/[^\s]+)/g,
i,
parser,
private_parser = document.createElement('a'),
result_list = content.match(regex),
url_list = [];
/*jslint regexp: false*/
function makeUnique(array_list) {
var temp = {},
i,
l,
r = [],
k;
for (i = 0; i < array_list.length; i += 1) {
temp[array_list[i]] = true;
for (l = 0; l < array_list.length; l += 1) {
temp[array_list[l]] = true;
}
for (k in temp) {
if (temp.hasOwnProperty(k)) {
......@@ -57,14 +59,15 @@
for (i = 0; i < url_list.length; i += 1) {
content = content.replace(
new RegExp(url_list[i].url, 'g'),
url_list[i].next);
url_list[i].next
);
}
return content;
}
gadget_klass
.setState({
jio_gadget: "",
jio_gadget: ""
})
.ready(function (gadget) {
return gadget.getDeclaredGadget("jio_gadget")
......@@ -80,7 +83,6 @@
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
.declareAcquiredMethod("translateHtml", "translateHtml")
.declareAcquiredMethod("redirect", "redirect")
......@@ -90,9 +92,7 @@
.declareMethod("render", function (options) {
var gadget = this,
hosting_subscription,
software_instance,
opml_outline,
opml_doc;
return new RSVP.Queue()
......@@ -105,22 +105,19 @@
})
.push(function () {
return gadget.jio_allDocs({
select_list: [
"parent_url",
"parent_id",
"title",
"opml_title",
"portal_type",
"_links",
"_embedded",
"reference"
],
query: '(portal_type:"global") AND (parent_id:"' +
options.doc.parent_id + '")'
}, function (error) {
console.log(error);
return {};
});
select_list: [
"parent_url",
"parent_id",
"title",
"opml_title",
"portal_type",
"_links",
"_embedded",
"reference"
],
query: '(portal_type:"global") AND (parent_id:"' +
options.doc.parent_id + '")'
});
})
.push(function (result) {
var i;
......@@ -131,7 +128,6 @@
return gadget.jio_get(options.doc.parent_id);
})
.push(function (outline_doc) {
opml_outline = outline_doc;
// get opml
return gadget.jio_get(outline_doc.parent_url);
})
......@@ -153,10 +149,10 @@
_embedded: {instance: {}}};
}
// fix URLs
software_instance._links.private_url.href = software_instance.
_links.private_url.href.replace("jio_private", "private");
software_instance._links.public_url.href = software_instance.
_links.public_url.href.replace("jio_public", "public");
software_instance._links.private_url.href = software_instance
._links.private_url.href.replace("jio_private", "private");
software_instance._links.public_url.href = software_instance
._links.public_url.href.replace("jio_public", "public");
pass_url = "https://" + atob(opml_doc.basic_login) +
"@" + software_instance._links.private_url.href.split("//")[1];
......@@ -202,8 +198,14 @@
gadget.state.promise.source + ".history"
)
.push(undefined, function (error) {
console.log(error);
return undefined;
return gadget.notifySubmitted({
status: "error",
message: "Failed to get promise history content! \n" +
error.message || ''
})
.push(function () {
return undefined;
});
})
.push(function (status_history) {
var i,
......@@ -223,7 +225,7 @@
//if (lines > len) {
// lines = len - start;
//}
for (i = start; i >= 0; i-= 1) {
for (i = start; i >= 0; i -= 1) {
message = status_history.data[i].message.slice(0, 60);
if (message.length >= 60) {
message += "...";
......@@ -266,7 +268,8 @@
editable: 0,
hidden: 0,
hidden_day_is_last_day: 0,
"default": new Date(status_history.data[i]['change-time']*1000).toUTCString(),
"default": new Date(status_history.data[i]['change-time'] * 1000)
.toUTCString(),
key: "change_date",
required: 0,
timezone_style: 0,
......@@ -506,23 +509,31 @@
}
},
form_definition: {
group_list: [[
"left",
[["your_title"], ["your_status"], ["your_status_date"], ["your_report_date"], ["your_public_url"], ["your_private_url"]]
],
[
"right",
[["your_hosting_title"], ["your_instance_title"], ["your_computer_reference"], ["your_computer_partition"],
["your_partition_ipv6"], ["your_software_release_url"]]
],
[
"center",
[["your_promise_output"]]
],
[
"bottom",
[["your_promise_history"]]
]]
group_list: [
[
"left",
[
["your_title"], ["your_status"], ["your_status_date"],
["your_report_date"], ["your_public_url"], ["your_private_url"]
]
],
[
"right",
[
["your_hosting_title"], ["your_instance_title"],
["your_computer_reference"], ["your_computer_partition"],
["your_partition_ipv6"], ["your_software_release_url"]
]
],
[
"center",
[["your_promise_output"]]
],
[
"bottom",
[["your_promise_history"]]
]
]
}
});
})
......@@ -543,4 +554,4 @@
});
});
});
}(window, rJS, RSVP, Handlebars, RegExp));
}(window, rJS, RSVP, Handlebars, RegExp, document, atob));
......@@ -250,7 +250,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.706.49244.32460</string> </value>
<value> <string>963.29333.34848.27204</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -268,7 +268,7 @@
</tuple>
<state>
<tuple>
<float>1508949544.51</float>
<float>1510666984.34</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -108,7 +108,7 @@
<item>
<key> <string>text_content</string> </key>
<value> <string>CACHE MANIFEST\n
# generated on Fri, 06 Nov 2017 15:47:33 +0000\n
# generated on Fri, 15 Nov 2017 15:47:33 +0000\n
# XXX + fonts\n
# images/ajax-loader.gif\n
CACHE:\n
......@@ -133,8 +133,6 @@ dygraph.js\n
handlebars.js\n
jiodev.js\n
erp5_launcher_nojqm.js\n
monitoring_jio_http_storage.js\n
monitoring_jio_parser_storage.js\n
monitoring_jio_storage.js\n
monitoring_jio_web_storage.js\n
jsen.min.js\n
......@@ -197,6 +195,8 @@ gadget_erp5_jio.html\n
gadget_erp5_jio.js\n
gadget_erp5_search_editor.html\n
gadget_erp5_search_editor.js\n
gadget_erp5_sort_editor.html\n
gadget_erp5_sort_editor.js\n
\n
# monitoring\n
gadget_officejs_monitoring.appcache\n
......@@ -222,6 +222,7 @@ gadget_erp5_page_ojsm_status_list.html\n
gadget_erp5_page_ojsm_synchronize.html\n
gadget_erp5_page_ojsm_erp5_configurator.html\n
gadget_erp5_page_ojsm_jump.html\n
gadget_officejs_monitoring_opml_edit.html\n
\n
# monitoring js\n
gadget_officejs_monitoring_jio.js\n
......@@ -248,7 +249,7 @@ gadget_officejs_jio_opml_view.js\n
gadget_erp5_page_ojsm_synchronize.js\n
gadget_erp5_page_ojsm_jump.js\n
gadget_erp5_page_ojsm_erp5_configurator.js\n
gadget_officejs_monitoring_global.js\n
gadget_officejs_monitoring_opml_edit.js\n
\n
# erp5_web_renderjs_ui\n
gadget_erp5_editor_panel.html\n
......@@ -383,7 +384,7 @@ NETWORK:\n
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.22437.57747.1757</string> </value>
<value> <string>963.30985.26464.16281</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -401,7 +402,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1510327329.0</float>
<float>1510766013.21</float>
<string>UTC</string>
</tuple>
</state>
......
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Monitoring OPML edit</title>
<link href="gadget_officejs_monitoring_custom.css" rel="stylesheet" type="text/css"/>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="handlebars.js"></script>
<script src="gadget_officejs_monitoring_opml_edit.js"></script>
<script id="template-message-error" type="text/x-handlebars-template">
<p><span class='ui-text-{{status}}'>{{message}}</span></p>
</script>
</head>
<body>
<div data-gadget-url="gadget_officejs_monitoring_jio.html" data-gadget-scope="jio_gadget" data-gadget-sandbox="public"></div>
<div class="ui-message-alert"></div>
</body>
</html>
\ No newline at end of file
......@@ -83,7 +83,7 @@
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>gadget_officejs_monitoring_global.js</string> </value>
<value> <string>gadget_officejs_monitoring_opml_edit.js</string> </value>
</item>
<item>
<key> <string>description</string> </key>
......@@ -93,7 +93,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>gadget_officejs_monitoring_global_js</string> </value>
<value> <string>gadget_officejs_monitoring_opml_edit_js</string> </value>
</item>
<item>
<key> <string>language</string> </key>
......@@ -111,7 +111,7 @@
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Monitoring Global Js</string> </value>
<value> <string>Monitoring OPML edit widget Js</string> </value>
</item>
<item>
<key> <string>version</string> </key>
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.1892.25677.55654</string> </value>
<value> <string>963.29541.62889.7577</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1509020867.3</float>
<float>1510680916.21</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -273,7 +273,7 @@
.declareService(function () {
return this.getDeclaredGadget("sync_gadget")
.push(function (sync_gadget) {
return sync_gadget.registerSync();
return sync_gadget.register();
});
})
......
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>962.52822.35420.57019</string> </value>
<value> <string>963.27666.8050.30907</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1509093907.79</float>
<float>1510668451.66</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS */
/*global window, rJS, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS) {
(function (window, rJS, RSVP) {
"use strict";
rJS(window)
rJS(window)
.ready(function (gadget) {
gadget.props = {};
return gadget.getDeclaredGadget("jio_gadget")
......@@ -16,8 +16,8 @@ rJS(window)
.declareMethod("render", function (options) {
var gadget = this;
return new RSVP.Queue()
.push(function () {
gadget.props.jio_gadget.createJio({
.push(function () {
return gadget.props.jio_gadget.createJio({
type: "query",
sub_storage: {
type: "drivetojiomapping",
......@@ -28,6 +28,8 @@ rJS(window)
}
}
});
})
.push(function () {
return gadget.changeState({
parameter_list: options.parameters,
save_to: 'config.tmp',
......@@ -51,14 +53,10 @@ rJS(window)
.push(function (form_gadget) {
var i,
parameter_dict = {},
group_list = [[
"left",
[]
],
[
"right",
[]
]];
group_list = [
["left", []],
["right", []]
];
for (i = 0; i < gadget.state.parameter_list.length; i += 1) {
parameter_dict[gadget.state.parameter_list[i].title] = {
"description": "",
......@@ -73,7 +71,7 @@ rJS(window)
"hidden": 0,
"type": "StringField" // for now everything are stringField
};
group_list[i%2][1].push([gadget.state.parameter_list[i].title]);
group_list[i % 2][1].push([gadget.state.parameter_list[i].title]);
}
return form_gadget.render({
erp5_document: {
......@@ -117,9 +115,8 @@ rJS(window)
return form_gadget.getContent();
})
.push(function (doc) {
var parameter_dict = {},
var key,
parameter_list = JSON.parse(JSON.stringify(gadget.state.parameter_list)),
key,
i;
for (i = 0; i < parameter_list.length; i += 1) {
key = gadget.state.key + '_' + parameter_list[i].title;
......@@ -132,10 +129,10 @@ rJS(window)
.push(function () {
return {status: 'OK'};
}, function (error) {
console.log(error);
//console.log(error);
return {status: 'ERROR', code: error.target.status,
url: gadget.state.url, stage: "Saving file"};
});
});
}(window, rJS));
\ No newline at end of file
}(window, rJS, RSVP));
\ No newline at end of file
......@@ -239,7 +239,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>962.48797.18350.58214</string> </value>
<value> <string>963.27984.14453.52343</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -257,7 +257,7 @@
</tuple>
<state>
<tuple>
<float>1507902562.82</float>
<float>1510664009.77</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, RSVP, clearTimeout, setTimeout, console, XMLHttpRequest, document */
/*global window, rJS, RSVP, console, XMLHttpRequest, document */
/*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, RSVP, console, clearTimeout, setTimeout,
XMLHttpRequest, document) {
(function (window, rJS, RSVP, console, XMLHttpRequest, document) {
"use strict";
var gadget_klass = rJS(window);
......@@ -17,7 +16,7 @@
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", "notifySubmitted")
.declareMethod("registerSync", function (options) {
.declareMethod("register", function (options) {
var gadget = this;
function testOnline(url) {
......@@ -35,7 +34,7 @@
}
};
xhr.onerror = function (e) {
xhr.onerror = function () {
reject({
status: 'ERROR'
});
......@@ -46,42 +45,6 @@
});
}
function formatDate(d) {
function addZero(n) {
return n < 10 ? "0" + n : n.toString();
}
return d.getFullYear() + "-" + addZero(d.getMonth() + 1) +
"-" + addZero(d.getDate()) + " " + addZero(d.getHours()) +
":" + addZero(d.getMinutes()) + ":" + addZero(d.getSeconds());
}
function syncAllStorageWithCheck() {
gadget.props.offline = false;
return gadget.getSetting('sync_check_offline', 'true')
.push(function (check_offline) {
var parser;
if (check_offline === 'true') {
parser = document.createElement("a");
parser.href = document.URL;
return new RSVP.Queue()
.push(function () {
return testOnline(parser.origin);
})
.push(undefined, function () {
return {status: "ERROR"};
})
.push(function (online_result) {
if (online_result.status === "OK") {
return syncAllStorage();
}
gadget.props.offline = true;
});
}
return syncAllStorage();
});
}
function syncAllStorage() {
var has_error = false,
last_sync_time;
......@@ -104,8 +67,10 @@
return gadget.jio_repair();
})
.push(undefined, function (error) {
// should include error message in error
has_error = true;
console.error(error);
// return false so it will trigger the next run
return false;
})
.push(function () {
......@@ -116,18 +81,13 @@
]);
})
.push(function () {
var time = 3000,
classname = "success",
message = "Synchronisation finished.",
//log_message = '',
log_title = "OK: " + message;
var classname = "success",
message = "Synchronisation finished.";
if (has_error) {
classname = "error";
time = 5000;
//log_message = getErrorLog(gadget.props.error_list);
log_title = "Synchronisation finished with error(s).";
message = log_title + "\nYou can retry with manual sync.";
message = "Synchronisation finished with error(s).";
message += " \nYou can retry with manual sync.";
}
return gadget.notifySubmitted({
message: message,
......@@ -148,44 +108,63 @@
});
}
function syncAllStorageWithCheck() {
gadget.props.offline = false;
return gadget.getSetting('sync_check_offline', 'true')
.push(function (check_offline) {
var parser;
if (check_offline === 'true') {
parser = document.createElement("a");
parser.href = document.URL;
return new RSVP.Queue()
.push(function () {
return testOnline(parser.origin);
})
.push(undefined, function () {
return {status: "ERROR"};
})
.push(function (online_result) {
if (online_result.status === "OK") {
return syncAllStorage();
}
gadget.props.offline = true;
});
}
return syncAllStorage();
});
}
function syncDataTimer() {
if (gadget.props.timer) {
clearTimeout(gadget.props.timer);
}
gadget.props.timer = setTimeout(function () {
return new RSVP.Queue()
.push(function () {
return gadget.getSetting('sync_start_time');
})
.push(function (start_timestamp) {
var current_time = new Date().getTime();
if (start_timestamp !== undefined &&
(current_time - gadget.props.timer_interval) <=
start_timestamp) {
// There was a recent sync don't start a new sync before the time_interval!
return;
}
return syncAllStorageWithCheck();
})
.push(undefined, function (error) {
console.error(error);
return new RSVP.Queue()
.push(function () {
return RSVP.delay(gadget.props.timer_interval);
})
.push(function () {
return gadget.getSetting('sync_start_time');
})
.push(function (start_timestamp) {
var current_time = new Date().getTime();
if (start_timestamp !== undefined &&
(current_time - gadget.props.timer_interval) <=
start_timestamp) {
// There was another recent sync don't start a new sync before the time_interval!
return;
})
.push(function () {
return gadget.getSetting('sync_data_interval');
})
.push(function (timer_interval) {
if (gadget.props.offline === true) {
// Offline mode detected, next check will be in 3 minutes
timer_interval = 180000;
} else if (timer_interval === undefined) {
timer_interval = gadget.props.default_sync_interval;
}
gadget.props.timer_interval = timer_interval;
return syncDataTimer();
});
}, gadget.props.timer_interval);
return gadget.props.timer;
}
return syncAllStorageWithCheck();
})
.push(function () {
return gadget.getSetting('sync_data_interval');
})
.push(function (timer_interval) {
if (gadget.props.offline === true) {
// Offline mode detected, next check will be in 3 minutes
timer_interval = 180000;
} else if (timer_interval === undefined) {
timer_interval = gadget.props.default_sync_interval;
}
gadget.props.timer_interval = timer_interval;
return syncDataTimer();
});
}
......@@ -244,5 +223,4 @@
});
});
}(window, rJS, RSVP, console, clearTimeout, setTimeout, XMLHttpRequest,
document));
\ No newline at end of file
}(window, rJS, RSVP, console, XMLHttpRequest, document));
\ No newline at end of file
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.21916.52285.31846</string> </value>
<value> <string>963.29129.42634.5819</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1510233154.98</float>
<float>1510655414.57</float>
<string>UTC</string>
</tuple>
</state>
......
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