Format node names consistently

This change ensures that nodes whose name begins with `rabbit@` have that leading text removed. This saves UI space as, in production environments, the default node name is `rabbit@`.
This commit is contained in:
Luke Bakken 2017-09-14 13:49:57 -07:00
parent 58be516bc4
commit 332ca5cd45
5 changed files with 24 additions and 10 deletions

View File

@ -2,6 +2,8 @@
.*.sw?
*.beam
*.pem
erl_crash.dump
MnesiaCore.*
.erlang.mk/
/cover/
/debug/

View File

@ -7,8 +7,12 @@ PROCESS_THRESHOLDS=[[0.75, 'red'],
[0.5, 'yellow']];
function fmt_string(str, unknown) {
if (unknown == undefined) unknown = UNKNOWN_REPR;
if (str == undefined) return unknown;
if (unknown == undefined) {
unknown = UNKNOWN_REPR;
}
if (str == undefined) {
return unknown;
}
return fmt_escape_html("" + str);
}
@ -490,11 +494,19 @@ function fmt_maybe_wrap(txt, encoding) {
return fmt_escape_html(res);
}
// Note: since the default node name is 'rabbit'
// we strip it off here to save UI space
function fmt_node(node_host) {
var both = node_host.split('@');
var node = both.slice(0, 1);
var host = both.slice(1);
return node == 'rabbit' ? host : (node + '@' + host);
var fmt_node_re = /^rabbit@(.*)$/;
function do_fmt_node(nh) {
var rslt = null;
if (rslt = fmt_node_re.exec(nh)) {
return fmt_string(rslt[1]);
} else {
return fmt_string(nh);
}
};
return do_fmt_node(node_host);
}
function fmt_object_state(obj) {
@ -643,7 +655,7 @@ function link_user(name) {
}
function link_node(name) {
return _link_to(name, '#/nodes/' + esc(name))
return _link_to(fmt_node(name), '#/nodes/' + esc(name))
}
function link_policy(vhost, name) {

View File

@ -72,7 +72,7 @@
<div class="hider updatable">
<% if (nodes.length == 1) { %>
<p>Node: <%= nodes[0].name %> <a href="#/nodes/<%= esc(nodes[0].name) %>">(More about this node)</a></p>
<p>Node: <%= fmt_node(nodes[0].name) %> <a href="#/nodes/<%= esc(nodes[0].name) %>">(More about this node)</a></p>
<% } %>
<table class="list">

View File

@ -30,7 +30,7 @@
var partition = partitions[i];
%>
<tr<%= alt_rows(i)%>>
<td><%= partition.node %></td>
<td><%= fmt_node(partition.node) %></td>
<td>
<%
for (var j = 0; j < partition.others.length; j++) {

View File

@ -223,7 +223,7 @@
<td>
<select name="node">
<% for (var i = 0; i < nodes.length; i++) { %>
<option value="<%= fmt_string(nodes[i].name) %>"><%= nodes[i].name %></option>
<option value="<%= nodes[i].name %>"><%= fmt_node(nodes[i].name) %></option>
<% } %>
</select>
</td>