babeld-view.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. 'use strict';
  2. 'require uci';
  3. 'require view';
  4. 'require poll';
  5. 'require ui';
  6. 'require rpc';
  7. return view.extend({
  8. callGetInfo: rpc.declare({
  9. object: 'babeld',
  10. method: 'get_info'
  11. }),
  12. callGetXroutes: rpc.declare({
  13. object: 'babeld',
  14. method: 'get_xroutes'
  15. }),
  16. callGetRoutes: rpc.declare({
  17. object: 'babeld',
  18. method: 'get_routes'
  19. }),
  20. callGetNeighbours: rpc.declare({
  21. object: 'babeld',
  22. method: 'get_neighbours'
  23. }),
  24. fetch_babeld: function () {
  25. var data;
  26. var self = this;
  27. return new Promise(function (resolve, reject) {
  28. Promise.all([self.callGetInfo(), self.callGetXroutes(), self.callGetRoutes(), self.callGetNeighbours()])
  29. .then(function (res) {
  30. data = res;
  31. resolve([data]);
  32. })
  33. .catch(function (err) {
  34. console.error(err);
  35. reject([null]);
  36. });
  37. });
  38. },
  39. action_babeld: function () {
  40. var self = this;
  41. return new Promise(function (resolve, reject) {
  42. self
  43. .fetch_babeld()
  44. .then(function ([data]) {
  45. var info = data[0];
  46. var xroutes = data[1];
  47. var routes = data[2];
  48. var neighbours = data[3];
  49. var result = { info, xroutes, routes, neighbours };
  50. resolve(result);
  51. })
  52. .catch(function (err) {
  53. reject(err);
  54. });
  55. });
  56. },
  57. load: function () {
  58. var self = this;
  59. return new Promise(function (resolve, reject) {
  60. var script = E('script', { 'type': 'text/javascript' });
  61. script.onload = resolve;
  62. script.onerror = reject;
  63. script.src = L.resource('babeld.js');
  64. document.querySelector('head').appendChild(script);
  65. });
  66. },
  67. render: function () {
  68. var self = this;
  69. return this.action_babeld()
  70. .then(function (result) {
  71. var mainDiv = E('div', {
  72. 'id': 'babeld'
  73. }, []);
  74. renderTableInfo(result.info, mainDiv);
  75. renderTableXRoutes(result.xroutes, mainDiv);
  76. renderTableRoutes(result.routes, mainDiv);
  77. renderTableNeighbours(result.neighbours, mainDiv);
  78. var result = E([], {}, mainDiv);
  79. return result;
  80. })
  81. .catch(function (error) {
  82. console.error(error);
  83. });
  84. },
  85. handleSaveApply: null,
  86. handleSave: null,
  87. handleReset: null,
  88. });