| 
									
										
										
										
											2010-07-23 20:43:35 +08:00
										 |  |  | UNKNOWN_REPR = '<span class="unknown">?</span>'; | 
					
						
							| 
									
										
										
										
											2011-02-04 22:38:26 +08:00
										 |  |  | FD_THRESHOLDS=[[0.95, 'red'], | 
					
						
							| 
									
										
										
										
											2011-02-18 22:26:12 +08:00
										 |  |  |                [0.8, 'yellow']]; | 
					
						
							| 
									
										
										
										
											2011-02-04 22:38:26 +08:00
										 |  |  | SOCKETS_THRESHOLDS=[[1.0, 'red'], | 
					
						
							| 
									
										
										
										
											2011-02-18 22:26:12 +08:00
										 |  |  |                     [0.8, 'yellow']]; | 
					
						
							| 
									
										
										
										
											2011-02-04 22:38:26 +08:00
										 |  |  | PROCESS_THRESHOLDS=[[0.75, 'red'], | 
					
						
							| 
									
										
										
										
											2011-02-18 22:26:12 +08:00
										 |  |  |                     [0.5, 'yellow']]; | 
					
						
							| 
									
										
										
										
											2010-07-22 23:29:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-26 01:02:03 +08:00
										 |  |  | function fmt_string(str, unknown) { | 
					
						
							| 
									
										
										
										
											2017-09-15 04:49:57 +08:00
										 |  |  |     if (unknown == undefined) { | 
					
						
							|  |  |  |         unknown = UNKNOWN_REPR; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (str == undefined) { | 
					
						
							|  |  |  |         return unknown; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-11-30 21:43:42 +08:00
										 |  |  |     return fmt_escape_html("" + str); | 
					
						
							| 
									
										
										
										
											2010-07-22 23:29:19 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-06 21:08:12 +08:00
										 |  |  | function fmt_si_prefix(num0, max0, thousand, allow_fractions) { | 
					
						
							| 
									
										
										
										
											2013-06-17 22:40:42 +08:00
										 |  |  |     if (num == 0) return 0; | 
					
						
							| 
									
										
										
										
											2010-07-22 23:29:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-17 22:40:42 +08:00
										 |  |  |     function f(n, m, p) { | 
					
						
							|  |  |  |         if (m > thousand) return f(n / thousand, m / thousand, p + 1); | 
					
						
							| 
									
										
										
										
											2013-09-06 21:08:12 +08:00
										 |  |  |         else return [n, m, p]; | 
					
						
							| 
									
										
										
										
											2010-07-22 23:29:19 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-06 21:08:12 +08:00
										 |  |  |     var num_power = f(num0, max0, 0); | 
					
						
							| 
									
										
										
										
											2010-09-01 00:56:33 +08:00
										 |  |  |     var num = num_power[0]; | 
					
						
							| 
									
										
										
										
											2013-09-06 21:08:12 +08:00
										 |  |  |     var max = num_power[1]; | 
					
						
							|  |  |  |     var power = num_power[2]; | 
					
						
							| 
									
										
										
										
											2013-06-17 22:40:42 +08:00
										 |  |  |     var powers = ['', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']; | 
					
						
							| 
									
										
										
										
											2013-09-06 21:08:12 +08:00
										 |  |  |     return (((power != 0 || allow_fractions) && max <= 10) ? num.toFixed(1) : | 
					
						
							|  |  |  |             num.toFixed(0)) + powers[power]; | 
					
						
							| 
									
										
										
										
											2010-07-22 23:29:19 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-21 18:21:13 +08:00
										 |  |  | function fmt_boolean(b, unknown) { | 
					
						
							|  |  |  |     if (unknown == undefined) unknown = UNKNOWN_REPR; | 
					
						
							|  |  |  |     if (b == undefined) return unknown; | 
					
						
							| 
									
										
										
										
											2010-07-22 23:29:19 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return b ? "●" : "○"; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-14 19:45:45 +08:00
										 |  |  | function fmt_date(d) { | 
					
						
							| 
									
										
										
										
											2014-06-25 19:11:07 +08:00
										 |  |  |     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) { | 
					
						
							| 
									
										
										
										
											2011-01-14 19:45:45 +08:00
										 |  |  |     function f(i) { | 
					
						
							|  |  |  |         return i < 10 ? "0" + i : i; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-25 19:11:07 +08:00
										 |  |  |     return [d.getFullYear() + "-" + f(d.getMonth() + 1) + "-" + | 
					
						
							|  |  |  |             f(d.getDate()), f(d.getHours()) + ":" + f(d.getMinutes()) + | 
					
						
							|  |  |  |         ":" + f(d.getSeconds())]; | 
					
						
							| 
									
										
										
										
											2011-01-14 19:45:45 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-23 21:18:18 +08:00
										 |  |  | function fmt_timestamp(ts) { | 
					
						
							|  |  |  |     return fmt_date(new Date(ts)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-25 19:11:07 +08:00
										 |  |  | function fmt_timestamp_mini(ts) { | 
					
						
							|  |  |  |     return fmt_date_mini(new Date(ts)); | 
					
						
							| 
									
										
										
										
											2011-01-14 19:45:45 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-12 20:07:41 +08:00
										 |  |  | function fmt_time(t, suffix) { | 
					
						
							|  |  |  |     if (t == undefined || t == 0) return ''; | 
					
						
							|  |  |  |     return t + suffix; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 23:53:39 +08:00
										 |  |  | function fmt_millis(millis) { | 
					
						
							|  |  |  |     return Math.round(millis / 1000) + "s"; | 
					
						
							| 
									
										
										
										
											2012-09-27 22:46:31 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-13 01:22:32 +08:00
										 |  |  | function fmt_features(obj) { | 
					
						
							|  |  |  |     return fmt_table_short(args_to_features(obj)); | 
					
						
							| 
									
										
										
										
											2011-05-25 19:58:06 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-13 01:22:32 +08:00
										 |  |  | function fmt_policy_short(obj) { | 
					
						
							|  |  |  |     if (obj.policy != undefined && obj.policy != '') { | 
					
						
							| 
									
										
										
										
											2017-10-11 00:57:05 +08:00
										 |  |  |         return '<abbr class="policy" title="Policy: ' + | 
					
						
							| 
									
										
										
										
											2015-01-05 21:31:58 +08:00
										 |  |  |             fmt_escape_html(obj.policy) + '">' + | 
					
						
							| 
									
										
										
										
											2017-10-27 17:50:28 +08:00
										 |  |  |             link_policy(obj.vhost, obj.policy) + '</abbr> '; | 
					
						
							| 
									
										
										
										
											2014-08-13 01:22:32 +08:00
										 |  |  |     } else { | 
					
						
							|  |  |  |         return ''; | 
					
						
							| 
									
										
										
										
											2017-10-13 01:13:10 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-08-26 00:09:06 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function fmt_op_policy_short(obj) { | 
					
						
							| 
									
										
										
										
											2017-10-11 04:44:01 +08:00
										 |  |  |     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> '; | 
					
						
							| 
									
										
										
										
											2017-10-28 02:46:35 +08:00
										 |  |  |     } else { | 
					
						
							|  |  |  |         return ''; | 
					
						
							| 
									
										
										
										
											2014-08-13 01:22:32 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function fmt_features_short(obj) { | 
					
						
							| 
									
										
										
										
											2010-10-29 20:01:22 +08:00
										 |  |  |     var res = ''; | 
					
						
							| 
									
										
										
										
											2014-08-13 01:22:32 +08:00
										 |  |  |     var features = args_to_features(obj); | 
					
						
							| 
									
										
										
										
											2011-05-25 19:58:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-21 05:44:47 +08:00
										 |  |  |     if (obj.owner_pid_details != undefined) { | 
					
						
							|  |  |  |         res += '<acronym title="Exclusive queue: click for owning connection">' | 
					
						
							|  |  |  |             + link_conn(obj.owner_pid_details.name, "Excl") + '</acronym> '; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-25 19:58:06 +08:00
										 |  |  |     for (var k in ALL_ARGS) { | 
					
						
							| 
									
										
										
										
											2014-08-13 01:22:32 +08:00
										 |  |  |         if (features[k] != undefined) { | 
					
						
							| 
									
										
										
										
											2017-10-11 00:57:05 +08:00
										 |  |  |             res += '<abbr title="' + k + ': ' + fmt_string(features[k]) + | 
					
						
							|  |  |  |                 '">' + ALL_ARGS[k].short + '</abbr> '; | 
					
						
							| 
									
										
										
										
											2011-05-25 19:58:06 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-13 01:22:32 +08:00
										 |  |  |     if (features.arguments) { | 
					
						
							| 
									
										
										
										
											2017-10-11 00:57:05 +08:00
										 |  |  |         res += '<abbr title="' + fmt_table_flat(features.arguments) + | 
					
						
							|  |  |  |         '">Args</abbr> '; | 
					
						
							| 
									
										
										
										
											2011-05-25 19:58:06 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-19 23:29:16 +08:00
										 |  |  | 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; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-13 01:22:32 +08:00
										 |  |  | function args_to_features(obj) { | 
					
						
							| 
									
										
										
										
											2011-05-25 19:58:06 +08:00
										 |  |  |     var res = {}; | 
					
						
							|  |  |  |     for (var k in obj.arguments) { | 
					
						
							|  |  |  |         if (k in KNOWN_ARGS) { | 
					
						
							| 
									
										
										
										
											2017-03-23 02:58:01 +08:00
										 |  |  |             res[k] = fmt_escape_html(obj.arguments[k]); | 
					
						
							| 
									
										
										
										
											2011-05-25 19:58:06 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             if (res.arguments == undefined) res.arguments = {}; | 
					
						
							| 
									
										
										
										
											2017-03-23 02:58:01 +08:00
										 |  |  |             res.arguments[fmt_escape_html(k)] = fmt_escape_html(obj.arguments[k]); | 
					
						
							| 
									
										
										
										
											2011-05-25 19:58:06 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-08-05 05:18:52 +08:00
										 |  |  |     if (obj.exclusive) { | 
					
						
							|  |  |  |         res['exclusive'] = true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-10-29 20:01:22 +08:00
										 |  |  |     if (obj.durable) { | 
					
						
							| 
									
										
										
										
											2011-05-25 19:58:06 +08:00
										 |  |  |         res['durable'] = true; | 
					
						
							| 
									
										
										
										
											2010-10-29 20:01:22 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (obj.auto_delete) { | 
					
						
							| 
									
										
										
										
											2011-05-25 19:58:06 +08:00
										 |  |  |         res['auto-delete'] = true; | 
					
						
							| 
									
										
										
										
											2010-10-29 20:01:22 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-11-15 20:32:42 +08:00
										 |  |  |     if (obj.internal != undefined && obj.internal) { | 
					
						
							| 
									
										
										
										
											2011-05-25 19:58:06 +08:00
										 |  |  |         res['internal'] = true; | 
					
						
							| 
									
										
										
										
											2010-10-29 20:01:22 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-04-18 21:04:45 +08:00
										 |  |  |     if (obj.messages_delayed != undefined){ | 
					
						
							|  |  |  |         res['messages delayed'] = obj.messages_delayed; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-10-29 20:01:22 +08:00
										 |  |  |     return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-25 18:58:56 +08:00
										 |  |  | function fmt_mirrors(queue) { | 
					
						
							| 
									
										
										
										
											2011-07-15 22:52:29 +08:00
										 |  |  |     var synced = queue.synchronised_slave_nodes || []; | 
					
						
							|  |  |  |     var unsynced = queue.slave_nodes || []; | 
					
						
							|  |  |  |     unsynced = jQuery.grep(unsynced, | 
					
						
							|  |  |  |                            function (node, i) { | 
					
						
							| 
									
										
										
										
											2017-03-23 02:58:01 +08:00
										 |  |  |                                return jQuery.inArray(node, synced) == -1; | 
					
						
							| 
									
										
										
										
											2011-07-15 22:52:29 +08:00
										 |  |  |                            }); | 
					
						
							|  |  |  |     var res = ''; | 
					
						
							| 
									
										
										
										
											2011-08-16 20:24:17 +08:00
										 |  |  |     if (synced.length > 0) { | 
					
						
							| 
									
										
										
										
											2017-10-11 00:57:05 +08:00
										 |  |  |         res += ' <abbr title="Synchronised mirrors: ' + synced + '">+' + | 
					
						
							|  |  |  |             synced.length + '</abbr>'; | 
					
						
							| 
									
										
										
										
											2011-07-15 22:52:29 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-08-16 20:24:17 +08:00
										 |  |  |     if (synced.length == 0 && unsynced.length > 0) { | 
					
						
							| 
									
										
										
										
											2017-10-11 00:57:05 +08:00
										 |  |  |         res += ' <abbr title="There are no synchronised mirrors">+0</abbr>'; | 
					
						
							| 
									
										
										
										
											2011-08-16 20:24:17 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-07-15 22:52:29 +08:00
										 |  |  |     if (unsynced.length > 0) { | 
					
						
							| 
									
										
										
										
											2017-10-11 00:57:05 +08:00
										 |  |  |         res += ' <abbr class="warning" title="Unsynchronised mirrors: ' + | 
					
						
							|  |  |  |             unsynced + '">+' + unsynced.length + '</abbr>'; | 
					
						
							| 
									
										
										
										
											2011-05-25 18:58:56 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-07-15 22:52:29 +08:00
										 |  |  |     return res; | 
					
						
							| 
									
										
										
										
											2011-05-25 18:58:56 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-10 22:28:33 +08:00
										 |  |  | function fmt_sync_state(queue) { | 
					
						
							| 
									
										
										
										
											2013-01-08 23:41:53 +08:00
										 |  |  |     var res = '<p><b>Syncing: '; | 
					
						
							| 
									
										
										
										
											2013-01-09 03:38:03 +08:00
										 |  |  |     res += (queue.messages == 0) ? 100 : Math.round(100 * queue.sync_messages / | 
					
						
							|  |  |  |                                                     queue.messages); | 
					
						
							| 
									
										
										
										
											2013-01-08 23:41:53 +08:00
										 |  |  |     res += '%</b></p>'; | 
					
						
							|  |  |  |     return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 19:09:18 +08:00
										 |  |  | function fmt_members(queue) { | 
					
						
							|  |  |  |     var res = ''; | 
					
						
							| 
									
										
										
										
											2018-06-25 18:49:52 +08:00
										 |  |  |     var IsMayority = (queue.online.length >= (Math.floor(queue.members.length / 2) + 1)); | 
					
						
							| 
									
										
										
										
											2018-06-26 18:30:31 +08:00
										 |  |  |     var followers = queue.online; | 
					
						
							| 
									
										
										
										
											2018-05-17 19:09:18 +08:00
										 |  |  |     followers.splice(followers.indexOf(queue.node), 1); | 
					
						
							| 
									
										
										
										
											2018-06-25 18:49:52 +08:00
										 |  |  |     if (IsMayority) { | 
					
						
							| 
									
										
										
										
											2018-05-17 19:09:18 +08:00
										 |  |  |         res += ' <abbr title="Followers: ' + followers + '">+' + | 
					
						
							|  |  |  |             followers.length + '</abbr>'; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         res += ' <abbr class="warning" title="Cluster is in minority">+' + followers.length + '</abbr>'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-21 21:17:41 +08:00
										 |  |  | function fmt_channel_mode(ch) { | 
					
						
							|  |  |  |     if (ch.transactional) { | 
					
						
							| 
									
										
										
										
											2017-10-11 00:57:05 +08:00
										 |  |  |         return '<abbr title="Transactional">T</abbr>'; | 
					
						
							| 
									
										
										
										
											2011-01-21 21:17:41 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     else if (ch.confirm) { | 
					
						
							| 
									
										
										
										
											2017-10-11 00:57:05 +08:00
										 |  |  |         return '<abbr title="Confirm">C</abbr>'; | 
					
						
							| 
									
										
										
										
											2011-01-21 21:17:41 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |         return ''; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-29 23:32:17 +08:00
										 |  |  | function fmt_color(r, thresholds) { | 
					
						
							| 
									
										
										
										
											2010-07-23 20:43:35 +08:00
										 |  |  |     if (r == undefined) return ''; | 
					
						
							| 
									
										
										
										
											2010-07-22 23:29:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-29 23:32:17 +08:00
										 |  |  |     for (var i in thresholds) { | 
					
						
							| 
									
										
										
										
											2011-02-18 22:26:12 +08:00
										 |  |  |         var threshold = thresholds[i][0]; | 
					
						
							|  |  |  |         var color = thresholds[i][1]; | 
					
						
							| 
									
										
										
										
											2010-10-29 23:32:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-18 22:26:12 +08:00
										 |  |  |         if (r >= threshold) { | 
					
						
							|  |  |  |             return color; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-10-29 23:32:17 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-10-30 00:58:21 +08:00
										 |  |  |     return 'green'; | 
					
						
							| 
									
										
										
										
											2010-07-22 23:29:19 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-05 01:16:20 +08:00
										 |  |  | function fmt_rate_num(num) { | 
					
						
							|  |  |  |     if (num == undefined) return UNKNOWN_REPR; | 
					
						
							| 
									
										
										
										
											2012-01-05 05:23:58 +08:00
										 |  |  |     else if (num < 1)     return num.toFixed(2); | 
					
						
							|  |  |  |     else if (num < 10)    return num.toFixed(1); | 
					
						
							| 
									
										
										
										
											2015-09-03 18:00:05 +08:00
										 |  |  |     else                  return fmt_num_thousands(num); | 
					
						
							| 
									
										
										
										
											2013-06-17 22:40:42 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-03 18:00:05 +08:00
										 |  |  | 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; | 
					
						
							| 
									
										
										
										
											2012-01-05 01:16:20 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-19 22:14:06 +08:00
										 |  |  | function fmt_percent(num) { | 
					
						
							| 
									
										
										
										
											2013-11-20 19:18:13 +08:00
										 |  |  |     if (num === '') { | 
					
						
							|  |  |  |         return 'N/A'; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         return Math.round(num * 100) + '%'; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-11-19 22:14:06 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-07 00:14:42 +08:00
										 |  |  | 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); | 
					
						
							| 
									
										
										
										
											2014-06-11 23:33:53 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-07 00:14:42 +08:00
										 |  |  | 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]); | 
					
						
							| 
									
										
										
										
											2014-06-25 00:50:24 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-07 00:14:42 +08:00
										 |  |  | function fmt_detail_rate(obj, name, mode) { | 
					
						
							| 
									
										
										
										
											2015-02-18 21:43:51 +08:00
										 |  |  |     return pick_rate(fmt_rate, obj, name, mode); | 
					
						
							| 
									
										
										
										
											2010-09-02 19:58:34 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2010-07-28 01:04:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-07 00:14:42 +08:00
										 |  |  | function fmt_detail_rate_bytes(obj, name, mode) { | 
					
						
							| 
									
										
										
										
											2015-02-18 21:43:51 +08:00
										 |  |  |     return pick_rate(fmt_rate_bytes, obj, name, mode); | 
					
						
							| 
									
										
										
										
											2012-12-19 21:31:26 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-07 00:14:42 +08:00
										 |  |  | // ---------------------------------------------------------------------
 | 
					
						
							| 
									
										
										
										
											2010-07-28 01:04:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-07 00:14:42 +08:00
										 |  |  | // These are pluggable for charts etc
 | 
					
						
							| 
									
										
										
										
											2013-02-05 23:56:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-07 00:14:42 +08:00
										 |  |  | function fmt_plain(num) { | 
					
						
							|  |  |  |     return num; | 
					
						
							| 
									
										
										
										
											2013-02-05 23:56:51 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-07 00:14:42 +08:00
										 |  |  | function fmt_plain_axis(num, max) { | 
					
						
							|  |  |  |     return fmt_si_prefix(num, max, 1000, true); | 
					
						
							| 
									
										
										
										
											2013-02-05 23:56:51 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-07 00:14:42 +08:00
										 |  |  | function fmt_rate(num) { | 
					
						
							|  |  |  |     return fmt_rate_num(num) + '/s'; | 
					
						
							| 
									
										
										
										
											2011-07-06 19:03:23 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-17 22:40:42 +08:00
										 |  |  | function fmt_rate_axis(num, max) { | 
					
						
							| 
									
										
										
										
											2014-11-07 00:14:42 +08:00
										 |  |  |     return fmt_plain_axis(num, max) + '/s'; | 
					
						
							| 
									
										
										
										
											2013-04-09 19:54:02 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-07 00:14:42 +08:00
										 |  |  | function fmt_bytes(bytes) { | 
					
						
							|  |  |  |     if (bytes == undefined) return UNKNOWN_REPR; | 
					
						
							|  |  |  |     return fmt_si_prefix(bytes, bytes, 1024, false) + 'B'; | 
					
						
							| 
									
										
										
										
											2013-04-09 19:54:02 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-11 23:33:53 +08:00
										 |  |  | function fmt_bytes_axis(num, max) { | 
					
						
							| 
									
										
										
										
											2013-05-01 18:54:15 +08:00
										 |  |  |     num = parseInt(num); | 
					
						
							| 
									
										
										
										
											2014-06-11 23:33:53 +08:00
										 |  |  |     return fmt_bytes(isNaN(num) ? 0 : num); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-07 00:14:42 +08:00
										 |  |  | function fmt_rate_bytes(num) { | 
					
						
							|  |  |  |     return fmt_bytes(num) + '/s'; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-06-11 23:33:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | function fmt_rate_bytes_axis(num, max) { | 
					
						
							|  |  |  |     return fmt_bytes_axis(num, max) + '/s'; | 
					
						
							| 
									
										
										
										
											2011-07-06 19:03:23 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-07 00:14:42 +08:00
										 |  |  | function fmt_ms(num) { | 
					
						
							|  |  |  |     return fmt_rate_num(num) + 'ms'; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // ---------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-07 21:20:10 +08:00
										 |  |  | function fmt_maybe_vhost(name) { | 
					
						
							|  |  |  |     return vhosts_interesting ? | 
					
						
							|  |  |  |         ' in virtual host <b>' + fmt_escape_html(name) + '</b>' | 
					
						
							|  |  |  |         : ''; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-27 00:42:03 +08:00
										 |  |  | function fmt_exchange(name) { | 
					
						
							| 
									
										
										
										
											2013-03-06 20:29:30 +08:00
										 |  |  |     return fmt_escape_html(fmt_exchange0(name)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function fmt_exchange0(name) { | 
					
						
							|  |  |  |     return name == '' ? '(AMQP default)' : name; | 
					
						
							| 
									
										
										
										
											2010-08-27 00:42:03 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-25 21:13:04 +08:00
										 |  |  | function fmt_exchange_type(type) { | 
					
						
							|  |  |  |     for (var i in exchange_types) { | 
					
						
							|  |  |  |         if (exchange_types[i].name == type) { | 
					
						
							|  |  |  |             return fmt_escape_html(type); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-10-11 00:57:05 +08:00
										 |  |  |     return '<div class="status-red"><abbr title="Exchange type not found. ' + | 
					
						
							| 
									
										
										
										
											2012-01-25 21:13:04 +08:00
										 |  |  |         'Publishing to this exchange will fail.">' + fmt_escape_html(type) + | 
					
						
							| 
									
										
										
										
											2017-10-11 00:57:05 +08:00
										 |  |  |         '</abbr></div>'; | 
					
						
							| 
									
										
										
										
											2012-01-25 21:13:04 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-27 00:42:03 +08:00
										 |  |  | function fmt_exchange_url(name) { | 
					
						
							| 
									
										
										
										
											2011-11-30 21:43:42 +08:00
										 |  |  |     return name == '' ? 'amq.default' : fmt_escape_html(name); | 
					
						
							| 
									
										
										
										
											2010-08-27 00:42:03 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-29 20:22:46 +08:00
										 |  |  | function fmt_download_filename(host) { | 
					
						
							|  |  |  |     var now = new Date(); | 
					
						
							| 
									
										
										
										
											2010-10-01 01:02:05 +08:00
										 |  |  |     return host.replace('@', '_') + "_" + now.getFullYear() + "-" + | 
					
						
							|  |  |  |         (now.getMonth() + 1) + "-" + now.getDate() + ".json"; | 
					
						
							| 
									
										
										
										
											2010-09-29 20:22:46 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-12 21:08:17 +08:00
										 |  |  | function fmt_table_short(table) { | 
					
						
							| 
									
										
										
										
											2011-02-12 02:04:05 +08:00
										 |  |  |     return '<table class="mini">' + fmt_table_body(table, ':') + '</table>'; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function fmt_table_long(table) { | 
					
						
							|  |  |  |     return '<table class="facts">' + fmt_table_body(table, '') + | 
					
						
							| 
									
										
										
										
											2011-07-29 19:58:18 +08:00
										 |  |  |         '</table>'; | 
					
						
							| 
									
										
										
										
											2011-02-12 02:04:05 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function fmt_table_body(table, x) { | 
					
						
							| 
									
										
										
										
											2010-10-12 21:08:17 +08:00
										 |  |  |     var res = ''; | 
					
						
							|  |  |  |     for (k in table) { | 
					
						
							| 
									
										
										
										
											2015-01-05 21:31:27 +08:00
										 |  |  |         res += '<tr><th>' + fmt_escape_html(k) + x + '</th>' + | 
					
						
							|  |  |  |             '<td>' + fmt_amqp_value(table[k]) + '</td>'; | 
					
						
							| 
									
										
										
										
											2010-10-12 21:08:17 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-12 02:04:05 +08:00
										 |  |  | function fmt_amqp_value(val) { | 
					
						
							| 
									
										
										
										
											2011-02-17 00:00:12 +08:00
										 |  |  |     if (val instanceof Array) { | 
					
						
							| 
									
										
										
										
											2011-03-03 00:49:00 +08:00
										 |  |  |         var val2 = new Array(); | 
					
						
							|  |  |  |         for (var i = 0; i < val.length; i++) { | 
					
						
							|  |  |  |             val2[i] = fmt_amqp_value(val[i]); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return val2.join("<br/>"); | 
					
						
							| 
									
										
										
										
											2011-02-17 00:00:12 +08:00
										 |  |  |     } else if (val instanceof Object) { | 
					
						
							| 
									
										
										
										
											2011-02-17 19:47:23 +08:00
										 |  |  |         return fmt_table_short(val); | 
					
						
							| 
									
										
										
										
											2011-02-12 02:04:05 +08:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2012-05-02 00:39:07 +08:00
										 |  |  |         var t = typeof(val); | 
					
						
							|  |  |  |         if (t == 'string') { | 
					
						
							| 
									
										
										
										
											2017-10-11 00:57:05 +08:00
										 |  |  |             return '<abbr class="type" title="string">' + | 
					
						
							|  |  |  |                 fmt_escape_html(val) + '</abbr>'; | 
					
						
							| 
									
										
										
										
											2012-05-02 00:39:07 +08:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2017-10-11 00:57:05 +08:00
										 |  |  |             return '<abbr class="type" title="' + t + '">' + val + '</abbr>'; | 
					
						
							| 
									
										
										
										
											2012-05-02 00:39:07 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-10-28 22:30:32 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-25 19:58:06 +08:00
										 |  |  | function fmt_table_flat(table) { | 
					
						
							|  |  |  |     var res = []; | 
					
						
							|  |  |  |     for (k in table) { | 
					
						
							| 
									
										
										
										
											2015-01-06 23:46:10 +08:00
										 |  |  |         res.push(fmt_escape_html(k) + ': ' + fmt_amqp_value_flat(table[k])); | 
					
						
							| 
									
										
										
										
											2011-05-25 19:58:06 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     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; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-09 18:49:47 +08:00
										 |  |  | 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'; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-02 21:37:04 +08:00
										 |  |  | 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]; | 
					
						
							| 
									
										
										
										
											2015-01-19 20:48:28 +08:00
										 |  |  |         if (jQuery.inArray(application.name, node.enabled_plugins) != -1 ) { | 
					
						
							| 
									
										
										
										
											2014-07-02 21:37:04 +08:00
										 |  |  |             plugins.push(application.name); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-10-11 00:57:05 +08:00
										 |  |  |     return '<abbr title="Enabled plugins: ' + plugins.join(", ") + '">' + | 
					
						
							|  |  |  |         plugins.length + '</abbr>'; | 
					
						
							| 
									
										
										
										
											2014-07-02 21:37:04 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function get_plugins_list(node) { | 
					
						
							|  |  |  |     var result = []; | 
					
						
							|  |  |  |     for (var i = 0; i < node.applications.length; i++) { | 
					
						
							|  |  |  |         var application = node.applications[i]; | 
					
						
							| 
									
										
										
										
											2015-01-19 20:48:28 +08:00
										 |  |  |         if (jQuery.inArray(application.name, node.enabled_plugins) != -1 ) { | 
					
						
							| 
									
										
										
										
											2014-07-02 21:37:04 +08:00
										 |  |  |             result.push(application); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 00:49:03 +08:00
										 |  |  | function fmt_rabbit_version(applications) { | 
					
						
							|  |  |  |     for (var i in applications) { | 
					
						
							|  |  |  |         if (applications[i].name == 'rabbit') { | 
					
						
							|  |  |  |             return applications[i].version; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return 'unknown'; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-24 23:59:23 +08:00
										 |  |  | function fmt_strip_tags(txt) { | 
					
						
							| 
									
										
										
										
											2017-03-28 19:40:08 +08:00
										 |  |  |     if(txt === null) { | 
					
						
							|  |  |  |         return ""; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if(txt === undefined) { | 
					
						
							|  |  |  |         return ""; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return ("" + txt).replace(/<(?:.|\n)*?>/gm, ''); | 
					
						
							| 
									
										
										
										
											2017-03-24 23:59:23 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-22 02:20:33 +08:00
										 |  |  | function fmt_escape_html(txt) { | 
					
						
							| 
									
										
										
										
											2012-04-24 20:35:32 +08:00
										 |  |  |     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) { | 
					
						
							| 
									
										
										
										
											2017-03-28 19:40:08 +08:00
										 |  |  |     if(txt === null) { | 
					
						
							|  |  |  |         return ""; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if(txt === undefined) { | 
					
						
							|  |  |  |         return ""; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return ("" + txt).replace(/&/g, '&') | 
					
						
							| 
									
										
										
										
											2012-01-23 23:34:25 +08:00
										 |  |  |         .replace(/</g, '<') | 
					
						
							| 
									
										
										
										
											2011-03-17 00:22:59 +08:00
										 |  |  |         .replace(/>/g, '>') | 
					
						
							| 
									
										
										
										
											2011-12-14 22:55:27 +08:00
										 |  |  |         .replace(/\"/g, '"'); | 
					
						
							| 
									
										
										
										
											2011-03-17 00:22:59 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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); | 
					
						
							| 
									
										
										
										
											2011-02-22 02:20:33 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-05 21:26:32 +08:00
										 |  |  | function fmt_node(node_host) { | 
					
						
							| 
									
										
										
										
											2017-09-19 01:49:00 +08:00
										 |  |  |     return fmt_string(node_host); | 
					
						
							| 
									
										
										
										
											2011-06-14 00:36:26 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-02 22:57:43 +08:00
										 |  |  | function fmt_object_state(obj) { | 
					
						
							|  |  |  |     if (obj.state == undefined) return ''; | 
					
						
							| 
									
										
										
										
											2012-01-18 20:18:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-13 23:10:30 +08:00
										 |  |  |     var colour = 'green'; | 
					
						
							| 
									
										
										
										
											2013-12-06 01:51:34 +08:00
										 |  |  |     var text = obj.state; | 
					
						
							| 
									
										
										
										
											2012-01-13 23:10:30 +08:00
										 |  |  |     var explanation; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-06 01:51:34 +08:00
										 |  |  |     if (obj.idle_since !== undefined) { | 
					
						
							|  |  |  |         colour = 'grey'; | 
					
						
							|  |  |  |         explanation = 'Idle since ' + obj.idle_since; | 
					
						
							|  |  |  |         text = 'idle'; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-12-13 00:39:08 +08:00
										 |  |  |     // Only connections can be 'blocked' or 'blocking'
 | 
					
						
							| 
									
										
										
										
											2013-12-06 01:51:34 +08:00
										 |  |  |     else if (obj.state == 'blocked') { | 
					
						
							| 
									
										
										
										
											2012-01-13 23:10:30 +08:00
										 |  |  |         colour = 'red'; | 
					
						
							| 
									
										
										
										
											2013-12-13 00:39:08 +08:00
										 |  |  |         explanation = 'Resource alarm: connection blocked.'; | 
					
						
							| 
									
										
										
										
											2012-01-13 23:10:30 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-12-02 22:57:43 +08:00
										 |  |  |     else if (obj.state == 'blocking') { | 
					
						
							| 
									
										
										
										
											2012-01-13 23:10:30 +08:00
										 |  |  |         colour = 'yellow'; | 
					
						
							| 
									
										
										
										
											2013-12-13 00:39:08 +08:00
										 |  |  |         explanation = 'Resource alarm: connection will block on publish.'; | 
					
						
							| 
									
										
										
										
											2012-01-13 23:10:30 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-12-02 22:57:43 +08:00
										 |  |  |     else if (obj.state == 'flow') { | 
					
						
							| 
									
										
										
										
											2013-12-02 21:47:07 +08:00
										 |  |  |         colour = 'yellow'; | 
					
						
							| 
									
										
										
										
											2017-06-17 10:05:31 +08:00
										 |  |  |         explanation = 'Publishing rate recently throttled by server.'; | 
					
						
							| 
									
										
										
										
											2012-01-13 03:03:36 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-09-10 21:11:50 +08:00
										 |  |  |     else if (obj.state == 'down') { | 
					
						
							|  |  |  |         colour = 'red'; | 
					
						
							|  |  |  |         explanation = 'The queue is located on a cluster node or nodes that ' + | 
					
						
							|  |  |  |             'are down.'; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-09-11 19:05:18 +08:00
										 |  |  |     else if (obj.state == 'crashed') { | 
					
						
							|  |  |  |         colour = 'red'; | 
					
						
							|  |  |  |         explanation = 'The queue has crashed repeatedly and been unable to ' + | 
					
						
							|  |  |  |             'restart.'; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-07-26 00:52:13 +08:00
										 |  |  |     else if (obj.state == 'stopped') { | 
					
						
							|  |  |  |         colour = 'red'; | 
					
						
							|  |  |  |         explanation = 'The queue process was stopped by the vhost supervisor.'; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-01-13 03:03:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-21 23:36:17 +08:00
										 |  |  |     return fmt_state(colour, text, explanation); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function fmt_state(colour, text, explanation) { | 
					
						
							|  |  |  |     var key; | 
					
						
							| 
									
										
										
										
											2012-01-13 23:10:30 +08:00
										 |  |  |     if (explanation) { | 
					
						
							| 
									
										
										
										
											2017-10-11 00:57:05 +08:00
										 |  |  |         key = '<abbr class="normal" title="' + explanation + '">' + | 
					
						
							|  |  |  |             text + '</abbr>'; | 
					
						
							| 
									
										
										
										
											2012-01-13 03:03:36 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2014-01-21 23:36:17 +08:00
										 |  |  |         key = text; | 
					
						
							| 
									
										
										
										
											2012-01-13 03:03:36 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-01-21 23:36:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-24 22:46:15 +08:00
										 |  |  |     return '<div class="colour-key status-key-' + colour + '"></div>' + key; | 
					
						
							| 
									
										
										
										
											2012-01-13 03:03:36 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-02 01:31:34 +08:00
										 |  |  | 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); | 
					
						
							| 
									
										
										
										
											2012-04-24 01:43:28 +08:00
										 |  |  |     if (uri.indexOf('?') == -1) { | 
					
						
							|  |  |  |         return uri; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2017-10-11 00:57:05 +08:00
										 |  |  |         return '<abbr title="' + uri + '">' + | 
					
						
							|  |  |  |             uri.substr(0, uri.indexOf('?')) + '?...</abbr>'; | 
					
						
							| 
									
										
										
										
											2012-04-24 01:43:28 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-30 04:47:58 +08:00
										 |  |  | function fmt_uri_with_credentials(uri) { | 
					
						
							|  |  |  |     if (typeof uri == 'string') { | 
					
						
							|  |  |  |         // mask password
 | 
					
						
							| 
									
										
										
										
											2017-08-30 07:27:39 +08:00
										 |  |  |         var mask = /^([a-zA-Z0-9+-.]+):\/\/(.*):(.*)@/; | 
					
						
							| 
									
										
										
										
											2017-08-30 04:47:58 +08:00
										 |  |  |         return uri.replace(mask, "$1://$2:[redacted]@"); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         return UNKNOWN_REPR; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-06 23:14:13 +08:00
										 |  |  | function fmt_client_name(properties) { | 
					
						
							|  |  |  |     var res = []; | 
					
						
							|  |  |  |     if (properties.product != undefined) { | 
					
						
							| 
									
										
										
										
											2013-01-21 20:30:55 +08:00
										 |  |  |         res.push(fmt_trunc(properties.product, 10)); | 
					
						
							| 
									
										
										
										
											2012-09-06 23:14:13 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (properties.platform != undefined) { | 
					
						
							| 
									
										
										
										
											2013-01-21 20:30:55 +08:00
										 |  |  |         res.push(fmt_trunc(properties.platform, 10)); | 
					
						
							| 
									
										
										
										
											2012-09-06 23:14:13 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     res = res.join(" / "); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (properties.version != undefined) { | 
					
						
							| 
									
										
										
										
											2013-01-21 20:30:55 +08:00
										 |  |  |         res += '<sub>' + fmt_trunc(properties.version) + '</sub>'; | 
					
						
							| 
									
										
										
										
											2012-09-06 23:14:13 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-21 20:30:55 +08:00
										 |  |  | function fmt_trunc(str, max_length) { | 
					
						
							|  |  |  |     return str.length > max_length ? | 
					
						
							| 
									
										
										
										
											2017-10-11 00:57:05 +08:00
										 |  |  |         ('<abbr class="normal" title="' + fmt_escape_html(str) + '">' + | 
					
						
							|  |  |  |          fmt_escape_html(str.substring(0, max_length)) + '...</abbr>') : | 
					
						
							| 
									
										
										
										
											2015-01-06 23:45:05 +08:00
										 |  |  |         fmt_escape_html(str); | 
					
						
							| 
									
										
										
										
											2013-01-21 20:30:55 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-05 22:27:03 +08:00
										 |  |  | 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(' ') + '"'; | 
					
						
							| 
									
										
										
										
											2010-07-22 23:29:19 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-24 18:37:54 +08:00
										 |  |  | function esc(str) { | 
					
						
							| 
									
										
										
										
											2010-09-14 22:46:19 +08:00
										 |  |  |     return encodeURIComponent(str); | 
					
						
							| 
									
										
										
										
											2010-08-25 19:24:34 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-19 23:29:16 +08:00
										 |  |  | function link_conn(name, desc) { | 
					
						
							| 
									
										
										
										
											2013-03-06 20:29:30 +08:00
										 |  |  |     if (desc == undefined) { | 
					
						
							|  |  |  |         return _link_to(short_conn(name), '#/connections/' + esc(name)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |         return _link_to(desc, '#/connections/' + esc(name), false); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-08-25 19:24:34 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-03 00:06:59 +08:00
										 |  |  | function link_channel(name) { | 
					
						
							| 
									
										
										
										
											2017-08-01 23:31:03 +08:00
										 |  |  |     return _link_to(short_chan(name), '#/channels/' + esc(name)); | 
					
						
							| 
									
										
										
										
											2010-09-03 00:06:59 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-05 22:27:03 +08:00
										 |  |  | function link_exchange(vhost, name, args) { | 
					
						
							| 
									
										
										
										
											2010-08-27 00:42:03 +08:00
										 |  |  |     var url = esc(vhost) + '/' + (name == '' ? 'amq.default' : esc(name)); | 
					
						
							| 
									
										
										
										
											2013-09-05 22:27:03 +08:00
										 |  |  |     return _link_to(fmt_exchange0(name), '#/exchanges/' + url, true, args); | 
					
						
							| 
									
										
										
										
											2010-08-27 00:42:03 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-05 22:27:03 +08:00
										 |  |  | function link_queue(vhost, name, args) { | 
					
						
							|  |  |  |     return _link_to(name, '#/queues/' + esc(vhost) + '/' + esc(name), true, args); | 
					
						
							| 
									
										
										
										
											2010-08-27 17:55:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-26 01:18:31 +08:00
										 |  |  | function link_vhost(name) { | 
					
						
							| 
									
										
										
										
											2017-08-01 23:31:03 +08:00
										 |  |  |     return _link_to(name, '#/vhosts/' + esc(name)); | 
					
						
							| 
									
										
										
										
											2010-08-26 01:18:31 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function link_user(name) { | 
					
						
							| 
									
										
										
										
											2017-08-01 23:31:03 +08:00
										 |  |  |     return _link_to(name, '#/users/' + esc(name)); | 
					
						
							| 
									
										
										
										
											2010-08-26 01:18:31 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-03 01:19:14 +08:00
										 |  |  | function link_node(name) { | 
					
						
							| 
									
										
										
										
											2017-09-19 02:40:19 +08:00
										 |  |  |     return _link_to(fmt_node(name), '#/nodes/' + esc(name)); | 
					
						
							| 
									
										
										
										
											2010-11-03 01:19:14 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-08 00:39:09 +08:00
										 |  |  | function link_policy(vhost, name) { | 
					
						
							| 
									
										
										
										
											2017-08-01 23:31:03 +08:00
										 |  |  |     return _link_to(name, '#/policies/' + esc(vhost) + '/' + esc(name)); | 
					
						
							| 
									
										
										
										
											2012-05-18 22:33:13 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-05 22:27:03 +08:00
										 |  |  | function _link_to(name, url, highlight, args) { | 
					
						
							| 
									
										
										
										
											2013-03-06 20:29:30 +08:00
										 |  |  |     if (highlight == undefined) highlight = true; | 
					
						
							| 
									
										
										
										
											2013-09-05 22:27:03 +08:00
										 |  |  |     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 + '"' : '') + '>' + | 
					
						
							| 
									
										
										
										
											2013-03-06 20:29:30 +08:00
										 |  |  |         (highlight ? fmt_highlight_filter(name) : fmt_escape_html(name)) + | 
					
						
							|  |  |  |         '</a>'; | 
					
						
							| 
									
										
										
										
											2010-09-03 00:06:59 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-06 02:04:15 +08:00
										 |  |  | function fmt_highlight_filter(text) { | 
					
						
							| 
									
										
										
										
											2013-03-06 20:29:30 +08:00
										 |  |  |     if (current_filter == '') return fmt_escape_html(text); | 
					
						
							| 
									
										
										
										
											2013-11-13 19:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-13 00:41:31 +08:00
										 |  |  |     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; | 
					
						
							| 
									
										
										
										
											2013-03-06 02:04:15 +08:00
										 |  |  |     if (ix == -1) { | 
					
						
							| 
									
										
										
										
											2013-03-06 20:29:30 +08:00
										 |  |  |         return fmt_escape_html(text); | 
					
						
							| 
									
										
										
										
											2013-03-06 02:04:15 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2013-03-06 20:29:30 +08:00
										 |  |  |         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)); | 
					
						
							| 
									
										
										
										
											2013-03-06 02:04:15 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-09-03 00:06:59 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-22 18:46:52 +08:00
										 |  |  | function filter_ui_pg(items, truncate, appendselect) { | 
					
						
							| 
									
										
										
										
											2013-03-06 22:59:31 +08:00
										 |  |  |     var total = items.length; | 
					
						
							| 
									
										
										
										
											2013-03-06 02:04:15 +08:00
										 |  |  |     if (current_filter != '') { | 
					
						
							|  |  |  |         var items2 = []; | 
					
						
							|  |  |  |         for (var i in items) { | 
					
						
							|  |  |  |             var item = items[i]; | 
					
						
							| 
									
										
										
										
											2013-11-13 00:41:31 +08:00
										 |  |  |             var item_name = item.name.toLowerCase(); | 
					
						
							| 
									
										
										
										
											2013-11-13 19:09:44 +08:00
										 |  |  |             if ((current_filter_regex_on && | 
					
						
							|  |  |  |                  current_filter_regex && | 
					
						
							|  |  |  |                  current_filter_regex.test(item_name)) || | 
					
						
							|  |  |  |                 item_name.indexOf(current_filter.toLowerCase()) != -1) { | 
					
						
							| 
									
										
										
										
											2013-03-06 02:04:15 +08:00
										 |  |  |                 items2.push(item); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         items.length = items2.length; | 
					
						
							|  |  |  |         for (var i in items2) items[i] = items2[i]; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-09-29 21:45:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-13 01:09:02 +08:00
										 |  |  |     var res = '<div class="filter"><table' + | 
					
						
							| 
									
										
										
										
											2013-03-07 18:43:24 +08:00
										 |  |  |         (current_filter == '' ? '' : ' class="filter-active"') + | 
					
						
							| 
									
										
										
										
											2013-11-13 01:09:02 +08:00
										 |  |  |         '><tr><th>Filter:</th>' + | 
					
						
							| 
									
										
										
										
											2013-03-06 22:59:31 +08:00
										 |  |  |         '<td><input id="filter" type="text" value="' + | 
					
						
							| 
									
										
										
										
											2013-11-13 00:41:31 +08:00
										 |  |  |         fmt_escape_html(current_filter) + '"/>' + | 
					
						
							|  |  |  |         '<input type="checkbox" name="filter-regex-mode" id="filter-regex-mode"' + | 
					
						
							|  |  |  |         (current_filter_regex_on ? ' checked' : '') + | 
					
						
							| 
									
										
										
										
											2017-10-27 00:17:52 +08:00
										 |  |  |         '/><label for="filter-regex-mode">Regex</label> <span class="help" id="filter-regex"></span>' + | 
					
						
							| 
									
										
										
										
											2013-11-13 01:09:02 +08:00
										 |  |  |         '</td></tr></table>'; | 
					
						
							| 
									
										
										
										
											2013-03-06 20:29:30 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-26 20:42:29 +08:00
										 |  |  |     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'); | 
					
						
							| 
									
										
										
										
											2013-03-06 20:29:30 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-28 19:40:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-22 18:46:52 +08:00
										 |  |  |     selected += appendselect; | 
					
						
							| 
									
										
										
										
											2015-10-22 15:55:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     res += '<p id="filter-truncate"><span class="updatable">' + selected + | 
					
						
							|  |  |  |         '</span>' + truncate + '</p>'; | 
					
						
							|  |  |  |     res += '</div>'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-25 23:13:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-22 15:55:36 +08:00
										 |  |  | function filter_ui(items) { | 
					
						
							|  |  |  |     current_truncate = (current_truncate == null) ? | 
					
						
							|  |  |  |         parseInt(get_pref('truncate')) : current_truncate; | 
					
						
							|  |  |  |      var truncate_input = '<input type="text" id="truncate" value="' + | 
					
						
							|  |  |  |         current_truncate + '">'; | 
					
						
							| 
									
										
										
										
											2017-03-28 19:40:08 +08:00
										 |  |  |      var selected = ''; | 
					
						
							| 
									
										
										
										
											2013-04-25 23:13:44 +08:00
										 |  |  |     if (items.length > current_truncate) { | 
					
						
							| 
									
										
										
										
											2013-04-26 19:30:52 +08:00
										 |  |  |         selected += '<span id="filter-warning-show"> ' + | 
					
						
							|  |  |  |             '(only showing first</span> '; | 
					
						
							| 
									
										
										
										
											2013-04-25 23:13:44 +08:00
										 |  |  |         items.length = current_truncate; | 
					
						
							| 
									
										
										
										
											2010-09-29 21:45:40 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-03-06 22:59:31 +08:00
										 |  |  |     else { | 
					
						
							| 
									
										
										
										
											2015-11-27 07:27:46 +08:00
										 |  |  |         selected += ', page size up to '; | 
					
						
							| 
									
										
										
										
											2013-03-06 22:59:31 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-10-22 20:35:37 +08:00
										 |  |  |    return filter_ui_pg(items, truncate_input, selected); | 
					
						
							| 
									
										
										
										
											2013-03-06 22:59:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-25 20:48:58 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-17 23:59:49 +08:00
										 |  |  | function paginate_header_ui(pages, context){ | 
					
						
							|  |  |  |      var res = '<h2 class="updatable">' ; | 
					
						
							|  |  |  |      res += ' All ' + context +' (' + pages.total_count + ((pages.filtered_count != pages.total_count) ?   ' Filtered: ' + pages.filtered_count  : '') +  ')'; | 
					
						
							|  |  |  |      res += '</h2>' | 
					
						
							|  |  |  |     return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-03 04:51:27 +08:00
										 |  |  | function paginate_ui(pages, context){ | 
					
						
							| 
									
										
										
										
											2015-11-17 23:59:49 +08:00
										 |  |  |     var res = paginate_header_ui(pages, context); | 
					
						
							|  |  |  |     res += '<div class="hider">'; | 
					
						
							|  |  |  |     res += '<h3>Pagination</h3>'; | 
					
						
							|  |  |  |     res += '<div class="filter">'; | 
					
						
							|  |  |  |     res += '<table class="updatable">'; | 
					
						
							| 
									
										
										
										
											2019-01-03 04:51:27 +08:00
										 |  |  |     res += '<tr>'; | 
					
						
							| 
									
										
										
										
											2016-01-24 18:28:51 +08:00
										 |  |  |     res += '<th><label for="'+ context +'-page">Page </label> <select id="'+ context +'-page" class="pagination_class pagination_class_select"  >'; | 
					
						
							| 
									
										
										
										
											2015-11-17 23:59:49 +08:00
										 |  |  |     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>'; | 
					
						
							| 
									
										
										
										
											2016-01-24 18:28:51 +08:00
										 |  |  |     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"' ; | 
					
						
							| 
									
										
										
										
											2015-11-17 23:59:49 +08:00
										 |  |  |     res +=   'value = ' + fmt_filter_name_request(context, "") + '>' ; | 
					
						
							|  |  |  |     res +=   '</input></th></span>' ; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-24 18:28:51 +08:00
										 |  |  |     res += '<th> <input type="checkbox" data-page-start="1" class="pagination_class pagination_class_checkbox" id="'+ context +'-filter-regex-mode"' ; | 
					
						
							| 
									
										
										
										
											2017-03-28 19:40:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 00:17:52 +08:00
										 |  |  |     res += fmt_regex_request(context, "") + '></input> <label for="filter-regex-mode">Regex</label> <span class="help" id="filter-regex"></span></th>' ; | 
					
						
							| 
									
										
										
										
											2017-03-28 19:40:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-17 23:59:49 +08:00
										 |  |  |     res +=' </table>' ; | 
					
						
							|  |  |  |     res += '<p id="filter-truncate"><span class="updatable">'; | 
					
						
							| 
									
										
										
										
											2015-11-27 07:27:46 +08:00
										 |  |  |     res += '<span><label for="'+ context +'-pagesize"> Displaying ' + pages.item_count + '  item'+ ((pages.item_count > 1) ? 's' : '' ) + ' , page size up to: </label> '; | 
					
						
							| 
									
										
										
										
											2016-01-24 18:28:51 +08:00
										 |  |  |     res +=       ' <input id="'+ context +'-pagesize" data-page-start="1" class="pagination_class shortinput pagination_class_input" type="text" '; | 
					
						
							| 
									
										
										
										
											2015-11-17 23:59:49 +08:00
										 |  |  |     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; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-22 15:55:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-29 21:45:40 +08:00
										 |  |  | 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; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-10-12 00:05:06 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | function fmt_sort(display, sort) { | 
					
						
							|  |  |  |     var prefix = ''; | 
					
						
							|  |  |  |     if (current_sort == sort) { | 
					
						
							|  |  |  |         prefix = '<span class="arrow">' + | 
					
						
							| 
									
										
										
										
											2018-02-07 06:20:30 +08:00
										 |  |  |             (current_sort_reverse ? '▽ ' : '△ ') + | 
					
						
							| 
									
										
										
										
											2010-10-12 00:05:06 +08:00
										 |  |  |             '</span>'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return '<a class="sort" sort="' + sort + '">' + prefix + display + '</a>'; | 
					
						
							| 
									
										
										
										
											2011-02-17 00:00:12 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-03-30 20:14:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-27 01:09:25 +08:00
										 |  |  | function group_count(mode, group, bools) { | 
					
						
							| 
									
										
										
										
											2014-09-19 22:44:43 +08:00
										 |  |  |     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++; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-09-27 01:09:25 +08:00
										 |  |  |     return count; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-09-19 22:44:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-27 01:09:25 +08:00
										 |  |  | function group_heading(mode, group, bools) { | 
					
						
							|  |  |  |     var count = group_count(mode, group, bools); | 
					
						
							| 
									
										
										
										
											2014-09-19 22:44:43 +08:00
										 |  |  |     if (count == 0) { | 
					
						
							|  |  |  |         return ''; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |         return '<th colspan="' + count + '">' + group + '</th>'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-01 00:17:05 +08:00
										 |  |  | function fmt_permissions(obj, permissions, lookup, show, warning) { | 
					
						
							|  |  |  |     var res = []; | 
					
						
							|  |  |  |     for (var i in permissions) { | 
					
						
							|  |  |  |         var permission = permissions[i]; | 
					
						
							|  |  |  |         if (permission[lookup] == obj.name) { | 
					
						
							| 
									
										
										
										
											2015-01-05 21:39:09 +08:00
										 |  |  |             res.push(fmt_escape_html(permission[show])); | 
					
						
							| 
									
										
										
										
											2011-04-01 00:17:05 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return res.length == 0 ? warning : res.join(', '); | 
					
						
							| 
									
										
										
										
											2011-04-09 00:00:05 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-28 22:34:15 +08:00
										 |  |  | var radio_id = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function fmt_radio(name, text, value, current) { | 
					
						
							|  |  |  |     radio_id++; | 
					
						
							|  |  |  |     return '<label class="radio" for="radio-' + radio_id + '">' + | 
					
						
							| 
									
										
										
										
											2014-09-19 22:19:43 +08:00
										 |  |  |         '<input type="radio" id="radio-' + radio_id + '" name="' + name + | 
					
						
							| 
									
										
										
										
											2013-01-28 22:34:15 +08:00
										 |  |  |         '" value="' + value + '"' + | 
					
						
							|  |  |  |         ((value == current) ? ' checked="checked"' : '') + | 
					
						
							|  |  |  |         '>' + text + '</label>'; | 
					
						
							| 
									
										
										
										
											2012-11-16 21:27:31 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-19 22:19:43 +08:00
										 |  |  | 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>'; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-30 20:14:24 +08:00
										 |  |  | function properties_size(obj) { | 
					
						
							|  |  |  |     var count = 0; | 
					
						
							|  |  |  |     for (k in obj) { | 
					
						
							|  |  |  |         if (obj.hasOwnProperty(k)) count++; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return count; | 
					
						
							| 
									
										
										
										
											2017-03-28 19:40:08 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-11-13 05:25:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-03 04:55:44 +08:00
										 |  |  | function stored_value_or_default(template, defaultValue){ | 
					
						
							| 
									
										
										
										
											2019-01-03 05:08:26 +08:00
										 |  |  |     var stored_value = get_pref(template); | 
					
						
							|  |  |  |     var result = (((stored_value == null) | 
					
						
							|  |  |  |       || (stored_value == undefined) | 
					
						
							|  |  |  |       || (stored_value == '')) ? defaultValue : | 
					
						
							|  |  |  |     stored_value); | 
					
						
							| 
									
										
										
										
											2015-11-13 05:25:01 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |    return ((result == undefined) ? defaultValue : result); | 
					
						
							| 
									
										
										
										
											2011-04-09 00:00:05 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-10-15 18:44:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-22 18:46:52 +08:00
										 |  |  | function fmt_page_number_request(template, defaultPage){ | 
					
						
							| 
									
										
										
										
											2017-03-28 19:40:08 +08:00
										 |  |  |      if  ((defaultPage == undefined) || (defaultPage <= 0)) | 
					
						
							| 
									
										
										
										
											2015-10-22 18:46:52 +08:00
										 |  |  |          defaultPage = 1; | 
					
						
							| 
									
										
										
										
											2019-01-03 04:55:44 +08:00
										 |  |  |     return stored_value_or_default(template + '_current_page_number', defaultPage); | 
					
						
							| 
									
										
										
										
											2015-10-15 18:44:36 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-10-22 18:46:52 +08:00
										 |  |  | function fmt_page_size_request(template, defaultPageSize){ | 
					
						
							|  |  |  |     if  ((defaultPageSize == undefined) || (defaultPageSize < 0)) | 
					
						
							| 
									
										
										
										
											2015-10-15 18:44:36 +08:00
										 |  |  |         defaultPageSize = 100; | 
					
						
							| 
									
										
										
										
											2019-01-03 04:55:44 +08:00
										 |  |  |     result = stored_value_or_default(template + '_current_page_size', defaultPageSize); | 
					
						
							| 
									
										
										
										
											2015-10-22 18:46:52 +08:00
										 |  |  |     if (result > 500) result = 500; // max
 | 
					
						
							| 
									
										
										
										
											2015-10-15 18:44:36 +08:00
										 |  |  |     return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-13 05:25:01 +08:00
										 |  |  | function fmt_filter_name_request(template, defaultName){ | 
					
						
							| 
									
										
										
										
											2019-01-03 05:50:44 +08:00
										 |  |  |     return fmt_escape_html(stored_value_or_default(template + '_current_filter_name', defaultName)); | 
					
						
							| 
									
										
										
										
											2015-11-13 05:25:01 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-17 23:59:49 +08:00
										 |  |  | function fmt_regex_request(template, defaultName){ | 
					
						
							| 
									
										
										
										
											2019-01-03 05:50:44 +08:00
										 |  |  |     return fmt_escape_html(stored_value_or_default(template + '_current_regex', defaultName)); | 
					
						
							| 
									
										
										
										
											2015-11-17 23:59:49 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-11-13 05:25:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-01 21:58:41 +08:00
										 |  |  | function fmt_vhost_state(vhost){ | 
					
						
							|  |  |  |     var cluster_state = vhost.cluster_state; | 
					
						
							|  |  |  |     var down_nodes = []; | 
					
						
							|  |  |  |     var ok_count = 0; | 
					
						
							|  |  |  |     var non_ok_count = 0; | 
					
						
							|  |  |  |     for(var node in cluster_state){ | 
					
						
							|  |  |  |         var node_state = cluster_state[node]; | 
					
						
							| 
									
										
										
										
											2017-08-02 22:39:48 +08:00
										 |  |  |         if(cluster_state[node] == "stopped" || cluster_state[node] == "nodedown"){ | 
					
						
							| 
									
										
										
										
											2017-08-01 21:58:41 +08:00
										 |  |  |             non_ok_count++; | 
					
						
							|  |  |  |             down_nodes.push(node); | 
					
						
							|  |  |  |         } else if(cluster_state[node] == "running"){ | 
					
						
							|  |  |  |             ok_count++; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if(non_ok_count == 0 ){ | 
					
						
							|  |  |  |         return fmt_state('green', 'running', ''); | 
					
						
							|  |  |  |     } else if(non_ok_count > 0 && ok_count == 0){ | 
					
						
							| 
									
										
										
										
											2017-08-02 22:39:48 +08:00
										 |  |  |         return fmt_state('red', 'stopped', 'Vhost supervisor is not running.'); | 
					
						
							| 
									
										
										
										
											2017-08-01 21:58:41 +08:00
										 |  |  |     } else if(non_ok_count > 0 && ok_count > 0){ | 
					
						
							| 
									
										
										
										
											2017-08-02 22:39:48 +08:00
										 |  |  |         return fmt_state('yellow', 'partial', 'Vhost supervisor is stopped on some cluster nodes: ' + down_nodes.join(', ')); | 
					
						
							| 
									
										
										
										
											2017-08-01 21:58:41 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-15 18:44:36 +08:00
										 |  |  | function isNumberKey(evt){ | 
					
						
							|  |  |  |     var charCode = (evt.which) ? evt.which : event.keyCode | 
					
						
							|  |  |  |     if (charCode > 31 && (charCode < 48 || charCode > 57)) | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  | } |