const ptitle = _('keep only one protocol');
const ntitle = _('keep only one neighbor');
-var cbiFilterSelect = form.Value.extend({
+const cbiFilterSelect = form.Value.extend({
__name__: 'CBI.LLDPD.FilterSelect',
- __init__: function() {
+ __init__() {
this.super('__init__', arguments);
this.selected = null;
},
/** @private */
- handleRowClick: function(section_id, ev) {
- var row = ev.currentTarget;
- var tbody = row.parentNode;
- var selected = row.getAttribute('data-filter');
- var input = tbody.querySelector('[id="' + this.cbid(section_id) + '-' + selected + '"]');
+ handleRowClick(section_id, ev) {
+ const row = ev.currentTarget;
+ const tbody = row.parentNode;
+ const selected = row.getAttribute('data-filter');
+ const input = tbody.querySelector('[id="' + this.cbid(section_id) + '-' + selected + '"]');
this.selected = selected;
row.classList.add('lldpd-filter-selected');
},
- formvalue: function(section_id) {
+ formvalue(section_id) {
return this.selected || this.cfgvalue(section_id);
},
- renderFrame: function(section_id, in_table, option_index, nodes) {
- var tmp = this.description;
+ renderFrame(section_id, in_table, option_index, nodes) {
+ const tmp = this.description;
// Prepend description with table legend
this.description =
'<li>' + 'N — ' + ntitle + '</li>' +
'</ul>' + this.description;
- var rendered = this.super('renderFrame', arguments);
+ const rendered = this.super('renderFrame', arguments);
// Restore original description
this.description = tmp;
return rendered;
},
- renderWidget: function(section_id, option_index, cfgvalue) {
+ renderWidget(section_id, option_index, cfgvalue) {
//default value is "15" - rows are zero based
- var selected = parseInt(cfgvalue) || 15;
+ const selected = parseInt(cfgvalue) || 15;
- var tbody = [];
+ const tbody = [];
- var renderFilterVal = L.bind(function(row, col) {
+ const renderFilterVal = L.bind(function(row, col) {
return this.filterVal[row][col] ? '✔' : '';
}, this);
- for (var i = 0; i < this.filterVal.length; i++) {
+ for (let i = 0; i < this.filterVal.length; i++) {
tbody.push(E('tr', {
'class': ((selected == i) ? 'lldpd-filter-selected' : ''),
'click': L.bind(this.handleRowClick, this, section_id),
]));
};
- var table = E('table', { 'class': 'lldpd-filter', 'id': this.cbid(section_id) }, [
+ const table = E('table', { 'class': 'lldpd-filter', 'id': this.cbid(section_id) }, [
E('thead', {}, [
E('tr', {}, [
E('th', { 'rowspan': 2 }),
},
});
-var CBIMultiIOSelect = form.MultiValue.extend({
+const CBIMultiIOSelect = form.MultiValue.extend({
__name__: 'CBI.MultiIOSelect',
- renderWidget: function(section_id, option_index, cfgvalue) {
- var value = (cfgvalue != null) ? cfgvalue : this.default ? this.default : '',
+ renderWidget(section_id, option_index, cfgvalue) {
+ const value = (cfgvalue != null) ? cfgvalue : this.default ? this.default : '',
choices = this.transformChoices() ? this.transformChoices() : '';
- var widget = new ui.Dropdown(L.toArray(value), choices, {
+ const widget = new ui.Dropdown(L.toArray(value), choices, {
id: this.cbid(section_id),
sort: this.keylist,
multiple: true,
function init() {
return new Promise(function(resolveFn, rejectFn) {
- var data = session.getLocalData('luci-app-lldpd');
+ let data = session.getLocalData('luci-app-lldpd');
if (data !== null) {
return resolveFn();
}
method: 'getInitList',
params: [ 'name' ],
expect: { '': {} },
- filter: function(res) {
- for (var k in res)
+ filter(res) {
+ for (let k in res)
return +res[k].enabled;
return null;
}
expect: { result: false }
});
-var usage = _('See syntax <a %s>here</a>.').format('href=https://lldpd.github.io/usage.html target="_blank"');
+const usage = _('See syntax <a %s>here</a>.').format('href=https://lldpd.github.io/usage.html target="_blank"');
const validateioentries = function(section_id, value) {
if (value) {
const a = value.split(' ');
const noex = a.filter(el=> !el.startsWith('!'));
const ex = a.filter(el=> el.startsWith('!') && !el.startsWith('!!'));
- for (var i of noex) {
- for (var e of ex) {
+ for (let i of noex) {
+ for (let e of ex) {
if ('!'+i == e){
return emsg.format(i, e);
}
};
return L.view.extend({
- __init__: function() {
+ __init__() {
this.super('__init__', arguments);
// Inject CSS
- var head = document.getElementsByTagName('head')[0];
- var css = E('link', { 'href':
+ const head = document.getElementsByTagName('head')[0];
+ const css = E('link', { 'href':
L.resource('lldpd/lldpd.css')
+ '?v=#PKG_VERSION', 'rel': 'stylesheet' });
head.appendChild(css);
},
- load: function() {
+ load() {
return Promise.all([
+ network.getDevices(),
callInitList('lldpd'),
lldpd.init(),
uci.load('lldpd'),
- network.getDevices()
]);
},
// -----------------------------------------------------------------------------------------
/** @private */
- populateBasicOptions: function(s, tab, data) {
- var o;
- var serviceEnabled = data[0];
- var net_devices = data[3];
+ populateBasicOptions(s, tab, [net_devices, serviceEnabled]) {
+ let o;
// Service enable/disable
o = s.taboption(tab, form.Flag, 'enabled', _('Enable service'));
if (value == '1') {
// Enable and start
- callInitAction('lldpd', 'enable').then(function() {
+ callInitAction('lldpd', 'enable').then(() => {
return callInitAction('lldpd', 'start');
});
}
else {
// Stop and disable
- callInitAction('lldpd', 'stop').then(function() {
+ callInitAction('lldpd', 'stop').then(() => {
return callInitAction('lldpd', 'disable');
});
}
/* This function returns the value for a specified key. Used to fill
various location fields derived from an lldpd location config string */
function getLocationValueFromConfString(_key) {
- var inStr = this ? this.section.formvalue('config', 'lldp_location'):
+ let inStr = this ? this.section.formvalue('config', 'lldp_location'):
uci.get('lldpd', 'config', 'lldp_location');
inStr = inStr ? inStr: '';
};
function write_lldp_location() {
- var _input = this ? this.section.formvalue('config', '_lldp_location_type'):
+ const _input = this ? this.section.formvalue('config', '_lldp_location_type'):
'1';
if(_input){
if (_input == '1') {
/* location coordinate latitude
48.85667N longitude 2.2014E altitude 117.47 m datum WGS84 */
- var lat = this.section.formvalue('config', '_coordinate_lat'),
- lon = this.section.formvalue('config', '_coordinate_lon'),
- alt = this.section.formvalue('config', '_coordinate_alt'),
- dat = this.section.formvalue('config', '_coordinate_dat');
+ const lat = this.section.formvalue('config', '_coordinate_lat');
+ const lon = this.section.formvalue('config', '_coordinate_lon');
+ const alt = this.section.formvalue('config', '_coordinate_alt');
+ const dat = this.section.formvalue('config', '_coordinate_dat');
if(lat && lon && dat) {
uci.set('lldpd', 'config', 'lldp_location',
'coordinate latitude ' + lat +
else if (_input == '2') {
/* location address country US
street "Commercial Road" city "Roseville" */
- var cc = this.section.formvalue('config', '_civic_cc'),
- city = this.section.formvalue('config', '_civic_city'),
- str = this.section.formvalue('config', '_civic_str'),
- bldg = this.section.formvalue('config', '_civic_bldg'),
- nmbr = this.section.formvalue('config', '_civic_nmbr'),
- zip = this.section.formvalue('config', '_civic_zip');
+ const cc = this.section.formvalue('config', '_civic_cc');
+ const city = this.section.formvalue('config', '_civic_city');
+ const str = this.section.formvalue('config', '_civic_str');
+ const bldg = this.section.formvalue('config', '_civic_bldg');
+ const nmbr = this.section.formvalue('config', '_civic_nmbr');
+ const zip = this.section.formvalue('config', '_civic_zip');
uci.set('lldpd', 'config', 'lldp_location',
'address country ' + cc.toUpperCase()
}
else if (_input == '3') {
/* location elin 12345 */
- var elin = this.section.formvalue('config', '_elin');
+ const elin = this.section.formvalue('config', '_elin');
if(elin)
uci.set('lldpd', 'config', 'lldp_location', 'elin ' + elin);
}
o.rmempty = true;
o.write = function(section_id, value) {
if (value) {
- const words = value.trim().split(/\s+/),
- regex = /^coordinate|^address|^elin/;
- var start;
+ const words = value.trim().split(/\s+/);
+ const regex = /^coordinate|^address|^elin/;
+ let start;
words.forEach(w=>{
if (w.match(regex)) start = w;
});
};
o.validate = function(section_id, value) {
if (value) {
- const words = value.trim().split(/\s+/),
- regex = /^coordinate|^address|^elin/;
- var _eval = _("Must contain: 'coordinate ...', 'address ...' or 'elin ...'");
+ const words = value.trim().split(/\s+/);
+ const regex = /^coordinate|^address|^elin/;
+ let _eval = _("Must contain: 'coordinate ...', 'address ...' or 'elin ...'");
words.forEach(w=>{
if (w.match(regex)) _eval = true;
});
o.datatype = "maxlength(20)";
o.validate = function(section_id, value) {
if (!value) return true;
- var valid = _('valid syntax: 0 .. 90.000[N|S]');
+ let valid = _('valid syntax: 0 .. 90.000[N|S]');
valid = (parseFloat(value) >= 0 && parseFloat(value) <= 90) ?
/^-?\d+(?:\.\d+)?[NnSs]$/.test(value) ? true : valid : valid;
return valid;
o.datatype = "maxlength(20)";
o.validate = function(section_id, value) {
if (!value) return true;
- var valid = _('valid syntax: 0 .. 180.000[E|W]');
+ let valid = _('valid syntax: 0 .. 180.000[E|W]');
valid = (parseFloat(value) >= 0 && parseFloat(value) <= 180) ?
/^-?\d+(?:\.\d+)?[WwEe]$/.test(value) ? true : valid : valid;
return valid;
}
o.write = write_lldp_location;
- const min_alt = -100000.00,
- max_alt = 42849672.95;
+ const min_alt = -100000.00;
+ const max_alt = 42849672.95;
o = s.taboption(tab, form.Value, '_coordinate_alt',
_('Altitude'), '%f .. %f [m|f]'.format(min_alt, max_alt));
o.depends({ '_lldp_location_type' : '1'});
o.datatype = 'maxlength(20)';
o.validate = function(section_id, value) {
if (!value) return true;
- var valid = _('valid syntax: %f .. %f [mf]').format(min_alt, max_alt);
+ let valid = _('valid syntax: %f .. %f [mf]').format(min_alt, max_alt);
valid = (parseFloat(value) >= min_alt && parseFloat(value) <= max_alt) ?
/^-?\d+(?:\.\d+)?\ [mf]$/.test(value) ? true : valid : valid;
return valid;
o.placeholder = 'EU';
o.validate = function(section_id, value) {
if(!value) return true;
- var valid = _('Two character CC required');
+ let valid = _('Two character CC required');
valid = (value.length == 2) ?
/^[A-Z]{2}$/i.test(value) ? true : valid : valid;
return valid;
// -----------------------------------------------------------------------------------------
/** @private */
- populateIfacesOptions: function(s, tab, data) {
- var o;
- var net_devices = data[3];
+ populateIfacesOptions(s, tab, [net_devices, serviceEnabled]) {
+ let o;
// Interfaces to listen on
// This value: lldpd.init handles as a list value, and produces a CSV for lldpd.conf: 'configure system interface pattern'
// -----------------------------------------------------------------------------------------
/** @private */
- populateAdvancedOptions: function(s, tab, data) {
- var o;
+ populateAdvancedOptions(s, tab, {net_devices, serviceEnabled}) {
+ let o;
// SNMP agentX socket
/* **Note**: The init file tests for SNMP support, so agentxsocket is at worst inert. */
// -----------------------------------------------------------------------------------------
/** @private */
- populateProtocolsOptions: function(s, tab, data) {
- var o;
+ populateProtocolsOptions(s, tab, {net_devices, serviceEnabled}) {
+ let o;
o = s.taboption(tab, form.SectionValue, '_protocols', form.TypedSection, 'lldpd');
- var ss = o.subsection;
+ let ss = o.subsection;
ss.anonymous = true;
ss.addremove = false;
// -----------------------------------------------------------------------------------------
/** @private */
- populateExtraTLVOptions: function(s, tab, data) {
+ populateExtraTLVOptions(s, tab, [net_devices, serviceEnabled]) {
let o, ss, oo;
///// Custom TLV
ss.addbtntitle = _('Add Custom TLV', 'lldpd Custom TLV');
oo = ss.option(lldpd.CBIMultiIOSelect, 'ports',
_('Network Interface(s)'));
- data[3].forEach(nd => {
+ net_devices.forEach(nd => {
oo.value(nd.getName());
oo.value('!'+nd.getName());
});
},
/** @private */
- populateOptions: function(s, data) {
- var o;
+ populateOptions(s, data) {
+ let o;
s.tab('basic', _('Basic Settings'));
this.populateBasicOptions(s, 'basic', data);
this.populateProtocolsOptions(s, 'protocols', data);
},
- render: function(data) {
- var m, s;
+ render(data) {
+ let m, s;
m = new form.Map('lldpd', _('LLDPd Settings'),
_('LLDPd is an implementation of IEEE 802.1ab') + ' ' +