summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-babeld/htdocs/luci-static/resources/view/babeld/babeld-view.js
blob: 1714866d0f84d08e2dccae05de0b716f6b79d1f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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,
});