2 * Copyright (c) 2018-2020, Tano Systems LLC. All Rights Reserved.
3 * Anton Kikin <a.kikin@tano-systems.com>
4 * Copyright (c) 2023-2024. All Rights Reserved.
5 * Paul Donald <newtwen+github@gmail.com>
16 * Filter neighbors (-H)
18 * The filter column means that filtering is enabled
19 * The 1proto column tells that only one protocol will be kept.
20 * The 1neigh column tells that only one neighbor will be kept.
23 * filter 1proto 1neigh filter 1proto 1neigh
46 const etitle
= _('enable filter');
47 const ptitle
= _('keep only one protocol');
48 const ntitle
= _('keep only one neighbor');
50 var cbiFilterSelect
= form
.Value
.extend({
51 __name__
: 'CBI.LLDPD.FilterSelect',
53 __init__: function() {
54 this.super('__init__', arguments
);
83 handleRowClick: function(section_id
, ev
) {
84 var row
= ev
.currentTarget
;
85 var tbody
= row
.parentNode
;
86 var selected
= row
.getAttribute('data-filter');
87 var input
= tbody
.querySelector('[id="' + this.cbid(section_id
) + '-' + selected
+ '"]');
89 this.selected
= selected
;
91 tbody
.querySelectorAll('tr').forEach(function(e
) {
92 e
.classList
.remove('lldpd-filter-selected');
96 row
.classList
.add('lldpd-filter-selected');
99 formvalue: function(section_id
) {
100 return this.selected
|| this.cfgvalue(section_id
);
103 renderFrame: function(section_id
, in_table
, option_index
, nodes
) {
104 var tmp
= this.description
;
106 // Prepend description with table legend
108 '<ul><li>' + 'E — ' + etitle
+ '</li>' +
109 '<li>' + 'P — ' + ptitle
+ '</li>' +
110 '<li>' + 'N — ' + ntitle
+ '</li>' +
111 '</ul>' + this.description
;
113 var rendered
= this.super('renderFrame', arguments
);
115 // Restore original description
116 this.description
= tmp
;
121 renderWidget: function(section_id
, option_index
, cfgvalue
) {
122 //default value is "15" - rows are zero based
123 var selected
= parseInt(cfgvalue
) || 15;
127 var renderFilterVal
= L
.bind(function(row
, col
) {
128 return this.filterVal
[row
][col
] ? '✔' : '';
131 for (var i
= 0; i
< this.filterVal
.length
; i
++) {
133 'class': ((selected
== i
) ? 'lldpd-filter-selected' : ''),
134 'click': L
.bind(this.handleRowClick
, this, section_id
),
139 'class': 'cbi-input-radio',
140 'data-update': 'click change',
142 'id': this.cbid(section_id
) + '-' + i
,
143 'name': this.cbid(section_id
),
144 'checked': (selected
== i
) ? '' : null,
149 E('td', {'title': etitle
}, renderFilterVal(i
, 0)),
150 E('td', {'title': ptitle
}, renderFilterVal(i
, 1)),
151 E('td', {'title': ntitle
}, renderFilterVal(i
, 2)),
152 E('td', {'title': etitle
}, renderFilterVal(i
, 3)),
153 E('td', {'title': ptitle
}, renderFilterVal(i
, 4)),
154 E('td', {'title': ntitle
}, renderFilterVal(i
, 5))
158 var table
= E('table', { 'class': 'lldpd-filter', 'id': this.cbid(section_id
) }, [
161 E('th', { 'rowspan': 2 }),
162 E('th', { 'rowspan': 2 }, _('Filter')),
163 E('th', { 'colspan': 3 }, _('Incoming')),
164 E('th', { 'colspan': 3 }, _('Outgoing'))
175 E('tbody', {}, tbody
)
182 var CBIMultiIOSelect
= form
.MultiValue
.extend({
183 __name__
: 'CBI.MultiIOSelect',
185 renderWidget: function(section_id
, option_index
, cfgvalue
) {
186 var value
= (cfgvalue
!= null) ? cfgvalue
: this.default ? this.default : '',
187 choices
= this.transformChoices() ? this.transformChoices() : '';
189 var widget
= new ui
.Dropdown(L
.toArray(value
), choices
, {
190 id
: this.cbid(section_id
),
197 disabled
: (this.readonly
!= null) ? this.readonly
: this.map
.readonly
,
198 validate
: L
.bind(this.validate
, this, section_id
),
201 return widget
.render();
206 return new Promise(function(resolveFn
, rejectFn
) {
207 var data
= session
.getLocalData('luci-app-lldpd');
214 return uci
.load('luci').then(function() {
215 session
.setLocalData('luci-app-lldpd', data
);
221 return L
.Class
.extend({
222 cbiFilterSelect
: cbiFilterSelect
,
223 CBIMultiIOSelect
: CBIMultiIOSelect
,