Skip to content

Commit

Permalink
Ping, cleanup options
Browse files Browse the repository at this point in the history
  • Loading branch information
veniware committed Feb 25, 2024
1 parent 04d1060 commit 3da2bad
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 15 deletions.
18 changes: 9 additions & 9 deletions Protest/Front/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ class Monitor extends Window {
if (this.chartsList[i].index !== message.index) { continue; }

if (this.chartsList[i].options.type === "percents") {
this.chartsList[i].Update(message.value);
this.chartsList[i].Update(message.data);
}
else {
this.chartsList[i].Update(parseInt(message.value));
this.chartsList[i].Update(parseInt(message.data));
}
break;
}
Expand Down Expand Up @@ -787,20 +787,20 @@ class Monitor extends Window {
}
};

const Update = value=> {
const Update = data=> {
if (list.length * gap > 800) list.shift();
list.push(value);
list.push(data);

if (value > 0) {
if (min > value) { min = value; }
if (max < value) { max = value; }
if (data > 0) {
if (min > data) { min = data; }
if (max < data) { max = data; }
}

if (value < 0) {
if (data < 0) {
valueLabel.textContent = `${options.prefix}: --`;
}
else {
valueLabel.textContent = `${options.prefix}: ${value}${options.unit}`;
valueLabel.textContent = `${options.prefix}: ${data}${options.unit}`;
}

if (max >= 0) {
Expand Down
64 changes: 60 additions & 4 deletions Protest/Front/ping.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,36 @@ class Ping extends Console {
this.playButton = this.AddToolbarButton("Start", "mono/play.svg?light");
this.pauseButton = this.AddToolbarButton("Pause", "mono/pause.svg?light");
this.toolbar.appendChild(this.AddToolbarSeparator());
this.clearButton = this.AddToolbarButton("Clear", "mono/wing.svg?light");
this.clearDropDown = this.AddToolbarDropdown("mono/wing.svg?light");
this.copyButton = this.AddToolbarButton("Copy", "mono/copy.svg?light");
this.optionsButton = this.AddToolbarButton("Options", "mono/wrench.svg?light");
this.toolbar.appendChild(this.AddToolbarSeparator());
this.AddSendToChatButton();

const optionRemoveAll = document.createElement("div");
optionRemoveAll.style.padding = "4px 8px";
optionRemoveAll.textContent = "Clear";
this.clearDropDown.list.append(optionRemoveAll);

const optionRemoveReachable = document.createElement("div");
optionRemoveReachable.style.padding = "4px 8px";
optionRemoveReachable.textContent = "Remove reachable";
this.clearDropDown.list.append(optionRemoveReachable);

const optionRemoveUnreachable = document.createElement("div");
optionRemoveUnreachable.style.padding = "4px 8px";
optionRemoveUnreachable.textContent = "Remove unreachable";
this.clearDropDown.list.append(optionRemoveUnreachable);

this.playButton.disabled = this.params.status === "play";
this.pauseButton.disabled = this.params.status === "pause";

if (this.params.entries) { //restore entries from previous session
let temp = this.params.entries;
this.params.entries = [];
for (let i = 0; i < temp.length; i++)
for (let i=0; i<temp.length; i++) {
this.Push(temp[i]);
}
}

this.playButton.addEventListener("click", ()=> {
Expand All @@ -64,8 +80,8 @@ class Ping extends Console {
}
});

this.clearButton.addEventListener("click", ()=> {
const btnOK = this.ConfirmBox("Are you sure you want to clear the list?");
optionRemoveAll.addEventListener("click", ()=> {
const btnOK = this.ConfirmBox("Are you sure you want to clear the list?", false, "mono/wing.svg");
if (btnOK) btnOK.addEventListener("click", ()=> {
this.playButton.disabled = true;
this.pauseButton.disabled = true;
Expand All @@ -78,6 +94,46 @@ class Ping extends Console {
});
});

optionRemoveReachable.addEventListener("click", ()=> {
const btnOK = this.ConfirmBox("Are you sure you want to remove all reachable hosts?", false, "mono/wing.svg");
if (btnOK) btnOK.addEventListener("click", ()=> {
let split = this.request.split(";");
for (let i = 0; i < split.length; i++) {
if (split[i].length === 0) continue;

let isReachable = this.hashtable[split[i]].ping.filter(o=>o!==-1).some(o=>!isNaN(o));
if (isReachable) {
this.Remove(this.hashtable[split[i]].host);
}
}

if (Object.keys(this.hashtable).length === 0) {
this.playButton.disabled = true;
this.pauseButton.disabled = true;
}
});
});

optionRemoveUnreachable.addEventListener("click", ()=> {
const btnOK = this.ConfirmBox("Are you sure you want to remove all unreachable hosts?", false, "mono/wing.svg");
if (btnOK) btnOK.addEventListener("click", ()=> {
let split = this.request.split(";");
for (let i = 0; i < split.length; i++) {
if (split[i].length === 0) continue;

let isUnreachable = this.hashtable[split[i]].ping.filter(o=>o!==-1).every(o=>isNaN(o));
if (isUnreachable) {
this.Remove(this.hashtable[split[i]].host);
}
}

if (Object.keys(this.hashtable).length === 0) {
this.playButton.disabled = true;
this.pauseButton.disabled = true;
}
});
});

this.copyButton.addEventListener("click", ()=> {
let paramsCopy = structuredClone(this.params);
paramsCopy.status = "pause";
Expand Down
2 changes: 1 addition & 1 deletion Protest/Protest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<verDoty>$([System.DateTime]::UtcNow.DayOfYear)</verDoty>

<VersionPrefix>5.0.$(verYear).$(verDoty)</VersionPrefix>
<!--<VersionSuffix>beta</VersionSuffix>-->
<VersionSuffix>beta</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<Version>$(VersionPrefix)</Version>

Expand Down
2 changes: 1 addition & 1 deletion Protest/Tools/Monitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public static async void WebSocketHandler(HttpListenerContext ctx) {

if (ping) {
long icmpResult = HandlePing(target, Math.Min(interval, 1000));
await WsWriteText(ws, $"{{\"index\":0,\"value\":{icmpResult}}}");
await WsWriteText(ws, $"{{\"index\":0,\"data\":{icmpResult}}}");
}

long elapsedTime = (DateTime.UtcNow.Ticks - startTime) / 10_000;
Expand Down

0 comments on commit 3da2bad

Please sign in to comment.