Skip to content

Commit 32425c1

Browse files
committed
switch: server-side IDs
1 parent 6005ed3 commit 32425c1

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

kvmd/apps/kvmd/switch/state.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,17 @@ def __inner_get_state(self, mask: int) -> dict: # pylint: disable=too-many-bran
163163
},
164164
}
165165
if x_summary:
166-
state["summary"] = {"active_port": self.__active_port, "synced": self.__synced}
166+
state["summary"] = {
167+
"active_port": self.__active_port,
168+
"active_id": (
169+
"" if self.__active_port < 0 else (
170+
f"{self.__active_port // 4 + 1}.{self.__active_port % 4 + 1}"
171+
if len(self.__units) > 1 else
172+
f"{self.__active_port + 1}"
173+
)
174+
),
175+
"synced": self.__synced,
176+
}
167177
if x_edids:
168178
state["edids"] = {
169179
"all": {
@@ -224,6 +234,7 @@ def __inner_get_state(self, mask: int) -> dict: # pylint: disable=too-many-bran
224234
"unit": unit,
225235
"channel": ch,
226236
"name": self.__port_names[port],
237+
"id": (f"{unit + 1}.{ch + 1}" if len(self.__units) > 1 else f"{ch + 1}"),
227238
"atx": {
228239
"click_delays": {
229240
"power": self.__atx_cp_delays[port],

web/share/js/kvm/switch.js

+3-11
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ export function Switch() {
306306
if (active < 0 || active >= __state.model.ports.length) {
307307
$("switch-active-port").innerText = "N/A";
308308
} else {
309-
$("switch-active-port").innerText = "p" + __formatPort(__state.model, active);
309+
$("switch-active-port").innerText = "p" + summary.active_id;
310310
}
311311
for (let port = 0; port < __state.model.ports.length; ++port) {
312312
__setLedState($(`__switch-port-led-p${port}`), "green", (port === active));
@@ -361,7 +361,7 @@ export function Switch() {
361361
content += `
362362
<tr>
363363
<td>Port:</td>
364-
<td class="value">${__formatPort(model, port)}</td>
364+
<td class="value">${pa.id}</td>
365365
<td>&nbsp;&nbsp;</td>
366366
<td>
367367
<div class="buttons-row">
@@ -541,7 +541,7 @@ export function Switch() {
541541
}
542542
};
543543

544-
wm.modal(`Port ${__formatPort(__state.model, port)} settings`, create_content, true, true).then(function(ok) {
544+
wm.modal(`Port ${__state.model.ports[port].id} settings`, create_content, true, true).then(function(ok) {
545545
if (ok) {
546546
let params = {
547547
"port": port,
@@ -557,14 +557,6 @@ export function Switch() {
557557
});
558558
};
559559

560-
var __formatPort = function(model, port) {
561-
if (model.units.length > 1) {
562-
return `${model.ports[port].unit + 1}.${model.ports[port].channel + 1}`;
563-
} else {
564-
return `${port + 1}`;
565-
}
566-
};
567-
568560
var __setLedState = function(el, color, on) {
569561
el.classList.toggle(`led-${color}`, on);
570562
el.classList.toggle("led-gray", !on);

0 commit comments

Comments
 (0)