From 490c6856a046cfed06d9089379feeaaf139b157e Mon Sep 17 00:00:00 2001 From: Herbert Wolverson Date: Wed, 3 Jul 2024 11:38:10 -0500 Subject: [PATCH] Semi-functional placeholder for the Shaped Devices page. --- .../src/node_manager/js_build/esbuild.sh | 2 +- .../js_build/src/shaped-devices.js | 33 +++++++++++++++++++ src/rust/lqosd/src/node_manager/local_api.rs | 2 ++ .../local_api/shaped_device_api.rs | 7 ++++ .../node_manager/static2/shaped_devices.html | 12 +++++++ .../src/node_manager/static2/template.html | 6 ++-- .../lqosd/src/node_manager/static_pages.rs | 10 +++--- 7 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 src/rust/lqosd/src/node_manager/js_build/src/shaped-devices.js create mode 100644 src/rust/lqosd/src/node_manager/local_api/shaped_device_api.rs create mode 100644 src/rust/lqosd/src/node_manager/static2/shaped_devices.html diff --git a/src/rust/lqosd/src/node_manager/js_build/esbuild.sh b/src/rust/lqosd/src/node_manager/js_build/esbuild.sh index 0e9638a3..4919bd06 100755 --- a/src/rust/lqosd/src/node_manager/js_build/esbuild.sh +++ b/src/rust/lqosd/src/node_manager/js_build/esbuild.sh @@ -1,6 +1,6 @@ #!/bin/bash set -e -scripts=( index.js template.js login.js first-run.js ) +scripts=( index.js template.js login.js first-run.js shaped-devices.js ) for script in "${scripts[@]}" do echo "Building {$script}" diff --git a/src/rust/lqosd/src/node_manager/js_build/src/shaped-devices.js b/src/rust/lqosd/src/node_manager/js_build/src/shaped-devices.js new file mode 100644 index 00000000..4ed0ee78 --- /dev/null +++ b/src/rust/lqosd/src/node_manager/js_build/src/shaped-devices.js @@ -0,0 +1,33 @@ +import {simpleRow, theading} from "./helpers/builders"; + +function loadDevices() { + $.get("/local-api/devicesAll", (data) => { + console.log(data); + let table = document.createElement("table"); + table.classList.add("table", "table-striped"); + let thead = document.createElement("thead"); + thead.appendChild(theading("Circuit")); + thead.appendChild(theading("Device")); + thead.appendChild(theading("Plans")); + thead.appendChild(theading("IP")); + table.appendChild(thead); + let tb = document.createElement("tbody"); + data.forEach((d) => { + let tr = document.createElement("tr"); + tr.appendChild(simpleRow(d.circuit_name)); + tr.appendChild(simpleRow(d.device_name)); + tr.appendChild(simpleRow(d.download_max_mbps + " / " + d.upload_max_mbps)); + tr.appendChild(simpleRow("")); + tb.append(tr); + }) + table.appendChild(tb); + + let target = document.getElementById("deviceTable"); + while (target.children.length > 0) { + target.removeChild(target.lastChild); + } + target.appendChild(table); + }) +} + +loadDevices(); \ No newline at end of file diff --git a/src/rust/lqosd/src/node_manager/local_api.rs b/src/rust/lqosd/src/node_manager/local_api.rs index 0ff0d8b3..a5cb3d44 100644 --- a/src/rust/lqosd/src/node_manager/local_api.rs +++ b/src/rust/lqosd/src/node_manager/local_api.rs @@ -1,6 +1,7 @@ mod dashboard_themes; mod version_check; mod device_counts; +mod shaped_device_api; use axum::Router; use axum::routing::{get, post}; @@ -13,4 +14,5 @@ pub fn local_api() -> Router { .route("/dashletGet", post(dashboard_themes::get_theme)) .route("/versionCheck", get(version_check::version_check)) .route("/deviceCount", get(device_counts::count_users)) + .route("/devicesAll", get(shaped_device_api::all_shaped_devices)) } \ No newline at end of file diff --git a/src/rust/lqosd/src/node_manager/local_api/shaped_device_api.rs b/src/rust/lqosd/src/node_manager/local_api/shaped_device_api.rs new file mode 100644 index 00000000..21d4253a --- /dev/null +++ b/src/rust/lqosd/src/node_manager/local_api/shaped_device_api.rs @@ -0,0 +1,7 @@ +use axum::Json; +use lqos_config::ShapedDevice; +use crate::shaped_devices_tracker::SHAPED_DEVICES; + +pub async fn all_shaped_devices() -> Json> { + Json(SHAPED_DEVICES.read().unwrap().devices.clone()) +} \ No newline at end of file diff --git a/src/rust/lqosd/src/node_manager/static2/shaped_devices.html b/src/rust/lqosd/src/node_manager/static2/shaped_devices.html new file mode 100644 index 00000000..490bae9d --- /dev/null +++ b/src/rust/lqosd/src/node_manager/static2/shaped_devices.html @@ -0,0 +1,12 @@ +
+
+
Shaped Devices
+
+
+
+ Loading, Please Wait... +
+
+
+ + \ No newline at end of file diff --git a/src/rust/lqosd/src/node_manager/static2/template.html b/src/rust/lqosd/src/node_manager/static2/template.html index 31977e99..fa839d30 100644 --- a/src/rust/lqosd/src/node_manager/static2/template.html +++ b/src/rust/lqosd/src/node_manager/static2/template.html @@ -24,7 +24,7 @@