Commit 04787147 by Alain Takoudjou

[slapos_jio] monitor status link will now add opml and redirect to status view

Monitor link on SlapOS interface will add OPML. New opml will be synced immediately then redirect to  status view.
1 parent 86038e90
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>971.11856.29335.23364</string> </value>
<value> <string>971.49094.61098.53060</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1540470762.22</float>
<float>1542710985.33</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -44,19 +44,57 @@
return partition_class;
}
function getDoc(gadget) {
if (gadget.options.doc && gadget.options.doc !== undefined) {
return gadget.options.doc;
}
return gadget.jio_get(gadget.options.value.jio_key);
}
function getMonitorParameterDict(gadget, doc) {
if (doc.portal_type === "Hosting Subscription") {
return gadget.jio_getAttachment(gadget.options.value.jio_key,
gadget.props.hateoas_url + gadget.options.value.jio_key +
"/HostingSubscription_getMonitorParameterDict");
}
}
function getStatus(gadget) {
var result;
return new RSVP.Queue()
.push(function () {
return gadget.jio_get(gadget.options.value.jio_key);
return getDoc(gadget);
})
.push(function (result) {
.push(function (jio_doc) {
result = jio_doc;
if (gadget.state.monitor_dict === undefined ||
!gadget.state.has_monitor_info) {
return getMonitorParameterDict(gadget, jio_doc)
.push(function (param_dict) {
return gadget.changeState({
monitor_dict: param_dict,
has_monitor_info: true
});
});
}
})
.push(function () {
var monitor_url,
status_class = 'ui-btn-no-data',
status_title = 'Instances',
status_style = "";
status_class = checkHostingSubscriptionStatus(result);
monitor_url = 'https://monitor.app.officejs.com/#/?page=ojsm_dispatch&query=portal_type%3A%22Hosting%20Subscription%22%20AND%20title%3A' + result.title;
if (gadget.state.monitor_dict.url &&
gadget.state.monitor_dict.username &&
gadget.state.monitor_dict.password) {
monitor_url = "https://monitor.app.officejs.com/#page=settings_configurator&url=" +
gadget.state.monitor_dict.url + "&username=" +
gadget.state.monitor_dict.username + "&password=" +
gadget.state.monitor_dict.password;
} else {
monitor_url = 'https://monitor.app.officejs.com/#/?page=ojsm_dispatch&query=portal_type%3A%22Hosting%20Subscription%22%20AND%20title%3A' + result.title;
  • For correct escaping I think it should be :

    Query.objectToSearchText({
      type: "complex",
      operator: "AND",
      query_list: [
        { type: "simple", key: "portal_type", value: "Hosting Subscription" },
        { type: "simple", key: "title", value: result.title }
      ]
    });
    

    /cc @rafael ( I don't know if there's a MR I just saw this commit in RSS and got curious) )

  • No, it was push directly :/

  • ( about the "I don't know if there's a MR", I was worried that you ( @rafael ) don't get notification because if commit is in a MR you will be notified because "participating" in the MR, that's the reason why I @ you explicitly )

}
if (status_class === 'ui-btn-no-data') {
status_style = "color: transparent !important;";
......@@ -73,6 +111,9 @@
}
gadget_klass
.setState({
has_monitor_info: false
})
.ready(function (gadget) {
gadget.props = {};
return gadget.getSetting("hateoas_url")
......@@ -82,6 +123,7 @@
})
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("translateHtml", "translateHtml")
.declareMethod("getContent", function () {
......
......@@ -257,7 +257,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>968.33068.10194.31522</string> </value>
<value> <string>971.49164.31619.41506</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -275,7 +275,7 @@
</tuple>
<state>
<tuple>
<float>1530119779.91</float>
<float>1542713467.3</float>
<string>UTC</string>
</tuple>
</state>
......
import json
def getCredentialFromUrl(url_string):
username = password = url = ''
param_list = url_string.split('#')
if len(param_list) == 2:
param_list = param_list[1].split('&')
for param in param_list:
key, value = param.split('=')
if key == 'url':
url = value
elif key == 'username':
username = value
elif key == 'password':
password = value
return (url, username, password,)
hosting_subscription = context
if hosting_subscription.getSlapState() == 'destroy_requested':
return json.dumps({})
instance = hosting_subscription.getPredecessorValue()
if instance is None or instance.getSlapState() == 'destroy_requested':
return json.dumps({})
parameter_dict = instance.getConnectionXmlAsDict()
url_string = parameter_dict.get('monitor-setup-url', '')
if url_string:
if parameter_dict.has_key('monitor-user') and \
parameter_dict.has_key('monitor-password') and \
parameter_dict.has_key('monitor-base-url'):
username = parameter_dict.get('monitor-user')
password = parameter_dict.get('monitor-password')
url = parameter_dict.get('monitor-base-url') + '/public/feeds'
else:
url, username, password = getCredentialFromUrl(url_string)
else:
return json.dumps({})
return json.dumps({
'username': username,
'password': password,
'url': url
})
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>HostingSubscription_getMonitorParameterDict</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!