Skip to content

Commit

Permalink
Add progress bar for salt updates
Browse files Browse the repository at this point in the history
  • Loading branch information
CameronRP committed Jul 8, 2024
1 parent 880ebd4 commit ef5cf20
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/TheCacophonyProject/go-cptv v0.0.0-20201215230510-ae7134e91a71
github.com/TheCacophonyProject/lepton3 v0.0.0-20211005194419-22311c15d6ee
github.com/TheCacophonyProject/rtc-utils v1.2.0
github.com/TheCacophonyProject/salt-updater v0.4.0
github.com/TheCacophonyProject/salt-updater v0.8.0
github.com/gobuffalo/packr v1.30.1
github.com/godbus/dbus v4.1.0+incompatible
github.com/gorilla/mux v1.8.0
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ github.com/TheCacophonyProject/audiobait/v3 v3.0.1 h1:7MGtBVqwuxLs4Tuw3VUQy1z/vc
github.com/TheCacophonyProject/audiobait/v3 v3.0.1/go.mod h1:EDM0fyF6oHPUmtOfY4QsLmOL4mfpLOtsngaQfHbttKk=
github.com/TheCacophonyProject/event-reporter v1.3.2-0.20200210010421-ca3fcb76a231 h1:nLqfSx3zDBzghlP/S8X2j/WRtW0e3BZvSkMm1J/Fa8U=
github.com/TheCacophonyProject/event-reporter v1.3.2-0.20200210010421-ca3fcb76a231/go.mod h1:kei6S/4x+VHp5yiwYPqvcNnhuRpZ8iLsh95Sue6kPvc=
github.com/TheCacophonyProject/event-reporter/v3 v3.2.1/go.mod h1:0ejh8kTFM9iC3/Q+etu7Hf4XivPu35PDH5oQ1XY3KNU=
github.com/TheCacophonyProject/event-reporter/v3 v3.3.0/go.mod h1:dGIYfhABsJHKjcsxtftDwpdcfLOWTYKeIyCYxCOIMrc=
github.com/TheCacophonyProject/event-reporter/v3 v3.7.0 h1:B+a5PXqBh7Bkf2HDo+j94Ascqw6SCTlOhSN9TXZfjY8=
github.com/TheCacophonyProject/event-reporter/v3 v3.7.0/go.mod h1:WTppJtTBxduasM1Or5SAh4Mm0YrTDnprOChjnGYgyEI=
Expand Down Expand Up @@ -83,8 +82,8 @@ github.com/TheCacophonyProject/rpi-net-manager v0.4.0-deb12 h1:0EowolSaXYxt8DOlV
github.com/TheCacophonyProject/rpi-net-manager v0.4.0-deb12/go.mod h1:6Xl1Dp7F8IyvufOv0O5EfoXQjqoA/qNLeoWh3Rv1Y0c=
github.com/TheCacophonyProject/rtc-utils v1.2.0 h1:570sPJE/s0b21NrP9VVeSI/gBh/dLK+G5Ne/ZFwkNv0=
github.com/TheCacophonyProject/rtc-utils v1.2.0/go.mod h1:uV1SIy93TLZrrBcqDczUNFUz2G/Pk6pZNUdTRglmANU=
github.com/TheCacophonyProject/salt-updater v0.4.0 h1:2RCgdI4wr/ZoeWOvfGlZ/Epgz3GTC+Vc7/wS6EI90c0=
github.com/TheCacophonyProject/salt-updater v0.4.0/go.mod h1:fVlMqJZpvT8HeT4GcmQlvMq8+AtvF4NZ/LuEVSoA5E8=
github.com/TheCacophonyProject/salt-updater v0.8.0 h1:boiKcKXTtR4+VxADKza9DGD8zj15AfZOB4DbkqNphUM=
github.com/TheCacophonyProject/salt-updater v0.8.0/go.mod h1:jzmJe2yOF4Vme6Mj7RL9S4VyTTceY7dsAVdSMW/91UE=
github.com/TheCacophonyProject/trap-controller v0.0.0-20230227002937-262a1adfaa47 h1:QSQnyDIk04eLq1FcegZbA4nF3QtBU+co0VX/g94u8I8=
github.com/TheCacophonyProject/trap-controller v0.0.0-20230227002937-262a1adfaa47/go.mod h1:tGi6Qpp0vY9ycT9AM+a0/5DMW5kkvS2ofe7pdRMFqoU=
github.com/TheCacophonyProject/window v0.0.0-20190821235241-ab92c2ee24b6/go.mod h1:Vww417iimOb0s46Ndsm8U/vYtwc0dZUet4uW8QzBo4M=
Expand All @@ -96,7 +95,6 @@ github.com/alexflint/go-arg v0.0.0-20180516182405-f7c0423bd11e/go.mod h1:PHxo6ZW
github.com/alexflint/go-arg v1.0.0/go.mod h1:Cto8k5VtkP4pp0EXiWD4ZJMFOOinZ38ggVcQ/6CGuRI=
github.com/alexflint/go-arg v1.1.0/go.mod h1:3Rj4baqzWaGGmZA2+bVTV8zQOZEjBQAPBnL5xLT+ftY=
github.com/alexflint/go-arg v1.2.0/go.mod h1:3Rj4baqzWaGGmZA2+bVTV8zQOZEjBQAPBnL5xLT+ftY=
github.com/alexflint/go-arg v1.3.0/go.mod h1:9iRbDxne7LcR/GSvEr7ma++GLpdIU1zrghf2y2768kM=
github.com/alexflint/go-arg v1.4.2/go.mod h1:9iRbDxne7LcR/GSvEr7ma++GLpdIU1zrghf2y2768kM=
github.com/alexflint/go-scalar v1.0.0/go.mod h1:GpHzbCOZXEKMEcygYQ5n/aa4Aq84zbxjy3MxYW0gjYw=
github.com/alexflint/go-scalar v1.1.0/go.mod h1:LoFvNMqS1CPrMVltza4LvnGKhaSpc3oyLEBUZVhhS2o=
Expand Down
9 changes: 9 additions & 0 deletions html/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ <h3>Device<br></h3>
<label class="form-check-label" for="auto-update-checkbox">AutoUpdate</label>
</div>

<div class="row">
<p class="col-2 text-left">Salt update progress:</p>
<p id="salt-update-progress" class="col-9 monospace"></p>
</div>
<div class="row">
<p class="col-2 text-left">Salt update state:</p>
<p id="salt-update-progress-text" class="col-9 monospace"></p>
</div>

<div class="row">
<p class="col-2 text-left">Running Salt Command:</p>
<p id="running-salt-command" class="col-9 monospace"></p>
Expand Down
21 changes: 18 additions & 3 deletions static/js/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function runSaltUpdate() {
if (xmlHttp.status == 200) {
$("#salt-update-button").attr("disabled", true);
$("#salt-update-button").html("Running Salt Update...");
pollSaltUpdateState();
setTimeout(updateSaltState, 2000);
} else {
console.log(response);
}
Expand Down Expand Up @@ -117,10 +117,18 @@ async function updateSaltState() {
});

if (response.ok) {
var jsonString = await response.text();
var data = JSON.parse(await response.text());

var data = JSON.parse(jsonString);
if (data.RunningUpdate) {
document.getElementById("salt-update-button").setAttribute("disabled", true);
document.getElementById("salt-update-button").textContent = "Running Salt Update...";
setTimeout(updateSaltState, 2000);
} else {
enableSaltButton();
}

document.getElementById("salt-update-progress").textContent = data.UpdateProgressPercentage;
document.getElementById("salt-update-progress-text").textContent = data.UpdateProgressStr;
document.getElementById("running-salt-command").textContent =
data.RunningUpdate ? "Yes" : "No";
document.getElementById("running-salt-arguements").textContent =
Expand All @@ -135,13 +143,20 @@ async function updateSaltState() {
} else {
alert("Error updating salt");
console.error("Error with response:", await response.text());
enableSaltButton();
}
} catch (error) {
alert("Error updating salt");
console.error("Error with fetching salt update:", error);
enableSaltButton();
}
}

function enableSaltButton() {
document.getElementById("salt-update-button").removeAttribute("disabled");
document.getElementById("salt-update-button").textContent = "Run Salt Update...";
}

var runningSaltUpdate = true;
// Check salt update state. Returns true if it is no longer running
function checkSaltUpdateState() {
Expand Down

0 comments on commit ef5cf20

Please sign in to comment.