Skip to content

Commit 41245fa

Browse files
Merge pull request #13512 from rabbitmq/mgmt-ui-page-name
Change browser tab/window title according to currently loaded view (tab)
2 parents 826e6c7 + f2da1b5 commit 41245fa

File tree

2 files changed

+81
-2
lines changed

2 files changed

+81
-2
lines changed

deps/rabbitmq_management/priv/www/js/dispatcher.js

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,77 @@
1+
(function (factory) {
2+
if (typeof define === 'function' && define.amd) {
3+
define(['jquery', 'sammy'], factory);
4+
} else {
5+
(window.Sammy = window.Sammy || {}).Title = factory(window.jQuery, window.Sammy);
6+
}
7+
}(function ($, Sammy) {
8+
9+
// Sammy.Title is a very simple plugin to easily set the document's title.
10+
// It supplies a helper for setting the title (`title()`) within routes,
11+
// and an app level method for setting the global title (`setTitle()`)
12+
Sammy.Title = function() {
13+
14+
// setTitle allows setting a global title or a function that modifies the
15+
// title for each route/page.
16+
//
17+
// ### Example
18+
//
19+
// // setting a title prefix
20+
// $.sammy(function() {
21+
//
22+
// this.setTitle('My App -');
23+
//
24+
// this.get('#/', function() {
25+
// this.title('Home'); // document's title == "My App - Home"
26+
// });
27+
// });
28+
//
29+
// // setting a title with a function
30+
// $.sammy(function() {
31+
//
32+
// this.setTitle(function(title) {
33+
// return [title, " /// My App"].join('');
34+
// });
35+
//
36+
// this.get('#/', function() {
37+
// this.title('Home'); // document's title == "Home /// My App";
38+
// });
39+
// });
40+
//
41+
this.setTitle = function(title) {
42+
if (!$.isFunction(title)) {
43+
this.title_function = function(additional_title) {
44+
return [title, additional_title].join(' ');
45+
}
46+
} else {
47+
this.title_function = title;
48+
}
49+
};
50+
51+
// *Helper* title() sets the document title, passing it through the function
52+
// defined by setTitle() if set.
53+
this.helper('title', function() {
54+
var new_title = $.makeArray(arguments).join(' ');
55+
if (this.app.title_function) {
56+
new_title = this.app.title_function(new_title);
57+
}
58+
document.title = new_title;
59+
});
60+
61+
};
62+
63+
return Sammy.Title;
64+
65+
}));
66+
167
dispatcher_add(function(sammy) {
268
function path(p, r, t) {
369
sammy.get(p, function() {
470
render(r, t, p);
571
});
672
}
773
sammy.get('#/', function() {
74+
this.title('Overview');
875
var reqs = {'overview': {path: '/overview',
976
options: {ranges: ['lengths-over',
1077
'msg-rates-over']}},
@@ -15,6 +82,7 @@ dispatcher_add(function(sammy) {
1582
render(reqs, 'overview', '#/');
1683
});
1784
sammy.get('#/', function() {
85+
this.title('Overview');
1886
var reqs = {'overview': {path: '/overview',
1987
options: {ranges: ['lengths-over',
2088
'msg-rates-over']}},
@@ -34,6 +102,7 @@ dispatcher_add(function(sammy) {
34102
});
35103

36104
sammy.get('#/nodes/:name', function() {
105+
this.title('Node ' + this.params['name']);
37106
var name = esc(this.params['name']);
38107
render({'node': {path: '/nodes/' + name,
39108
options: {ranges: ['node-stats']}}},
@@ -42,6 +111,7 @@ dispatcher_add(function(sammy) {
42111

43112
if (ac.canAccessVhosts()) {
44113
sammy.get('#/connections', function() {
114+
this.title('Connections');
45115
renderConnections();
46116
});
47117
sammy.get('#/connections/:name', function() {
@@ -74,17 +144,20 @@ dispatcher_add(function(sammy) {
74144
return false;
75145
});
76146
sammy.get('#/channels', function() {
147+
this.title('Channels');
77148
renderChannels();
78149
});
79150
sammy.get('#/channels/:name', function() {
80151
render({'channel': {path: '/channels/' + esc(this.params['name']),
81152
options:{ranges:['data-rates-ch','msg-rates-ch']}}},
82153
'channel', '#/channels');
83154
});
84-
sammy.get('#/exchanges', function() {
155+
sammy.get('#/exchanges', function() {
156+
this.title('Exchanges');
85157
renderExchanges();
86158
});
87159
sammy.get('#/exchanges/:vhost/:name', function() {
160+
this.title('Exchange ' + esc(this.params['vhost']) + '/' + this.params['name']);
88161
var path = '/exchanges/' + esc(this.params['vhost']) + '/' + esc(this.params['name']);
89162
render({'exchange': {path: path,
90163
options: {ranges:['msg-rates-x']}},
@@ -108,12 +181,14 @@ dispatcher_add(function(sammy) {
108181
});
109182

110183
sammy.get('#/queues', function() {
184+
this.title('Queues');
111185
renderQueues();
112186
});
113187

114188
sammy.get('#/queues/:vhost/:name', function() {
115189
var vhost = this.params['vhost'];
116190
var queue = this.params['name'];
191+
this.title('Queue ' + esc(vhost) + '/' + queue);
117192
var path = '/queues/' + esc(vhost) + '/' + esc(queue);
118193
var requests = {'queue': {path: path,
119194
options: {ranges:['lengths-q', 'msg-rates-q', 'data-rates-q']}},
@@ -198,7 +273,8 @@ dispatcher_add(function(sammy) {
198273
});
199274

200275
sammy.get('#/users', function() {
201-
renderUsers();
276+
this.title('Users');
277+
renderUsers();
202278
});
203279
sammy.get('#/users/:id', function() {
204280
var vhosts = JSON.parse(sync_get('/vhosts'));
@@ -262,6 +338,7 @@ dispatcher_add(function(sammy) {
262338
'operator_policies': '/operator-policies',
263339
'vhosts': '/vhosts'}, 'policies');
264340
sammy.get('#/policies/:vhost/:id', function() {
341+
this.title('Policies');
265342
render({'policy': '/policies/' + esc(this.params['vhost'])
266343
+ '/' + esc(this.params['id'])},
267344
'policy', '#/policies');

deps/rabbitmq_management/priv/www/js/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ function dispatcher_add(fun) {
7474
}
7575

7676
function dispatcher() {
77+
this.use('Title');
78+
this.setTitle('RabbitMQ: ');
7779
for (var i in dispatcher_modules) {
7880
dispatcher_modules[i](this);
7981
}

0 commit comments

Comments
 (0)