This repository has been archived by the owner on Nov 17, 2020. It is now read-only.
/
formatters.js
1067 lines (921 loc) · 31.4 KB
/
formatters.js
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
const UNKNOWN_REPR = '<span class="unknown">?</span>';
const FD_THRESHOLDS = [[0.95, 'red'],
[0.8, 'yellow']];
const SOCKETS_THRESHOLDS = [[1.0, 'red'],
[0.8, 'yellow']];
const PROCESS_THRESHOLDS = [[0.75, 'red'],
[0.5, 'yellow']];
const TAB_HIGHLIGHTER = "\u2192";
const WHITESPACE_HIGHLIGHTER = "\u23B5";
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);
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 ? "●" : "○";
}
function fmt_date(d) {
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) {
function f(i) {
return i < 10 ? "0" + i : i;
}
return [d.getFullYear() + "-" + f(d.getMonth() + 1) + "-" +
f(d.getDate()), f(d.getHours()) + ":" + f(d.getMinutes()) +
":" + f(d.getSeconds())];
}
function fmt_timestamp(ts) {
return fmt_date(new Date(ts));
}
function fmt_timestamp_mini(ts) {
return fmt_date_mini(new Date(ts));
}
function fmt_time(t, suffix) {
if (typeof t === "undefined") return '';
return t + suffix;
}
function fmt_millis(millis) {
return Math.round(millis / 1000) + "s";
}
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: ' +
fmt_escape_html(obj.policy) + '">' +
link_policy(obj.vhost, obj.policy) + '</abbr> ';
} else {
return '';
}
}
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> ';
} 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 fmt_activity_status(obj) {
return obj.replace('_', ' ');
}
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_feature(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;
}
if (obj.messages_delayed != undefined){
res['messages delayed'] = obj.messages_delayed;
}
return res;
}
function fmt_mirrors(queue) {
var synced = queue.synchronised_slave_nodes || [];
var unsynced = queue.slave_nodes || [];
unsynced = jQuery.grep(unsynced,
function (node, i) {
return jQuery.inArray(node, synced) == -1;
});
var res = '';
if (synced.length > 0) {
res += ' <abbr title="Synchronised mirrors: ' + synced + '">+' +
synced.length + '</abbr>';
}
if (synced.length == 0 && unsynced.length > 0) {
res += ' <abbr title="There are no synchronised mirrors">+0</abbr>';
}
if (unsynced.length > 0) {
res += ' <abbr class="warning" title="Unsynchronised mirrors: ' +
unsynced + '">+' + unsynced.length + '</abbr>';
}
return res;
}
function fmt_sync_state(queue) {
var res = '<p><b>Syncing: ';
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 isMajority = (queue.online.length >= (Math.floor(queue.members.length / 2) + 1));
var followers = queue.online;
followers.splice(followers.indexOf(queue.node), 1);
if (isMajority) {
res += ' <abbr title="Followers: ' + followers + '">+' +
followers.length + '</abbr>';
} else {
res += ' <abbr class="warning" title="Cluster is in minority">+' + followers.length + '</abbr>';
}
return res;
}
function fmt_channel_mode(ch) {
if (ch.transactional) {
return '<abbr title="Transactional">T</abbr>';
}
else if (ch.confirm) {
return '<abbr title="Confirm">C</abbr>';
}
else {
return '';
}
}
function fmt_color(r, thresholds) {
if (r == undefined) return '';
for (var i in thresholds) {
var threshold = thresholds[i][0];
var color = thresholds[i][1];
if (r >= threshold) {
return color;
}
}
return 'green';
}
function fmt_rate_num(num) {
if (num == undefined) return UNKNOWN_REPR;
else if (num < 1) return num.toFixed(2);
else if (num < 10) return num.toFixed(1);
else return fmt_num_thousands(num);
}
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;
}
function fmt_percent(num) {
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) {
return pick_rate(fmt_rate, obj, name, mode);
}
function fmt_detail_rate_bytes(obj, name, mode) {
return pick_rate(fmt_rate_bytes, obj, name, mode);
}
// ---------------------------------------------------------------------
// 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';
}
function fmt_bytes(bytes) {
if (bytes == undefined) return UNKNOWN_REPR;
var prefix = fmt_si_prefix(bytes, bytes, 1024, false);
return prefix + (prefix != bytes ? 'iB' : 'B');
}
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';
}
// ---------------------------------------------------------------------
function fmt_maybe_vhost(name) {
return vhosts_interesting ?
' in virtual host <b>' + fmt_escape_html(name) + '</b>'
: '';
}
function fmt_exchange(name) {
return fmt_escape_html(fmt_exchange0(name));
}
function fmt_exchange0(name) {
return name == '' ? '(AMQP default)' : name;
}
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. ' +
'Publishing to this exchange will fail.">' + fmt_escape_html(type) +
'</abbr></div>';
}
function fmt_exchange_url(name) {
return name == '' ? 'amq.default' : fmt_escape_html(name);
}
function fmt_download_filename(host) {
var now = new Date();
return host.replace('@', '_') + "_" + now.getFullYear() + "-" +
(now.getMonth() + 1) + "-" + now.getDate() + ".json";
}
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) {
var res = '';
for (k in table) {
res += '<tr><th>' + fmt_escape_html(k) + x + '</th>' +
'<td>' + fmt_amqp_value(table[k]) + '</td>';
}
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) {
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_feature(txt) {
// Exclude SAC which is the only boolean feature
if(txt === false) {
return undefined;
} else {
return fmt_escape_html0(txt).replace(/\n/g, '<br/>');
}
}
function fmt_escape_html(txt) {
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, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/\"/g, '"');
}
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) {
return fmt_string(node_host);
}
function fmt_object_state(obj) {
if (obj.state == undefined) return '';
var colour = 'green';
var text = obj.state;
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') {
colour = 'red';
explanation = 'Resource alarm: connection blocked.';
}
else if (obj.state == 'blocking') {
colour = 'yellow';
explanation = 'Resource alarm: connection will block on publish.';
}
else if (obj.state == 'flow') {
colour = 'yellow';
explanation = 'Publishing rate recently throttled by server.';
}
else if (obj.state == 'terminated') {
colour = 'yellow';
var terminated_by = "";
if (obj.terminated_by) {
terminated_by = " by \"" + String(obj.terminated_by) + "\"";
}
explanation = 'The queue is being deleted' + terminated_by + ".";
}
else if (obj.state == 'down') {
colour = 'red';
explanation = 'The queue is located on a cluster node or nodes that ' +
'are down.';
}
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.';
}
return fmt_state(colour, text, explanation);
}
function fmt_state(colour, text, explanation) {
var key;
if (explanation) {
key = '<abbr class="normal" title="' + explanation + '">' +
text + '</abbr>';
}
else {
key = text;
}
return '<div class="colour-key status-key-' + colour + '"></div>' + key;
}
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);
if (uri.indexOf('?') == -1) {
return uri;
}
else {
return '<abbr title="' + uri + '">' +
uri.substr(0, uri.indexOf('?')) + '?...</abbr>';
}
}
function fmt_uri_with_credentials(uri) {
if (typeof uri == 'object') {
var res = [];
for (i in uri) {
res.push(fmt_uri_with_credentials(uri[i]));
}
return res;
}
else if (typeof uri == 'string') {
// mask password
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, 120));
}
if (properties.platform != undefined) {
res.push(fmt_trunc(properties.platform, 120));
}
res = res.join(" / ");
if (properties.version != undefined) {
res += '<sub>' + fmt_trunc(properties.version) + '</sub>';
}
if (properties.client_id != undefined) {
res += '<sub>' + fmt_trunc(properties.client_id, 120) + '</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(' ') + '"';
}
function esc(str) {
return encodeURIComponent(str);
}
// Replaces a sequence of characters matched by a regular expression
// group with the given character. Replaced group is combined with the stripped
// original using the provided combine function.
function replace_char_sequence_individually(input, regex, replacement, combine) {
let ms = input.match(regex);
if (ms == null) {
return input;
} else {
let n = ms[0].length;
return combine(replacement.repeat(n), input.replace(regex, ""));
}
}
// Replaces a leading sequence of characters matched by a regular expression
// group with the given character.
function replace_leading_chars(input, regex, replacement) {
return replace_char_sequence_individually(input, regex, replacement, function(patch, stripped_input) {
return patch + stripped_input;
});
}
// Replaces a trailing sequence of characters matched by a regular expression
// group with the given character.
function replace_trailing_chars(input, regex, replacement) {
return replace_char_sequence_individually(input, regex, replacement, function(patch, stripped_input) {
return stripped_input + patch;
});
}
// Highlights extra (leading and trailing) whitespace and tab characters
// with suitable Unicode characters for improved visiblity.
// Note that mid-word whitespace should not be highighted, which makes
// the implementation trickier than a simple chain of replace/2 calls.
function highlight_extra_whitespace(str) {
// Highlight leading and trailing whitespace individually but all tabs.
// This assumes that spaces are reasonable to use in the middle of a name
// but tabs are not used intentionally and must be highlighted even in the middle.
return [[replace_trailing_chars, /(\s+)$/g, WHITESPACE_HIGHLIGHTER],
[replace_leading_chars, /^(\s+)/g, WHITESPACE_HIGHLIGHTER]].reduce(function(acc, triplet) {
return triplet[0](acc, triplet[1], triplet[2]);
}, str.replace(/\t/g, TAB_HIGHLIGHTER));
}
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);
}
}
function link_channel(name) {
return _link_to(short_chan(name), '#/channels/' + esc(name));
}
function link_exchange(vhost, name, args) {
var url = esc(vhost) + '/' + (name == '' ? 'amq.default' : esc(name));
return _link_to(fmt_exchange0(highlight_extra_whitespace(name)), '#/exchanges/' + url, true, args);
}
function link_queue(vhost, name, args) {
return _link_to(highlight_extra_whitespace(name), '#/queues/' + esc(vhost) + '/' + esc(name), true, args);
}
function link_vhost(name) {
return _link_to(name, '#/vhosts/' + esc(name));
}
function link_user(name) {
return _link_to(name, '#/users/' + esc(name));
}
function link_node(name) {
return _link_to(fmt_node(name), '#/nodes/' + esc(name));
}
function link_policy(vhost, name) {
return _link_to(name, '#/policies/' + esc(vhost) + '/' + esc(name));
}
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>';
}
function fmt_highlight_filter(text) {
if (current_filter == '') return fmt_escape_html(text);
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;
if (ix == -1) {
return fmt_escape_html(text);
}
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));
}
}
function filter_ui_pg(items, truncate, appendselect) {
var total = items.length;
if (current_filter != '') {
var items2 = [];
for (var i in items) {
var item = items[i];
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) {
items2.push(item);
}
}
items.length = items2.length;
for (var i in items2) items[i] = items2[i];
}
var res = '<div class="filter"><table' +
(current_filter == '' ? '' : ' class="filter-active"') +
'><tr><th>Filter:</th>' +
'<td><input id="filter" type="text" value="' +
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>';
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');
selected += appendselect;
res += '<p id="filter-truncate"><span class="updatable">' + selected +
'</span>' + truncate + '</p>';
res += '</div>';
return res;
}
function filter_ui(items) {
var current_truncate = parseInt(get_pref('truncate'));
var truncate_input = '<input type="text" id="truncate" value="' +
current_truncate + '">';
var selected = '';
if (items.length > current_truncate) {
selected += '<span id="filter-warning-show"> ' +
'(only showing first</span> ';
items.length = current_truncate;
}
else {
selected += ', page size up to ';
}
return filter_ui_pg(items, truncate_input, selected);
}
function paginate_header_ui(pages, context){
var res = '<h2 class="updatable">';
res += ' All ' + context +' (' + pages.total_count + ((pages.filtered_count != pages.total_count) ? ', filtered down to ' + pages.filtered_count : '') + ')';
res += '</h2>';
return res;
}
function paginate_ui(pages, context){
var res = paginate_header_ui(pages, context);
res += '<div class="hider">';
res += '<h3>Pagination</h3>';
res += '<div class="filter">';
res += '<table class="updatable">';
res += '<tr>';
res += '<th><label for="'+ context +'-page">Page </label> <select id="'+ context +'-page" class="pagination_class pagination_class_select" >';
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>';
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"';
res += 'value = ' + fmt_filter_name_request(context, "") + '>';
res += '</input></th></span>';
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>' ;
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> ';
res += ' <input id="'+ context +'-pagesize" data-page-start="1" class="pagination_class shortinput pagination_class_input" type="text" ';
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;
}
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;
}
function fmt_sort(display, sort) {
var prefix = '';
if (current_sort == sort) {
prefix = '<span class="arrow">' +
(current_sort_reverse ? '▽ ' : '△ ') +
'</span>';
}
return '<a class="sort" sort="' + sort + '">' + prefix + display + '</a>';
}
function group_count(mode, group, bools) {
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++;
}
return count;
}
function group_heading(mode, group, bools) {
var count = group_count(mode, group, bools);
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(', ');
}
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 +
'" 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;
}