From 7a2c9d6d171d83950b7a80d175bffd007fff1bae Mon Sep 17 00:00:00 2001 From: Manuel Weiser Date: Sat, 1 Mar 2025 12:18:33 +0100 Subject: [PATCH] add OctoPrint integration with configurable fields and update functionality --- html/spoolman.html | 29 ++++++++++++++++++++- src/api.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++--- src/api.h | 6 ++++- src/main.cpp | 5 ++++ src/website.cpp | 18 +++++++++++-- 5 files changed, 115 insertions(+), 8 deletions(-) diff --git a/html/spoolman.html b/html/spoolman.html index 9b2bcca..365237a 100644 --- a/html/spoolman.html +++ b/html/spoolman.html @@ -52,11 +52,18 @@ if (spoolmanUrl && spoolmanUrl.trim() !== "") { document.getElementById('spoolmanUrl').value = spoolmanUrl; } + + // Initialize OctoPrint fields visibility + toggleOctoFields(); }; function checkSpoolmanInstance() { const url = document.getElementById('spoolmanUrl').value; - fetch(`/api/checkSpoolman?url=${encodeURIComponent(url)}`) + const spoolmanOctoEnabled = document.getElementById('spoolmanOctoEnabled').checked; + const spoolmanOctoUrl = document.getElementById('spoolmanOctoUrl').value; + const spoolmanOctoToken = document.getElementById('spoolmanOctoToken').value; + + fetch(`/api/checkSpoolman?url=${encodeURIComponent(url)}&octoEnabled=${spoolmanOctoEnabled}&octoUrl=${spoolmanOctoUrl}&octoToken=${spoolmanOctoToken}`) .then(response => response.json()) .then(data => { if (data.healthy) { @@ -90,6 +97,15 @@ document.getElementById('bambuStatusMessage').innerText = 'Error while saving: ' + error.message; }); } + + /** + * Controls visibility of OctoPrint configuration fields based on checkbox state + * Called on page load and when checkbox changes + */ + function toggleOctoFields() { + const octoEnabled = document.getElementById('spoolmanOctoEnabled').checked; + document.getElementById('octoFields').style.display = octoEnabled ? 'block' : 'none'; + }