Commit 85794c9d authored by Romain Courteaud's avatar Romain Courteaud

slapos_jio: xxx status gadget

parent f1070df6
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Background</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="handlebars.js"></script>
<script src="gadget_slapos_status.js"></script>
<link href="gadget_slapos_compute_node_status.css" rel="stylesheet" type="text/css"/>
<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>
<div class="ui-block-c" style="width:50%"><div class="ui-bar ui-corner-all last-child {{right_class}}" style="{{right_style}}">
<a class="ui-btn ui-btn-icon-left ui-icon-desktop" href="{{monitor_url}}" target=_blank> {{right_title}} </a></div></div>
</script>
</head>
<body>
</body>
</html>
\ No newline at end of file
/*globals window, rJS, Handlebars*/
/*jslint indent: 2, nomen: true, maxlen: 80*/
(function (window, rJS, Handlebars) {
"use strict";
var gadget_klass = rJS(window),
inline_status_source = gadget_klass.__template_element
.getElementById("inline-status-template")
.innerHTML,
inline_status_template = Handlebars.compile(inline_status_source);
function checkComputeNodeStatus(options) {
if (!options || !options.news || !options.news.text) {
return 'ui-btn-no-data';
}
if (options.news.text.startsWith("#access")) {
if (options.news.no_data_since_15_minutes) {
return 'ui-btn-error';
}
if (options.news.no_data_since_5_minutes) {
return 'ui-btn-warning';
}
return 'ui-btn-ok';
}
if (options.news.no_data) {
return 'ui-btn-no-data';
}
return 'ui-btn-error';
}
function checkComputePartitionStatus(options) {
var message,
compute_partition,
partition_class = 'ui-btn-ok',
error_amount = 0,
total_amount = 0;
if (!options || !options.compute_partition_news) {
return 'ui-btn-no-data';
}
for (compute_partition in options.compute_partition_news) {
if (options.compute_partition_news.hasOwnProperty(compute_partition) &&
options.compute_partition_news[compute_partition].text) {
message = options.compute_partition_news[compute_partition].text;
if (message.startsWith("#error")) {
partition_class = 'ui-btn-warning';
error_amount += 1;
}
total_amount += 1;
if ((error_amount > 0) && (error_amount < total_amount)) {
// No need to continue the result will be a warnning
return partition_class;
}
}
}
if (total_amount === 0) {
return 'ui-btn-no-data';
}
if (error_amount === total_amount) {
// No need to continue the result will be a warnning
return 'ui-btn-error';
}
return partition_class;
}
function getStatus(gadget, result) {
var monitor_url,
status_class = 'ui-btn-no-data',
status_title = 'Compute Node',
right_title = 'Partitions',
right_class = 'ui-btn-no-data',
status_style = '',
right_style = '';
if (result && result.news && result.news.compute_node) {
status_class = checkComputeNodeStatus({news: result.news.compute_node});
}
if ((status_class === 'ui-btn-error') ||
(status_class === 'ui-btn-no-data')) {
right_class = status_class;
} else {
if (result && result.news && result.news.partition) {
right_class = checkComputePartitionStatus(
{compute_partition_news: result.news.partition}
);
}
}
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({
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
.declareAcquiredMethod("jio_get", "jio_get")
.declareMethod("getContent", function () {
return {};
})
.declareJob("getStatus", function (result) {
return getStatus(this, {news: result});
})
.onLoop(function () {
var gadget = this;
if (gadget.state.jio_key) {
return gadget.jio_get(gadget.state.jio_key)
.push(function (result) {
return gadget.changeState(result);
});
}
}, 300000)
.declareMethod("render", function (options) {
var state_dict = options.value.result;
state_dict.jio_key = options.value.jio_key;
return this.changeState(state_dict);
})
.onStateChange(function () {
return getStatus(this, this.state);
});
}(window, rJS, Handlebars));
\ No newline at end of file
image_module/gadget_slapos_panel_png
image_module/gadget_slapos_invoice_logo_png
web_page_module/rjs_gadget_slapos_status_html
web_page_module/rjs_gadget_slapos_status_js
web_page_module/gadget_erp5_page_slap_cloud_contract_view_html
web_page_module/gadget_erp5_page_slap_cloud_contract_view_js
web_page_module/gadget_erp5_page_slap_request_contract_activation_html
......
......@@ -40,14 +40,14 @@ web_page_module/rjs_gadget_erp5_page_slap_compute_node_get_token_html
web_page_module/rjs_gadget_erp5_page_slap_compute_node_get_token_js
web_page_module/rjs_gadget_erp5_page_slap_compute_node_list_html
web_page_module/rjs_gadget_erp5_page_slap_compute_node_list_js
web_page_module/rjs_gadget_erp5_page_slap_computer_network_view_html
web_page_module/rjs_gadget_erp5_page_slap_computer_network_view_js
web_page_module/rjs_gadget_erp5_page_slap_compute_node_request_certificate_html
web_page_module/rjs_gadget_erp5_page_slap_compute_node_request_certificate_js
web_page_module/rjs_gadget_erp5_page_slap_compute_node_revoke_certificate_html
web_page_module/rjs_gadget_erp5_page_slap_compute_node_revoke_certificate_js
web_page_module/rjs_gadget_erp5_page_slap_compute_node_view_html
web_page_module/rjs_gadget_erp5_page_slap_compute_node_view_js
web_page_module/rjs_gadget_erp5_page_slap_computer_network_view_html
web_page_module/rjs_gadget_erp5_page_slap_computer_network_view_js
web_page_module/rjs_gadget_erp5_page_slap_controller_html
web_page_module/rjs_gadget_erp5_page_slap_controller_js
web_page_module/rjs_gadget_erp5_page_slap_delete_network_html
......@@ -204,6 +204,8 @@ web_page_module/rjs_gadget_slapos_project_status_html
web_page_module/rjs_gadget_slapos_project_status_js
web_page_module/rjs_gadget_slapos_site_status_html
web_page_module/rjs_gadget_slapos_site_status_js
web_page_module/rjs_gadget_slapos_status_html
web_page_module/rjs_gadget_slapos_status_js
web_page_module/rjs_gadget_slapos_translation_data_js
web_page_module/rjs_gadget_slapos_translation_html
web_page_module/rjs_gadget_slapos_utils_js
......
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