Commit 01bfd371 by Rafael Monnerat

slapos_jio: Use onLoop instead RSVP.delay and make a major clean up on the code.

1 parent a298c46e
Showing 28 changed files with 779 additions and 513 deletions
......@@ -12,14 +12,6 @@
<script src="gadget_slapos_computer_status.js"></script>
<link href="gadget_slapos_computer_status.css" rel="stylesheet" type="text/css"/>
<script id="sensor-status-template" type="text/x-handlebars-template">
<ul class="grid-items">
<li><a class="ui-btn ui-first-child {{status_class}}" data-i18n={{status_title}} >{{status_title}}</a></li>
<li><a class="ui-btn ui-first-child {{right_class}}" style="{{right_style}}">{{right_title}}</a></li>
</ul>
</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>
......
......@@ -40,6 +40,17 @@
</value>
</item>
<item>
<key> <string>_Copy_or_Move_Permission</string> </key>
<value>
<list>
<string>Manager</string>
<string>Authenticated</string>
<string>Developer</string>
<string>Owner</string>
</list>
</value>
</item>
<item>
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
......@@ -74,6 +85,15 @@
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>creators</string> </key>
<value>
<tuple>
<string>ERP5TypeTestCase</string>
<string>zope</string>
</tuple>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>gadget_slapos_computer_status.html</string> </value>
</item>
......@@ -92,6 +112,25 @@
<value> <string>en</string> </value>
</item>
<item>
<key> <string>modification_date</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1523884656.58</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Web Page</string> </value>
</item>
......@@ -234,7 +273,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>965.65216.36649.54425</string> </value>
<value> <string>966.58781.43824.3635</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +291,7 @@
</tuple>
<state>
<tuple>
<float>1520342668.3</float>
<float>1530120172.2</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -4,18 +4,10 @@
(function (window, rJS, RSVP, Handlebars) {
"use strict";
var gadget_klass = rJS(window),
sensor_status_source = gadget_klass.__template_element
.getElementById("sensor-status-template")
.innerHTML,
sensor_status_template = Handlebars.compile(sensor_status_source),
inline_status_source = gadget_klass.__template_element
.getElementById("inline-status-template")
.innerHTML,
inline_status_template = Handlebars.compile(inline_status_source),
loading_source = gadget_klass.__template_element
.getElementById("loading-template")
.innerHTML,
loading_template = Handlebars.compile(loading_source);
inline_status_template = Handlebars.compile(inline_status_source);
function checkComputerStatus(options) {
if ((!options) || (options && !options.news)) {
......@@ -73,6 +65,41 @@
return partition_class;
}
function getStatus(gadget) {
return new RSVP.Queue()
.push(function () {
return gadget.jio_get(gadget.options.value.jio_key);
})
.push(function (result) {
var monitor_url,
status_class = 'ui-btn-no-data',
status_title = 'Computer',
right_title = 'Partitions',
right_class = 'ui-btn-no-data',
status_style = '',
right_style = '';
status_class = checkComputerStatus(result);
right_class = checkComputerPartitionStatus(result);
monitor_url = 'https://monitor.app.officejs.com/#/?page=ojsm_dispatch&query=portal_type%3A%22Software%20Instance%22%20AND%20aggregate_reference%3A%22' + result.reference + '%22';
if (status_class === 'ui-btn-no-data') {
status_style = "color: transparent !important;";
}
gadget.element.innerHTML = inline_status_template({
monitor_url: monitor_url,
status_class: status_class,
status_title: status_title,
status_style: status_style,
right_class: right_class,
right_title: right_title,
right_style: right_style
});
return gadget;
});
}
gadget_klass
.ready(function (gadget) {
gadget.props = {};
......@@ -88,74 +115,20 @@
.declareMethod("getContent", function () {
return {};
})
.declareJob("getStatus", function () {
var gadget = this;
return getStatus(gadget);
})
.onLoop(function () {
var gadget = this;
return getStatus(gadget);
}, 300000)
.declareMethod("render", function (options) {
var gadget = this,
status_style,
middle_style,
queue = new RSVP.Queue();
function getComputerStatus(options) {
queue.push(function () {
return gadget.jio_get(options.value.jio_key);
// return gadget.jio_get("computer_module/20171103-94D99B");
})
.push(function (result) {
var project,
data_supply_line,
data_supply_line_list,
count = 0,
tmp,
sum = 0,
i,
no_data = true,
no_data_since_24_hours = true,
value = "",
template,
monitor_url,
status_class = 'ui-btn-no-data',
status_title = 'Computer',
right_title = 'Partitions',
right_class = 'ui-btn-no-data',
status_style = "color: transparent !important;",
right_style = 'color: transparent !important;';
if ((options.value !== undefined) && (options.doc === undefined)) {
options.doc = options.value.doc;
}
status_class = checkComputerStatus(result);
right_class = checkComputerPartitionStatus(result);
i = options;
// right_title = value.max? Math.round(value.max * 100 * 10) / 10 + '%': 'nan';
right_style = '';
status_style = '';
template = inline_status_template;
monitor_url = 'https://monitor.app.officejs.com/#/?page=ojsm_dispatch&query=portal_type%3A%22Software%20Instance%22%20AND%20aggregate_reference%3A%22' + result.reference + '%22';
if (status_class === 'ui-btn-no-data') {
status_style = "color: transparent !important;";
//monitor_url = "";
}
gadget.element.innerHTML = template({
monitor_url: monitor_url,
status_class: status_class,
status_title: status_title,
status_style: status_style,
middle_style: middle_style,
right_class: right_class,
right_title: right_title,
right_style: right_style
});
return RSVP.delay(300000);
})
.push(function () {
gadget.element.innerHTML = loading_template();
return getComputerStatus(options);
});
}
return queue.push(getComputerStatus(options));
var gadget = this;
gadget.options = options;
gadget.flag = options.value.jio_key;
return gadget.getStatus();
});
}(window, rJS, RSVP, Handlebars));
\ No newline at end of file
......@@ -40,6 +40,17 @@
</value>
</item>
<item>
<key> <string>_Copy_or_Move_Permission</string> </key>
<value>
<list>
<string>Manager</string>
<string>Authenticated</string>
<string>Developer</string>
<string>Owner</string>
</list>
</value>
</item>
<item>
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
......@@ -70,6 +81,15 @@
</value>
</item>
<item>
<key> <string>creators</string> </key>
<value>
<tuple>
<string>ERP5TypeTestCase</string>
<string>zope</string>
</tuple>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>gadget_slapos_computer_status.js</string> </value>
</item>
......@@ -88,6 +108,25 @@
<value> <string>en</string> </value>
</item>
<item>
<key> <string>modification_date</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1523884656.64</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Web Script</string> </value>
</item>
......@@ -230,7 +269,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>965.42326.49975.23552</string> </value>
<value> <string>968.33041.14393.16810</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +287,7 @@
</tuple>
<state>
<tuple>
<float>1520343714.57</float>
<float>1530119165.7</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -12,13 +12,6 @@
<script src="gadget_slapos_hosting_subscription_status.js"></script>
<link href="gadget_slapos_computer_status.css" rel="stylesheet" type="text/css"/>
<script id="sensor-status-template" type="text/x-handlebars-template">
<ul class="grid-items">
<li><a class="ui-btn ui-first-child {{status_class}}" data-i18n={{status_title}} >{{status_title}}</a></li>
</ul>
</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>
......
......@@ -40,6 +40,17 @@
</value>
</item>
<item>
<key> <string>_Copy_or_Move_Permission</string> </key>
<value>
<list>
<string>Manager</string>
<string>Authenticated</string>
<string>Developer</string>
<string>Owner</string>
</list>
</value>
</item>
<item>
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
......@@ -74,6 +85,14 @@
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>creators</string> </key>
<value>
<tuple>
<string>zope</string>
</tuple>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>gadget_slapos_hosting_subscription_status.html</string> </value>
</item>
......@@ -92,6 +111,25 @@
<value> <string>en</string> </value>
</item>
<item>
<key> <string>modification_date</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1523884656.83</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Web Page</string> </value>
</item>
......@@ -234,7 +272,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>965.42084.6603.48605</string> </value>
<value> <string>968.33074.267.61440</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +290,7 @@
</tuple>
<state>
<tuple>
<float>1520343086.84</float>
<float>1530120259.86</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -4,18 +4,10 @@
(function (window, rJS, RSVP, Handlebars) {
"use strict";
var gadget_klass = rJS(window),
sensor_status_source = gadget_klass.__template_element
.getElementById("sensor-status-template")
.innerHTML,
sensor_status_template = Handlebars.compile(sensor_status_source),
inline_status_source = gadget_klass.__template_element
.getElementById("inline-status-template")
.innerHTML,
inline_status_template = Handlebars.compile(inline_status_source),
loading_source = gadget_klass.__template_element
.getElementById("loading-template")
.innerHTML,
loading_template = Handlebars.compile(loading_source);
inline_status_template = Handlebars.compile(inline_status_source);
function checkHostingSubscriptionStatus(options) {
var message,
......@@ -52,6 +44,34 @@
return partition_class;
}
function getStatus(gadget) {
return new RSVP.Queue()
.push(function () {
return gadget.jio_get(gadget.options.value.jio_key);
})
.push(function (result) {
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 (status_class === 'ui-btn-no-data') {
status_style = "color: transparent !important;";
}
gadget.element.innerHTML = inline_status_template({
monitor_url: monitor_url,
status_class: status_class,
status_title: status_title,
status_style: status_style
});
return gadget;
}
);
}
gadget_klass
.ready(function (gadget) {
gadget.props = {};
......@@ -67,63 +87,19 @@
.declareMethod("getContent", function () {
return {};
})
.declareMethod("render", function (options) {
var gadget = this,
status_style,
middle_style,
queue = new RSVP.Queue();
function getInstallationStatus(options) {
queue.push(function () {
return gadget.jio_get(options.value.jio_key);
})
.push(function (result) {
var project,
data_supply_line,
data_supply_line_list,
count = 0,
tmp,
sum = 0,
i,
no_data = true,
no_data_since_24_hours = true,
value = "",
template,
monitor_url,
status_class = 'ui-btn-no-data',
status_title = 'Instances',
status_style = "color: transparent !important;";
if ((options.value !== undefined) && (options.doc === undefined)) {
options.doc = options.value.doc;
}
status_class = checkHostingSubscriptionStatus(result);
status_style = '';
template = inline_status_template;
monitor_url = 'https://monitor.app.officejs.com/#/?page=ojsm_dispatch&query=portal_type%3A%22Hosting%20Subscription%22%20AND%20title%3A' + result.title;
if (status_class === 'ui-btn-no-data') {
status_style = "color: transparent !important;";
}
gadget.element.innerHTML = template({
monitor_url: monitor_url,
status_class: status_class,
status_title: status_title,
status_style: status_style,
middle_style: middle_style
});
return RSVP.delay(300000);
})
.declareJob("getStatus", function () {
var gadget = this;
return getStatus(gadget);
})
.onLoop(function () {
var gadget = this;
return getStatus(gadget);
}, 300000)
.push(function () {
gadget.element.innerHTML = loading_template();
return getInstallationStatus(options);
});
}
return queue.push(getInstallationStatus(options));
.declareMethod("render", function (options) {
var gadget = this;
gadget.options = options;
gadget.flag = options.value.jio_key;
return gadget.getStatus();
});
}(window, rJS, RSVP, Handlebars));
\ No newline at end of file
......@@ -70,6 +70,14 @@
</value>
</item>
<item>
<key> <string>creators</string> </key>
<value>
<tuple>
<string>zope</string>
</tuple>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>gadget_slapos_hosting_subscription_status.js</string> </value>
</item>
......@@ -88,6 +96,25 @@
<value> <string>en</string> </value>
</item>
<item>
<key> <string>modification_date</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1523884656.86</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Web Script</string> </value>
</item>
......@@ -216,7 +243,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>ERP5TypeTestCase</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -230,7 +257,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>964.17481.5463.24917</string> </value>
<value> <string>968.33068.10194.31522</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +275,7 @@
</tuple>
<state>
<tuple>
<float>1519209652.66</float>
<float>1530119779.91</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -12,14 +12,6 @@
<script src="gadget_slapos_installation_status.js"></script>
<link href="gadget_slapos_computer_status.css" rel="stylesheet" type="text/css"/>
<script id="sensor-status-template" type="text/x-handlebars-template">
<ul class="grid-items">
<li><a class="ui-btn ui-first-child {{status_class}}" data-i18n={{status_title}} >{{status_title}}</a></li>
<li><a class="ui-btn ui-first-child {{right_class}}" style="{{right_style}}">{{right_title}}</a></li>
</ul>
</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}}" >{{status_title}}</div></div>
<div class="ui-block-c" style="width:50%"><div class="ui-bar ui-corner-all last-child {{right_class}}" style="{{right_style}}">{{right_title}}</div></div>
......
......@@ -40,6 +40,17 @@
</value>
</item>
<item>
<key> <string>_Copy_or_Move_Permission</string> </key>
<value>
<list>
<string>Manager</string>
<string>Authenticated</string>
<string>Developer</string>
<string>Owner</string>
</list>
</value>
</item>
<item>
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
......@@ -74,6 +85,14 @@
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>creators</string> </key>
<value>
<tuple>
<string>zope</string>
</tuple>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>gadget_slapos_installation_status.html</string> </value>
</item>
......@@ -92,6 +111,25 @@
<value> <string>en</string> </value>
</item>
<item>
<key> <string>modification_date</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1523884656.9</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Web Page</string> </value>
</item>
......@@ -234,7 +272,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>965.65289.26932.60672</string> </value>
<value> <string>966.58781.43824.3635</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +290,7 @@
</tuple>
<state>
<tuple>
<float>1520343230.79</float>
<float>1530120100.87</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -4,18 +4,10 @@
(function (window, rJS, RSVP, Handlebars) {
"use strict";
var gadget_klass = rJS(window),
sensor_status_source = gadget_klass.__template_element
.getElementById("sensor-status-template")
.innerHTML,
sensor_status_template = Handlebars.compile(sensor_status_source),
inline_status_source = gadget_klass.__template_element
.getElementById("inline-status-template")
.innerHTML,
inline_status_template = Handlebars.compile(inline_status_source),
loading_source = gadget_klass.__template_element
.getElementById("loading-template")
.innerHTML,
loading_template = Handlebars.compile(loading_source);
inline_status_template = Handlebars.compile(inline_status_source);
function checkInstallationStatus(options) {
if ((!options) || (options && !options.news)) {
......@@ -33,6 +25,29 @@
}
}
function getStatus(gadget) {
return new RSVP.Queue()
.push(function () {
return gadget.jio_get(gadget.options.value.jio_key);
})
.push(function (result) {
var status_class = 'ui-btn-no-data',
status_title = 'Installation',
status_style = "";
status_class = checkInstallationStatus(result);
if (status_class === 'ui-btn-no-data') {
status_style = "color: transparent !important;";
}
gadget.element.innerHTML = inline_status_template({
status_class: status_class,
status_title: status_title,
status_style: status_style
});
return gadget;
});
}
gadget_klass
.ready(function (gadget) {
gadget.props = {};
......@@ -48,61 +63,20 @@
.declareMethod("getContent", function () {
return {};
})
.declareMethod("render", function (options) {
var gadget = this,
status_style,
middle_style,
queue = new RSVP.Queue();
function getInstallationStatus(options) {
queue.push(function () {
return gadget.jio_get(options.value.jio_key);
})
.push(function (result) {
var project,
data_supply_line,
data_supply_line_list,
count = 0,
tmp,
sum = 0,
i,
no_data = true,
no_data_since_24_hours = true,
value = "",
template,
status_class = 'ui-btn-no-data',
status_title = 'Installation',
status_style = "color: transparent !important;";
if ((options.value !== undefined) && (options.doc === undefined)) {
options.doc = options.value.doc;
}