luci-app-olsr-services: simplify table updates
Signed-off-by: Andreas Bräu <ab@andi95.de>
This commit is contained in:
parent
74c16ee65f
commit
8e32f4478f
1 changed files with 18 additions and 23 deletions
|
@ -3,12 +3,6 @@
|
||||||
'require view';
|
'require view';
|
||||||
'require poll';
|
'require poll';
|
||||||
|
|
||||||
const tableHead = '<div class="tr cbi-section-table-titles">' +
|
|
||||||
'<div class="th cbi-section-table-cell">' + _('Url') + '</div>' +
|
|
||||||
'<div class="th cbi-section-table-cell">' + _('Protocol') + '</div>' +
|
|
||||||
'<div class="th cbi-section-table-cell">' + _('Source') + '</div>' +
|
|
||||||
'</div>';
|
|
||||||
|
|
||||||
var getOlsrd4Services = rpc.declare({
|
var getOlsrd4Services = rpc.declare({
|
||||||
object: 'olsr-services',
|
object: 'olsr-services',
|
||||||
method: 'services4',
|
method: 'services4',
|
||||||
|
@ -21,22 +15,19 @@ var getOlsrd6Services = rpc.declare({
|
||||||
expect: {}
|
expect: {}
|
||||||
});
|
});
|
||||||
|
|
||||||
function updateServicesTable(servicesArray) {
|
function createTableData(servicesArray) {
|
||||||
var table = document.getElementById("olsr_services");
|
var tableData = [];
|
||||||
var tempElement = document.createElement('div');
|
servicesArray.forEach(function (service) {
|
||||||
tempElement.innerHTML = tableHead;
|
|
||||||
table.replaceChildren(tempElement.firstChild);
|
|
||||||
servicesArray.forEach(function (service, index) {
|
|
||||||
var node = document.createElement('div');
|
|
||||||
var index = 1 + index % 2;
|
|
||||||
var sourceUrl = service.isIpv6 ? '[' + service.source + ']' : service.source;
|
var sourceUrl = service.isIpv6 ? '[' + service.source + ']' : service.source;
|
||||||
node.classList.add('tr', 'cbi-section-table-row', 'cbi-rowstyle-' + index);
|
tableData.push(
|
||||||
node.innerHTML =
|
[
|
||||||
'<div class="td cbi-section-table-cell left"><a href="' + service.url + '">' + service.description + '</a></div>' +
|
E('a', { 'href': service.url }, service.description),
|
||||||
'<div class="td cbi-section-table-cell left">' + service.protocol + '</div>' +
|
service.protocol,
|
||||||
'<div class="td cbi-section-table-cell left"><a href="http://' + sourceUrl + '/cgi-bin-status.html">' + service.source + '</a></div>';
|
E('a', { 'href': 'http://' + sourceUrl + '/cgi-bin-status.html' }, service.source)
|
||||||
table.appendChild(node);
|
]
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
return tableData;
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractServiceInformation(results) {
|
function extractServiceInformation(results) {
|
||||||
|
@ -66,15 +57,19 @@ return view.extend({
|
||||||
poll.add(function () {
|
poll.add(function () {
|
||||||
Promise.all([getOlsrd4Services(), getOlsrd6Services()]).then(function (results) {
|
Promise.all([getOlsrd4Services(), getOlsrd6Services()]).then(function (results) {
|
||||||
var servicesArray = extractServiceInformation(results);
|
var servicesArray = extractServiceInformation(results);
|
||||||
updateServicesTable(servicesArray);
|
cbi_update_table("#olsr_services", createTableData(servicesArray));
|
||||||
});
|
});
|
||||||
}, 30);
|
}, 30);
|
||||||
return E([], {}, [
|
return E([], {}, [
|
||||||
E('h2', { 'name': 'content' }, [_('Services')]),
|
E('h2', { 'name': 'content' }, [_('Services')]),
|
||||||
E('legend', {}, [_('Internal services')]),
|
E('legend', {}, [_('Internal services')]),
|
||||||
E('fieldset', { 'class': 'cbi-section' }, [
|
E('fieldset', { 'class': 'cbi-section' }, [
|
||||||
E('div', { 'class': 'table cbi-section-table', 'id': 'olsr_services' }, [
|
E('table', { 'id': 'olsr_services' }, [
|
||||||
E(tableHead)
|
E('tr', { 'class' : 'tr table-titles'}, [
|
||||||
|
E('td', { 'class' : 'th'}, _('Url')),
|
||||||
|
E('td', { 'class' : 'th'}, _('Protocol')),
|
||||||
|
E('td', { 'class' : 'th'}, _('Source'))
|
||||||
|
]),
|
||||||
])
|
])
|
||||||
]),
|
]),
|
||||||
]);
|
]);
|
||||||
|
|
Loading…
Reference in a new issue