rabbitmq-server/deps/rabbitmq_management/priv/www/js/formatters.js

983 lines
28 KiB
JavaScript
Raw Normal View History

UNKNOWN_REPR = '<span class="unknown">?</span>';
2011-02-04 22:38:26 +08:00
FD_THRESHOLDS=[[0.95, 'red'],
2011-02-18 22:26:12 +08:00
[0.8, 'yellow']];
2011-02-04 22:38:26 +08:00
SOCKETS_THRESHOLDS=[[1.0, 'red'],
2011-02-18 22:26:12 +08:00
[0.8, 'yellow']];
2011-02-04 22:38:26 +08:00
PROCESS_THRESHOLDS=[[0.75, 'red'],
2011-02-18 22:26:12 +08:00
[0.5, 'yellow']];
function fmt_string(str, unknown) {
if (unknown == undefined) {
unknown = UNKNOWN_REPR;
}
if (str == undefined) {
return unknown;
}
return fmt_escape_html("" + str);
}
function fmt_si_prefix(num0, max0, thousand, allow_fractions) {
if (num == 0) return 0;
function f(n, m, p) {
if (m > thousand) return f(n / thousand, m / thousand, p + 1);
else return [n, m, p];
}
var num_power = f(num0, max0, 0);
2010-09-01 00:56:33 +08:00
var num = num_power[0];
var max = num_power[1];
var power = num_power[2];
var powers = ['', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'];
return (((power != 0 || allow_fractions) && max <= 10) ? num.toFixed(1) :
num.toFixed(0)) + powers[power];
}
function fmt_boolean(b, unknown) {
if (unknown == undefined) unknown = UNKNOWN_REPR;
if (b == undefined) return unknown;
return b ? "&#9679;" : "&#9675;";
}
2011-01-14 19:45:45 +08:00
function fmt_date(d) {
2014-06-25 19:11:07 +08:00
var res = fmt_date0(d);
return res[0] + ' ' + res[1];
}
function fmt_date_mini(d) {
var res = fmt_date0(d);
return res[1] + '<sub>' + res[0] + '</sub>';
}
function fmt_date0(d) {
2011-01-14 19:45:45 +08:00
function f(i) {
return i < 10 ? "0" + i : i;
}
2014-06-25 19:11:07 +08:00
return [d.getFullYear() + "-" + f(d.getMonth() + 1) + "-" +
f(d.getDate()), f(d.getHours()) + ":" + f(d.getMinutes()) +
":" + f(d.getSeconds())];
2011-01-14 19:45:45 +08:00
}
function fmt_timestamp(ts) {
return fmt_date(new Date(ts));
}
2014-06-25 19:11:07 +08:00
function fmt_timestamp_mini(ts) {
return fmt_date_mini(new Date(ts));
2011-01-14 19:45:45 +08:00
}
2012-06-12 20:07:41 +08:00
function fmt_time(t, suffix) {
if (t == undefined || t == 0) return '';
return t + suffix;
}
2012-10-02 23:53:39 +08:00
function fmt_millis(millis) {
return Math.round(millis / 1000) + "s";
2012-09-27 22:46:31 +08:00
}
function fmt_features(obj) {
return fmt_table_short(args_to_features(obj));
}
function fmt_policy_short(obj) {
if (obj.policy != undefined && obj.policy != '') {
return '<abbr class="policy" title="Policy: ' +
2015-01-05 21:31:58 +08:00
fmt_escape_html(obj.policy) + '">' +
link_policy(obj.vhost, obj.policy) + '</abbr> ';
} else {
return '';
}
2016-08-26 00:09:06 +08:00
}
function fmt_op_policy_short(obj) {
if (obj.operator_policy != undefined && obj.operator_policy != '') {
return '<abbr class="policy" title="Operator policy: ' +
fmt_escape_html(obj.operator_policy) + '">' +
fmt_escape_html(obj.operator_policy) + '</abbr> ';
2017-10-28 02:46:35 +08:00
} else {
return '';
}
}
function fmt_features_short(obj) {
var res = '';
var features = args_to_features(obj);
if (obj.owner_pid_details != undefined) {
res += '<acronym title="Exclusive queue: click for owning connection">'
+ link_conn(obj.owner_pid_details.name, "Excl") + '</acronym> ';
}
for (var k in ALL_ARGS) {
if (features[k] != undefined) {
res += '<abbr title="' + k + ': ' + fmt_string(features[k]) +
'">' + ALL_ARGS[k].short + '</abbr> ';
}
}
if (features.arguments) {
res += '<abbr title="' + fmt_table_flat(features.arguments) +
'">Args</abbr> ';
}
return res;
}
function short_conn(name) {
var pat = /^(.*)->/;
var match = pat.exec(name);
return (match != null && match.length == 2) ? match[1] : name;
}
function short_chan(name) {
var pat = /^(.*)->.*( \(.*\))/;
var match = pat.exec(name);
return (match != null && match.length == 3) ? match[1] + match[2] : name;
}
function args_to_features(obj) {
var res = {};
for (var k in obj.arguments) {
if (k in KNOWN_ARGS) {
res[k] = fmt_escape_html(obj.arguments[k]);
}
else {
if (res.arguments == undefined) res.arguments = {};
res.arguments[fmt_escape_html(k)] = fmt_escape_html(obj.arguments[k]);
}
}
if (obj.exclusive) {
res['exclusive'] = true;
}
if (obj.durable) {
res['durable'] = true;
}
if (obj.auto_delete) {
res['auto-delete'] = true;
}
if (obj.internal != undefined && obj.internal) {
res['internal'] = true;
}
2016-04-18 21:04:45 +08:00
if (obj.messages_delayed != undefined){
res['messages delayed'] = obj.messages_delayed;
}
return res;
}
2011-05-25 18:58:56 +08:00
function fmt_mirrors(queue) {
2011-07-15 22:52:29 +08:00
var synced = queue.synchronised_slave_nodes || [];
var unsynced = queue.slave_nodes || [];
unsynced = jQuery.grep(unsynced,
function (node, i) {
return jQuery.inArray(node, synced) == -1;
2011-07-15 22:52:29 +08:00
});
var res = '';
2011-08-16 20:24:17 +08:00
if (synced.length > 0) {
res += ' <abbr title="Synchronised mirrors: ' + synced + '">+' +
synced.length + '</abbr>';
2011-07-15 22:52:29 +08:00
}
2011-08-16 20:24:17 +08:00
if (synced.length == 0 && unsynced.length > 0) {
res += ' <abbr title="There are no synchronised mirrors">+0</abbr>';
2011-08-16 20:24:17 +08:00
}
2011-07-15 22:52:29 +08:00
if (unsynced.length > 0) {
res += ' <abbr class="warning" title="Unsynchronised mirrors: ' +
unsynced + '">+' + unsynced.length + '</abbr>';
2011-05-25 18:58:56 +08:00
}
2011-07-15 22:52:29 +08:00
return res;
2011-05-25 18:58:56 +08:00
}
2013-12-10 22:28:33 +08:00
function fmt_sync_state(queue) {
var res = '<p><b>Syncing: ';
2013-01-09 03:38:03 +08:00
res += (queue.messages == 0) ? 100 : Math.round(100 * queue.sync_messages /
queue.messages);
res += '%</b></p>';
return res;
}
function fmt_members(queue) {
var res = '';
var IsMayority = (queue.online.length >= (Math.floor(queue.members.length / 2) + 1));
var followers = queue.online;
followers.splice(followers.indexOf(queue.node), 1);
if (IsMayority) {
res += ' <abbr title="Followers: ' + followers + '">+' +
followers.length + '</abbr>';
} else {
res += ' <abbr class="warning" title="Cluster is in minority">+' + followers.length + '</abbr>';
}
return res;
}
2011-01-21 21:17:41 +08:00
function fmt_channel_mode(ch) {
if (ch.transactional) {
return '<abbr title="Transactional">T</abbr>';
2011-01-21 21:17:41 +08:00
}
else if (ch.confirm) {
return '<abbr title="Confirm">C</abbr>';
2011-01-21 21:17:41 +08:00
}
else {
return '';
}
}
2010-10-29 23:32:17 +08:00
function fmt_color(r, thresholds) {
if (r == undefined) return '';
2010-10-29 23:32:17 +08:00
for (var i in thresholds) {
2011-02-18 22:26:12 +08:00
var threshold = thresholds[i][0];
var color = thresholds[i][1];
2010-10-29 23:32:17 +08:00
2011-02-18 22:26:12 +08:00
if (r >= threshold) {
return color;
}
2010-10-29 23:32:17 +08:00
}
2010-10-30 00:58:21 +08:00
return 'green';
}
2012-01-05 01:16:20 +08:00
function fmt_rate_num(num) {
if (num == undefined) return UNKNOWN_REPR;
2012-01-05 05:23:58 +08:00
else if (num < 1) return num.toFixed(2);
else if (num < 10) return num.toFixed(1);
2015-09-03 18:00:05 +08:00
else return fmt_num_thousands(num);
}
2015-09-03 18:00:05 +08:00
function fmt_num_thousands(num) {
var conv_num = parseFloat(num); // to avoid errors, if someone calls fmt_num_thousands(someNumber.toFixed(0))
return fmt_num_thousands_unfixed(conv_num.toFixed(0));
}
function fmt_num_thousands_unfixed(num) {
if (num == undefined) return UNKNOWN_REPR;
num = '' + num;
if (num.length < 4) return num;
res= fmt_num_thousands_unfixed(num.slice(0, -3)) + ',' + num.slice(-3);
return res;
2012-01-05 01:16:20 +08:00
}
function fmt_percent(num) {
2013-11-20 19:18:13 +08:00
if (num === '') {
return 'N/A';
} else {
return Math.round(num * 100) + '%';
}
}
function pick_rate(fmt, obj, name, mode) {
if (obj == undefined || obj[name] == undefined ||
obj[name + '_details'] == undefined) return '';
var details = obj[name + '_details'];
return fmt(mode == 'avg' ? details.avg_rate : details.rate);
}
function pick_abs(fmt, obj, name, mode) {
if (obj == undefined || obj[name] == undefined ||
obj[name + '_details'] == undefined) return '';
var details = obj[name + '_details'];
return fmt(mode == 'avg' ? details.avg : obj[name]);
}
function fmt_detail_rate(obj, name, mode) {
2015-02-18 21:43:51 +08:00
return pick_rate(fmt_rate, obj, name, mode);
}
function fmt_detail_rate_bytes(obj, name, mode) {
2015-02-18 21:43:51 +08:00
return pick_rate(fmt_rate_bytes, obj, name, mode);
2012-12-19 21:31:26 +08:00
}
// ---------------------------------------------------------------------
// These are pluggable for charts etc
function fmt_plain(num) {
return num;
}
function fmt_plain_axis(num, max) {
return fmt_si_prefix(num, max, 1000, true);
}
function fmt_rate(num) {
return fmt_rate_num(num) + '/s';
}
function fmt_rate_axis(num, max) {
return fmt_plain_axis(num, max) + '/s';
2013-04-09 19:54:02 +08:00
}
function fmt_bytes(bytes) {
if (bytes == undefined) return UNKNOWN_REPR;
return fmt_si_prefix(bytes, bytes, 1024, false) + 'B';
2013-04-09 19:54:02 +08:00
}
function fmt_bytes_axis(num, max) {
num = parseInt(num);
return fmt_bytes(isNaN(num) ? 0 : num);
}
function fmt_rate_bytes(num) {
return fmt_bytes(num) + '/s';
}
function fmt_rate_bytes_axis(num, max) {
return fmt_bytes_axis(num, max) + '/s';
}
function fmt_ms(num) {
return fmt_rate_num(num) + 'ms';
}
// ---------------------------------------------------------------------
2014-08-07 21:20:10 +08:00
function fmt_maybe_vhost(name) {
return vhosts_interesting ?
' in virtual host <b>' + fmt_escape_html(name) + '</b>'
: '';
}
2010-08-27 00:42:03 +08:00
function fmt_exchange(name) {
return fmt_escape_html(fmt_exchange0(name));
}
function fmt_exchange0(name) {
return name == '' ? '(AMQP default)' : name;
2010-08-27 00:42:03 +08:00
}
2012-01-25 21:13:04 +08:00
function fmt_exchange_type(type) {
for (var i in exchange_types) {
if (exchange_types[i].name == type) {
return fmt_escape_html(type);
}
}
return '<div class="status-red"><abbr title="Exchange type not found. ' +
2012-01-25 21:13:04 +08:00
'Publishing to this exchange will fail.">' + fmt_escape_html(type) +
'</abbr></div>';
2012-01-25 21:13:04 +08:00
}
2010-08-27 00:42:03 +08:00
function fmt_exchange_url(name) {
return name == '' ? 'amq.default' : fmt_escape_html(name);
2010-08-27 00:42:03 +08:00
}
function fmt_download_filename(host) {
var now = new Date();
return host.replace('@', '_') + "_" + now.getFullYear() + "-" +
(now.getMonth() + 1) + "-" + now.getDate() + ".json";
}
2010-10-12 21:08:17 +08:00
function fmt_table_short(table) {
return '<table class="mini">' + fmt_table_body(table, ':') + '</table>';
}
function fmt_table_long(table) {
return '<table class="facts">' + fmt_table_body(table, '') +
'</table>';
}
function fmt_table_body(table, x) {
2010-10-12 21:08:17 +08:00
var res = '';
for (k in table) {
2015-01-05 21:31:27 +08:00
res += '<tr><th>' + fmt_escape_html(k) + x + '</th>' +
'<td>' + fmt_amqp_value(table[k]) + '</td>';
2010-10-12 21:08:17 +08:00
}
return res;
}
function fmt_amqp_value(val) {
if (val instanceof Array) {
var val2 = new Array();
for (var i = 0; i < val.length; i++) {
val2[i] = fmt_amqp_value(val[i]);
}
return val2.join("<br/>");
} else if (val instanceof Object) {
2011-02-17 19:47:23 +08:00
return fmt_table_short(val);
} else {
var t = typeof(val);
if (t == 'string') {
return '<abbr class="type" title="string">' +
fmt_escape_html(val) + '</abbr>';
} else {
return '<abbr class="type" title="' + t + '">' + val + '</abbr>';
}
}
}
function fmt_table_flat(table) {
var res = [];
for (k in table) {
res.push(fmt_escape_html(k) + ': ' + fmt_amqp_value_flat(table[k]));
}
return res.join(', ');
}
function fmt_amqp_value_flat(val) {
if (val instanceof Array) {
var val2 = new Array();
for (var i = 0; i < val.length; i++) {
val2[i] = fmt_amqp_value_flat(val[i]);
}
return '[' + val2.join(",") + ']';
} else if (val instanceof Object) {
return '(' + fmt_table_flat(val) + ')';
} else if (typeof(val) == 'string') {
return fmt_escape_html(val);
} else {
return val;
}
}
function fmt_uptime(u) {
var uptime = Math.floor(u / 1000);
var sec = uptime % 60;
var min = Math.floor(uptime / 60) % 60;
var hour = Math.floor(uptime / 3600) % 24;
var day = Math.floor(uptime / 86400);
if (day > 0)
return day + 'd ' + hour + 'h';
else if (hour > 0)
return hour + 'h ' + min + 'm';
else
return min + 'm ' + sec + 's';
}
function fmt_plugins_small(node) {
if (node.applications === undefined) return '';
var plugins = [];
for (var i = 0; i < node.applications.length; i++) {
var application = node.applications[i];
if (jQuery.inArray(application.name, node.enabled_plugins) != -1 ) {
plugins.push(application.name);
}
}
return '<abbr title="Enabled plugins: ' + plugins.join(", ") + '">' +
plugins.length + '</abbr>';
}
function get_plugins_list(node) {
var result = [];
for (var i = 0; i < node.applications.length; i++) {
var application = node.applications[i];
if (jQuery.inArray(application.name, node.enabled_plugins) != -1 ) {
result.push(application);
}
}
return result;
}
function fmt_rabbit_version(applications) {
for (var i in applications) {
if (applications[i].name == 'rabbit') {
return applications[i].version;
}
}
return 'unknown';
}
function fmt_strip_tags(txt) {
if(txt === null) {
return "";
}
if(txt === undefined) {
return "";
}
return ("" + txt).replace(/<(?:.|\n)*?>/gm, '');
}
function fmt_escape_html(txt) {
2012-04-24 20:35:32 +08:00
return fmt_escape_html0(txt).replace(/\n/g, '<br/>');
}
function fmt_escape_html_one_line(txt) {
return fmt_escape_html0(txt).replace(/\n/g, '');
}
function fmt_escape_html0(txt) {
if(txt === null) {
return "";
}
if(txt === undefined) {
return "";
}
return ("" + txt).replace(/&/g, '&amp;')
2012-01-23 23:34:25 +08:00
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/\"/g, '&quot;');
}
function fmt_maybe_wrap(txt, encoding) {
if (encoding == 'string') return fmt_escape_html(txt);
var WRAP = 120;
var res = '';
while (txt != '') {
var i = txt.indexOf('\n');
if (i == -1 || i > WRAP) {
i = Math.min(WRAP, txt.length);
res += txt.substring(0, i) + '\n';
txt = txt.substring(i);
}
else {
res += txt.substring(0, i + 1);
txt = txt.substring(i + 1);
}
}
return fmt_escape_html(res);
}
function fmt_node(node_host) {
2017-09-19 01:49:00 +08:00
return fmt_string(node_host);
2011-06-14 00:36:26 +08:00
}
function fmt_object_state(obj) {
if (obj.state == undefined) return '';
2012-01-13 23:10:30 +08:00
var colour = 'green';
var text = obj.state;
2012-01-13 23:10:30 +08:00
var explanation;
if (obj.idle_since !== undefined) {
colour = 'grey';
explanation = 'Idle since ' + obj.idle_since;
text = 'idle';
}
// Only connections can be 'blocked' or 'blocking'
else if (obj.state == 'blocked') {
2012-01-13 23:10:30 +08:00
colour = 'red';
explanation = 'Resource alarm: connection blocked.';
2012-01-13 23:10:30 +08:00
}
else if (obj.state == 'blocking') {
2012-01-13 23:10:30 +08:00
colour = 'yellow';
explanation = 'Resource alarm: connection will block on publish.';
2012-01-13 23:10:30 +08:00
}
else if (obj.state == 'flow') {
colour = 'yellow';
explanation = 'Publishing rate recently throttled by server.';
}
else if (obj.state == 'down') {
colour = 'red';
explanation = 'The queue is located on a cluster node or nodes that ' +
'are down.';
}
2014-09-11 19:05:18 +08:00
else if (obj.state == 'crashed') {
colour = 'red';
explanation = 'The queue has crashed repeatedly and been unable to ' +
'restart.';
}
else if (obj.state == 'stopped') {
colour = 'red';
explanation = 'The queue process was stopped by the vhost supervisor.';
}
2014-01-21 23:36:17 +08:00
return fmt_state(colour, text, explanation);
}
function fmt_state(colour, text, explanation) {
var key;
2012-01-13 23:10:30 +08:00
if (explanation) {
key = '<abbr class="normal" title="' + explanation + '">' +
text + '</abbr>';
}
else {
2014-01-21 23:36:17 +08:00
key = text;
}
2014-01-21 23:36:17 +08:00
return '<div class="colour-key status-key-' + colour + '"></div>' + key;
}
2013-02-02 01:31:34 +08:00
function fmt_shortened_uri(uri) {
if (typeof uri == 'object') {
var res = '';
for (i in uri) {
res += fmt_shortened_uri(uri[i]) + '<br/>';
}
return res;
}
var uri = fmt_escape_html(uri);
2012-04-24 01:43:28 +08:00
if (uri.indexOf('?') == -1) {
return uri;
}
else {
return '<abbr title="' + uri + '">' +
uri.substr(0, uri.indexOf('?')) + '?...</abbr>';
2012-04-24 01:43:28 +08:00
}
}
function fmt_uri_with_credentials(uri) {
if (typeof uri == 'string') {
// mask password
2017-08-30 07:27:39 +08:00
var mask = /^([a-zA-Z0-9+-.]+):\/\/(.*):(.*)@/;
return uri.replace(mask, "$1://$2:[redacted]@");
} else {
return UNKNOWN_REPR;
}
}
function fmt_client_name(properties) {
var res = [];
if (properties.product != undefined) {
res.push(fmt_trunc(properties.product, 10));
}
if (properties.platform != undefined) {
res.push(fmt_trunc(properties.platform, 10));
}
res = res.join(" / ");
if (properties.version != undefined) {
res += '<sub>' + fmt_trunc(properties.version) + '</sub>';
}
return res;
}
function fmt_trunc(str, max_length) {
return str.length > max_length ?
('<abbr class="normal" title="' + fmt_escape_html(str) + '">' +
fmt_escape_html(str.substring(0, max_length)) + '...</abbr>') :
fmt_escape_html(str);
}
function alt_rows(i, args) {
var css = [(i % 2 == 0) ? 'alt1' : 'alt2'];
if (args != undefined && args['x-internal-purpose'] != undefined) {
css.push('internal-purpose');
}
return ' class="' + css.join(' ') + '"';
}
2010-08-24 18:37:54 +08:00
function esc(str) {
return encodeURIComponent(str);
}
function link_conn(name, desc) {
if (desc == undefined) {
return _link_to(short_conn(name), '#/connections/' + esc(name));
}
else {
return _link_to(desc, '#/connections/' + esc(name), false);
}
}
2010-09-03 00:06:59 +08:00
function link_channel(name) {
2017-08-01 23:31:03 +08:00
return _link_to(short_chan(name), '#/channels/' + esc(name));
2010-09-03 00:06:59 +08:00
}
function link_exchange(vhost, name, args) {
2010-08-27 00:42:03 +08:00
var url = esc(vhost) + '/' + (name == '' ? 'amq.default' : esc(name));
return _link_to(fmt_exchange0(name), '#/exchanges/' + url, true, args);
2010-08-27 00:42:03 +08:00
}
function link_queue(vhost, name, args) {
return _link_to(name, '#/queues/' + esc(vhost) + '/' + esc(name), true, args);
2010-08-27 17:55:32 +08:00
}
function link_vhost(name) {
2017-08-01 23:31:03 +08:00
return _link_to(name, '#/vhosts/' + esc(name));
}
function link_user(name) {
2017-08-01 23:31:03 +08:00
return _link_to(name, '#/users/' + esc(name));
}
function link_node(name) {
return _link_to(fmt_node(name), '#/nodes/' + esc(name));
}
2012-08-08 00:39:09 +08:00
function link_policy(vhost, name) {
2017-08-01 23:31:03 +08:00
return _link_to(name, '#/policies/' + esc(vhost) + '/' + esc(name));
2012-05-18 22:33:13 +08:00
}
function _link_to(name, url, highlight, args) {
if (highlight == undefined) highlight = true;
var title = null;
if (args != undefined && args['x-internal-purpose'] != undefined) {
var purpose = args['x-internal-purpose'];
title = 'This is used internally by the ' + purpose + ' mechanism.';
}
return '<a href="' + url + '"' +
(title ? ' title="' + title + '"' : '') + '>' +
(highlight ? fmt_highlight_filter(name) : fmt_escape_html(name)) +
'</a>';
2010-09-03 00:06:59 +08:00
}
2013-03-06 02:04:15 +08:00
function fmt_highlight_filter(text) {
if (current_filter == '') return fmt_escape_html(text);
2013-11-13 00:41:31 +08:00
var text_to_match = current_filter.toLowerCase();
if (current_filter_regex) {
var potential_match = current_filter_regex.exec(text.toLowerCase());
if (potential_match) {
text_to_match = potential_match[0];
}
}
var ix = text.toLowerCase().indexOf(text_to_match);
var l = text_to_match.length;
2013-03-06 02:04:15 +08:00
if (ix == -1) {
return fmt_escape_html(text);
2013-03-06 02:04:15 +08:00
}
else {
return fmt_escape_html(text.substring(0, ix)) +
'<span class="filter-highlight">' +
fmt_escape_html(text.substring(ix, ix + l)) + '</span>' +
fmt_escape_html(text.substring(ix + l));
2013-03-06 02:04:15 +08:00
}
2010-09-03 00:06:59 +08:00
}
2015-10-22 18:46:52 +08:00
function filter_ui_pg(items, truncate, appendselect) {
2013-03-06 22:59:31 +08:00
var total = items.length;
2013-03-06 02:04:15 +08:00
if (current_filter != '') {
var items2 = [];
for (var i in items) {
var item = items[i];
2013-11-13 00:41:31 +08:00
var item_name = item.name.toLowerCase();
if ((current_filter_regex_on &&
current_filter_regex &&
current_filter_regex.test(item_name)) ||
item_name.indexOf(current_filter.toLowerCase()) != -1) {
2013-03-06 02:04:15 +08:00
items2.push(item);
}
}
items.length = items2.length;
for (var i in items2) items[i] = items2[i];
}
var res = '<div class="filter"><table' +
2013-03-07 18:43:24 +08:00
(current_filter == '' ? '' : ' class="filter-active"') +
'><tr><th>Filter:</th>' +
2013-03-06 22:59:31 +08:00
'<td><input id="filter" type="text" value="' +
2013-11-13 00:41:31 +08:00
fmt_escape_html(current_filter) + '"/>' +
'<input type="checkbox" name="filter-regex-mode" id="filter-regex-mode"' +
(current_filter_regex_on ? ' checked' : '') +
'/><label for="filter-regex-mode">Regex</label> <span class="help" id="filter-regex"></span>' +
'</td></tr></table>';
2013-03-26 20:42:29 +08:00
function items_desc(l) {
return l == 1 ? (l + ' item') : (l + ' items');
}
var selected = current_filter == '' ? (items_desc(items.length)) :
(items.length + ' of ' + items_desc(total) + ' selected');
2015-10-22 18:46:52 +08:00
selected += appendselect;
2015-10-22 15:55:36 +08:00
res += '<p id="filter-truncate"><span class="updatable">' + selected +
'</span>' + truncate + '</p>';
res += '</div>';
return res;
}
2013-04-25 23:13:44 +08:00
2015-10-22 15:55:36 +08:00
function filter_ui(items) {
current_truncate = (current_truncate == null) ?
parseInt(get_pref('truncate')) : current_truncate;
var truncate_input = '<input type="text" id="truncate" value="' +
current_truncate + '">';
var selected = '';
2013-04-25 23:13:44 +08:00
if (items.length > current_truncate) {
selected += '<span id="filter-warning-show"> ' +
'(only showing first</span> ';
2013-04-25 23:13:44 +08:00
items.length = current_truncate;
}
2013-03-06 22:59:31 +08:00
else {
selected += ', page size up to ';
2013-03-06 22:59:31 +08:00
}
2015-10-22 20:35:37 +08:00
return filter_ui_pg(items, truncate_input, selected);
2013-03-06 22:59:31 +08:00
}
2015-11-17 23:59:49 +08:00
function paginate_header_ui(pages, context){
var res = '<h2 class="updatable">' ;
res += ' All ' + context +' (' + pages.total_count + ((pages.filtered_count != pages.total_count) ? ' Filtered: ' + pages.filtered_count : '') + ')';
res += '</h2>'
return res;
}
2019-01-03 04:51:27 +08:00
function paginate_ui(pages, context){
2015-11-17 23:59:49 +08:00
var res = paginate_header_ui(pages, context);
res += '<div class="hider">';
res += '<h3>Pagination</h3>';
res += '<div class="filter">';
res += '<table class="updatable">';
2019-01-03 04:51:27 +08:00
res += '<tr>';
2016-01-24 18:28:51 +08:00
res += '<th><label for="'+ context +'-page">Page </label> <select id="'+ context +'-page" class="pagination_class pagination_class_select" >';
2015-11-17 23:59:49 +08:00
var page = fmt_page_number_request(context, pages.page);
if (pages.page_count > 0 && page > pages.page_count){
page = pages.page_count;
update_pages(context, page);
return;
};
for (var i = 1; i <= pages.page_count; i++) { ;
if (i == page) {;
res += ' <option selected="selected" value="'+ i + '">' + i + '</option>';
} else { ;
res += '<option value="' + i + '"> ' + i + '</option>';
} };
res += '</select> </th>';
res += '<th><label for="'+ context +'-pageof">of </label> ' + pages.page_count +'</th>';
2016-01-24 18:28:51 +08:00
res += '<th><span><label for="'+ context +'-name"> - Filter: </label> <input id="'+ context +'-name" data-page-start="1" class="pagination_class pagination_class_input" type="text"' ;
2015-11-17 23:59:49 +08:00
res += 'value = ' + fmt_filter_name_request(context, "") + '>' ;
res += '</input></th></span>' ;
2016-01-24 18:28:51 +08:00
res += '<th> <input type="checkbox" data-page-start="1" class="pagination_class pagination_class_checkbox" id="'+ context +'-filter-regex-mode"' ;
res += fmt_regex_request(context, "") + '></input> <label for="filter-regex-mode">Regex</label> <span class="help" id="filter-regex"></span></th>' ;
2015-11-17 23:59:49 +08:00
res +=' </table>' ;
res += '<p id="filter-truncate"><span class="updatable">';
res += '<span><label for="'+ context +'-pagesize"> Displaying ' + pages.item_count + ' item'+ ((pages.item_count > 1) ? 's' : '' ) + ' , page size up to: </label> ';
2016-01-24 18:28:51 +08:00
res += ' <input id="'+ context +'-pagesize" data-page-start="1" class="pagination_class shortinput pagination_class_input" type="text" ';
2015-11-17 23:59:49 +08:00
res += 'value = "' + fmt_page_size_request(context, pages.page_size) +'"';
res += 'onkeypress = "return isNumberKey(event)"> </input></span></p>' ;
res += '</tr>'
res += '</div>'
res += '</div>'
return res;
}
2015-10-22 15:55:36 +08:00
function maybe_truncate(items) {
var maximum = 500;
var str = '';
if (items.length > maximum) {
str = '<p class="warning">Only ' + maximum + ' of ' +
items.length + ' items are shown.</p>';
items.length = maximum;
}
return str;
}
2010-10-12 00:05:06 +08:00
function fmt_sort(display, sort) {
var prefix = '';
if (current_sort == sort) {
prefix = '<span class="arrow">' +
(current_sort_reverse ? '&#9661; ' : '&#9651; ') +
2010-10-12 00:05:06 +08:00
'</span>';
}
return '<a class="sort" sort="' + sort + '">' + prefix + display + '</a>';
}
2014-09-27 01:09:25 +08:00
function group_count(mode, group, bools) {
2014-09-19 22:44:43 +08:00
var count = 0;
for (var i = 0; i < bools.length; i++) {
if (bools[i]) count++;
}
var options = COLUMNS[mode][group];
for (var i = 0; i < options.length; i++) {
var column = options[i][0];
if (show_column(mode, column)) count++;
}
2014-09-27 01:09:25 +08:00
return count;
}
2014-09-19 22:44:43 +08:00
2014-09-27 01:09:25 +08:00
function group_heading(mode, group, bools) {
var count = group_count(mode, group, bools);
2014-09-19 22:44:43 +08:00
if (count == 0) {
return '';
}
else {
return '<th colspan="' + count + '">' + group + '</th>';
}
}
function fmt_permissions(obj, permissions, lookup, show, warning) {
var res = [];
for (var i in permissions) {
var permission = permissions[i];
if (permission[lookup] == obj.name) {
res.push(fmt_escape_html(permission[show]));
}
}
return res.length == 0 ? warning : res.join(', ');
2011-04-09 00:00:05 +08:00
}
2013-01-28 22:34:15 +08:00
var radio_id = 0;
function fmt_radio(name, text, value, current) {
radio_id++;
return '<label class="radio" for="radio-' + radio_id + '">' +
'<input type="radio" id="radio-' + radio_id + '" name="' + name +
2013-01-28 22:34:15 +08:00
'" value="' + value + '"' +
((value == current) ? ' checked="checked"' : '') +
'>' + text + '</label>';
}
function fmt_checkbox(name, text, current) {
return '<label class="checkbox" for="checkbox-' + name + '">' +
'<input type="checkbox" id="checkbox-' + name + '" name="' + name +
'"' + (current ? ' checked="checked"' : '') + '>' + text + '</label>';
}
function properties_size(obj) {
var count = 0;
for (k in obj) {
if (obj.hasOwnProperty(k)) count++;
}
return count;
}
2015-11-13 05:25:01 +08:00
2019-01-03 04:55:44 +08:00
function stored_value_or_default(template, defaultValue){
2019-01-03 05:08:26 +08:00
var stored_value = get_pref(template);
var result = (((stored_value == null)
|| (stored_value == undefined)
|| (stored_value == '')) ? defaultValue :
stored_value);
2015-11-13 05:25:01 +08:00
return ((result == undefined) ? defaultValue : result);
2011-04-09 00:00:05 +08:00
}
2015-10-15 18:44:36 +08:00
2015-10-22 18:46:52 +08:00
function fmt_page_number_request(template, defaultPage){
if ((defaultPage == undefined) || (defaultPage <= 0))
2015-10-22 18:46:52 +08:00
defaultPage = 1;
2019-01-03 04:55:44 +08:00
return stored_value_or_default(template + '_current_page_number', defaultPage);
2015-10-15 18:44:36 +08:00
}
2015-10-22 18:46:52 +08:00
function fmt_page_size_request(template, defaultPageSize){
if ((defaultPageSize == undefined) || (defaultPageSize < 0))
2015-10-15 18:44:36 +08:00
defaultPageSize = 100;
2019-01-03 04:55:44 +08:00
result = stored_value_or_default(template + '_current_page_size', defaultPageSize);
2015-10-22 18:46:52 +08:00
if (result > 500) result = 500; // max
2015-10-15 18:44:36 +08:00
return result;
}
2015-11-13 05:25:01 +08:00
function fmt_filter_name_request(template, defaultName){
return fmt_escape_html(stored_value_or_default(template + '_current_filter_name', defaultName));
2015-11-13 05:25:01 +08:00
}
2015-11-17 23:59:49 +08:00
function fmt_regex_request(template, defaultName){
return fmt_escape_html(stored_value_or_default(template + '_current_regex', defaultName));
2015-11-17 23:59:49 +08:00
}
2015-11-13 05:25:01 +08:00
function fmt_vhost_state(vhost){
var cluster_state = vhost.cluster_state;
var down_nodes = [];
var ok_count = 0;
var non_ok_count = 0;
for(var node in cluster_state){
var node_state = cluster_state[node];
if(cluster_state[node] == "stopped" || cluster_state[node] == "nodedown"){
non_ok_count++;
down_nodes.push(node);
} else if(cluster_state[node] == "running"){
ok_count++;
}
}
if(non_ok_count == 0 ){
return fmt_state('green', 'running', '');
} else if(non_ok_count > 0 && ok_count == 0){
return fmt_state('red', 'stopped', 'Vhost supervisor is not running.');
} else if(non_ok_count > 0 && ok_count > 0){
return fmt_state('yellow', 'partial', 'Vhost supervisor is stopped on some cluster nodes: ' + down_nodes.join(', '));
}
}
2015-10-15 18:44:36 +08:00
function isNumberKey(evt){
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}