l2: drop the comments and define the column list once

Review feedback on #307: these files are served from flash byte for byte,
so comments ride along on every page load. The three added in this branch
are gone, 357 bytes across l2.js and style.css. The column list existed in
three copies inside renderL2() and is now a single const.
This commit is contained in:
d00f
2026-08-08 17:55:27 +02:00
parent ccb90ed16f
commit 22a09bd06a
2 changed files with 4 additions and 8 deletions
+4 -7
View File
@@ -65,10 +65,10 @@ function delL2(idx) {
} }
var l2All = []; var l2All = [];
const l2Cols = ['port', 'mac', 'vlan', 'type'];
var l2SortCol = 'port'; var l2SortCol = 'port';
var l2SortDir = 1; var l2SortDir = 1;
/* Sort keys: ports are numbers except the CPU, which must not compare as one. */
function l2Key(e, col) { function l2Key(e, col) {
if (col === 'port') return e.port === 'CPU' ? Number.MAX_SAFE_INTEGER : Number(e.port); if (col === 'port') return e.port === 'CPU' ? Number.MAX_SAFE_INTEGER : Number(e.port);
if (col === 'vlan') return Number(e.vlan); if (col === 'vlan') return Number(e.vlan);
@@ -87,12 +87,12 @@ function renderL2() {
var tbl = document.getElementById('l2table'); var tbl = document.getElementById('l2table');
if (!tbl) return; if (!tbl) return;
var f = {}; var f = {};
['port', 'mac', 'vlan', 'type'].forEach(function(c) { l2Cols.forEach(function(c) {
var el = document.getElementById('l2f_' + c); var el = document.getElementById('l2f_' + c);
f[c] = el ? el.value.trim().toLowerCase() : ''; f[c] = el ? el.value.trim().toLowerCase() : '';
}); });
var rows = l2All.filter(function(e) { var rows = l2All.filter(function(e) {
return ['port', 'mac', 'vlan', 'type'].every(function(c) { return l2Cols.every(function(c) {
return !f[c] || String(e[c]).toLowerCase().indexOf(f[c]) !== -1; return !f[c] || String(e[c]).toLowerCase().indexOf(f[c]) !== -1;
}); });
}); });
@@ -100,7 +100,7 @@ function renderL2() {
var x = l2Key(a, l2SortCol), y = l2Key(b, l2SortCol); var x = l2Key(a, l2SortCol), y = l2Key(b, l2SortCol);
return (x < y ? -1 : x > y ? 1 : 0) * l2SortDir; return (x < y ? -1 : x > y ? 1 : 0) * l2SortDir;
}); });
['port', 'mac', 'vlan', 'type'].forEach(function(c) { l2Cols.forEach(function(c) {
var a = document.getElementById('l2a_' + c); var a = document.getElementById('l2a_' + c);
if (a) a.textContent = (c === l2SortCol) ? (l2SortDir > 0 ? ' \u25b2' : ' \u25bc') : ' \u21c5'; if (a) a.textContent = (c === l2SortCol) ? (l2SortDir > 0 ? ' \u25b2' : ' \u25bc') : ' \u21c5';
}); });
@@ -155,9 +155,6 @@ function getL2() {
e.vlan = parseInt(e.vlan, 16); e.vlan = parseInt(e.vlan, 16);
e.idx = parseInt(e.idx, 16); e.idx = parseInt(e.idx, 16);
e.type = e.type == "s" ? t('l2_static') : t('l2_learned'); e.type = e.type == "s" ? t('l2_static') : t('l2_learned');
/* Label the CPU port before mapping to physical numbering: the
* SFP port maps to physical 9 as well, and tagging afterwards
* relabelled every SFP entry as CPU. */
e.port = e.port == 9 ? 'CPU' : logToPhysPort[e.port]; e.port = e.port == 9 ? 'CPU' : logToPhysPort[e.port];
return e; return e;
}); });
-1
View File
@@ -165,7 +165,6 @@ select { text-align-last: right; font-family: monospace}
option { direction: rtl; font-family: sans-serif} option { direction: rtl; font-family: sans-serif}
#vlanTable td { text-align: left; } #vlanTable td { text-align: left; }
/* L2 table: sortable headers and per-column filters */
.l2sort{cursor:pointer;user-select:none} .l2sort{cursor:pointer;user-select:none}
.l2sort:hover{text-decoration:underline} .l2sort:hover{text-decoration:underline}
.l2arrow{opacity:0.55;font-size:0.85em} .l2arrow{opacity:0.55;font-size:0.85em}