123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- /*
- * 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,
- });
|