diff --git a/server/index.js b/server/index.js index 29050bfec..158c6bdc2 100644 --- a/server/index.js +++ b/server/index.js @@ -734,17 +734,37 @@ app.get('/api/version', async (req, res) => { const packageJson = require('../package.json'); const currentVersion = packageJson.version || 'N/A'; - // Use UpdateManager to check for updates respecting user's channel preference - const updateInfo = await updateManager.checkForUpdates(); + let latestVersion = currentVersion; + let updateAvailable = false; + + try { + // Try to check for updates, but don't fail if it doesn't work + const updateInfo = await updateManager.checkForUpdates(); + latestVersion = updateInfo.latestVersion || currentVersion; + updateAvailable = updateInfo.hasUpdate || false; + } catch (updateError) { + // Log the error but continue with current version info + console.error("[Version API] Error checking for updates:", updateError.message); + } res.json({ version: currentVersion, - latestVersion: updateInfo.latestVersion, - updateAvailable: updateInfo.hasUpdate + latestVersion: latestVersion, + updateAvailable: updateAvailable }); } catch (error) { - console.error("Error in version endpoint:", error); - res.status(500).json({ error: "Could not retrieve version" }); + console.error("[Version API] Error in version endpoint:", error); + // Still try to return current version if possible + try { + const packageJson = require('../package.json'); + res.json({ + version: packageJson.version || 'N/A', + latestVersion: packageJson.version || 'N/A', + updateAvailable: false + }); + } catch (fallbackError) { + res.status(500).json({ error: "Could not retrieve version" }); + } } }); diff --git a/src/public/js/debug-toggles.js b/src/public/js/debug-toggles.js new file mode 100644 index 000000000..0f25b3467 --- /dev/null +++ b/src/public/js/debug-toggles.js @@ -0,0 +1,93 @@ +// Debug function for notification toggles +// Copy and paste this into the browser console when the alert modal is open + +function debugToggles() { + console.log('=== Toggle Debug Info ==='); + + // Check if modal is open + const modal = document.getElementById('alert-management-modal'); + console.log('Modal found:', !!modal); + console.log('Modal visible:', modal && !modal.classList.contains('hidden')); + + // Check active tab + const activeTab = document.querySelector('.alert-tab.active'); + console.log('Active tab:', activeTab ? activeTab.getAttribute('data-tab') : 'none'); + + // Check toggle elements + const emailToggle = document.getElementById('global-email-toggle'); + const webhookToggle = document.getElementById('global-webhook-toggle'); + + console.log('\n--- Toggle Elements ---'); + console.log('Email toggle found:', !!emailToggle); + if (emailToggle) { + console.log('Email toggle checked:', emailToggle.checked); + console.log('Email toggle disabled:', emailToggle.disabled); + console.log('Email toggle parent:', emailToggle.parentElement); + } + + console.log('\nWebhook toggle found:', !!webhookToggle); + if (webhookToggle) { + console.log('Webhook toggle checked:', webhookToggle.checked); + console.log('Webhook toggle disabled:', webhookToggle.disabled); + console.log('Webhook toggle parent:', webhookToggle.parentElement); + } + + // Check config sections + const emailSection = document.getElementById('email-config-section'); + const webhookSection = document.getElementById('webhook-config-section'); + + console.log('\n--- Config Sections ---'); + console.log('Email section found:', !!emailSection); + if (emailSection) { + console.log('Email section opacity:', emailSection.style.opacity); + console.log('Email section inputs:', emailSection.querySelectorAll('input').length); + } + + console.log('\nWebhook section found:', !!webhookSection); + if (webhookSection) { + console.log('Webhook section opacity:', webhookSection.style.opacity); + console.log('Webhook section inputs:', webhookSection.querySelectorAll('input').length); + } + + // Check current config + console.log('\n--- Current Config ---'); + if (window.PulseApp && window.PulseApp.ui && window.PulseApp.ui.alertManagementModal) { + console.log('PulseApp.ui.alertManagementModal available'); + } + + // Test toggle click + console.log('\n--- Testing Toggle Click ---'); + if (emailToggle) { + console.log('Simulating email toggle click...'); + const event = new Event('change', { bubbles: true }); + emailToggle.checked = !emailToggle.checked; + emailToggle.dispatchEvent(event); + } +} + +// Run the debug function +debugToggles(); + +// Additional helper to manually trigger toggle setup +function manualSetupToggles() { + if (window.PulseApp && window.PulseApp.ui && window.PulseApp.ui.alertManagementModal) { + // Try to access the setupNotificationToggles function if it's exposed + console.log('Attempting manual toggle setup...'); + + // Manually recreate the setup logic + const emailToggle = document.getElementById('global-email-toggle'); + const webhookToggle = document.getElementById('global-webhook-toggle'); + + if (emailToggle) { + emailToggle.addEventListener('change', (e) => { + console.log('[Manual] Email toggle changed to:', e.target.checked); + }); + } + + if (webhookToggle) { + webhookToggle.addEventListener('change', (e) => { + console.log('[Manual] Webhook toggle changed to:', e.target.checked); + }); + } + } +} \ No newline at end of file diff --git a/src/public/js/ui/alertManagementModal.js b/src/public/js/ui/alertManagementModal.js index 8b843cb67..f566f652c 100644 --- a/src/public/js/ui/alertManagementModal.js +++ b/src/public/js/ui/alertManagementModal.js @@ -165,7 +165,13 @@ PulseApp.ui.alertManagementModal = (() => { openAlertRuleModal, editAlertRule, toggleAlertRule, - deleteAlertRule + deleteAlertRule, + // Debug functions + debugToggles: () => { + console.log('Email toggle:', document.getElementById('global-email-toggle')); + console.log('Webhook toggle:', document.getElementById('global-webhook-toggle')); + setupNotificationToggles(); + } }; Object.entries(functions).forEach(([name, func]) => { @@ -574,20 +580,20 @@ PulseApp.ui.alertManagementModal = (() => {

Master switches for all alert notifications

-
@@ -721,8 +727,10 @@ PulseApp.ui.alertManagementModal = (() => { // Load all alert rules (unified) loadAllAlertRules(); - // Set up event listeners for notifications - setupNotificationToggles(); + // Set up event listeners for notifications with a small delay to ensure DOM is ready + setTimeout(() => { + setupNotificationToggles(); + }, 10); // setupEmailTestButton(); // Redundant - handled in initializeNotificationsTab // Create rule button now uses onclick attribute directly @@ -1276,8 +1284,13 @@ PulseApp.ui.alertManagementModal = (() => { const emailToggle = document.getElementById('global-email-toggle'); const webhookToggle = document.getElementById('global-webhook-toggle'); + if (emailToggle) { - emailToggle.addEventListener('change', async (e) => { + // Remove any existing listeners first + const newEmailToggle = emailToggle.cloneNode(true); + emailToggle.parentNode.replaceChild(newEmailToggle, emailToggle); + + newEmailToggle.addEventListener('change', async (e) => { try { await handleGlobalEmailToggle(e.target.checked); } catch (error) { @@ -1287,7 +1300,11 @@ PulseApp.ui.alertManagementModal = (() => { } if (webhookToggle) { - webhookToggle.addEventListener('change', async (e) => { + // Remove any existing listeners first + const newWebhookToggle = webhookToggle.cloneNode(true); + webhookToggle.parentNode.replaceChild(newWebhookToggle, webhookToggle); + + newWebhookToggle.addEventListener('change', async (e) => { try { await handleGlobalWebhookToggle(e.target.checked); } catch (error) { @@ -1302,7 +1319,7 @@ PulseApp.ui.alertManagementModal = (() => { const response = await fetch('/api/config', { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ ALERT_EMAIL_ENABLED: enabled ? 'true' : 'false' }) + body: JSON.stringify({ GLOBAL_EMAIL_ENABLED: enabled ? 'true' : 'false' }) }); if (!response.ok) { @@ -1311,17 +1328,20 @@ PulseApp.ui.alertManagementModal = (() => { // Update currentConfig if (currentConfig) { - currentConfig.ALERT_EMAIL_ENABLED = enabled ? 'true' : 'false'; + currentConfig.GLOBAL_EMAIL_ENABLED = enabled ? 'true' : 'false'; } - // Show visual feedback - const toggleEl = document.getElementById('global-email-toggle'); - if (toggleEl) { - // Briefly flash the toggle to indicate success - const parent = toggleEl.parentElement; - parent.classList.add('ring-2', 'ring-green-500'); - setTimeout(() => parent.classList.remove('ring-2', 'ring-green-500'), 1000); - } + // Update visibility of email configuration section + updateEmailConfigVisibility(enabled); + + // Visual feedback disabled - remove this comment block to re-enable + // const toggleEl = document.getElementById('global-email-toggle'); + // if (toggleEl) { + // // Briefly flash the toggle to indicate success + // const parent = toggleEl.parentElement; + // parent.classList.add('ring-2', 'ring-green-500'); + // setTimeout(() => parent.classList.remove('ring-2', 'ring-green-500'), 1000); + // } } catch (error) { console.error('Error updating email toggle:', error); @@ -1339,7 +1359,7 @@ PulseApp.ui.alertManagementModal = (() => { const response = await fetch('/api/config', { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ ALERT_WEBHOOK_ENABLED: enabled ? 'true' : 'false' }) + body: JSON.stringify({ GLOBAL_WEBHOOK_ENABLED: enabled ? 'true' : 'false' }) }); if (!response.ok) { @@ -1348,17 +1368,20 @@ PulseApp.ui.alertManagementModal = (() => { // Update currentConfig if (currentConfig) { - currentConfig.ALERT_WEBHOOK_ENABLED = enabled ? 'true' : 'false'; + currentConfig.GLOBAL_WEBHOOK_ENABLED = enabled ? 'true' : 'false'; } - // Show visual feedback - const toggleEl = document.getElementById('global-webhook-toggle'); - if (toggleEl) { - // Briefly flash the toggle to indicate success - const parent = toggleEl.parentElement; - parent.classList.add('ring-2', 'ring-green-500'); - setTimeout(() => parent.classList.remove('ring-2', 'ring-green-500'), 1000); - } + // Update visibility of webhook configuration section + updateWebhookConfigVisibility(enabled); + + // Visual feedback disabled - remove this comment block to re-enable + // const toggleEl = document.getElementById('global-webhook-toggle'); + // if (toggleEl) { + // // Briefly flash the toggle to indicate success + // const parent = toggleEl.parentElement; + // parent.classList.add('ring-2', 'ring-green-500'); + // setTimeout(() => parent.classList.remove('ring-2', 'ring-green-500'), 1000); + // } } catch (error) { console.error('Error updating webhook toggle:', error); @@ -1389,6 +1412,7 @@ PulseApp.ui.alertManagementModal = (() => { inputs.forEach(input => { input.disabled = !enabled; }); + } else { } } @@ -1401,6 +1425,7 @@ PulseApp.ui.alertManagementModal = (() => { inputs.forEach(input => { input.disabled = !enabled; }); + } else { } } @@ -1420,14 +1445,14 @@ PulseApp.ui.alertManagementModal = (() => { // }); if (emailToggle && currentConfig) { - const emailEnabled = currentConfig.ALERT_EMAIL_ENABLED === 'true'; + const emailEnabled = currentConfig.GLOBAL_EMAIL_ENABLED === 'true'; // console.log('[Global Toggles] Setting email toggle to:', emailEnabled); emailToggle.checked = emailEnabled; updateEmailConfigVisibility(emailEnabled); } if (webhookToggle && currentConfig) { - const webhookEnabled = currentConfig.ALERT_WEBHOOK_ENABLED === 'true'; + const webhookEnabled = currentConfig.GLOBAL_WEBHOOK_ENABLED === 'true'; // console.log('[Global Toggles] Setting webhook toggle to:', webhookEnabled); webhookToggle.checked = webhookEnabled; updateWebhookConfigVisibility(webhookEnabled); diff --git a/toggle-debug.html b/toggle-debug.html new file mode 100644 index 000000000..3d99bbbaf --- /dev/null +++ b/toggle-debug.html @@ -0,0 +1,55 @@ + + + + Toggle Debug Test + + + +

Toggle Debug Test

+

Open the browser console and run: debugToggles()

+

Or add this to the alertManagementModal.js temporarily to debug

+ + \ No newline at end of file