From 8e32f4478f90ce8674cde724e6e23f51481b01fd Mon Sep 17 00:00:00 2001 From: Andreas Bräu Date: Wed, 27 Oct 2021 21:36:40 +0200 Subject: luci-app-olsr-services: simplify table updates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andreas Bräu --- .../resources/view/freifunk-services/services.js | 41 ++++++++++------------ 1 file changed, 18 insertions(+), 23 deletions(-) (limited to 'applications/luci-app-olsr-services/htdocs/luci-static') diff --git a/applications/luci-app-olsr-services/htdocs/luci-static/resources/view/freifunk-services/services.js b/applications/luci-app-olsr-services/htdocs/luci-static/resources/view/freifunk-services/services.js index 3a3d11ae1d..57bd83d93f 100644 --- a/applications/luci-app-olsr-services/htdocs/luci-static/resources/view/freifunk-services/services.js +++ b/applications/luci-app-olsr-services/htdocs/luci-static/resources/view/freifunk-services/services.js @@ -3,12 +3,6 @@ 'require view'; 'require poll'; -const tableHead = '
' + - '
' + _('Url') + '
' + - '
' + _('Protocol') + '
' + - '
' + _('Source') + '
' + - '
'; - var getOlsrd4Services = rpc.declare({ object: 'olsr-services', method: 'services4', @@ -21,22 +15,19 @@ var getOlsrd6Services = rpc.declare({ expect: {} }); -function updateServicesTable(servicesArray) { - var table = document.getElementById("olsr_services"); - var tempElement = document.createElement('div'); - tempElement.innerHTML = tableHead; - table.replaceChildren(tempElement.firstChild); - servicesArray.forEach(function (service, index) { - var node = document.createElement('div'); - var index = 1 + index % 2; +function createTableData(servicesArray) { + var tableData = []; + servicesArray.forEach(function (service) { var sourceUrl = service.isIpv6 ? '[' + service.source + ']' : service.source; - node.classList.add('tr', 'cbi-section-table-row', 'cbi-rowstyle-' + index); - node.innerHTML = - '' + - '
' + service.protocol + '
' + - ''; - table.appendChild(node); + tableData.push( + [ + E('a', { 'href': service.url }, service.description), + service.protocol, + E('a', { 'href': 'http://' + sourceUrl + '/cgi-bin-status.html' }, service.source) + ] + ); }); + return tableData; } function extractServiceInformation(results) { @@ -66,15 +57,19 @@ return view.extend({ poll.add(function () { Promise.all([getOlsrd4Services(), getOlsrd6Services()]).then(function (results) { var servicesArray = extractServiceInformation(results); - updateServicesTable(servicesArray); + cbi_update_table("#olsr_services", createTableData(servicesArray)); }); }, 30); return E([], {}, [ E('h2', { 'name': 'content' }, [_('Services')]), E('legend', {}, [_('Internal services')]), E('fieldset', { 'class': 'cbi-section' }, [ - E('div', { 'class': 'table cbi-section-table', 'id': 'olsr_services' }, [ - E(tableHead) + E('table', { 'id': 'olsr_services' }, [ + E('tr', { 'class' : 'tr table-titles'}, [ + E('td', { 'class' : 'th'}, _('Url')), + E('td', { 'class' : 'th'}, _('Protocol')), + E('td', { 'class' : 'th'}, _('Source')) + ]), ]) ]), ]); -- cgit v1.2.3