mirror of
https://github.com/LibreQoE/LibreQoS.git
synced 2025-02-25 18:55:32 -06:00
feat: add save functionality and validation to sonar config
This commit is contained in:
parent
fe3ebbbf61
commit
b2228141cc
@ -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");
|
||||
}
|
||||
|
@ -66,7 +66,7 @@
|
||||
<div class="form-text">Comma-separated list of active status IDs</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-outline-primary">Save Changes</button>
|
||||
<button type="button" id="saveButton" class="btn btn-outline-primary">Save Changes</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user