1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
/*
* Copyright (c) 2018-2020, Tano Systems LLC. All Rights Reserved.
* Anton Kikin <a.kikin@tano-systems.com>
* Copyright (c) 2023-2024. All Rights Reserved.
* Paul Donald <newtwen+github@gmail.com>
*/
'use strict';
'require ui';
'require form';
'require network';
'require session';
'require uci';
/*
* Filter neighbors (-H)
*
* The filter column means that filtering is enabled
* The 1proto column tells that only one protocol will be kept.
* The 1neigh column tells that only one neighbor will be kept.
*
* incoming outgoing
* filter 1proto 1neigh filter 1proto 1neigh
* 0
* 1 x x x x
* 2 x x
* 3 x x
* 4 x x
* 5 x
* 6 x
* 7 x x x x x
* 8 x x x
* 9 x x x x
* 10 x x
* 11 x x
* 12 x x x x
* 13 x x x
* 14 x x x x
* 15 x x x
* 16 x x x x x
* 17 x x x x
* 18 x x x
* 19 x x x
*/
const etitle = _('enable filter');
const ptitle = _('keep only one protocol');
const ntitle = _('keep only one neighbor');
var cbiFilterSelect = form.Value.extend({
__name__: 'CBI.LLDPD.FilterSelect',
__init__: function() {
this.super('__init__', arguments);
this.selected = null;
this.filterVal = [
[ 0, 0, 0, 0, 0, 0 ],
[ 1, 1, 0, 1, 1, 0 ],
[ 1, 1, 0, 0, 0, 0 ],
[ 0, 0, 0, 1, 1, 0 ],
[ 1, 0, 0, 1, 0, 0 ],
[ 1, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 1, 0, 0 ],
[ 1, 1, 1, 1, 1, 0 ],
[ 1, 1, 1, 0, 0, 0 ],
[ 1, 0, 1, 1, 1, 0 ],
[ 0, 0, 0, 1, 0, 1 ],
[ 1, 0, 1, 0, 0, 0 ],
[ 1, 0, 1, 1, 0, 1 ],
[ 1, 0, 1, 1, 0, 0 ],
[ 1, 1, 0, 1, 0, 1 ],
[ 1, 1, 0, 1, 0, 0 ],
[ 1, 1, 1, 1, 0, 1 ],
[ 1, 1, 1, 1, 0, 0 ],
[ 1, 0, 0, 1, 0, 1 ],
[ 1, 0, 0, 1, 1, 0 ]
];
},
/** @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 + '"]');
this.selected = selected;
tbody.querySelectorAll('tr').forEach(function(e) {
e.classList.remove('lldpd-filter-selected');
});
input.checked = true;
row.classList.add('lldpd-filter-selected');
},
formvalue: function(section_id) {
return this.selected || this.cfgvalue(section_id);
},
renderFrame: function(section_id, in_table, option_index, nodes) {
var tmp = this.description;
// Prepend description with table legend
this.description =
'<ul><li>' + 'E — ' + etitle + '</li>' +
'<li>' + 'P — ' + ptitle + '</li>' +
'<li>' + 'N — ' + ntitle + '</li>' +
'</ul>' + this.description;
var rendered = this.super('renderFrame', arguments);
// Restore original description
this.description = tmp;
return rendered;
},
renderWidget: function(section_id, option_index, cfgvalue) {
//default value is "15" - rows are zero based
var selected = parseInt(cfgvalue) || 15;
var tbody = [];
var renderFilterVal = L.bind(function(row, col) {
return this.filterVal[row][col] ? '✔' : '';
}, this);
for (var 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),
'data-filter': i,
}, [
E('td', {}, [
E('input', {
'class': 'cbi-input-radio',
'data-update': 'click change',
'type': 'radio',
'id': this.cbid(section_id) + '-' + i,
'name': this.cbid(section_id),
'checked': (selected == i) ? '' : null,
'value': i
})
]),
E('td', {}, i),
E('td', {'title': etitle}, renderFilterVal(i, 0)),
E('td', {'title': ptitle}, renderFilterVal(i, 1)),
E('td', {'title': ntitle}, renderFilterVal(i, 2)),
E('td', {'title': etitle}, renderFilterVal(i, 3)),
E('td', {'title': ptitle}, renderFilterVal(i, 4)),
E('td', {'title': ntitle}, renderFilterVal(i, 5))
]));
};
var table = E('table', { 'class': 'lldpd-filter', 'id': this.cbid(section_id) }, [
E('thead', {}, [
E('tr', {}, [
E('th', { 'rowspan': 2 }),
E('th', { 'rowspan': 2 }, _('Filter')),
E('th', { 'colspan': 3 }, _('Incoming')),
E('th', { 'colspan': 3 }, _('Outgoing'))
]),
E('tr', {}, [
E('th', {}, 'E'),
E('th', {}, 'P'),
E('th', {}, 'N'),
E('th', {}, 'E'),
E('th', {}, 'P'),
E('th', {}, 'N'),
])
]),
E('tbody', {}, tbody)
]);
return table;
},
});
var CBIMultiIOSelect = form.MultiValue.extend({
__name__: 'CBI.MultiIOSelect',
renderWidget: function(section_id, option_index, cfgvalue) {
var value = (cfgvalue != null) ? cfgvalue : this.default ? this.default : '',
choices = this.transformChoices() ? this.transformChoices() : '';
var widget = new ui.Dropdown(L.toArray(value), choices, {
id: this.cbid(section_id),
sort: this.keylist,
multiple: true,
optional: true,
display_items: 5,
dropdown_items: -1,
create: true,
disabled: (this.readonly != null) ? this.readonly : this.map.readonly,
validate: L.bind(this.validate, this, section_id),
});
return widget.render();
}
});
function init() {
return new Promise(function(resolveFn, rejectFn) {
var data = session.getLocalData('luci-app-lldpd');
if (data !== null) {
return resolveFn();
}
data = {};
return uci.load('luci').then(function() {
session.setLocalData('luci-app-lldpd', data);
return resolveFn();
});
});
}
return L.Class.extend({
cbiFilterSelect: cbiFilterSelect,
CBIMultiIOSelect: CBIMultiIOSelect,
init: init,
});
|