luci-app-babeld: lint fixes

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
This commit is contained in:
Paul Donald
2026-02-15 07:40:56 +01:00
parent 4de7515207
commit b62a318cc2
2 changed files with 182 additions and 182 deletions

View File

@@ -1,169 +0,0 @@
function renderTableXRoutes(ubus_data, target_div) {
var data = ubus_data;
for (var protocol in data) {
var target = target_div;
var title = document.createElement('h3');
title.appendChild(document.createTextNode('X-Routes ' + protocol));
target.appendChild(title);
var table = document.createElement('table');
table.setAttribute('class', 'table');
table.setAttribute('id', 'babel_overview_xroutes_' + protocol);
var headerRow = document.createElement('tr');
headerRow.setAttribute('class', 'tr table-titles');
var headerContent = '<th class="th" style="font-weight: 700;">' + '%h'.format(protocol) + ' Prefix</th>\
<th class="th" style="font-weight: 700;">Metric</th>\
<th class="th" style="font-weight: 700;">Source-Prefix</th>';
headerRow.innerHTML = headerContent;
table.appendChild(headerRow);
for (var prefix in data[protocol]) {
var prefixRow = document.createElement('tr');
prefixRow.setAttribute('class', 'tr');
var prefixContent = '<td class="td" data-title="xroutes_' + '%h'.format(protocol) + '_prefix">' + '%h'.format(data[protocol][prefix]["address"]) + '</td>\
<td class="td" data-title="xroutes_' + '%h'.format(protocol) + '_metric">' + '%d'.format(data[protocol][prefix]["metric"]) + '</td>\
<td class="td" data-title="xroutes_' + '%h'.format(protocol) + '_src_prefix">' + '%h'.format(data[protocol][prefix]["src_prefix"]) + '</td>';
prefixRow.innerHTML = prefixContent;
table.appendChild(prefixRow);
}
target.appendChild(table);
}
}
function renderTableRoutes(ubus_data, target_div) {
var data = ubus_data;
for (var protocol in data) {
var target = target_div;
var title = document.createElement('h3');
title.appendChild(document.createTextNode('Routes ' + protocol));
target.appendChild(title);
var table = document.createElement('table');
table.setAttribute('class', 'table');
table.setAttribute('id', 'babel_overview_routes_' + protocol);
var headerRow = document.createElement('tr');
headerRow.setAttribute('class', 'tr table-titles');
var headerContent = '<th class="th" style="font-weight: 700;">' + '%h'.format(protocol) + ' Prefix</th>\
<th class="th" style="font-weight: 700;">Source-Prefix</th>\
<th class="th" style="font-weight: 700;">Route-Metric</th>\
<th class="th" style="font-weight: 700;">Route Smoothed Metric</th>\
<th class="th" style="font-weight: 700;">Refmetric</th>\
<th class="th" style="font-weight: 700;">ID</th>\
<th class="th" style="font-weight: 700;">Seq. No.</th>\
<th class="th" style="font-weight: 700;">Age</th>\
<th class="th" style="font-weight: 700;">Via</th>\
<th class="th" style="font-weight: 700;">Nexthop</th>\
<th class="th" style="font-weight: 700;">Installed</th>\
<th class="th" style="font-weight: 700;">Feasible</th>';
headerRow.innerHTML = headerContent;
table.appendChild(headerRow);
for (var prefix in data[protocol]) {
var prefixRow = document.createElement('tr');
prefixRow.setAttribute('class', 'tr');
var prefixContent = '<td class="td" data-title="routes_' + '%h'.format(protocol) + '_prefix">' + '%h'.format(data[protocol][prefix]["address"]) + '</td>\
<td class="td" data-title="routes_' + '%h'.format(protocol) + '_src_prefix">' + '%h'.format(data[protocol][prefix]["src_prefix"]) + '</td>\
<td class="td" data-title="routes_' + '%h'.format(protocol) + '_metric">' + '%d'.format(data[protocol][prefix]["route_metric"]) + '</td>\
<td class="td" data-title="routes_' + '%h'.format(protocol) + '_rout_smoothed_metric">' + '%d'.format(data[protocol][prefix]["route_smoothed_metric"]) + '</td>\
<td class="td" data-title="routes_' + '%h'.format(protocol) + '_refmetric">' + '%d'.format(data[protocol][prefix]["refmetric"]) + '</td>\
<td class="td" data-title="routes_' + '%h'.format(protocol) + '_id">' + '%h'.format(data[protocol][prefix]["id"]) + '</td>\
<td class="td" data-title="routes_' + '%h'.format(protocol) + '_seqno">' + '%d'.format(data[protocol][prefix]["seqno"]) + '</td>\
<td class="td" data-title="routes_' + '%h'.format(protocol) + '_age">' + '%d'.format(data[protocol][prefix]["age"]) + '</td>\
<td class="td" data-title="routes_' + '%h'.format(protocol) + '_via">' + '%h'.format(data[protocol][prefix]["via"]) + '</td>\
<td class="td" data-title="routes_' + '%h'.format(protocol) + '_nexthop">' + '%h'.format(data[protocol][prefix]["nexthop"]) + '</td>\
<td class="td" data-title="routes_' + '%h'.format(protocol) + '_installed">' + '%b'.format(data[protocol][prefix]["installed"]) + '</td>\
<td class="td" data-title="routes_' + '%h'.format(protocol) + '_feasible">' + '%b'.format(data[protocol][prefix]["feasible"]) + '</td>';
prefixRow.innerHTML = prefixContent;
table.appendChild(prefixRow);
}
target.appendChild(table);
}
}
function renderTableNeighbours(ubus_data, target_div) {
var data = ubus_data;
for (var protocol in data) {
var target = target_div;
var title = document.createElement('h3');
title.appendChild(document.createTextNode('Neighbours ' + protocol));
target.appendChild(title);
var table = document.createElement('table');
table.setAttribute('class', 'table');
table.setAttribute('id', 'babel_overview_neighbours_' + protocol);
var headerRow = document.createElement('tr');
headerRow.setAttribute('class', 'tr table-titles');
var headerContent = '<th class="th" style="font-weight: 700;">' + '%h'.format(protocol) + ' Neighbour</th>\
<th class="th" style="font-weight: 700;">Device</th>\
<th class="th" style="font-weight: 700;">Multicast Hellos</th>\
<th class="th" style="font-weight: 700;">Unicast Hellos</th>\
<th class="th" style="font-weight: 700;">RX cost</th>\
<th class="th" style="font-weight: 700;">TX cost</th>\
<th class="th" style="font-weight: 700;">RTT</th>\
<th class="th" style="font-weight: 700;">Interface up</th>';
headerRow.innerHTML = headerContent;
table.appendChild(headerRow);
for (var neighbour in data[protocol]) {
var neighbourRow = document.createElement('tr');
neighbourRow.setAttribute('class', 'tr');
var neighbourContent = '<td class="td" data-title="neighbours_' + '%h'.format(protocol) + '_neighbour">' + '%h'.format(data[protocol][neighbour]["address"]) + '</td>\
<td class="td" data-title="neighbours_' + '%h'.format(protocol) + '_dev">' + '%h'.format(data[protocol][neighbour]["dev"]) + '</td>\
<td class="td" data-title="neighbours_' + '%h'.format(protocol) + '_hello_reach">' + '%d'.format(data[protocol][neighbour]["hello_reach"]) + '</td>\
<td class="td" data-title="neighbours_' + '%h'.format(protocol) + '_uhello_reach">' + '%d'.format(data[protocol][neighbour]["uhello_reach"]) + '</td>\
<td class="td" data-title="neighbours_' + '%h'.format(protocol) + '_rxcost">' + '%d'.format(data[protocol][neighbour]["rxcost"]) + '</td>\
<td class="td" data-title="neighbours_' + '%h'.format(protocol) + '_txcost">' + '%d'.format(data[protocol][neighbour]["txcost"]) + '</td>\
<td class="td" data-title="neighbours_' + '%h'.format(protocol) + '_rtt">' + '%d'.format(data[protocol][neighbour]["rtt"]) + '</td>\
<td class="td" data-title="neighbours_' + '%h'.format(protocol) + '_if_up">' + '%b'.format(data[protocol][neighbour]["if_up"]) + '</td>';
neighbourRow.innerHTML = neighbourContent;
table.appendChild(neighbourRow);
}
target.appendChild(table);
}
}
function renderTableInfo(ubus_data, target_div) {
var data = ubus_data;
var target = target_div;
var title = document.createElement('h3');
title.appendChild(document.createTextNode('Info'));
target.appendChild(title);
var table = document.createElement('table');
table.setAttribute('class', 'table');
table.setAttribute('id', 'babel_overview_info');
var headerRow = document.createElement('tr');
headerRow.setAttribute('class', 'tr table-titles');
var headerContent = '<th class="th" style="font-weight: 700;">Babeld Version</th>\
<th class="th" style="font-weight: 700;">My-ID</th>\
<th class="th" style="font-weight: 700;">Host</th>';
headerRow.innerHTML = headerContent;
table.appendChild(headerRow);
var neighbourRow = document.createElement('tr');
neighbourRow.setAttribute('class', 'tr');
var neighbourContent = '<td class="td" data-title="info_babeld_version">' + '%h'.format(data["babeld_version"]) + '</td>\
<td class="td" data-title="info_dev">' + '%h'.format(data["my_id"]) + '</td>\
<td class="td" data-title="info_host">' + '%h'.format(data["host"]) + '</td>';
neighbourRow.innerHTML = neighbourContent;
table.appendChild(neighbourRow);
target.appendChild(table);
}

View File

@@ -5,6 +5,177 @@
'require ui';
'require rpc';
function renderTableXRoutes(ubus_data, target_div) {
const data = ubus_data;
for (let protocol in data) {
const target = target_div;
const title = document.createElement('h3');
title.appendChild(document.createTextNode('X-Routes ' + protocol));
target.appendChild(title);
const table = document.createElement('table');
table.setAttribute('class', 'table');
table.setAttribute('id', 'babel_overview_xroutes_' + protocol);
const headerRow = document.createElement('tr');
headerRow.setAttribute('class', 'tr table-titles');
const headerContent = '<th class="th" style="font-weight: 700;">' + '%h'.format(protocol) + ' Prefix</th>\
<th class="th" style="font-weight: 700;">Metric</th>\
<th class="th" style="font-weight: 700;">Source-Prefix</th>';
headerRow.innerHTML = headerContent;
table.appendChild(headerRow);
for (let prefix in data[protocol]) {
const prefixRow = document.createElement('tr');
prefixRow.setAttribute('class', 'tr');
const prefixContent = '<td class="td" data-title="xroutes_' + '%h'.format(protocol) + '_prefix">' + '%h'.format(data[protocol][prefix]["address"]) + '</td>\
<td class="td" data-title="xroutes_' + '%h'.format(protocol) + '_metric">' + '%d'.format(data[protocol][prefix]["metric"]) + '</td>\
<td class="td" data-title="xroutes_' + '%h'.format(protocol) + '_src_prefix">' + '%h'.format(data[protocol][prefix]["src_prefix"]) + '</td>';
prefixRow.innerHTML = prefixContent;
table.appendChild(prefixRow);
}
target.appendChild(table);
}
}
function renderTableRoutes(ubus_data, target_div) {
const data = ubus_data;
for (let protocol in data) {
const target = target_div;
const title = document.createElement('h3');
title.appendChild(document.createTextNode('Routes ' + protocol));
target.appendChild(title);
const table = document.createElement('table');
table.setAttribute('class', 'table');
table.setAttribute('id', 'babel_overview_routes_' + protocol);
const headerRow = document.createElement('tr');
headerRow.setAttribute('class', 'tr table-titles');
const headerContent = '<th class="th" style="font-weight: 700;">' + '%h'.format(protocol) + ' Prefix</th>\
<th class="th" style="font-weight: 700;">Source-Prefix</th>\
<th class="th" style="font-weight: 700;">Route-Metric</th>\
<th class="th" style="font-weight: 700;">Route Smoothed Metric</th>\
<th class="th" style="font-weight: 700;">Refmetric</th>\
<th class="th" style="font-weight: 700;">ID</th>\
<th class="th" style="font-weight: 700;">Seq. No.</th>\
<th class="th" style="font-weight: 700;">Age</th>\
<th class="th" style="font-weight: 700;">Via</th>\
<th class="th" style="font-weight: 700;">Nexthop</th>\
<th class="th" style="font-weight: 700;">Installed</th>\
<th class="th" style="font-weight: 700;">Feasible</th>';
headerRow.innerHTML = headerContent;
table.appendChild(headerRow);
for (let prefix in data[protocol]) {
const prefixRow = document.createElement('tr');
prefixRow.setAttribute('class', 'tr');
const prefixContent = '<td class="td" data-title="routes_' + '%h'.format(protocol) + '_prefix">' + '%h'.format(data[protocol][prefix]["address"]) + '</td>\
<td class="td" data-title="routes_' + '%h'.format(protocol) + '_src_prefix">' + '%h'.format(data[protocol][prefix]["src_prefix"]) + '</td>\
<td class="td" data-title="routes_' + '%h'.format(protocol) + '_metric">' + '%d'.format(data[protocol][prefix]["route_metric"]) + '</td>\
<td class="td" data-title="routes_' + '%h'.format(protocol) + '_rout_smoothed_metric">' + '%d'.format(data[protocol][prefix]["route_smoothed_metric"]) + '</td>\
<td class="td" data-title="routes_' + '%h'.format(protocol) + '_refmetric">' + '%d'.format(data[protocol][prefix]["refmetric"]) + '</td>\
<td class="td" data-title="routes_' + '%h'.format(protocol) + '_id">' + '%h'.format(data[protocol][prefix]["id"]) + '</td>\
<td class="td" data-title="routes_' + '%h'.format(protocol) + '_seqno">' + '%d'.format(data[protocol][prefix]["seqno"]) + '</td>\
<td class="td" data-title="routes_' + '%h'.format(protocol) + '_age">' + '%d'.format(data[protocol][prefix]["age"]) + '</td>\
<td class="td" data-title="routes_' + '%h'.format(protocol) + '_via">' + '%h'.format(data[protocol][prefix]["via"]) + '</td>\
<td class="td" data-title="routes_' + '%h'.format(protocol) + '_nexthop">' + '%h'.format(data[protocol][prefix]["nexthop"]) + '</td>\
<td class="td" data-title="routes_' + '%h'.format(protocol) + '_installed">' + '%b'.format(data[protocol][prefix]["installed"]) + '</td>\
<td class="td" data-title="routes_' + '%h'.format(protocol) + '_feasible">' + '%b'.format(data[protocol][prefix]["feasible"]) + '</td>';
prefixRow.innerHTML = prefixContent;
table.appendChild(prefixRow);
}
target.appendChild(table);
}
}
function renderTableNeighbours(ubus_data, target_div) {
const data = ubus_data;
for (let protocol in data) {
const target = target_div;
const title = document.createElement('h3');
title.appendChild(document.createTextNode('Neighbours ' + protocol));
target.appendChild(title);
const table = document.createElement('table');
table.setAttribute('class', 'table');
table.setAttribute('id', 'babel_overview_neighbours_' + protocol);
const headerRow = document.createElement('tr');
headerRow.setAttribute('class', 'tr table-titles');
const headerContent = '<th class="th" style="font-weight: 700;">' + '%h'.format(protocol) + ' Neighbour</th>\
<th class="th" style="font-weight: 700;">Device</th>\
<th class="th" style="font-weight: 700;">Multicast Hellos</th>\
<th class="th" style="font-weight: 700;">Unicast Hellos</th>\
<th class="th" style="font-weight: 700;">RX cost</th>\
<th class="th" style="font-weight: 700;">TX cost</th>\
<th class="th" style="font-weight: 700;">RTT</th>\
<th class="th" style="font-weight: 700;">Interface up</th>';
headerRow.innerHTML = headerContent;
table.appendChild(headerRow);
for (let neighbour in data[protocol]) {
const neighbourRow = document.createElement('tr');
neighbourRow.setAttribute('class', 'tr');
const neighbourContent = '<td class="td" data-title="neighbours_' + '%h'.format(protocol) + '_neighbour">' + '%h'.format(data[protocol][neighbour]["address"]) + '</td>\
<td class="td" data-title="neighbours_' + '%h'.format(protocol) + '_dev">' + '%h'.format(data[protocol][neighbour]["dev"]) + '</td>\
<td class="td" data-title="neighbours_' + '%h'.format(protocol) + '_hello_reach">' + '%d'.format(data[protocol][neighbour]["hello_reach"]) + '</td>\
<td class="td" data-title="neighbours_' + '%h'.format(protocol) + '_uhello_reach">' + '%d'.format(data[protocol][neighbour]["uhello_reach"]) + '</td>\
<td class="td" data-title="neighbours_' + '%h'.format(protocol) + '_rxcost">' + '%d'.format(data[protocol][neighbour]["rxcost"]) + '</td>\
<td class="td" data-title="neighbours_' + '%h'.format(protocol) + '_txcost">' + '%d'.format(data[protocol][neighbour]["txcost"]) + '</td>\
<td class="td" data-title="neighbours_' + '%h'.format(protocol) + '_rtt">' + '%d'.format(data[protocol][neighbour]["rtt"]) + '</td>\
<td class="td" data-title="neighbours_' + '%h'.format(protocol) + '_if_up">' + '%b'.format(data[protocol][neighbour]["if_up"]) + '</td>';
neighbourRow.innerHTML = neighbourContent;
table.appendChild(neighbourRow);
}
target.appendChild(table);
}
}
function renderTableInfo(ubus_data, target_div) {
const data = ubus_data;
const target = target_div;
const title = document.createElement('h3');
title.appendChild(document.createTextNode('Info'));
target.appendChild(title);
const table = document.createElement('table');
table.setAttribute('class', 'table');
table.setAttribute('id', 'babel_overview_info');
const headerRow = document.createElement('tr');
headerRow.setAttribute('class', 'tr table-titles');
const headerContent = '<th class="th" style="font-weight: 700;">Babeld Version</th>\
<th class="th" style="font-weight: 700;">My-ID</th>\
<th class="th" style="font-weight: 700;">Host</th>';
headerRow.innerHTML = headerContent;
table.appendChild(headerRow);
const neighbourRow = document.createElement('tr');
neighbourRow.setAttribute('class', 'tr');
const neighbourContent = '<td class="td" data-title="info_babeld_version">' + '%h'.format(data["babeld_version"]) + '</td>\
<td class="td" data-title="info_dev">' + '%h'.format(data["my_id"]) + '</td>\
<td class="td" data-title="info_host">' + '%h'.format(data["host"]) + '</td>';
neighbourRow.innerHTML = neighbourContent;
table.appendChild(neighbourRow);
target.appendChild(table);
}
return view.extend({
callGetInfo: rpc.declare({
object: 'babeld',
@@ -23,9 +194,9 @@ return view.extend({
method: 'get_neighbours'
}),
fetch_babeld: function () {
var data;
var self = this;
fetch_babeld() {
let data;
let self = this;
return new Promise(function (resolve, reject) {
Promise.all([self.callGetInfo(), self.callGetXroutes(), self.callGetRoutes(), self.callGetNeighbours()])
.then(function (res) {
@@ -39,8 +210,8 @@ return view.extend({
});
},
action_babeld: function () {
var self = this;
action_babeld() {
let self = this;
return new Promise(function (resolve, reject) {
self
.fetch_babeld()
@@ -58,22 +229,20 @@ return view.extend({
});
},
load: function () {
var self = this;
load() {
return new Promise(function (resolve, reject) {
var script = E('script', { 'type': 'text/javascript' });
const 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;
render() {
return this.action_babeld()
.then(function (result) {
var mainDiv = E('div', {
const mainDiv = E('div', {
'id': 'babeld'
}, []);
@@ -82,8 +251,8 @@ return view.extend({
renderTableRoutes(result.routes, mainDiv);
renderTableNeighbours(result.neighbours, mainDiv);
var result = E([], {}, mainDiv);
return result;
const fresult = E([], {}, mainDiv);
return fresult;
})
.catch(function (error) {
console.error(error);