-
Notifications
You must be signed in to change notification settings - Fork 4k
Expand file tree
/
Copy pathmain.js
More file actions
1935 lines (1736 loc) · 59.2 KB
/
main.js
File metadata and controls
1935 lines (1736 loc) · 59.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
$(document).ready(function() {
var url_string = window.location.href;
var url = new URL(url_string);
var error = url.searchParams.get('error');
if (error) {
if (oauth.enabled) {
renderWarningMessageInLoginStatus(oauth, fmt_escape_html(error));
}
} else {
if (oauth.enabled) {
startWithOAuthLogin(oauth);
} else {
startWithLoginPage();
}
}
});
function startWithLoginPage() {
replace_content('outer', format('login', {}));
start_app_login();
}
function removeDuplicates(array){
let output = []
for(let item of array) {
if(!output.includes(item)) {
output.push(item)
}
}
return output
}
function startWithOAuthLogin (oauth) {
store_pref("oauth-return-to", window.location.hash);
if (!oauth.logged_in) {
hasAnyResourceServerReady(oauth, (oauth, warnings) => { render_login_oauth(oauth, warnings); start_app_login(); })
} else {
start_app_login()
}
}
function render_login_oauth(oauth, messages) {
let formatData = {};
formatData.warnings = [];
formatData.notAuthorized = false;
formatData.resource_servers = oauth.resource_servers;
formatData.declared_resource_servers_count = oauth.declared_resource_servers_count;
formatData.oauth_disable_basic_auth = oauth.oauth_disable_basic_auth;
formatData.strict_auth_mechanism = oauth.strict_auth_mechanism;
formatData.preferred_auth_mechanism = oauth.preferred_auth_mechanism;
if (Array.isArray(messages)) {
formatData.warnings = messages
} else if (typeof messages == "string") {
formatData.warnings = [messages]
formatData.notAuthorized = messages == "Not authorized"
}
replace_content('outer', format('login_oauth', formatData))
setup_visibility()
$('#login').off('click', 'div.section h2, div.section-hidden h2');
$('#login').on('click', 'div.section h2, div.section-hidden h2', function() {
toggle_visibility($(this));
});
}
function renderWarningMessageInLoginStatus(oauth, message) {
render_login_oauth(oauth, message)
}
function dispatcher_add(fun) {
dispatcher_modules.push(fun);
if (dispatcher_modules.length == extension_count) {
start_app();
}
}
function dispatcher() {
this.use('Title');
this.setTitle('RabbitMQ: ');
for (var i in dispatcher_modules) {
dispatcher_modules[i](this);
}
}
function start_app_login () {
app = new Sammy.Application(function () {
this.get('/', function () {})
this.get('#/', function () {})
if (!oauth.enabled || !oauth.oauth_disable_basic_auth) {
this.put('#/login', function() {
set_basic_auth(this.params['username'], this.params['password'])
check_login()
});
}
})
if (oauth.enabled) {
if (has_auth_credentials()) {
check_login();
} else {
app.run();
}
} else
if (!has_auth_credentials() || !check_login()) {
app.run();
}
}
function check_login () {
user = JSON.parse(sync_get('/whoami'));
if (user == false || user.error) {
clear_auth();
if (oauth.enabled) {
renderWarningMessageInLoginStatus(oauth, 'Not authorized');
} else {
replace_content('login-status', '<p>Login failed</p>');
}
return false;
}
check_version()
hide_popup_warn()
replace_content('outer', format('layout', {}))
var user_login_session_timeout = parseInt(user.login_session_timeout)
if (!isNaN(user_login_session_timeout)) {
update_login_session_timeout(user_login_session_timeout)
}
ui_data_model.vhosts = JSON.parse(sync_get('/vhosts'));
ac.update(user, ui_data_model)
if (ac.isMonitoringUser()) {
ui_data_model.nodes = JSON.parse(sync_get('/nodes'))
}
var overview = JSON.parse(sync_get('/overview'))
display.update(overview, ui_data_model)
setup_global_vars(overview)
setup_constant_events()
update_vhosts()
update_interval()
setup_extensions()
return true
}
function start_app() {
if (app !== undefined) {
app.unload();
}
// Oh boy. Sammy uses various different methods to determine if
// the URL hash has changed. Unsurprisingly this is a native event
// in modern browsers, and falls back to an icky polling function
// in MSIE. But it looks like there's a bug. The polling function
// should get installed when the app is started. But it's guarded
// behind if (Sammy.HashLocationProxy._interval != null). And of
// course that's not specific to the application; it's pretty
// global. So we need to manually clear that in order for links to
// work in MSIE.
// Filed as https://github.com/quirkey/sammy/issues/171
//
// Note for when we upgrade: HashLocationProxy has become
// DefaultLocationProxy in later versions, but otherwise the issue
// remains.
// updated to the version 0.7.6 this _interval = null is fixed
// just leave the history here.
//Sammy.HashLocationProxy._interval = null;
var url = this.location.toString();
var hash = this.location.hash;
var pathname = this.location.pathname;
if (url.indexOf('#') == -1) {
this.location = url + '#/';
} else if (hash.indexOf('#token_type') != - 1 && pathname == '/') {
// This is equivalent to previous `if` clause when uaa authorisation is used.
// Tokens are passed in the url hash, so the url always contains a #.
// We need to check the current path is `/` and token is present,
// so we can redirect to `/#/`
this.location = url.replace(/#token_type.+/gi, '#/');
}
app = new Sammy.Application(dispatcher);
app.run();
}
function setup_constant_events() {
$('#update-every').on('change', function() {
var interval = $(this).val();
store_pref('interval', interval);
if (interval == '')
interval = null;
else
interval = parseInt(interval);
set_timer_interval(interval);
});
$('#show-vhost').on('change', function() {
current_vhost = $(this).val();
store_pref('vhost', current_vhost);
if (current_reqs && Object.keys(current_reqs).length > 0) {
update();
}
notifyOnVhostChange(current_vhost);
});
if (!vhosts_interesting) {
$('#vhost-form').hide();
}
}
function update_vhosts() {
if (display.vhosts) {
$('#vhost-form').show();
$('li#vhost').show();
}else {
$('#vhost-form').hide();
$('li#vhost').hide();
}
var select = $('#show-vhost').get(0);
select.options.length = ui_data_model.vhosts.length + 1;
var index = 0;
for (var i = 0; i < ui_data_model.vhosts.length; i++) {
var vhost = ui_data_model.vhosts[i].name;
select.options[i + 1] = new Option(vhost, vhost);
if (vhost == current_vhost) index = i + 1;
}
select.selectedIndex = index;
current_vhost = select.options[index].value;
store_pref('vhost', current_vhost);
}
function setup_extensions() {
var extensions = JSON.parse(sync_get('/extensions'));
extension_count = 0;
var javascript_files = [];
for (var i in extensions) {
var extension = extensions[i];
if ($.isPlainObject(extension)) {
if (extension.hasOwnProperty('javascript')) {
// Collect JavaScript files for sequential loading
if (Array.isArray(extension.javascript)) {
for (var j = 0; j < extension.javascript.length; j++) {
javascript_files.push(extension.javascript[j]);
}
} else {
javascript_files.push(extension.javascript);
}
}
if (extension.hasOwnProperty('css')) {
dynamic_css_load(extension.css);
}
extension_count++;
}
}
// Load JavaScript files sequentially to ensure dependencies are available
load_javascript_files_sequentially(javascript_files, 0);
}
function load_javascript_files_sequentially(files, index) {
if (index >= files.length) {
return; // All files loaded
}
console.debug(`Loading extension ${files[index]} ...`);
dynamic_javascript_file_load(files[index], function() {
// Load next file after current one has finished loading
console.debug(`Loaded extension ${files[index]} !`);
load_javascript_files_sequentially(files, index + 1);
});
}
function dynamic_javascript_load(arrayOrString) {
if (Array.isArray(arrayOrString)) {
for (const file of arrayOrString) {
dynamic_javascript_file_load(file);
}
}else {
dynamic_javascript_file_load(arrayOrString);
}
}
function dynamic_javascript_file_load(filename, callback) {
var element = document.createElement('script');
element.setAttribute('type', 'text/javascript');
element.setAttribute('src', 'js/' + filename);
// Set up callback to fire when script has loaded
if (callback) {
element.onload = callback;
element.onerror = function() {
console.error('Failed to load script: ' + filename);
callback(); // Continue loading other scripts even if one fails
};
}
document.getElementsByTagName('head')[0].appendChild(element);
return element;
}
function dynamic_css_load(arrayOrString) {
if (Array.isArray(arrayOrString)) {
for (const file of arrayOrString) {
dynamic_css_file_load(file);
}
}else {
dynamic_css_file_load(arrayOrString);
}
}
function dynamic_css_file_load(filename) {
var element = document.createElement('link');
element.setAttribute('rel', 'stylesheet');
element.setAttribute('type', 'text/css');
element.setAttribute('href', 'css/' + filename);
document.getElementsByTagName('head')[0].appendChild(element);
return element;
}
function update_interval() {
var intervalStr = get_pref('interval');
var interval;
if (intervalStr == null) interval = 5000;
else if (intervalStr == '') interval = null;
else interval = parseInt(intervalStr);
if (isNaN(interval)) interval = null; // Prevent DoS if cookie malformed
set_timer_interval(interval);
var select = $('#update-every').get(0);
var opts = select.options;
for (var i = 0; i < opts.length; i++) {
if (opts[i].value == intervalStr) {
select.selectedIndex = i;
break;
}
}
}
function go_to(url) {
this.location = url;
}
function go_to_home() {
// location.href = rabbit_path_prefix() + "/"
location.href = "/"
}
function set_timer_interval(interval) {
timer_interval = interval;
reset_timer();
}
function reset_timer() {
if (timer != null) {
clearInterval(timer);
}
if (timer_interval != null) {
timer = setInterval(partial_update, timer_interval);
}
}
function pause_auto_refresh() {
if (typeof globalThis.rmq_webui_auto_refresh_paused == 'undefined')
globalThis.rmq_webui_auto_refresh_paused = 0;
globalThis.rmq_webui_auto_refresh_paused++;
if (timer != null) {
clearInterval(timer);
}
}
function resume_auto_refresh() {
globalThis.rmq_webui_auto_refresh_paused--;
if (globalThis.rmq_webui_auto_refresh_paused == 0) {
reset_timer();
}
}
function update_manual(div, query) {
var path;
var template;
if (query == 'memory' || query == 'binary') {
path = current_reqs['node']['path'] + '?' + query + '=true';
template = query;
}
var data = JSON.parse(sync_get(path));
replace_content(div, format(template, data));
postprocess_partial();
}
function render(reqs, template, highlight) {
var old_template = current_template;
current_template = template;
current_reqs = reqs;
clear_postprocessors();
for (var i in outstanding_reqs) {
outstanding_reqs[i].abort();
}
outstanding_reqs = [];
current_highlight = highlight;
if (old_template !== current_template) {
window.scrollTo(0, 0);
}
update();
notifyActivatedTab(current_highlight);
}
function reset_current_reqs() {
current_reqs = {};
}
function update() {
replace_content('debug', '');
clearInterval(timer);
with_update(function(html) {
update_navigation();
update_warnings();
replace_content('main', html);
postprocess();
postprocess_partial();
render_charts();
maybe_scroll();
reset_timer();
});
}
function partial_update() {
if (!$(".pagination_class").is(":focus")) {
if ($('.updatable').length > 0) {
if (update_counter >= 200) {
update_counter = 0;
full_refresh();
return;
}
with_update(function(html) {
update_counter++;
replace_content('scratch', html);
var befores = $('#main .updatable');
var afters = $('#scratch .updatable');
if (befores.length != afters.length) {
console.log("before/after mismatch! Doing a full reload...");
full_refresh();
}
for (var i = 0; i < befores.length; i++) {
$(befores[i]).empty().append($(afters[i]).contents());
}
replace_content('scratch', '');
postprocess_partial();
render_charts();
});
}
}
}
function update_navigation() {
var l1 = '';
var l2 = '';
var descend = null;
for (var k in NAVIGATION) {
var val = NAVIGATION[k];
var path = val;
while (!leaf(path)) {
path = first_showable_child(path);
}
var selected = false;
if (contains_current_highlight(val)) {
selected = true;
if (!leaf(val) && val[2] && ac.canAccessVhosts()) {
descend = nav(val)
}
}
if (show(path)) {
if (val.length < 3 || ( val[2] && ac.canAccessVhosts() )) {
l1 += '<li id="' + navigation_tab_id(k) + '"><a href="' + nav(path) + '"' +
(selected ? ' class="selected"' : '') + '>' + k + '</a></li>'
}
}
}
if (descend) {
l2 = obj_to_ul(descend);
$('#main').addClass('with-rhs');
}
else {
$('#main').removeClass('with-rhs');
}
replace_content('tabs', l1);
replace_content('rhs', l2);
}
function update_warnings() {
feature_flags = JSON.parse(sync_get('/feature-flags'));
var needs_enabling = false;
for (var i = 0; i < feature_flags.length; i++) {
var feature_flag = feature_flags[i];
if (feature_flag.state == "disabled" && feature_flag.stability != "experimental") {
needs_enabling = true;
}
}
deprecated_features = JSON.parse(sync_get('/deprecated-features/used'));
var needs_deprecating = false;
if (deprecated_features.length > 0) {
needs_deprecating = true;
}
var l1 = '<p class="warning">';
if (needs_enabling) {
l1 += '<span>⚠</span> All stable feature flags must be enabled after completing an upgrade. <a href="https://www.rabbitmq.com/feature-flags.html">[Learn more]</a>';
}
if (needs_deprecating) {
if (needs_enabling) {
l1 += '<br/>'
}
l1 += '<span>⚠</span> Deprecated features are being used. <a href="https://www.rabbitmq.com/feature-flags.html">[Learn more]</a>'
}
l1 += '</p>';
if (needs_enabling || needs_deprecating) {
$('#main').addClass('with-warnings');
$('#rhs').addClass('with-warnings');
replace_content('warnings', l1);
} else {
$('#main').removeClass('with-warnings');
$('#rhs').removeClass('with-warnings');
}
}
function navigation_tab_id(value) {
return value.toLowerCase().replaceAll(/\s/g, "-")
}
function nav(pair) {
return pair[0];
}
function show(pair) {
var hasUserTag = jQuery.inArray(pair[1], user_tags) != -1
if (pair.length > 2 && pair[2]) {
return hasUserTag && ac.canAccessVhosts()
} else {
return hasUserTag
}
}
function leaf(pair) {
return typeof(nav(pair)) == 'string';
}
function first_showable_child(pair) {
var items = pair[0];
var ks = keys(items);
for (var i = 0; i < ks.length; i++) {
var child = items[ks[i]];
if (show(child)) return child;
}
return items[ks[0]]; // We'll end up not showing it anyway
}
function contains_current_highlight(val) {
if (leaf(val)) {
return current_highlight == nav(val);
}
else {
var b = false;
for (var k in val) {
b |= contains_current_highlight(val[k]);
}
return b;
}
}
function obj_to_ul(val) {
var res = '<ul>';
for (var k in val) {
var obj = val[k];
if (show(obj)) {
res += '<li>';
if (leaf(obj)) {
res += '<a href="' + nav(obj) + '"' +
(current_highlight == nav(obj) ? ' class="selected"' : '') +
'>' + k + '</a>';
}
else {
res += obj_to_ul(nav(obj));
}
res += '</li>';
}
}
return res + '</ul>';
}
function full_refresh() {
store_pref('position', x_position() + ',' + y_position());
location.reload();
}
function maybe_scroll() {
var pos = get_pref('position');
if (pos) {
clear_pref('position');
var xy = pos.split(",");
window.scrollTo(parseInt(xy[0]), parseInt(xy[1]));
}
}
function x_position() {
return window.pageXOffset ?
window.pageXOffset :
document.documentElement.scrollLeft ?
document.documentElement.scrollLeft :
document.body.scrollLeft;
}
function y_position() {
return window.pageYOffset ?
window.pageYOffset :
document.documentElement.scrollTop ?
document.documentElement.scrollTop :
document.body.scrollTop;
}
function with_update(fun) {
if(outstanding_reqs.length > 0){
return false;
}
var model = [];
model['extra_content'] = []; // magic key for extension point
with_reqs(apply_state(current_reqs), model, function(json) {
var html = format(current_template, json);
fun(html);
update_status('ok');
});
return true;
}
function apply_state(reqs) {
var reqs2 = {};
for (k in reqs) {
var req = reqs[k];
var options = {};
if (typeof(req) == "object") {
options = req.options;
req = req.path;
}
var req2;
if (options['vhost'] != undefined && current_vhost != '') {
var indexPage = req.indexOf("?page=");
if (indexPage >- 1) {
pageUrl = req.substr(indexPage);
req2 = req.substr(0,indexPage) + '/' + esc(current_vhost) + pageUrl;
} else
req2 = req + '/' + esc(current_vhost);
}
else {
req2 = req;
}
var qs = [];
if (options['sort'] != undefined && current_sort != null) {
qs.push('sort=' + current_sort);
qs.push('sort_reverse=' + current_sort_reverse);
}
if (options['ranges'] != undefined) {
for (i in options['ranges']) {
var type = options['ranges'][i];
var range = get_pref('chart-range').split('|');
var prefix;
if (type.substring(0, 8) == 'lengths-') {
prefix = 'lengths';
}
else if (type.substring(0, 10) == 'msg-rates-') {
prefix = 'msg_rates';
}
else if (type.substring(0, 11) == 'data-rates-') {
prefix = 'data_rates';
}
else if (type == 'node-stats') {
prefix = 'node_stats';
}
qs.push(prefix + '_age=' + parseInt(range[0]));
qs.push(prefix + '_incr=' + parseInt(range[1]));
}
}
/* Unknown options are used as query parameters as is. */
Object.keys(options).forEach(function (key) {
/* Skip known keys we already handled and undefined parameters. */
if (key == 'vhost' || key == 'sort' || key == 'ranges')
return;
if (!key || options[key] == undefined)
return;
qs.push(esc(key) + '=' + esc(options[key]));
});
qs = qs.join('&');
if (qs != '')
if (req2.indexOf("?page=") >- 1)
qs = '&' + qs;
else
qs = '?' + qs;
reqs2[k] = req2 + qs;
}
return reqs2;
}
function show_popup(type, text, _mode) {
var cssClass = '.form-popup-' + type;
function hide() {
$(cssClass).fadeOut(100, function() {
$(this).remove();
});
}
hide();
$('#outer').after(format('popup', {'type': type, 'text': text}));
$(cssClass).fadeIn(100);
var closeButtonCssClass = cssClass + ' span';
$('div#outer,' + closeButtonCssClass).on('click', function(event) {
if ($(event.target).eq($(closeButtonCssClass)) || !$(event.target).closest(cssClass).length) {
$('.popup-owner').removeClass('popup-owner');
hide();
}
});
}
function hide_popup_warn() {
var cssClass = '.form-popup-warn';
$('.popup-owner').removeClass('popup-owner');
$(cssClass).fadeOut(100, function() {
$(this).remove();
});
}
function submit_import(form) {
if (form.file.value) {
var confirm_upload = confirm('Are you sure you want to import a definitions file? Some entities (vhosts, users, queues, etc) may be overwritten!');
if (confirm_upload === true) {
var file = form.file.files[0]; // FUTURE: limit upload file size (?)
var vhost_upload = $("select[name='vhost-upload'] option:selected");
var vhost_selected = vhost_upload.index() > 0;
var vhost_name = null;
if (vhost_selected) {
vhost_name = vhost_upload.val();
}
var vhost_part = '';
if (vhost_name) {
vhost_part = '/' + esc(vhost_name);
}
var form_action = "/definitions" + vhost_part;
var fd = new FormData();
fd.append('file', file);
with_req('POST', form_action, fd, function(resp) {
show_popup('info', 'Your definitions were imported successfully.');
});
}
}
return false;
};
function postprocess() {
$('form.confirm-queue').on('submit', function() {
return confirm("Are you sure? The queue is going to be deleted. " +
"Messages cannot be recovered after deletion.");
});
$('form.confirm-purge-queue').on('submit', function() {
return confirm("Are you sure? Messages cannot be recovered after purging.");
});
$('form.confirm').on('submit', function() {
return confirm("Are you sure? This object cannot be recovered " +
"after deletion.");
});
$('form.enable-feature-flag').on('submit', function() {
full_refresh();
});
$('label').map(function() {
if ($(this).attr('for') == '') {
var id = 'auto-label-' + Math.floor(Math.random()*1000000000);
var input = $(this).parents('tr').first().find('input, select');
if (input.attr('id') == '') {
$(this).attr('for', id);
input.attr('id', id);
}
}
});
$('#download-definitions').on('click', function() {
var idx = $("select[name='vhost-download'] option:selected").index()
var vhost = ((idx <=0 ) ? "" : "/" + esc($("select[name='vhost-download'] option:selected").val()))
var download_filename = esc($('#download-filename').val())
var path = '/definitions' + vhost
with_req('GET', path, null, function(resp) {
if (resp.status >= 200 && resp.status <= 299) {
var type = resp.getResponseHeader('Content-Type')
var blob = new Blob([resp.response], { type: type })
if (typeof window.navigator.msSaveBlob !== 'undefined') {
window.navigator.msSaveBlob(blob, download_filename)
} else {
var URL = window.URL || window.webkitURL
var downloadUrl = URL.createObjectURL(blob)
var a = document.createElement("a")
if (typeof a.download === 'undefined') {
window.location = downloadUrl
} else {
a.href = downloadUrl
a.download = download_filename
document.body.appendChild(a)
a.click()
}
var cleanup = function () {
URL.revokeObjectURL(downloadUrl)
document.body.removeChild(a)
};
setTimeout(cleanup, 1000)
}
} else {
// Unsuccessful status
show_popup('warn', 'Error downloading definitions')
}
});
});
$('.update-manual').on('click', function() {
update_manual($(this).attr('for'), $(this).attr('query'));
});
$(document).on('keyup', '.multifield input', function() {
update_multifields();
});
$(document).on('change', '.multifield select', function() {
update_multifields();
});
$('.controls-appearance').on('change', function() {
var params = $(this).get(0).options;
var selected = $(this).val();
for (i = 0; i < params.length; i++) {
var param = params[i].value;
if (param == selected) {
$('#' + param + '-div').slideDown(100);
} else {
$('#' + param + '-div').slideUp(100);
}
}
});
$(document).on('click', '.help', function() {
show_popup('help', HELP[$(this).attr('id')]);
});
$(document).on('click', '.popup-options-link', function() {
$('.popup-owner').removeClass('popup-owner');
$(this).addClass('popup-owner');
var template = $(this).attr('type') + '-options';
show_popup('options', format(template, {span: $(this)}), 'fade');
});
$(document).on('click', '.rate-visibility-option', function() {
var k = $(this).attr('data-pref');
var show = get_pref(k) !== 'true';
store_pref(k, '' + show);
partial_update();
});
$(document).on('focus', 'input, select', function() {
update_counter = 0; // If there's interaction, reset the counter.
});
$('.tag-link').on('click', function() {
$('#tags').val($(this).attr('tag'));
});
$('.argument-link').on('click', function() {
var field = $(this).attr('field');
var row = $('#' + field).find('.mf').last();
var key = row.find('input').first();
var value = row.find('input').last();
var type = row.find('select').last();
key.val($(this).attr('key'));
value.val($(this).attr('value'));
type.val($(this).attr('type'));
update_multifields();
});
$(document).on('click', 'form.auto-submit select, form.auto-submit input', function(){
$(this).parents('form').submit();
});
$('#filter').on('keyup', debounce(update_filter, 500));
$('#filter-regex-mode').on('change', update_filter_regex_mode);
$('#truncate').on('keyup', debounce(update_truncate, 500));
if (! user_administrator) {
$('.administrator-only').remove();
}
invokeRegisteredPostProcessors();
update_multifields();
}
function is_valid_regexp(value) {
try {
var _ = new RegExp(value, 'i');
return true;
} catch (e) {
return false;
}
}
function url_pagination_template_context(template, context, defaultPage, defaultPageSize){
var page_number_request = fmt_page_number_request(context, defaultPage);
var page_size = fmt_page_size_request(context, defaultPageSize);
var name_request = fmt_filter_name_request(context, "");
var use_regex = fmt_regex_request(context, "") == "checked";
if (use_regex) {
// rabbitmq/rabbitmq-server#8008: if the expression cannot be compiled to a reg exp,
// assume a regular text filter
var valid_regexp = is_valid_regexp(name_request);
if (!valid_regexp) {
show_popup('warn', fmt_escape_html(`Filter expression '${name_request}' is not a valid regular expression, will perform a regular text query`));
use_regex = false;
}
if (use_regex && valid_regexp) {
name_request = esc(name_request);
}
}
return '/' + template +
'?page=' + page_number_request +
'&page_size=' + page_size +
'&name=' + name_request +
'&use_regex=' + use_regex;
}
function url_pagination_template(template, defaultPage, defaultPageSize){
return url_pagination_template_context(template, template, defaultPage, defaultPageSize);
}
function stored_page_info(template, page_start){
var pageSize = fmt_strip_tags($('#' + template+'-pagesize').val());
var filterName = fmt_strip_tags($('#' + template+'-name').val());
store_pref(template + '_current_page_number', page_start);
if (filterName != null && filterName != undefined) {
store_pref(template + '_current_filter_name', filterName);
}
var regex_on = $("#" + template + "-filter-regex-mode").is(':checked');
if (regex_on != null && regex_on != undefined) {
store_pref(template + '_current_regex', regex_on ? "checked" : " " );
}
if (pageSize != null && pageSize != undefined) {
store_pref(template + '_current_page_size', pageSize);
}
}
function update_pages(template, page_start){
stored_page_info(template, page_start);
switch (template) {
case 'queues' : renderQueues(); break;
case 'exchanges' : renderExchanges(); break;
case 'connections' : renderConnections(); break;
case 'channels' : renderChannels(); break;
case 'users' : renderUsers(); break;
default:
renderCallback = RENDER_CALLBACKS[template];
if (renderCallback != undefined) {
renderCallback();
}
break;
}
}
function renderQueues() {
ensure_queues_chart_range();
render({'queues': {
path: url_pagination_template('queues', 1, 100),
options: {
sort: true,
vhost: true,
pagination: true