Skip to content

Commit d38ab61

Browse files
ikavgomichaelklishin
authored andcommitted
Change browser tab/window title according to currently loaded 'page'.
It is very hard now to distinguish different tabs. With this addition we have titles like 'RabbitMQ - Queue vhost/name', 'RabbitMQ - Exchanges'. To be continued... (cherry picked from commit a0abfaa)
1 parent f5dcc91 commit d38ab61

File tree

2 files changed

+78
-2
lines changed

2 files changed

+78
-2
lines changed

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

+76-2
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']}}},
@@ -81,10 +150,12 @@ dispatcher_add(function(sammy) {
81150
options:{ranges:['data-rates-ch','msg-rates-ch']}}},
82151
'channel', '#/channels');
83152
});
84-
sammy.get('#/exchanges', function() {
153+
sammy.get('#/exchanges', function() {
154+
this.title('Exchanges');
85155
renderExchanges();
86156
});
87157
sammy.get('#/exchanges/:vhost/:name', function() {
158+
this.title('Exchange ' + esc(this.params['vhost']) + '/' + this.params['name']);
88159
var path = '/exchanges/' + esc(this.params['vhost']) + '/' + esc(this.params['name']);
89160
render({'exchange': {path: path,
90161
options: {ranges:['msg-rates-x']}},
@@ -108,12 +179,14 @@ dispatcher_add(function(sammy) {
108179
});
109180

110181
sammy.get('#/queues', function() {
182+
this.title('Queues');
111183
renderQueues();
112184
});
113185

114186
sammy.get('#/queues/:vhost/:name', function() {
115187
var vhost = this.params['vhost'];
116188
var queue = this.params['name'];
189+
this.title('Queue ' + esc(vhost) + '/' + queue);
117190
var path = '/queues/' + esc(vhost) + '/' + esc(queue);
118191
var requests = {'queue': {path: path,
119192
options: {ranges:['lengths-q', 'msg-rates-q', 'data-rates-q']}},
@@ -198,7 +271,8 @@ dispatcher_add(function(sammy) {
198271
});
199272

200273
sammy.get('#/users', function() {
201-
renderUsers();
274+
this.title('Users');
275+
renderUsers();
202276
});
203277
sammy.get('#/users/:id', function() {
204278
var vhosts = JSON.parse(sync_get('/vhosts'));

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

+2
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)