From 698c114609b7b5e666a96a5bb9d7fba531236521 Mon Sep 17 00:00:00 2001 From: openhands Date: Sun, 9 Nov 2025 14:30:50 +0000 Subject: [PATCH] Fix discovery scan button integration and add debugging - Add event binding for discovery scan button - Implement startDiscoveryScan method with proper UI updates - Add comprehensive debug logging to track discovery flow - Fix discovery results container detection - Improve error handling and user feedback Now the discovery workflow should work properly: 1. Click 'Start Discovery Scan' button 2. See progress status and results 3. Click 'Use This Signal' to populate form 4. Click 'Apply All as Protocol Signals' to create all --- static/discovery.js | 54 +++++++- static/protocol_mapping.js | 1 + test_discovery_integration.html | 223 ++++++++++++++++++++++++++++++++ 3 files changed, 277 insertions(+), 1 deletion(-) create mode 100644 test_discovery_integration.html diff --git a/static/discovery.js b/static/discovery.js index 5f68096..7c1ded4 100644 --- a/static/discovery.js +++ b/static/discovery.js @@ -12,6 +12,14 @@ class SimplifiedProtocolDiscovery { } bindDiscoveryEvents() { + // Discovery scan button + const startScanBtn = document.getElementById('start-discovery-scan'); + if (startScanBtn) { + startScanBtn.addEventListener('click', () => { + this.startDiscoveryScan(); + }); + } + // Auto-fill signal form from discovery document.addEventListener('click', (e) => { if (e.target.classList.contains('use-discovered-endpoint')) { @@ -123,6 +131,45 @@ class SimplifiedProtocolDiscovery { } } + // Start discovery scan + async startDiscoveryScan() { + console.log('Starting discovery scan...'); + + // Update UI + const startBtn = document.getElementById('start-discovery-scan'); + const stopBtn = document.getElementById('stop-discovery-scan'); + const statusDiv = document.getElementById('discovery-status'); + + if (startBtn) startBtn.disabled = true; + if (stopBtn) stopBtn.disabled = false; + if (statusDiv) { + statusDiv.innerHTML = '
Discovery scan in progress...
'; + } + + try { + // Run discovery + const results = await this.discoverAndSuggestSignals(); + + // Update status + if (statusDiv) { + statusDiv.innerHTML = `
Discovery complete. Found ${results.length} devices.
`; + } + + this.showNotification(`Discovery complete. Found ${results.length} devices.`, 'success'); + + } catch (error) { + console.error('Discovery scan failed:', error); + if (statusDiv) { + statusDiv.innerHTML = '
Discovery scan failed
'; + } + this.showNotification('Discovery scan failed', 'error'); + } finally { + // Reset UI + if (startBtn) startBtn.disabled = false; + if (stopBtn) stopBtn.disabled = true; + } + } + // Advanced discovery features async discoverAndSuggestSignals(networkRange = '192.168.1.0/24') { console.log(`Starting discovery scan on ${networkRange}`); @@ -187,8 +234,13 @@ class SimplifiedProtocolDiscovery { } displayDiscoveryResults(suggestedSignals) { + console.log('Displaying discovery results:', suggestedSignals); const resultsContainer = document.getElementById('discovery-results'); - if (!resultsContainer) return; + if (!resultsContainer) { + console.error('Discovery results container not found!'); + this.showNotification('Discovery results container not found', 'error'); + return; + } resultsContainer.innerHTML = '

Discovery Results

'; diff --git a/static/protocol_mapping.js b/static/protocol_mapping.js index 72eafc8..a55fd82 100644 --- a/static/protocol_mapping.js +++ b/static/protocol_mapping.js @@ -257,6 +257,7 @@ function autoPopulateSignalForm(discoveryData) { console.log('Auto-populating signal form with:', discoveryData); // First, open the "Add New Signal" modal + console.log('Opening Add Signal modal...'); showAddSignalModal(); // Wait for modal to be fully loaded and visible diff --git a/test_discovery_integration.html b/test_discovery_integration.html new file mode 100644 index 0000000..f99a125 --- /dev/null +++ b/test_discovery_integration.html @@ -0,0 +1,223 @@ + + + + + + Discovery Integration Test + + + +
+

Discovery Integration Test

+ +
+

Test 1: Check if Functions are Available

+ +
+
+ +
+

Test 2: Simulate Discovery Results

+ +
+
+ +
+

Test 3: Test Auto-Population

+ +
+
+ +
+

Test 4: Test API Endpoints

+ +
+
+
+ + + + \ No newline at end of file