diff --git a/src/rust/lqosd/src/node_manager/js_build/src/config_lts.js b/src/rust/lqosd/src/node_manager/js_build/src/config_lts.js index 0b538668..daf17797 100644 --- a/src/rust/lqosd/src/node_manager/js_build/src/config_lts.js +++ b/src/rust/lqosd/src/node_manager/js_build/src/config_lts.js @@ -1,4 +1,44 @@ -import {loadConfig} from "./config/config_helper"; +import {saveConfig, loadConfig} from "./config/config_helper"; + +function validateConfig() { + // Validate numeric fields + const collationPeriod = parseInt(document.getElementById("collationPeriod").value); + if (isNaN(collationPeriod) || collationPeriod < 1) { + alert("Collation Period must be a number greater than 0"); + return false; + } + + const uispInterval = parseInt(document.getElementById("uispInterval").value); + if (isNaN(uispInterval) || uispInterval < 0) { + alert("UISP Reporting Interval must be a number of at least 0"); + return false; + } + + // Validate URL format if provided + const ltsUrl = document.getElementById("ltsUrl").value.trim(); + if (ltsUrl) { + try { + new URL(ltsUrl); + } catch { + alert("LTS Server URL must be a valid URL"); + return false; + } + } + + return true; +} + +function updateConfig() { + // Update only the long-term stats section + window.config.long_term_stats = { + gather_stats: document.getElementById("gatherStats").checked, + collation_period_seconds: parseInt(document.getElementById("collationPeriod").value), + license_key: document.getElementById("licenseKey").value.trim() || null, + uisp_reporting_interval_seconds: parseInt(document.getElementById("uispInterval").value) || null, + lts_url: document.getElementById("ltsUrl").value.trim() || null, + use_insight: document.getElementById("useInsight").checked + }; +} loadConfig(() => { // window.config now contains the configuration. @@ -11,16 +51,22 @@ loadConfig(() => { document.getElementById("useInsight").checked = lts.use_insight ?? false; // Numeric fields - if (lts.collation_period_seconds) { - document.getElementById("collationPeriod").value = lts.collation_period_seconds; - } - if (lts.uisp_reporting_interval_seconds) { - document.getElementById("uispInterval").value = lts.uisp_reporting_interval_seconds; - } + document.getElementById("collationPeriod").value = lts.collation_period_seconds ?? 60; + document.getElementById("uispInterval").value = lts.uisp_reporting_interval_seconds ?? 300; // Optional string fields document.getElementById("licenseKey").value = lts.license_key ?? ""; document.getElementById("ltsUrl").value = lts.lts_url ?? ""; + + // Add save button click handler + document.getElementById('saveButton').addEventListener('click', () => { + if (validateConfig()) { + updateConfig(); + saveConfig(() => { + alert("Configuration saved successfully!"); + }); + } + }); } else { console.error("Long-term stats configuration not found in window.config"); } diff --git a/src/rust/lqosd/src/node_manager/static2/config_lts.html b/src/rust/lqosd/src/node_manager/static2/config_lts.html index 9c8a8b93..16ce80aa 100644 --- a/src/rust/lqosd/src/node_manager/static2/config_lts.html +++ b/src/rust/lqosd/src/node_manager/static2/config_lts.html @@ -60,7 +60,7 @@
Experimental next-gen statistics system (alpha)
- +