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 ) {
if ( unknown == undefined ) unkown = 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
}
function fmt _bytes ( bytes ) {
2010-07-23 20:43:35 +08:00
if ( bytes == undefined ) return UNKNOWN _REPR ;
2010-07-22 23:29:19 +08:00
function f ( n , p ) {
if ( n > 1024 ) return f ( n / 1024 , p + 1 ) ;
else return [ n , p ] ;
}
2010-09-01 00:56:33 +08:00
var num _power = f ( bytes , 0 ) ;
var num = num _power [ 0 ] ;
var power = num _power [ 1 ] ;
2012-03-23 23:17:25 +08:00
var powers = [ 'B' , 'kB' , 'MB' , 'GB' , 'TB' , 'PB' , 'EB' , 'ZB' , 'YB' ] ;
2010-07-22 23:29:19 +08:00
return ( power == 0 ? num . toFixed ( 0 ) : num . toFixed ( 1 ) ) + powers [ power ] ;
}
2012-09-19 06:47:42 +08:00
function fmt _memory ( memory , key ) {
return '<div class="memory-key memory_' + key + '"></div>' +
fmt _bytes ( memory [ key ] ) ;
}
2010-07-22 23:29:19 +08:00
function fmt _boolean ( b ) {
2010-07-23 20:43:35 +08:00
if ( b == undefined ) return UNKNOWN _REPR ;
2010-07-22 23:29:19 +08:00
return b ? "●" : "○" ;
}
2011-01-14 19:45:45 +08:00
function fmt _date ( d ) {
function f ( i ) {
return i < 10 ? "0" + i : i ;
}
2011-05-04 00:38:53 +08:00
return d . getFullYear ( ) + "-" + f ( d . getMonth ( ) + 1 ) + "-" +
2012-01-14 01:41:39 +08:00
f ( d . getDate ( ) ) + " " + f ( d . getHours ( ) ) + ":" + f ( d . getMinutes ( ) ) +
2011-05-04 00:38:53 +08:00
":" + f ( d . getSeconds ( ) ) ;
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
}
2010-10-29 20:01:22 +08:00
function fmt _parameters ( obj ) {
2011-05-25 19:58:06 +08:00
return fmt _table _short ( args _to _params ( obj ) ) ;
}
function fmt _parameters _short ( obj ) {
2010-10-29 20:01:22 +08:00
var res = '' ;
2011-05-25 19:58:06 +08:00
var params = args _to _params ( obj ) ;
for ( var k in ALL _ARGS ) {
if ( params [ k ] != undefined ) {
2011-11-30 21:43:42 +08:00
res += '<acronym title="' + k + ': ' + fmt _string ( params [ k ] ) +
'">' + ALL _ARGS [ k ] . short + '</acronym> ' ;
2011-05-25 19:58:06 +08:00
}
}
if ( params . arguments ) {
res += '<acronym title="' + fmt _table _flat ( params . arguments ) +
'">Args</acronym>' ;
}
return res ;
}
function args _to _params ( obj ) {
var res = { } ;
for ( var k in obj . arguments ) {
if ( k in KNOWN _ARGS ) {
res [ k ] = obj . arguments [ k ] ;
}
else {
if ( res . arguments == undefined ) res . arguments = { } ;
res . arguments [ k ] = obj . arguments [ k ] ;
}
}
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
}
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 ) {
return jQuery . inArray ( node , synced ) == - 1
} ) ;
var res = '' ;
2011-08-16 20:24:17 +08:00
if ( synced . length > 0 ) {
res += ' <acronym title="Synchronised mirrors: ' + synced + '">+' +
2011-07-15 22:52:29 +08:00
synced . length + '</acronym>' ;
}
2011-08-16 20:24:17 +08:00
if ( synced . length == 0 && unsynced . length > 0 ) {
res += ' <acronym title="There are no synchronised mirrors">+0</acronym>' ;
}
2011-07-15 22:52:29 +08:00
if ( unsynced . length > 0 ) {
res += ' <acronym class="warning" title="Unsynchronised mirrors: ' +
unsynced + '">+' + unsynced . length + '</acronym>' ;
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
}
2011-01-21 21:17:41 +08:00
function fmt _channel _mode ( ch ) {
if ( ch . transactional ) {
return '<acronym title="Transactional">T</acronym>' ;
}
else if ( ch . confirm ) {
return '<acronym title="Confirm">C</acronym>' ;
}
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
}
2011-02-28 19:19:36 +08:00
function fmt _rate ( obj , name , show _total , cssClass ) {
2012-01-05 01:16:20 +08:00
var res = fmt _rate0 ( obj , name , fmt _rate _num , show _total ) ;
2011-02-28 19:19:36 +08:00
if ( cssClass == undefined || res == '' ) {
return res ;
}
else {
return '<span class="' + cssClass + '">' + res + '</span>' ;
}
2010-09-02 19:58:34 +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 ) ;
else return num . toFixed ( 0 ) ;
2012-01-05 01:16:20 +08:00
}
2010-09-02 19:58:34 +08:00
function fmt _rate _bytes ( obj , name ) {
2010-10-29 20:01:22 +08:00
return fmt _rate0 ( obj , name , fmt _bytes , true ) ;
2010-09-02 19:58:34 +08:00
}
2010-07-28 01:04:48 +08:00
2010-10-29 20:01:22 +08:00
function fmt _rate0 ( obj , name , fmt , show _total ) {
2010-09-02 19:58:34 +08:00
if ( obj == undefined || obj [ name ] == undefined ) return '' ;
2010-10-29 20:01:22 +08:00
var res = '' ;
2010-09-02 19:58:34 +08:00
if ( obj [ name + '_details' ] != undefined ) {
2010-10-29 20:01:22 +08:00
res = fmt ( obj [ name + '_details' ] . rate ) + '/s' ;
}
if ( show _total ) {
res += '<sub>(' + fmt ( obj [ name ] ) + ' total)</sub>' ;
2010-09-02 19:58:34 +08:00
}
return res ;
2010-07-28 01:04:48 +08:00
}
2011-07-06 19:03:23 +08:00
function fmt _deliver _rate ( obj , show _redeliver , cssClass ) {
var res = fmt _rate ( obj , 'deliver_get' , false , cssClass ) ;
if ( show _redeliver ) {
res += '<sub>' + fmt _rate ( obj , 'redeliver' ) + '</sub>' ;
}
return res ;
}
2011-02-26 01:32:04 +08:00
function is _stat _empty ( obj , name ) {
2011-02-17 23:23:08 +08:00
if ( obj == undefined
2011-02-18 18:38:41 +08:00
|| obj [ name ] == undefined
|| obj [ name + '_details' ] == undefined
|| obj [ name + '_details' ] . rate < 0.00001 ) return true ;
2011-02-17 23:23:08 +08:00
return false ;
}
2011-07-05 20:19:06 +08:00
function is _col _empty ( objects , name , accessor ) {
if ( accessor == undefined ) accessor = function ( o ) { return o . message _stats ; } ;
for ( var i = 0 ; i < objects . length ; i ++ ) {
var object = objects [ i ] ;
if ( ! is _stat _empty ( accessor ( object ) , name ) ) {
2011-02-26 01:32:04 +08:00
return false ;
}
}
return true ;
}
2010-08-27 00:42:03 +08:00
function fmt _exchange ( name ) {
2011-11-30 21:43:42 +08:00
return name == '' ? '(AMQP default)' : fmt _escape _html ( 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 ) ;
}
}
return '<div class="red"><acronym title="Exchange type not found. ' +
'Publishing to this exchange will fail.">' + fmt _escape _html ( type ) +
'</acronym></div>' ;
}
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
}
2012-03-13 20:16:27 +08:00
function fmt _fd _used ( used ) {
if ( used == 'install_handle_from_sysinternals' ) {
return '<a href="http://technet.microsoft.com/en-us/sysinternals/bb896655" title="Install handle.exe from sysinternals to see used file descriptors - click for the download page.">?</a>' ;
}
else {
return used ;
}
}
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 ) {
2011-02-12 02:04:05 +08:00
res += '<tr><th>' + 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' ) {
return '<acronym class="type" title="string">' +
fmt _escape _html ( val ) + '</acronym>' ;
} else {
return '<acronym class="type" title="' + t + '">' + val + '</acronym>' ;
}
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 ) {
res . push ( k + ': ' + fmt _amqp _value _flat ( table [ k ] ) ) ;
}
return res . join ( ', ' ) ;
}
function fmt _amqp _value _flat ( val ) {
if ( val instanceof Array ) {
var val2 = new Array ( ) ;
for ( var i = 0 ; i < val . length ; i ++ ) {
val2 [ i ] = fmt _amqp _value _flat ( val [ i ] ) ;
}
return '[' + val2 . join ( "," ) + ']' ;
} else if ( val instanceof Object ) {
return '(' + fmt _table _flat ( val ) + ')' ;
} else if ( typeof ( val ) == 'string' ) {
return fmt _escape _html ( val ) ;
} else {
return val ;
}
}
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' ;
}
2010-11-16 23:41:17 +08:00
function fmt _idle ( obj ) {
if ( obj . idle _since == undefined ) {
return 'Active' ;
} else {
return '<acronym title="Idle since ' + obj . idle _since +
'">Idle</acronym>' ;
}
}
function fmt _idle _long ( obj ) {
if ( obj . idle _since == undefined ) {
return 'Active' ;
} else {
return 'Idle since<br/>' + obj . idle _since ;
}
}
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 ) {
2012-01-23 23:34:25 +08:00
return txt . replace ( /&/g , '&' )
. 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
}
2011-06-14 00:36:26 +08:00
function fmt _node _host ( node _host ) {
var both = node _host . split ( '@' ) ;
var node = both . slice ( 0 , 1 ) ;
var host = both . slice ( 1 ) ;
2011-06-14 00:45:02 +08:00
return host + ' <small>(' + node _host + ')</small>' ;
2011-06-14 00:36:26 +08:00
}
2012-01-13 23:10:30 +08:00
function fmt _connection _state ( conn ) {
2012-01-18 20:18:24 +08:00
if ( conn . state == undefined ) return '' ;
2012-01-13 23:10:30 +08:00
var colour = 'green' ;
var text = conn . state ;
var explanation ;
2012-09-24 19:44:21 +08:00
if ( conn . last _blocked _by == 'resource' && conn . state == 'blocked' ) {
2012-01-13 23:10:30 +08:00
colour = 'red' ;
2012-09-24 19:44:21 +08:00
explanation = 'Resource alarm: Connection blocked.' ;
2012-01-13 23:10:30 +08:00
}
else if ( conn . state == 'blocking' ) {
colour = 'yellow' ;
2012-09-24 19:44:21 +08:00
explanation = 'Resource alarm: Connection will block on publish.' ;
2012-01-13 23:10:30 +08:00
}
else if ( conn . last _blocked _by == 'flow' ) {
var age = conn . last _blocked _age . toFixed ( ) ;
if ( age < 5 ) {
colour = 'yellow' ;
text = 'flow' ;
2012-01-14 00:15:04 +08:00
explanation = 'Publishing rate recently restricted by server.' ;
2012-01-13 23:10:30 +08:00
}
2012-01-13 03:03:36 +08:00
}
2012-01-13 23:10:30 +08:00
if ( explanation ) {
return '<div class="' + colour + '"><acronym title="' + explanation +
'">' + text + '</acronym></div>' ;
2012-01-13 03:03:36 +08:00
}
else {
2012-01-13 23:10:30 +08:00
return '<div class="' + colour + '">' + text + '</div>' ;
2012-01-13 03:03:36 +08:00
}
}
2012-04-24 01:43:28 +08:00
function fmt _shortened _uri ( uri0 ) {
var uri = fmt _escape _html ( uri0 ) ;
if ( uri . indexOf ( '?' ) == - 1 ) {
return uri ;
}
else {
return '<acronym title="' + uri + '">' +
uri . substr ( 0 , uri . indexOf ( '?' ) ) + '?...</acronym>' ;
}
}
2012-09-06 23:14:13 +08:00
function fmt _client _name ( properties ) {
var res = [ ] ;
if ( properties . product != undefined ) {
res . push ( properties . product ) ;
}
if ( properties . platform != undefined ) {
res . push ( properties . platform ) ;
}
res = res . join ( " / " ) ;
if ( properties . version != undefined ) {
res += '<sub>' + properties . version + '</sub>' ;
}
return res ;
}
2010-07-22 23:29:19 +08:00
function alt _rows ( i ) {
2010-11-09 18:55:04 +08:00
return ( i % 2 == 0 ) ? ' class="alt1"' : ' class="alt2"' ;
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
}
function link _conn ( name ) {
2012-01-28 00:44:54 +08:00
return _link _to ( fmt _escape _html ( name ) , '#/connections/' + esc ( name ) )
2010-08-25 19:24:34 +08:00
}
2010-09-03 00:06:59 +08:00
function link _channel ( name ) {
2012-01-28 00:44:54 +08:00
return _link _to ( fmt _escape _html ( name ) , '#/channels/' + esc ( name ) )
2010-09-03 00:06:59 +08:00
}
2010-08-27 00:42:03 +08:00
function link _exchange ( vhost , name ) {
var url = esc ( vhost ) + '/' + ( name == '' ? 'amq.default' : esc ( name ) ) ;
2012-01-25 20:51:16 +08:00
return _link _to ( fmt _exchange ( name ) , '#/exchanges/' + url )
2010-08-27 00:42:03 +08:00
}
2010-08-27 17:55:32 +08:00
function link _queue ( vhost , name ) {
2012-01-25 20:51:16 +08:00
return _link _to ( fmt _escape _html ( name ) , '#/queues/' + esc ( vhost ) + '/' + esc ( name ) )
2010-08-27 17:55:32 +08:00
}
2010-08-26 01:18:31 +08:00
function link _vhost ( name ) {
2012-01-25 20:51:16 +08:00
return _link _to ( fmt _escape _html ( name ) , '#/vhosts/' + esc ( name ) )
2010-08-26 01:18:31 +08:00
}
function link _user ( name ) {
2012-01-25 20:51:16 +08:00
return _link _to ( fmt _escape _html ( name ) , '#/users/' + esc ( name ) )
2010-08-26 01:18:31 +08:00
}
2010-11-03 01:19:14 +08:00
function link _node ( name ) {
2012-01-25 20:51:16 +08:00
return _link _to ( fmt _escape _html ( 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 ) {
return _link _to ( fmt _escape _html ( name ) , '#/policies/' + esc ( vhost ) + '/' + esc ( name ) )
2012-05-18 22:33:13 +08:00
}
2012-01-25 20:51:16 +08:00
function _link _to ( name , url ) {
return '<a href="' + url + '">' + name + '</a>' ;
2010-09-03 00:06:59 +08:00
}
function message _rates ( stats ) {
var res = "" ;
if ( keys ( stats ) . length > 0 ) {
2010-12-14 01:38:26 +08:00
var items = [ [ 'Publish' , 'publish' ] , [ 'Confirm' , 'confirm' ] ,
2011-07-06 19:08:59 +08:00
[ 'Deliver' , 'deliver' ] ,
2011-11-25 20:56:24 +08:00
[ 'Redelivered' , 'redeliver' ] ,
2011-07-06 19:08:59 +08:00
[ 'Acknowledge' , 'ack' ] ,
2010-12-14 01:38:26 +08:00
[ 'Get' , 'get' ] , [ 'Deliver (noack)' , 'deliver_no_ack' ] ,
2010-12-08 17:59:43 +08:00
[ 'Get (noack)' , 'get_no_ack' ] ,
2012-09-24 19:30:07 +08:00
[ 'Return' , 'return_unroutable' ] ] ;
2010-09-03 00:06:59 +08:00
for ( var i in items ) {
var name = items [ i ] [ 0 ] ;
var key = items [ i ] [ 1 ] + '_details' ;
if ( key in stats ) {
res += '<div class="highlight">' + name ;
2012-01-05 01:16:20 +08:00
res += '<strong>' + fmt _rate _num ( stats [ key ] . rate ) + '</strong>' ;
2010-09-03 00:06:59 +08:00
res += 'msg/s</div>' ;
}
}
2010-10-20 18:38:05 +08:00
if ( res == "" ) {
res = '<p>Waiting for message rates...</p>' ;
}
2010-09-03 00:06:59 +08:00
}
else {
res = '<p>Currently idle</p>' ;
}
return res ;
2010-09-29 21:45:40 +08:00
}
2011-11-25 20:48:58 +08:00
function queue _length ( stats , name , key ) {
2011-12-07 01:54:35 +08:00
var rateMsg = ' ' ;
var detail = stats [ key + '_details' ]
if ( detail != undefined ) {
2012-01-05 05:41:04 +08:00
var rate = detail . rate ;
if ( rate > 0 ) rateMsg = '+' + fmt _rate _num ( rate ) + ' msg/s' ;
else if ( rate < 0 ) rateMsg = '-' + fmt _rate _num ( - rate ) + ' msg/s' ;
2011-12-07 01:54:35 +08:00
}
2011-11-25 20:48:58 +08:00
return '<div class="highlight">' + name +
'<strong>' + stats [ key ] + '</strong>' + rateMsg + '</div>' ;
}
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">' +
( current _sort _reverse ? '▲ ' : '▼ ' ) +
'</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
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 ) {
res . push ( permission [ show ] ) ;
}
}
return res . length == 0 ? warning : res . join ( ', ' ) ;
2011-04-09 00:00:05 +08:00
}
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 ;
2011-04-09 00:00:05 +08:00
}