From 861c6e2a8d251df629aa3ba3b79cac9be06eea4a Mon Sep 17 00:00:00 2001 From: Herbert Wolverson Date: Wed, 1 May 2024 10:09:11 -0500 Subject: [PATCH] Initial validation workflow for saving configuration. --- src/rust/lqos_node_manager/static/config.html | 120 ++++++++++++++++-- src/rust/lqos_node_manager/static/lqos.css | 3 +- 2 files changed, 111 insertions(+), 12 deletions(-) diff --git a/src/rust/lqos_node_manager/static/config.html b/src/rust/lqos_node_manager/static/config.html index 3abda7c0..ee688177 100644 --- a/src/rust/lqos_node_manager/static/config.html +++ b/src/rust/lqos_node_manager/static/config.html @@ -619,15 +619,15 @@ const bindings = [ // General { field: "bindVersion", path: ".version", data: "string", editable: false }, - { field: "bindPath", path: ".lqos_directory", data: "string", editable: true }, - { field: "bindNodeId", path: ".node_id", data: "string", editable: true }, - { field: "bindNodeName", path: ".node_name", data: "string", editable: true }, - { field: "bindPacketCaptureTime", path: ".packet_capture_time", data: "integer", editable: true }, - { field: "bindQueueCheckPeriodMs", path: ".queue_check_period_ms", data: "integer", editable: true }, + { field: "bindPath", path: ".lqos_directory", data: "string", editable: true, required: true }, + { field: "bindNodeId", path: ".node_id", data: "string", editable: true, required: true }, + { field: "bindNodeName", path: ".node_name", data: "string", editable: true, required: true }, + { field: "bindPacketCaptureTime", path: ".packet_capture_time", data: "integer", editable: true, min: 1, max: 300 }, + { field: "bindQueueCheckPeriodMs", path: ".queue_check_period_ms", data: "integer", editable: true, min: 100, max: 100000 }, // Anonymous Usage { field: "bindSendAnonymous", path: ".usage_stats.send_anonymous", data: "bool", editable: true }, - { field: "bindAnonymousServer", path: ".usage_stats.anonymous_server", data: "string", editable: true }, + { field: "bindAnonymousServer", path: ".usage_stats.anonymous_server", data: "string", editable: true, required: true }, // Tuning { field: "bindStopIrqBalance", path: ".tuning.stop_irq_balance", data: "bool", editable: true }, @@ -826,17 +826,115 @@ $("#bindSingleInterfaceNetworklan").val('3'); } - function validateConfig() { - for (var i=0; i', currentValue); + changes.push(i); + } + } catch { + //console.log(path + 'ignored'); + } } } + return changes; + } + + function validateConfig() { + console.log("Starting validator"); + $(".invalid").removeClass("invalid"); + let changes = detectChanges(); + if (changes.length === 0) { + console.log("Nothing changed!"); + alert("No configuration changes were made."); + return { + valid: false, + changes: [], + }; + } + + let valid = true; + let errors = []; + for (let i=0; i target.max) { + valid = false; + errors.push(target.path + " must be between " + target.min + " and " + target.max + "."); + $("#" + target.field).addClass("invalid"); + } + } + } + } + } + + if (!valid) { + let errorMessage = ""; + for (let i=0; i { - validateConfig(); + saveConfig(); }); } $.get("/api/config", (data) => { diff --git a/src/rust/lqos_node_manager/static/lqos.css b/src/rust/lqos_node_manager/static/lqos.css index 16a31208..f1cb8491 100644 --- a/src/rust/lqos_node_manager/static/lqos.css +++ b/src/rust/lqos_node_manager/static/lqos.css @@ -18,4 +18,5 @@ .row220 { height: 220px; } .redact { font-display: unset; } footer > a { color: white; } -footer { color: white; font-style: italic; } \ No newline at end of file +footer { color: white; font-style: italic; } +.invalid { background-color: #ffdddd } \ No newline at end of file