From b2228141ccce0e3d88b51d42e6b67214a7a2735d Mon Sep 17 00:00:00 2001 From: "Herbert Wolverson (aider)" Date: Wed, 22 Jan 2025 14:44:19 -0600 Subject: [PATCH] feat: add save functionality and validation to sonar config --- .../node_manager/js_build/src/config_sonar.js | 55 ++++++++++++++++++- .../node_manager/static2/config_sonar.html | 2 +- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/rust/lqosd/src/node_manager/js_build/src/config_sonar.js b/src/rust/lqosd/src/node_manager/js_build/src/config_sonar.js index ad495533..b42c0531 100644 --- a/src/rust/lqosd/src/node_manager/js_build/src/config_sonar.js +++ b/src/rust/lqosd/src/node_manager/js_build/src/config_sonar.js @@ -1,4 +1,4 @@ -import {loadConfig} from "./config/config_helper"; +import {saveConfig, loadConfig} from "./config/config_helper"; function arrayToString(arr) { return arr ? arr.join(', ') : ''; @@ -8,6 +8,49 @@ function stringToArray(str) { return str ? str.split(',').map(s => s.trim()).filter(s => s.length > 0) : []; } +function validateConfig() { + // Validate required fields when enabled + if (document.getElementById("enableSonar").checked) { + const apiUrl = document.getElementById("sonarApiUrl").value.trim(); + if (!apiUrl) { + alert("API URL is required when Sonar integration is enabled"); + return false; + } + try { + new URL(apiUrl); + } catch { + alert("API URL must be a valid URL"); + return false; + } + + const apiKey = document.getElementById("sonarApiKey").value.trim(); + if (!apiKey) { + alert("API Key is required when Sonar integration is enabled"); + return false; + } + + const snmpCommunity = document.getElementById("snmpCommunity").value.trim(); + if (!snmpCommunity) { + alert("SNMP Community is required when Sonar integration is enabled"); + return false; + } + } + return true; +} + +function updateConfig() { + // Update only the sonar_integration section + window.config.sonar_integration = { + enable_sonar: document.getElementById("enableSonar").checked, + sonar_api_url: document.getElementById("sonarApiUrl").value.trim(), + sonar_api_key: document.getElementById("sonarApiKey").value.trim(), + snmp_community: document.getElementById("snmpCommunity").value.trim(), + airmax_model_ids: stringToArray(document.getElementById("airmaxModelIds").value), + ltu_model_ids: stringToArray(document.getElementById("ltuModelIds").value), + active_status_ids: stringToArray(document.getElementById("activeStatusIds").value) + }; +} + loadConfig(() => { // window.config now contains the configuration. // Populate form fields with config values @@ -33,6 +76,16 @@ loadConfig(() => { arrayToString(sonar.ltu_model_ids); document.getElementById("activeStatusIds").value = arrayToString(sonar.active_status_ids); + + // Add save button click handler + document.getElementById('saveButton').addEventListener('click', () => { + if (validateConfig()) { + updateConfig(); + saveConfig(() => { + alert("Configuration saved successfully!"); + }); + } + }); } else { console.error("Sonar integration configuration not found in window.config"); } diff --git a/src/rust/lqosd/src/node_manager/static2/config_sonar.html b/src/rust/lqosd/src/node_manager/static2/config_sonar.html index 62fe9097..c6bf43c7 100644 --- a/src/rust/lqosd/src/node_manager/static2/config_sonar.html +++ b/src/rust/lqosd/src/node_manager/static2/config_sonar.html @@ -66,7 +66,7 @@
Comma-separated list of active status IDs
- +