'use strict'; 'require poll'; 'require rpc'; 'require uci'; 'require ui'; 'require view'; 'require olsr.common_js as olsr'; return olsr.olsrview.extend({ action_smartgw() { let self = this; return new Promise(function (resolve, reject) { self .fetch_jsoninfo('gateways') .then(function ([data, has_v4, has_v6, error]) { if (error) { reject(error); } function compare(a, b) { if (a.proto === b.proto) { return a.cost < b.cost; } else { return a.proto < b.proto; } } data.ipv4.sort(compare); data.ipv6.sort(compare); const result = { gws: data, has_v4: has_v4, has_v6: has_v6 }; resolve(result); }) .catch(function (err) { reject(err); }); }); }, load() { let self = this; poll.add(function () { self.render(); }, 5); return Promise.all([uci.load('olsrd'), uci.load('luci_olsr')]); }, render() { let gws_res; let has_v4; let has_v6; return this.action_smartgw() .then(function (result) { gws_res = result.gws; has_v4 = result.has_v4; has_v6 = result.has_v6; const fieldset = E('fieldset', { 'class': 'cbi-section' }, [ E('legend', {}, _('Overview of smart gateways in this network')), E('div', { 'class': 'table cbi-section-table', 'id': 'olsrd_smartgw' }, [ E('div', { 'class': 'tr cbi-section-table-titles' }, [ E('div', { 'class': 'th cbi-section-table-cell' }, _('Gateway')), E('div', { 'class': 'th cbi-section-table-cell' }, _('Selected')), E('div', { 'class': 'th cbi-section-table-cell' }, _('ETX')), E('div', { 'class': 'th cbi-section-table-cell' }, _('Hops')), E('div', { 'class': 'th cbi-section-table-cell' }, _('Uplink')), E('div', { 'class': 'th cbi-section-table-cell' }, _('Downlink')), E('div', { 'class': 'th cbi-section-table-cell' }, _('IPv4')), E('div', { 'class': 'th cbi-section-table-cell' }, _('IPv6')), E('div', { 'class': 'th cbi-section-table-cell' }, _('Prefix')), ]), ]), ]); let has_smartgw; uci.sections('olsrd', 'olsrd', function (s) { if (s.SmartGateway && s.SmartGateway === 'yes') { has_smartgw = true; } }); const rv = []; for (let gw of gws_res.ipv4) { gw.cost = parseFloat(gw.cost) / 1024 || 0; if (gw.cost >= 100) { gw.cost = 0; } rv.push({ proto: gw.IPv4 ? '4' : '6', originator: gw.originator, selected: gw.selected ? _('yes') : _('no'), cost: gw.cost > 0 ? gw.cost.toFixed(3) : _('infinite'), hops: gw.hops, uplink: gw.uplink, downlink: gw.downlink, v4: gw.IPv4 ? _('yes') : _('no'), v6: gw.IPv6 ? _('yes') : _('no'), prefix: gw.prefix, }); } const smartgwdiv = document.getElementById('olsrd_smartgw'); if (smartgwdiv) { let s = '