Commit afeff2aa authored by Thomas Gambier's avatar Thomas Gambier 🚴🏼 Committed by Rafael Monnerat

slapos_jio: fix computer and project status

  * fix JSLint
  * prevent the script from crashing when there is no data (no
partitions or no computer)
parent 3244ebb0
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
inline_status_template = Handlebars.compile(inline_status_source); inline_status_template = Handlebars.compile(inline_status_source);
function checkComputerStatus(options) { function checkComputerStatus(options) {
if ((!options) || (options && !options.news)) { if (!options || !options.news || !options.news.text) {
return 'ui-btn-no-data'; return 'ui-btn-no-data';
} }
if (options.news.text.startsWith("#access")) { if (options.news.text.startsWith("#access")) {
...@@ -21,14 +21,12 @@ ...@@ -21,14 +21,12 @@
return 'ui-btn-warning'; return 'ui-btn-warning';
} }
return 'ui-btn-ok'; return 'ui-btn-ok';
}
} else {
if (options.news.no_data) { if (options.news.no_data) {
return 'ui-btn-no-data'; return 'ui-btn-no-data';
} }
return 'ui-btn-error'; return 'ui-btn-error';
} }
}
function checkComputerPartitionStatus(options) { function checkComputerPartitionStatus(options) {
var message, var message,
...@@ -37,23 +35,26 @@ ...@@ -37,23 +35,26 @@
error_amount = 0, error_amount = 0,
total_amount = 0; total_amount = 0;
if ((!options) || (options && !options.computer_partition_news)) { if (!options || !options.computer_partition_news) {
return 'ui-btn-no-data'; return 'ui-btn-no-data';
} }
for (computer_partition in options.computer_partition_news) { for (computer_partition in options.computer_partition_news) {
if (options.computer_partition_news.hasOwnProperty(computer_partition) &&
options.computer_partition_news[computer_partition].text) {
message = options.computer_partition_news[computer_partition].text; message = options.computer_partition_news[computer_partition].text;
if (message.startsWith("#error")) { if (message.startsWith("#error")) {
partition_class = 'ui-btn-warning'; partition_class = 'ui-btn-warning';
error_amount++; error_amount += 1;
} }
total_amount++; total_amount += 1;
if ((error_amount > 0) && (error_amount < total_amount)) { if ((error_amount > 0) && (error_amount < total_amount)) {
// No need to continue the result will be a warnning // No need to continue the result will be a warnning
return partition_class; return partition_class;
} }
} }
}
if (total_amount === 0) { if (total_amount === 0) {
return 'ui-btn-no-data'; return 'ui-btn-no-data';
} }
...@@ -74,16 +75,23 @@ ...@@ -74,16 +75,23 @@
status_style = '', status_style = '',
right_style = ''; right_style = '';
if (result && result.news && result.news.computer) {
status_class = checkComputerStatus({news: result.news.computer}); status_class = checkComputerStatus({news: result.news.computer});
}
if ((status_class === 'ui-btn-error') || if ((status_class === 'ui-btn-error') ||
(status_class === 'ui-btn-no-data')) { (status_class === 'ui-btn-no-data')) {
right_class = status_class; right_class = status_class;
} else { } else {
if (result && result.news && result.news.partition) {
right_class = checkComputerPartitionStatus( right_class = checkComputerPartitionStatus(
{computer_partition_news: result.news.partition}); {computer_partition_news: result.news.partition}
);
}
} }
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'; monitor_url = 'https://monitor.app.officejs.com/#/' +
'?page=ojsm_dispatch&query=portal_type%3A%22Software%20Instance%22%20' +
'AND%20aggregate_reference%3A%22' + result.reference + '%22';
gadget.element.innerHTML = inline_status_template({ gadget.element.innerHTML = inline_status_template({
monitor_url: monitor_url, monitor_url: monitor_url,
......
...@@ -269,7 +269,7 @@ ...@@ -269,7 +269,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>974.62049.17150.785</string> </value> <value> <string>978.25610.31873.42666</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -287,7 +287,7 @@ ...@@ -287,7 +287,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1555352356.62</float> <float>1568302726.92</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*globals console, window, rJS, RSVP, loopEventListener, i18n, Handlebars, $*/ /*globals console, window, rJS, RSVP, loopEventListener, i18n, Handlebars, $*/
/*jslint indent: 2, nomen: true, maxlen: 80*/ /*jslint indent: 2, nomen: true, maxlen: 90*/
(function (window, rJS, RSVP, Handlebars) { (function (window, rJS, RSVP, Handlebars) {
"use strict"; "use strict";
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
inline_status_template = Handlebars.compile(inline_status_source); inline_status_template = Handlebars.compile(inline_status_source);
function checkComputerStatus(options) { function checkComputerStatus(options) {
if (!options) { if (!options || !options.text) {
return 'ui-btn-no-data'; return 'ui-btn-no-data';
} }
if (options.text.startsWith("#access")) { if (options.text.startsWith("#access")) {
...@@ -21,14 +21,12 @@ ...@@ -21,14 +21,12 @@
return 'ui-btn-warning'; return 'ui-btn-warning';
} }
return 'ui-btn-ok'; return 'ui-btn-ok';
}
} else {
if (options.no_data) { if (options.no_data) {
return 'ui-btn-no-data'; return 'ui-btn-no-data';
} }
return 'ui-btn-error'; return 'ui-btn-error';
} }
}
function checkComputerPartitionStatus(options) { function checkComputerPartitionStatus(options) {
var message, var message,
...@@ -42,18 +40,21 @@ ...@@ -42,18 +40,21 @@
} }
for (computer_partition in options) { for (computer_partition in options) {
if (options.hasOwnProperty(computer_partition) &&
options[computer_partition].text) {
message = options[computer_partition].text; message = options[computer_partition].text;
if (message.startsWith("#error")) { if (message.startsWith("#error")) {
partition_class = 'ui-btn-warning'; partition_class = 'ui-btn-warning';
error_amount++; error_amount += 1;
} }
total_amount++; total_amount += 1;
if ((error_amount > 0) && (error_amount < total_amount)) { if ((error_amount > 0) && (error_amount < total_amount)) {
// No need to continue the result will be a warnning // No need to continue the result will be a warnning
return partition_class; return partition_class;
} }
} }
}
if (!total_amount) { if (!total_amount) {
return 'ui-btn-no-data'; return 'ui-btn-no-data';
} }
...@@ -68,7 +69,11 @@ ...@@ -68,7 +69,11 @@
var previous_status = "START", var previous_status = "START",
status = 'ui-btn-no-data', status = 'ui-btn-no-data',
i; i;
if (!options || !options.news || !options.news.computer) {
return status;
}
for (i in options.news.computer) { for (i in options.news.computer) {
if (options.news.computer.hasOwnProperty(i)) {
status = checkComputerStatus(options.news.computer[i]); status = checkComputerStatus(options.news.computer[i]);
if (previous_status === "START") { if (previous_status === "START") {
previous_status = status; previous_status = status;
...@@ -85,6 +90,7 @@ ...@@ -85,6 +90,7 @@
} }
} }
} }
}
return status; return status;
} }
...@@ -93,8 +99,10 @@ ...@@ -93,8 +99,10 @@
status = 'ui-btn-no-data', status = 'ui-btn-no-data',
previous_status = "START"; previous_status = "START";
for (computer_reference in options.news.partition) { for (computer_reference in options.news.partition) {
if (options.news.partition.hasOwnProperty(computer_reference)) {
status = checkComputerPartitionStatus( status = checkComputerPartitionStatus(
options.news.partition[computer_reference]); options.news.partition[computer_reference]
);
if (previous_status === "START") { if (previous_status === "START") {
previous_status = status; previous_status = status;
} }
...@@ -114,6 +122,7 @@ ...@@ -114,6 +122,7 @@
} }
} }
} }
}
return status; return status;
} }
...@@ -135,7 +144,8 @@ ...@@ -135,7 +144,8 @@
right_class = checkProjectPartitionStatus(result); right_class = checkProjectPartitionStatus(result);
} }
monitor_url = gadget.props.hateoas_url + gadget.options.value.jio_key + '/Base_redirectToMonitor'; monitor_url = gadget.props.hateoas_url +
gadget.options.value.jio_key + '/Base_redirectToMonitor';
gadget.element.innerHTML = inline_status_template({ gadget.element.innerHTML = inline_status_template({
monitor_url: monitor_url, monitor_url: monitor_url,
status_class: status_class, status_class: status_class,
......
...@@ -257,7 +257,7 @@ ...@@ -257,7 +257,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>975.3495.41986.50397</string> </value> <value> <string>978.25609.22500.25258</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -275,7 +275,7 @@ ...@@ -275,7 +275,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1555352158.81</float> <float>1568302679.29</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