summaryrefslogtreecommitdiffstats
path: root/applications/luci-app-mwan3/htdocs/luci-static/resources/view/status/include/90_mwan3.js
blob: 12cc24b2f69a0e1e23239bb40518468b58d15d13 (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
'use strict';
'require baseclass';
'require rpc';

const callMwan3Status = rpc.declare({
	object: 'mwan3',
	method: 'status',
	params: ['section'],
	expect: {  },
});

document.querySelector('head').appendChild(E('link', {
	'rel': 'stylesheet',
	'type': 'text/css',
	'href': L.resource('view/mwan3/mwan3.css')
}));

return baseclass.extend({
	title: _('MultiWAN Manager'),

	load: function() {
		return Promise.all([
			callMwan3Status("interfaces"),
		]);
	},

	render: function (result) {
		if (!result[0].interfaces)
			return null;

		var container = E('div', { 'id': 'mwan3-service-status' });
		var iface;
		for ( iface in result[0].interfaces) {
			var state = '';
			var css = '';
			var time = '';
			var tname = '';
			switch (result[0].interfaces[iface].status) {
				case 'online':
					state = _('Online');
					css = 'alert-message success';
					time = '%t'.format(result[0].interfaces[iface].online);
					tname = _('Uptime');
					break;
				case 'offline':
					state = _('Offline');
					css = 'alert-message danger';
					time = '%t'.format(result[0].interfaces[iface].offline);
					tname = _('Downtime');
					break;
				case 'notracking':
					state = _('No Tracking');
					if ((result[0].interfaces[iface].uptime) > 0) {
						css = 'alert-message success';
						time = '%t'.format(result[0].interfaces[iface].uptime);
						tname = _('Uptime');
					}
					else {
						css = 'alert-message warning';
						time = '';
						tname = '';
					}
					break;
				default:
					css = 'alert-message warning';
					state = _('Disabled');
					time = '';
					tname = '';
					break;
			}

			if (time !== '' ) {
				container.appendChild(
					E('div', { 'class': css }, [
						E('div', {}, [
							E('strong', {}, [
								_('Interface'), ':', ' '
							]),
							iface
						]),
						E('div', {}, [
							E('strong', {}, [
								_('Status'), ':', ' '
							]),
							state
						]),
						E('div', {}, [
							E('strong', {}, [
								tname, ':', ' '
							]),
							time
						])
					])
				);
			}
			else {
				container.appendChild(
					E('div', { 'class': css }, [
						E('div', {}, [
							E('strong', {}, [
								_('Interface'), ':', ' '
							]),
							iface
						]),
						E('div', {}, [
							E('strong', {}, [
								_('Status'), ':', ' '
							]),
							state
						])
					])
				);
			}
		}

		return container;
	}
});