luci-app-olsrd2: New Package for OLSR2 configuration and status visualisation'
[feed/routing.git] / luci-app-olsrd2 / htdocs / luci-static / resources / view / olsrd2 / neighbors.js
diff --git a/luci-app-olsrd2/htdocs/luci-static/resources/view/olsrd2/neighbors.js b/luci-app-olsrd2/htdocs/luci-static/resources/view/olsrd2/neighbors.js
new file mode 100644 (file)
index 0000000..e38af4a
--- /dev/null
@@ -0,0 +1,58 @@
+'use strict';
+'require view';
+'require ui';
+'require rpc';
+'require poll';
+
+var callgetData = rpc.declare({
+       object: 'status.olsrd2',
+       method: 'getNeighbors'
+});
+
+function createTable(data) {
+    let tableData = [];
+    data.neighbors.forEach(row => {
+               let hostname = E('a',{ 'href': 'https://' + row.hostname + '/cgi-bin-olsrd2-neigh.html'},row.hostname);
+               let orginator = E('a',{ 'href': 'https://[' + row.originator + ']/cgi-bin-olsrd2-neigh.html'},row.originator);
+        tableData.push([
+            hostname,
+            orginator,
+            row.lladdr,
+            row.interface,
+            row.metric_in,
+            row.metric_in_raw
+        ])
+    });
+    return tableData;
+};
+
+return view.extend({
+       title: _('OLSRD2 mesh neighbors'),
+       handleSaveApply: null,
+       handleSave: null,
+       handleReset: null,
+
+
+       render: function(data) {
+
+               var tr = E('table', { 'class': 'table' });
+               tr.appendChild(E('tr', { 'class': 'tr cbi-section-table-titles' }, [
+                       E('th', { 'class': 'th left' }, [ 'Hostname' ]),
+                       E('th', { 'class': 'th left' }, [ 'Orginator' ]),
+                       E('th', { 'class': 'th left' }, [ 'MAC' ]),
+                       E('th', { 'class': 'th left' }, [ 'Interface' ]),
+                       E('th', { 'class': 'th left' }, [ 'Metric' ]),
+                       E('th', { 'class': 'th left' }, [ 'raw' ])
+               ]));
+        poll.add(() => {
+            Promise.all([
+                               callgetData()
+            ]).then((results) => {
+                cbi_update_table(tr, createTable(results[0]));
+            })
+        }, 30);
+        return tr
+
+       }
+
+});