Commit 60dbaeb2 authored by Alain Takoudjou's avatar Alain Takoudjou

[erp5_web_monitoring] load monitoring parameter from json serialized connection parameter

parent 58b41696
...@@ -260,41 +260,69 @@ ...@@ -260,41 +260,69 @@
}); });
} }
function getParameterDictFromUrl(uri_param) {
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')
};
}
}
function getParameterFromconnectionDict(connection_dict) {
if (connection_dict["monitor-url"] &&
connection_dict["monitor-url"].startsWith('http') &&
connection_dict["monitor-user"] &&
connection_dict["monitor-password"]) {
return {
opml_url: connection_dict["monitor-url"],
username: connection_dict["monitor-user"],
password: connection_dict["monitor-password"]
};
}
}
function readMonitoringParameter(parmeter_xml) { function readMonitoringParameter(parmeter_xml) {
var parser = new DOMParser(), var parser = new DOMParser(),
xmlDoc = parser.parseFromString(parmeter_xml, "text/xml"), xmlDoc = parser.parseFromString(parmeter_xml, "text/xml"),
parameter, parameter,
uri_param, uri_param,
json_parameter,
parameter_dict,
monitor_dict = {}; monitor_dict = {};
json_parameter = xmlDoc.getElementById("_");
if (json_parameter !== undefined && json_parameter !== null) {
parameter_dict = JSON.parse(json_parameter.textContent);
if (parameter_dict.hasOwnProperty("monitor-setup-url")) {
return getParameterDictFromUrl(
new URLSearchParams(parameter_dict["monitor-setup-url"])
);
}
return getParameterFromconnectionDict(parameter_dict);
}
parameter = xmlDoc.getElementById("monitor-setup-url"); parameter = xmlDoc.getElementById("monitor-setup-url");
if (parameter !== undefined && parameter !== null) { if (parameter !== undefined && parameter !== null) {
// monitor-setup-url exists // monitor-setup-url exists
uri_param = new URLSearchParams(parameter.textContent); uri_param = new URLSearchParams(parameter.textContent);
if (uri_param.has('url') && uri_param.has('password') && return getParameterDictFromUrl(uri_param);
uri_param.has('username') && uri_param.get('url').startsWith('http')) { }
return { parameter = xmlDoc.getElementById("monitor-url");
opml_url: uri_param.get('url'), if (parameter !== undefined && parameter !== null) {
username: uri_param.get('username'), monitor_dict.url = parameter.textContent.trim();
password: uri_param.get('password') parameter = xmlDoc.getElementById("monitor-user");
}; if (parameter === undefined && parameter !== null) {
return;
} }
} else { monitor_dict.username = parameter.textContent.trim();
parameter = xmlDoc.getElementById("monitor-url"); parameter = xmlDoc.getElementById("monitor-password");
if (parameter !== undefined && parameter !== null) { if (parameter === undefined && parameter !== null) {
monitor_dict.url = parameter.textContent.trim(); return;
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;
} }
monitor_dict.password = parameter.textContent.trim();
return monitor_dict;
} }
} }
...@@ -629,4 +657,4 @@ ...@@ -629,4 +657,4 @@
} }
}); });
}); });
}(window, rJS, RSVP, jsen, Handlebars, atob, btoa, DOMParser, URLSearchParams)); }(window, rJS, RSVP, jsen, Handlebars, atob, btoa, DOMParser, URLSearchParams));
\ No newline at end of file
...@@ -250,7 +250,7 @@ ...@@ -250,7 +250,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>965.42470.47064.30003</string> </value> <value> <string>967.60726.55816.57890</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>1519233144.55</float> <float>1527847350.32</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, 21 Fev 2018 10:37:42 +0000\n # generated on Fri, 20 May 2018 17:47:45 +0000\n
# XXX + fonts\n # XXX + fonts\n
# images/ajax-loader.gif\n # images/ajax-loader.gif\n
CACHE:\n CACHE:\n
...@@ -387,7 +387,7 @@ NETWORK:\n ...@@ -387,7 +387,7 @@ NETWORK:\n
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>965.42293.15886.45994</string> </value> <value> <string>966.64659.26947.45004</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -405,7 +405,7 @@ NETWORK:\n ...@@ -405,7 +405,7 @@ NETWORK:\n
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1519222522.75</float> <float>1527847381.11</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </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