diff --git a/internal/web/public/js/refresh.js b/internal/web/public/js/refresh.js new file mode 100644 index 0000000..f70ab6a --- /dev/null +++ b/internal/web/public/js/refresh.js @@ -0,0 +1,21 @@ +let ref = false; +let refInterval; + +autoRefresh(); + +function toggleRefresh() { + ref = !ref; + + autoRefresh() +} + +function autoRefresh() { + + if (ref) { + const timeout = document.getElementById("ref-timeout").value; + console.log("Refresh timeout", timeout); + refInterval = setInterval(loadAddrs, timeout * 1000); + } else { + clearInterval(refInterval); + } +} \ No newline at end of file diff --git a/internal/web/public/js/sort.js b/internal/web/public/js/sort.js index 8bdbd61..75c37af 100644 --- a/internal/web/public/js/sort.js +++ b/internal/web/public/js/sort.js @@ -17,11 +17,7 @@ function sortByAny(someArray, field) { if (field != oldField) { if (field == 'IP') { - someArray.sort((a, b) => { - const num1 = Number(a.IP.split(".").map((num) => (`000${num}`).slice(-3) ).join("")); - const num2 = Number(b.IP.split(".").map((num) => (`000${num}`).slice(-3) ).join("")); - return num1-num2; - }); + someArray.sort((a, b) => sortIP(a, b, true)); } else { someArray.sort(byFieldDown(field)); } @@ -30,11 +26,7 @@ function sortByAny(someArray, field) { } else { if (field == 'IP') { - someArray.sort((a, b) => { - const num1 = Number(a.IP.split(".").map((num) => (`000${num}`).slice(-3) ).join("")); - const num2 = Number(b.IP.split(".").map((num) => (`000${num}`).slice(-3) ).join("")); - return num2-num1; - }); + someArray.sort((a, b) => sortIP(a, b, false)); } else { someArray.sort(byFieldUp(field)); } @@ -51,4 +43,15 @@ function byFieldUp(fieldName){ function byFieldDown(fieldName){ return (a, b) => a[fieldName] > b[fieldName] ? 1 : -1; +} + +function sortIP(a, b, down) { + const num1 = Number(a.IP.split(".").map((num) => (`000${num}`).slice(-3) ).join("")); + const num2 = Number(b.IP.split(".").map((num) => (`000${num}`).slice(-3) ).join("")); + if (down) { + return num1-num2; + } else { + return num2-num1; + } + } \ No newline at end of file diff --git a/internal/web/templates/index.html b/internal/web/templates/index.html index f9582b8..525516a 100644 --- a/internal/web/templates/index.html +++ b/internal/web/templates/index.html @@ -3,14 +3,21 @@ +