nodes.js 904 B

12345678910111213141516171819202122232425262728293031323334
  1. var Backbone = require('backbone');
  2. var AppState = require('../app_state');
  3. var Node = require('../models/node'); //eslint-disable-line no-undef
  4. var Nodes = Backbone.Collection.extend({
  5. model: Node,
  6. comparator: 'id',
  7. constructor: function Nodes() {
  8. Backbone.Collection.prototype.constructor.apply(this, arguments);
  9. },
  10. url: function() {
  11. return AppState.apiPath('/nodes');
  12. },
  13. parse: function(resp) {
  14. resp['nodes'].forEach(function(n) {
  15. var jaddr = n['broadcast_address'];
  16. if (jaddr.includes(':')) {
  17. // ipv6 raw address contains ':'
  18. // it must be wrapped in '[ ]' when joined with port
  19. jaddr = '[' + jaddr + ']';
  20. }
  21. n['broadcast_address_http'] = jaddr + ':' + n['http_port'];
  22. });
  23. return resp['nodes'];
  24. }
  25. });
  26. module.exports = Nodes;