diff --git a/Protest/Front/monitor.js b/Protest/Front/monitor.js index 6a3d4777..72a23fff 100644 --- a/Protest/Front/monitor.js +++ b/Protest/Front/monitor.js @@ -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; } @@ -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) { diff --git a/Protest/Front/ping.js b/Protest/Front/ping.js index 00b5e817..e5a1817e 100644 --- a/Protest/Front/ping.js +++ b/Protest/Front/ping.js @@ -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 { @@ -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; @@ -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"; diff --git a/Protest/Protest.csproj b/Protest/Protest.csproj index 6fa5b845..101e5c31 100644 --- a/Protest/Protest.csproj +++ b/Protest/Protest.csproj @@ -29,7 +29,7 @@ $([System.DateTime]::UtcNow.DayOfYear) 5.0.$(verYear).$(verDoty) - + beta $(VersionPrefix) $(VersionPrefix) diff --git a/Protest/Tools/Monitor.cs b/Protest/Tools/Monitor.cs index 64ba0e95..c1fbc831 100644 --- a/Protest/Tools/Monitor.cs +++ b/Protest/Tools/Monitor.cs @@ -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;