Commit 4cec3212 authored by Alain Takoudjou's avatar Alain Takoudjou

[erp5_web_monitoring] Import OPML from master using allDocs jio method

Use allDocs to navigate through hosting subscription and import OPML configurations.
parent 96d46008
......@@ -5,7 +5,7 @@
rJS(window)
.setState({
erp5_url: "https://vifib.erp5.net/web_site_module/renderjs_runner"
erp5_url: "https://vifib.erp5.net/web_site_module/renderjs_runner/hateoas/"
})
/////////////////////////////////////////////////////////////////
// Acquired methods
......@@ -26,7 +26,7 @@
return form_gadget.getContent();
})
.push(function (content) {
master_url = content.erp5_url + "/hateoas/";
master_url = content.erp5_url;
return gadget.setSetting("hateoas_url", master_url);
})
.push(function () {
......
......@@ -250,7 +250,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>962.55724.5208.57309</string> </value>
<value> <string>963.16563.15280.46899</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -268,7 +268,7 @@
</tuple>
<state>
<tuple>
<float>1508343284.75</float>
<float>1509978780.17</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -25,7 +25,7 @@
<section class="ui-content-header-plain">
<h3 class="ui-content-title ui-body-c">
<span class="ui-icon ui-icon-custom ui-icon-database">&nbsp;</span>
Load Settings from remote Storage
Import OPML from remote Storage
</h3>
</section>
<section class="ui-body-c ui-content-section">
......
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>962.55732.38278.12270</string> </value>
<value> <string>963.16563.15280.46899</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1509023688.31</float>
<float>1509979675.96</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, RSVP, jsen, Rusha, Handlebars, atob */
/*global window, rJS, RSVP, jsen, Rusha, Handlebars, atob, btoa, DOMParser,
URLSearchParams */
/*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, RSVP, jsen, Rusha, Handlebars, atob) {
(function (window, rJS, RSVP, jsen, Rusha, Handlebars, atob, btoa, DOMParser,
URLSearchParams) {
"use strict";
var gadget_klass = rJS(window),
......@@ -23,7 +25,7 @@
.push(function (opml_result) {
var i,
opml_dict = {opml_description_list: []};
for (i = 0; i < opml_result.data.total_rows; i+= 1) {
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;
......@@ -249,6 +251,109 @@
});
}
function readMonitoringParameter(parmeter_xml) {
var parser = new DOMParser(),
xmlDoc = parser.parseFromString(parmeter_xml, "text/xml"),
parameter,
uri_param,
monitor_dict = {};
parameter = xmlDoc.getElementById("monitor-setup-url");
if (parameter !== undefined && parameter !== null) {
// monitor-setup-url exists
uri_param = new URLSearchParams(parameter.textContent);
if (uri_param.has('url') && uri_param.has('password') &&
uri_param.has('username') && uri_param.get('url').startsWith('http')) {
return {
opml_url: uri_param.get('url'),
username: uri_param.get('username'),
password: uri_param.get('password')
};
}
} else {
parameter = xmlDoc.getElementById("monitor-url");
if (parameter !== undefined && parameter !== null) {
monitor_dict.url = parameter.textContent.trim();
parameter = xmlDoc.getElementById("monitor-user");
if (parameter === undefined && parameter !== null) {
return;
}
monitor_dict.username = parameter.textContent.trim();
parameter = xmlDoc.getElementById("monitor-password");
if (parameter === undefined && parameter !== null) {
return;
}
monitor_dict.password = parameter.textContent.trim();
return monitor_dict;
}
}
}
function getInstanceOPMLListFromMaster(gadget, limit) {
var hosting_subscription_list = [],
opml_list = [],
uid_dict = {};
if (limit === undefined) {
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"]
]
})
.push(function (result) {
var i,
uid_search_list = [];
for (i = 0; i < result.data.total_rows; i += 1) {
hosting_subscription_list.push({
title: result.data.rows[i].value.title,
relative_url: result.data.rows[i].id
});
uid_search_list.push(result.data.rows[i].value.uid);
if (result.data.rows[i].value.default_predecessor_uid) {
uid_dict[result.data.rows[i].value.default_predecessor_uid] = i;
}
}
return gadget.state.erp5_gadget.allDocs({
query: '(portal_type:"Software Instance") AND ' +
'(predecessor_related_uid:("' + uid_search_list.join('","') + '"))',
select_list: ['uid', 'predecessor_related_uid', 'connection_xml'],
limit: [0, limit]
});
})
.push(function (result) {
var i,
tmp_parameter,
tmp_uid;
for (i = 0; i < result.data.total_rows; i += 1) {
tmp_uid = result.data.rows[i].value.uid;
if (uid_dict.hasOwnProperty(tmp_uid)) {
tmp_parameter = readMonitoringParameter(result.data.rows[i].value.connection_xml);
if (tmp_parameter !== undefined) {
opml_list.push({
portal_type: "opml",
title: hosting_subscription_list[uid_dict[tmp_uid]]
.title,
relative_url: hosting_subscription_list[uid_dict[tmp_uid]]
.relative_url,
url: tmp_parameter.opml_url,
username: tmp_parameter.username,
password: tmp_parameter.password,
basic_login: btoa(tmp_parameter.username + ':' +
tmp_parameter.password),
active: true
});
}
}
}
return opml_list;
});
}
gadget_klass
/////////////////////////////
// state
......@@ -276,6 +381,8 @@
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", "notifySubmitted")
/////////////////////////////////////////////////////////////////
// declared methods
......@@ -339,12 +446,12 @@
if (gadget.state.is_exporter) {
title_content = header_title({
title: "Export Monitor Configurations",
title: "Export OPML Configurations",
icon: "download"
});
} else {
title_content = header_title({
title: "Import Monitor Configurations",
title: "Import OPML Configurations",
icon: "upload"
});
}
......@@ -423,42 +530,79 @@
});
})
.push(function () {
var hosting_subscription_list = [],
has_failed = false,
uid_dict = {};
if (gadget.state.sync === "erp5" && gadget.state.storage_url) {
// start import from erp5 now
return gadget.setSetting("hateoas_url", gadget.state.storage_url)
return gadget.notifySubmitting()
.push(function () {
return gadget.setSetting("hateoas_url", gadget.state.storage_url);
})
.push(function () {
return gadget.state.erp5_gadget.createJio();
})
.push(function () {
// force login if not logged yet
return gadget.state.erp5_gadget.get("document2");
return gadget.getSetting('opml_import_limit', 100);
})
.push(function (select_limit) {
return getInstanceOPMLListFromMaster(gadget, select_limit);
})
.push(undefined, function () {
return false;
gadget.state.message
.innerHTML = notify_msg_template({
status: 'error',
message: 'Error: Failed to get Monitor Configuration from URL: ' +
gadget.state.storage_url
});
has_failed = true;
return [];
})
.push(function (opml_list) {
var i,
push_queue = new RSVP.Queue();
function pushOPML(opml_dict) {
push_queue
.push(function () {
// load monitoring information.
return gadget.state.erp5_gadget.getAttachment(
'hosting_subscription_module',
gadget.state.storage_url + 'hosting_subscription_module'
+ "/Base_getMonitoringInstanceParameterDictAsJson"
);
return gadget.jio_put(opml_dict.url, opml_dict);
})
.push(undefined, function (error) {
throw error;
});
}
for (i = 0; i < opml_list.length; i += 1) {
pushOPML(opml_list[i]);
}
return push_queue;
})
.push(undefined, function () {
gadget.state.message
.innerHTML = notify_msg_template({
status: 'error',
message: 'Error: Failed to get Monitor Configuration from URL: ' +
message: 'An error occurred while saving Configuration from URL: ' +
gadget.state.storage_url
});
return undefined;
has_failed = true;
})
.push(function (result) {
if (result !== undefined) {
return importMonitorConfiguration(gadget, result);
.push(function () {
if (!has_failed) {
return gadget.notifySubmitted("Failed to import Configurations");
} else {
return gadget.notifySubmitted("Configuration Saved!");
}
})
.push(function () {
if (!has_failed) {
return gadget.redirect({
"command": "display",
"options": {"page": "settings_configurator"}
});
}
});
}
});
});
}(window, rJS, RSVP, jsen, Rusha, Handlebars, atob));
}(window, rJS, RSVP, jsen, Rusha, Handlebars, atob, btoa, DOMParser,
URLSearchParams));
......@@ -250,7 +250,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.1954.36775.16384</string> </value>
<value> <string>963.17936.4203.52804</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -268,7 +268,7 @@
</tuple>
<state>
<tuple>
<float>1509024244.66</float>
<float>1509983206.06</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -140,6 +140,10 @@
return gadget.setSetting('listbox_lines_limit',
parseInt(doc.listbox_lines_limit, 10));
})
.push(function () {
return gadget.setSetting('opml_import_limit',
parseInt(doc.opml_import_limit, 10));
})
.push(function () {
return RSVP.all([
gadget.notifySubmitted('Parameters Updated')
......@@ -155,7 +159,8 @@
last_sync_time,
sync_data_interval,
check_online_access,
listbox_lines_limit;
listbox_lines_limit,
opml_import_limit;
if (options.url) {
// backward compatibility redirect to add opml
......@@ -165,6 +170,10 @@
return new RSVP.Queue()
.push(function () {
return gadget.getSetting('opml_import_limit', 100);
})
.push(function (import_limit) {
opml_import_limit = import_limit;
return gadget.getSetting('listbox_lines_limit', 20);
})
.push(function (lines_limit) {
......@@ -248,6 +257,16 @@
"hidden": 0,
"type": "CheckBoxField"
},
"my_opml_import_limit": {
"description": "Maximum number of OPML to import",
"title": "OPML Import Limit",
"default": opml_import_limit,
"css_class": "",
"editable": 1,
"key": "opml_import_limit",
"hidden": 0,
"type": "IntegerField"
},
"listbox": {
"column_list": column_list,
"show_anchor": 0,
......@@ -278,7 +297,8 @@
group_list: [[
"left",
[["your_last_sync_date"], ["my_auto_sync_interval"],
["my_listbox_lines_limit"], ["my_check_online_access"]]
["my_listbox_lines_limit"], ["my_opml_import_limit"],
["my_check_online_access"]]
],
[
"right",
......
......@@ -238,7 +238,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.8902.10923.27409</string> </value>
<value> <string>963.17877.3072.30788</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -256,7 +256,7 @@
</tuple>
<state>
<tuple>
<float>1509441073.68</float>
<float>1509981253.88</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -24,6 +24,7 @@
<key> <string>_Add_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
</tuple>
......@@ -42,6 +43,8 @@
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
......@@ -105,7 +108,7 @@
<item>
<key> <string>text_content</string> </key>
<value> <string>CACHE MANIFEST\n
# generated on Fri, 07 sep 2017 15:47:33 +0000\n
# generated on Fri, 06 Nov 2017 15:47:33 +0000\n
# XXX + fonts\n
# images/ajax-loader.gif\n
CACHE:\n
......@@ -190,6 +193,8 @@ gadget_html5_select.html\n
gadget_html5_select.js\n
gadget_erp5_field_password.html\n
gadget_erp5_field_password.js\n
gadget_erp5_field_integer.html\n
gadget_erp5_field_integer.js\n
gadget_erp5_jio.html\n
gadget_erp5_jio.js\n
\n
......@@ -290,12 +295,6 @@ NETWORK:\n
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
<item>
<key> <string>processing_status_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAU=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
......@@ -313,7 +312,7 @@ NETWORK:\n
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>publish</string> </value>
<value> <string>publish_alive</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
......@@ -339,7 +338,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1458647957.13</float>
<float>1509980323.24</float>
<string>UTC</string>
</tuple>
</state>
......@@ -348,7 +347,7 @@ NETWORK:\n
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>published</string> </value>
<value> <string>published_alive</string> </value>
</item>
</dictionary>
</list>
......@@ -384,7 +383,7 @@ NETWORK:\n
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.648.42463.52138</string> </value>
<value> <string>963.17891.16389.10547</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -402,64 +401,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1509023500.45</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
<record id="5" aka="AAAAAAAAAAU=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>detect_converted_file</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>external_processing_state</string> </key>
<value> <string>converted</string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>0.0.0.0</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1455289075.54</float>
<float>1509980460.49</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -48,7 +48,7 @@
<li><a href="{{hosting_list_href}}" class="ui-btn ui-btn-icon-left ui-icon-cubes" data-i18n="Hosting Subscriptions">Hosting Subscriptions</a></li>
<li><a href="{{configurator_href}}" class="ui-btn ui-btn-icon-left ui-icon-gear" data-i18n="Monitoring Configurations">Monitoring Configurations</a></li>
<li><a href="{{synchronize_href}}" class="ui-btn ui-btn-icon-left ui-icon-refresh" data-i18n="Synchronize" accesskey="r">Synchronize</a></li>
<li class="ui-last-child"><a href="{{import_export_href}}" class="ui-btn ui-btn-icon-left ui-icon-exchange" data-i18n="Import / Export">Import / Export</a></li>
<li class="ui-last-child"><a href="{{import_export_href}}" class="ui-btn ui-btn-icon-left ui-icon-exchange" data-i18n="OPML Import / Export">OPML Import / Export</a></li>
</script>
<script id="panel-template-body-desktop" type="text/x-handlebars-template">
......
......@@ -276,7 +276,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.2027.58161.62429</string> </value>
<value> <string>963.16563.15280.46899</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -294,7 +294,7 @@
</tuple>
<state>
<tuple>
<float>1509031392.08</float>
<float>1509979830.19</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