diff options
author | Ayushman Tripathi <ayushmantripathi7724@gmail.com> | 2023-07-25 17:13:26 +0530 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2023-09-26 09:30:05 +0200 |
commit | 0c3f396b2fbbe691713b6fe598ff41f8235ca20d (patch) | |
tree | dd283ec8b6d35691a46c23b04858a11aec52c331 /applications/luci-app-babeld/htdocs/luci-static/resources/view/babeld/babeld-view.js | |
parent | 08fbceecd9b7c98e79cb32b886a37c67c4bc63d7 (diff) |
luci-app-babeld: migrate to js
Signed-off-by: Ayushman Tripathi <ayushmantripathi7724@gmail.com>
[fixup commit message, resolve merge conflict]
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'applications/luci-app-babeld/htdocs/luci-static/resources/view/babeld/babeld-view.js')
-rw-r--r-- | applications/luci-app-babeld/htdocs/luci-static/resources/view/babeld/babeld-view.js | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/applications/luci-app-babeld/htdocs/luci-static/resources/view/babeld/babeld-view.js b/applications/luci-app-babeld/htdocs/luci-static/resources/view/babeld/babeld-view.js new file mode 100644 index 0000000000..1714866d0f --- /dev/null +++ b/applications/luci-app-babeld/htdocs/luci-static/resources/view/babeld/babeld-view.js @@ -0,0 +1,95 @@ +'use strict'; +'require uci'; +'require view'; +'require poll'; +'require ui'; +'require rpc'; + +return view.extend({ + callGetInfo: rpc.declare({ + object: 'babeld', + method: 'get_info' + }), + callGetXroutes: rpc.declare({ + object: 'babeld', + method: 'get_xroutes' + }), + callGetRoutes: rpc.declare({ + object: 'babeld', + method: 'get_routes' + }), + callGetNeighbours: rpc.declare({ + object: 'babeld', + method: 'get_neighbours' + }), + + fetch_babeld: function () { + var data; + var self = this; + return new Promise(function (resolve, reject) { + Promise.all([self.callGetInfo(), self.callGetXroutes(), self.callGetRoutes(), self.callGetNeighbours()]) + .then(function (res) { + data = res; + resolve([data]); + }) + .catch(function (err) { + console.error(err); + reject([null]); + }); + }); + }, + + action_babeld: function () { + var self = this; + return new Promise(function (resolve, reject) { + self + .fetch_babeld() + .then(function ([data]) { + var info = data[0]; + var xroutes = data[1]; + var routes = data[2]; + var neighbours = data[3]; + var result = { info, xroutes, routes, neighbours }; + resolve(result); + }) + .catch(function (err) { + reject(err); + }); + }); + }, + + load: function () { + var self = this; + return new Promise(function (resolve, reject) { + var script = E('script', { 'type': 'text/javascript' }); + script.onload = resolve; + script.onerror = reject; + script.src = L.resource('babeld.js'); + document.querySelector('head').appendChild(script); + }); + }, + render: function () { + var self = this; + return this.action_babeld() + .then(function (result) { + + var mainDiv = E('div', { + 'id': 'babeld' + }, []); + + renderTableInfo(result.info, mainDiv); + renderTableXRoutes(result.xroutes, mainDiv); + renderTableRoutes(result.routes, mainDiv); + renderTableNeighbours(result.neighbours, mainDiv); + + var result = E([], {}, mainDiv); + return result; + }) + .catch(function (error) { + console.error(error); + }); + }, + handleSaveApply: null, + handleSave: null, + handleReset: null, +}); |