Skip to content

Commit ba74268

Browse files
committed
Device, multiple uplinks
1 parent 62c5492 commit ba74268

File tree

4 files changed

+81
-58
lines changed

4 files changed

+81
-58
lines changed

Protest/Front/topology.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
height: 32px;
3939
border-bottom: 1px solid var(--clr-control);
4040
}
41+
.topology-find-listitem:last-child {
42+
border-bottom: 1px solid transparent;
43+
}
4144

4245
.topology-find-listitem:hover {
4346
background-color: var(--clr-highlight);

Protest/Front/topology.js

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class Topology extends Window {
130130
this.content.onmouseup = event=> this.Topology_onmouseup(event);
131131

132132
this.startButton.onclick = ()=> this.StartDialog();
133-
this.syncButton.onclick = ()=> this.UpdateDeviceUplink();
133+
this.syncButton.onclick = ()=> this.UpdateDeviceUplinkDialog();
134134
this.findButton.onclick = ()=> this.FindMode();
135135
this.vlanButton.onclick = ()=> this.VlanMode();
136136
this.trafficButton.onclick = ()=> this.TrafficMode();
@@ -2698,7 +2698,7 @@ class Topology extends Window {
26982698
updateDbButton.style.backgroundImage = "url(mono/upload.svg)";
26992699
optionsBox.appendChild(updateDbButton);
27002700

2701-
updateDbButton.onclick = ()=> this.UpdateDeviceUplink(file);
2701+
updateDbButton.onclick = ()=> this.UpdateDeviceUplinkDialog(file);
27022702
}
27032703

27042704
const overwriteProtocol = {};
@@ -2900,12 +2900,12 @@ class Topology extends Window {
29002900
}
29012901
}
29022902

2903-
UpdateDeviceUplink(target="*") {
2903+
UpdateDeviceUplinkDialog(target="*") {
29042904
const dialog = this.DialogBox("calc(100% - 40px)");
29052905
if (dialog === null) return;
29062906

29072907
const {okButton, innerBox} = dialog;
2908-
okButton.value = "Sync database uplinks";
2908+
okButton.value = "Save uplinks to Devices";
29092909

29102910
innerBox.parentElement.style.maxWidth = "720px";
29112911

@@ -2914,7 +2914,7 @@ class Topology extends Window {
29142914
innerBox.style.margin = "20px 20px 8px 20px";
29152915

29162916
const list = [];
2917-
2917+
29182918
for (const file in this.devices) {
29192919
if (target !== "*" && file !== target) continue;
29202920

@@ -2923,6 +2923,8 @@ class Topology extends Window {
29232923
if (device.isUnmanaged) continue;
29242924
if (!device.lldp || device.lldp.localPortName === 0) continue;
29252925

2926+
const type = device.initial.type.toLowerCase();
2927+
29262928
const switchBox = document.createElement("div");
29272929
switchBox.style.border = "2px solid var(--clr-control)";
29282930
switchBox.style.borderRadius = "4px";
@@ -2932,7 +2934,11 @@ class Topology extends Window {
29322934
titleBox.textContent = device.initial.hostname;
29332935
titleBox.style.fontWeight = "bold";
29342936
titleBox.style.backgroundColor = "var(--clr-control)";
2935-
titleBox.style.padding = "4px";
2937+
titleBox.style.padding = "4px 4px 4px 32px";
2938+
titleBox.style.backgroundImage = `url(${type in LOADER.deviceIcons ? LOADER.deviceIcons[type] : "mono/gear.svg"})`;
2939+
titleBox.style.backgroundSize = "24px 24px";
2940+
titleBox.style.backgroundPosition = "2px 50%";
2941+
titleBox.style.backgroundRepeat = "no-repeat";
29362942

29372943
const contentBox = document.createElement("div");
29382944

@@ -2978,6 +2984,7 @@ class Topology extends Window {
29782984
deviceLabel.style.overflow = "hidden";
29792985
deviceLabel.style.textOverflow = "ellipsis";
29802986
deviceLabel.style.whiteSpace = "nowrap";
2987+
deviceLabel.style.userSelect = "text";
29812988
newItem.appendChild(deviceLabel);
29822989

29832990
if ("hostname" in dbEntry && dbEntry.hostname.v.length > 0) {
@@ -2999,11 +3006,14 @@ class Topology extends Window {
29993006
}
30003007

30013008
list.push({
3009+
uplink: file,
30023010
toggle: toggle,
30033011
file : entry[i],
30043012
port : portName
30053013
});
30063014

3015+
deviceLabel.onclick = event=> event.stopPropagation();
3016+
30073017
newItem.onclick = ()=> {
30083018
toggle.checkbox.checked = !toggle.checkbox.checked;
30093019
};
@@ -3020,18 +3030,24 @@ class Topology extends Window {
30203030
for (let i=0; i<list.length; i++) {
30213031
if (!list[i].toggle.checkbox.checked) continue;
30223032

3023-
mods[list[i].file] = {
3024-
uplink: JSON.stringify({
3025-
device: file,
3026-
port: list[i].port
3027-
})
3028-
};
3033+
if (!mods[list[i].file]) {
3034+
mods[list[i].file] = [];
3035+
}
3036+
3037+
mods[list[i].file].push({
3038+
device: list[i].uplink,
3039+
port: list[i].port
3040+
});
3041+
}
3042+
3043+
for (const file in mods) {
3044+
mods[file] = { "uplink": JSON.stringify(mods[file]) };
30293045
}
30303046

30313047
try {
30323048
const response = await fetch("db/device/grid", {
30333049
method: "POST",
3034-
body : JSON.stringify(mods)
3050+
body: JSON.stringify(mods)
30353051
});
30363052

30373053
if (response.status !== 200) LOADER.HttpErrorHandler(response.status);

Protest/Front/view.js

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -315,56 +315,60 @@ class View extends Window {
315315
try {
316316
const json = JSON.parse(value);
317317

318-
const device = LOADER.devices.data[json.device];
319-
const port = json.port;
318+
for (let i=0; i<json.length; i++) {
319+
const device = LOADER.devices.data[json[i].device];
320+
const port = json[i].port;
320321

321-
if (!json.device || json.device.length === 0 || !device) {
322-
throw "device not found";
323-
}
322+
valueBox.style.display = "none";
324323

325-
valueBox.style.display = "none";
324+
const deviceButton = document.createElement("button");
325+
deviceButton.style.height = "32px";
326+
deviceButton.style.paddingLeft = "1px";
327+
deviceButton.style.paddingRight = "1px";
328+
deviceButton.style.margin = "2px";
329+
deviceButton.style.color = "var(--clr-dark)";
330+
deviceButton.style.backgroundColor = "transparent";
331+
deviceButton.style.whiteSpace = "nowrap";
332+
valueContainer.appendChild(deviceButton);
326333

327-
const deviceButton = document.createElement("button");
328-
deviceButton.style.height = "40px";
329-
deviceButton.style.paddingLeft = "4px";
330-
deviceButton.style.paddingRight = "4px";
331-
deviceButton.style.color = "var(--clr-dark)";
332-
deviceButton.style.backgroundColor = "transparent";
333-
deviceButton.style.whiteSpace = "nowrap";
334-
valueContainer.appendChild(deviceButton);
334+
deviceButton.onclick = ()=> LOADER.OpenDeviceByFile(json[i].device);
335335

336-
deviceButton.onclick = ()=> LOADER.OpenDeviceByFile(json.device);
336+
const deviceBox = document.createElement("div");
337+
deviceBox.style.backgroundSize = "24px 24px";
338+
deviceBox.style.borderRadius = "4px 0 0 4px";
339+
deviceBox.style.marginRight = "1px";
337340

338-
const deviceBox = document.createElement("div");
339-
const portBox = document.createElement("div");
340-
deviceBox.style.marginRight = "4px";
341-
deviceBox.style.padding = portBox.style.padding = "6px 4px 6px 32px";
342-
deviceBox.style.display = portBox.style.display = "inline-block";
343-
deviceBox.style.backgroundSize = portBox.style.backgroundSize = "24px 24px";
344-
deviceBox.style.backgroundPosition = portBox.style.backgroundPosition = "4px 50%";
345-
deviceBox.style.backgroundRepeat = portBox.style.backgroundRepeat = "no-repeat";
346-
deviceBox.style.border = portBox.style.border = "1px solid var(--clr-dark)";
347-
deviceBox.style.borderRadius = portBox.style.borderRadius = "4px";
341+
const portBox = document.createElement("div");
342+
portBox.style.backgroundSize = "28px 28px";
343+
portBox.style.borderRadius = "0 4px 4px 0";
348344

349-
deviceButton.append(deviceBox, portBox);
345+
deviceBox.style.padding = portBox.style.padding = "4px 8px 4px 32px";
346+
deviceBox.style.display = portBox.style.display = "inline-block";
347+
deviceBox.style.backgroundPosition = portBox.style.backgroundPosition = "2px 50%";
348+
deviceBox.style.backgroundRepeat = portBox.style.backgroundRepeat = "no-repeat";
349+
deviceBox.style.border = portBox.style.border = "1px solid var(--clr-dark)";
350350

351-
deviceBox.style.backgroundImage = "url(mono/switch.svg)";
351+
deviceButton.append(deviceBox, portBox);
352352

353-
if (device.name && device.name.v.length > 0) {
354-
deviceBox.textContent = device.name.v;
355-
}
356-
else if (device.hostname && device.hostname.v.length > 0) {
357-
deviceBox.textContent = device.hostname.v;
358-
}
359-
else if (device.ip && device.ip.v.length > 0) {
360-
deviceBox.textContent = device.ip.v;
361-
}
362-
else {
363-
deviceBox.textContent = "Device";
364-
}
353+
deviceBox.style.backgroundImage = "url(mono/switch.svg)";
365354

366-
portBox.textContent = port;
367-
portBox.style.backgroundImage = "url(mono/ethernetport.svg)";
355+
if (device.name && device.name.v.length > 0) {
356+
deviceBox.textContent = device.name.v;
357+
}
358+
else if (device.hostname && device.hostname.v.length > 0) {
359+
deviceBox.textContent = device.hostname.v;
360+
}
361+
else if (device.ip && device.ip.v.length > 0) {
362+
deviceBox.textContent = device.ip.v;
363+
}
364+
else {
365+
deviceBox.textContent = "Device";
366+
}
367+
368+
portBox.textContent = port;
369+
portBox.style.backgroundImage = "url(mono/ethernetport.svg)";
370+
371+
}
368372

369373
}
370374
catch (ex) {

Protest/Protest.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
2+
33
<PropertyGroup>
44
<Product>Pro-test</Product>
55
<AssemblyName>protest</AssemblyName>
@@ -53,11 +53,11 @@
5353
</ItemGroup>
5454

5555
<ItemGroup>
56-
<PackageReference Include="System.DirectoryServices" Version="9.0.10" />
57-
<PackageReference Include="System.Management" Version="9.0.10" />
56+
<PackageReference Include="System.DirectoryServices" Version="10.0.2" />
57+
<PackageReference Include="System.Management" Version="10.0.2" />
5858
<PackageReference Include="Yarp.ReverseProxy" Version="2.3.0" />
5959
<PackageReference Include="SSH.NET" Version="2025.1.0" />
60-
<PackageReference Include="Lextm.SharpSnmpLib" Version="12.5.6" />
60+
<PackageReference Include="Lextm.SharpSnmpLib" Version="12.5.7" />
6161
</ItemGroup>
6262

6363
</Project>

0 commit comments

Comments
 (0)