github.com/nsqio/nsq@v1.3.0/nsqadmin/static/js/models/channel.js (about)

     1  var _ = require('underscore');
     2  
     3  var AppState = require('../app_state');
     4  var Backbone = require('backbone');
     5  
     6  var Channel = Backbone.Model.extend({
     7      idAttribute: 'name',
     8  
     9      constructor: function Channel() {
    10          Backbone.Model.prototype.constructor.apply(this, arguments);
    11      },
    12  
    13      url: function() {
    14          return AppState.apiPath('/topics/' +
    15              encodeURIComponent(this.get('topic')) + '/' +
    16              encodeURIComponent(this.get('name')));
    17      },
    18  
    19      parse: function(response) {
    20          response['nodes'] = _.map(response['nodes'] || [], function(node) {
    21              var nodeParts = node['node'].split(':');
    22              var port = nodeParts.pop();
    23              var address = nodeParts.join(':');
    24              var hostname = node['hostname'];
    25              node['show_broadcast_address'] = hostname.toLowerCase() !== address.toLowerCase();
    26              node['hostname_port'] = hostname + ':' + port;
    27              return node;
    28          });
    29  
    30          response['clients'] = _.map(response['clients'] || [], function(client) {
    31              var clientId = client['client_id'];
    32              var hostname = client['hostname'];
    33              var shortHostname = hostname.split('.')[0];
    34  
    35              // ignore client_id if it's duplicative
    36              client['show_client_id'] = (clientId.toLowerCase() !== shortHostname.toLowerCase()
    37                                          && clientId.toLowerCase() !== hostname.toLowerCase());
    38  
    39              var port = client['remote_address'].split(':').pop();
    40              client['hostname_port'] = hostname + ':' + port;
    41  
    42              return client;
    43          });
    44  
    45          return response;
    46      }
    47  });
    48  
    49  module.exports = Channel;