Commit 76974db4 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_jio: Hosting Subscription / Instance Monitor Status rework

  Indicate when instance is Slave, Stopped or Destroyed on the News Dict
  Display monitor url and more information on the monitor gadget
parent 3ae3590c
......@@ -27,14 +27,14 @@
.push(function (result) {
var i, value, len = result.data.total_rows;
for (i = 0; i < len; i += 1) {
if (1 || (result.data.rows[i].hasOwnProperty("id"))) {
value = result.data.rows[i].id;
result.data.rows[i].value.computer_monitoring_status = {
if (1 || (result.data.rows[i].value.SoftwareInstance_getNewsDict)) {
value = result.data.rows[i].value.SoftwareInstance_getNewsDict;
result.data.rows[i].value.SoftwareInstance_getNewsDict = {
field_gadget_param : {
css_class: "",
description: "The Status",
hidden: result.data.rows[i].value.portal_type === "Slave Instance",
"default": {jio_key: value},
hidden: 0,
"default": {jio_key: value, result: value},
key: "status",
url: "gadget_slapos_instance_status.html",
title: "Status",
......@@ -142,7 +142,7 @@
['title', 'Title'],
['reference', 'Reference'],
['portal_type', 'Type'],
['computer_monitoring_status', 'Status']
['SoftwareInstance_getNewsDict', 'Status']
], monitor_scope_list = [['', ''],
['Enabled', 'enable'],
['Disabled', 'disable']
......@@ -267,7 +267,8 @@
"my_monitoring_status": {
"description": "",
"title": "Monitoring Status",
"default": {jio_key: gadget.state.jio_key},
"default": {jio_key: gadget.state.jio_key,
result: gadget.state.doc.news},
"css_class": "",
"required": 0,
"editable": 0,
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>974.29153.39901.20360</string> </value>
<value> <string>974.49068.53964.3174</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1552959641.55</float>
<float>1554168123.09</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -12,10 +12,15 @@
<script src="gadget_slapos_instance_status.js"></script>
<link href="gadget_slapos_computer_status.css" rel="stylesheet" type="text/css"/>
<script id="inline-status-template" type="text/x-handlebars-template">
<script id="inline-status-no-link-template" type="text/x-handlebars-template">
<div class="ui-block-a" style="width:50%"><div class="ui-bar ui-corner-all first-child {{status_class}}" style="{{status_style}}" >{{status_title}}</div></div>
</script>
<script id="inline-status-template" type="text/x-handlebars-template">
<div class="ui-block-a" style="width:50%"><div class="ui-bar ui-corner-all first-child {{status_class}}" style="{{status_style}}" >
<a class="ui-btn ui-btn-icon-left ui-icon-desktop" href="{{monitor_url}}" target=_blank>{{status_title}}</a></div></div>
</script>
<script id="loading-template" type="text/x-handlebars-template">
<button data-i18n="loading" type="submit" class="responsive ui-btn ui-icon-spinner ui-icon-spin ui-btn-icon-center ui-disabled" style="border:none;">loading</button>
</script>
......
......@@ -272,7 +272,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>966.58781.43824.3635</string> </value>
<value> <string>972.32024.53732.34406</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -290,7 +290,7 @@
</tuple>
<state>
<tuple>
<float>1530120129.88</float>
<float>1554213561.03</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -7,7 +7,12 @@
inline_status_source = gadget_klass.__template_element
.getElementById("inline-status-template")
.innerHTML,
inline_status_template = Handlebars.compile(inline_status_source);
inline_status_template = Handlebars.compile(inline_status_source),
inline_status_no_link_source = gadget_klass.__template_element
.getElementById("inline-status-no-link-template")
.innerHTML,
inline_status_no_link_template = Handlebars
.compile(inline_status_no_link_source);
function checkInstanceStatus(options) {
if ((!options) || (options && !options.news)) {
......@@ -19,31 +24,68 @@
if (options.no_data) {
return 'ui-btn-no-data';
}
else if (options.is_slave) {
return 'ui-btn-is-slave';
}
else if (options.is_stopped) {
return 'ui-btn-is-stopped';
}
else if (options.is_destroyed) {
return 'ui-btn-is-destroyed';
}
return 'ui-btn-error';
}
}
function getStatus(gadget) {
return new RSVP.Queue()
.push(function () {
return gadget.jio_get(gadget.options.value.jio_key);
})
.push(function (result) {
function getStatus(gadget, result) {
var status_class = 'ui-btn-no-data',
status_title = 'Instance',
status_style = "";
status_style = "",
monitor_url,
template = inline_status_template;
monitor_url = 'https://monitor.app.officejs.com/#/?page=ojsm_dispatch&query=portal_type%3A%22Software%20Instance%22%20AND%20reference%3A%22' + result.reference + '%22';
status_class = checkInstanceStatus(result);
if (status_class === 'ui-btn-no-data') {
status_style = "color: transparent !important;";
}
else if (status_class === 'ui-btn-is-slave') {
status_class = 'ui-btn-no-data';
status_title = 'Slave';
}
else if (status_class === 'ui-btn-is-stopped') {
status_class = 'ui-btn-no-data';
status_title = 'Stopped';
}
else if (status_class === 'ui-btn-is-destroyed') {
status_class = 'ui-btn-no-data';
status_title = 'Destroyed';
}
if (status_class === 'ui-btn-no-data') {
gadget.element.innerHTML = inline_status_no_link_template({
status_class: status_class,
status_title: status_title,
status_style: status_style
});
} else {
gadget.element.innerHTML = inline_status_template({
monitor_url: monitor_url,
status_class: status_class,
status_title: status_title,
status_style: status_style
});
}
return gadget;
}
function getStatusLoop(gadget) {
return new RSVP.Queue()
.push(function () {
return gadget.jio_get(gadget.options.value.jio_key);
})
.push(function (result) {
return getStatus(gadget, result);
});
}
......@@ -62,20 +104,20 @@
.declareMethod("getContent", function () {
return {};
})
.declareJob("getStatus", function () {
.declareJob("getStatus", function (result) {
var gadget = this;
return getStatus(gadget);
return getStatus(gadget, {news: result});
})
.onLoop(function () {
var gadget = this;
return getStatus(gadget);
return getStatusLoop(gadget);
}, 300000)
.declareMethod("render", function (options) {
var gadget = this;
gadget.options = options;
gadget.flag = options.value.jio_key;
return gadget.getStatus();
return gadget.getStatus(options.value.result);
});
}(window, rJS, RSVP, Handlebars));
\ No newline at end of file
......@@ -257,7 +257,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>968.33056.31297.6997</string> </value>
<value> <string>974.50044.7881.17544</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -275,7 +275,7 @@
</tuple>
<state>
<tuple>
<float>1530119074.09</float>
<float>1554213380.38</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -2,4 +2,27 @@ from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
portal_type = context.getPortalType()
if portal_type == "Slave Instance":
return {
"user": "SlapOS Master",
"text": "#nodata is a slave %s" % context.getReference(),
"is_slave": 1
}
slap_state = context.getSlapState()
if portal_type == "Software Instance" and slap_state == "stop_requested":
return {
"user": "SlapOS Master",
"text": "#nodata is an stopped instance %s" % context.getReference(),
"is_stopped": 1
}
if portal_type == "Software Instance" and slap_state == "destroy_requested":
return {
"user": "SlapOS Master",
"text": "#nodata is an destroyed instance %s" % context.getReference(),
"is_destroyed": 1
}
return context.Base_getNewsDict(context)
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