Fix modal opening timeout issue with better debugging and increased timeout
This commit is contained in:
parent
db8dc90a85
commit
7318e121de
|
|
@ -1,9 +1,21 @@
|
||||||
// Simplified Protocol Mapping Functions
|
// Simplified Protocol Mapping Functions
|
||||||
// Uses human-readable signal names and tags instead of complex IDs
|
// Uses human-readable signal names and tags instead of complex IDs
|
||||||
|
|
||||||
let currentProtocolFilter = 'all';
|
(function() {
|
||||||
let editingSignalId = null;
|
'use strict';
|
||||||
let allTags = new Set();
|
|
||||||
|
// Check if global variables already exist before declaring
|
||||||
|
if (typeof window.currentProtocolFilter === 'undefined') {
|
||||||
|
window.currentProtocolFilter = 'all';
|
||||||
|
}
|
||||||
|
if (typeof window.editingSignalId === 'undefined') {
|
||||||
|
window.editingSignalId = null;
|
||||||
|
}
|
||||||
|
if (typeof window.allTags === 'undefined') {
|
||||||
|
window.allTags = new Set();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use window object variables directly to avoid redeclaration conflicts
|
||||||
|
|
||||||
// Simplified Signal Management Functions
|
// Simplified Signal Management Functions
|
||||||
async function loadAllSignals() {
|
async function loadAllSignals() {
|
||||||
|
|
@ -112,15 +124,38 @@ async function applyFilters() {
|
||||||
|
|
||||||
// Modal Functions
|
// Modal Functions
|
||||||
function showAddSignalModal() {
|
function showAddSignalModal() {
|
||||||
editingSignalId = null;
|
console.log('showAddSignalModal called');
|
||||||
document.getElementById('modal-title').textContent = 'Add Protocol Signal';
|
window.editingSignalId = null;
|
||||||
document.getElementById('signal-form').reset();
|
|
||||||
document.getElementById('protocol-address-help').textContent = '';
|
// Safely update modal elements if they exist
|
||||||
document.getElementById('signal-modal').style.display = 'block';
|
const modalTitle = document.getElementById('modal-title');
|
||||||
|
if (modalTitle) {
|
||||||
|
modalTitle.textContent = 'Add Protocol Signal';
|
||||||
|
}
|
||||||
|
|
||||||
|
const signalForm = document.getElementById('signal-form');
|
||||||
|
if (signalForm) {
|
||||||
|
signalForm.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
const protocolAddressHelp = document.getElementById('protocol-address-help');
|
||||||
|
if (protocolAddressHelp) {
|
||||||
|
protocolAddressHelp.textContent = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
const signalModal = document.getElementById('signal-modal');
|
||||||
|
console.log('Modal element found:', signalModal);
|
||||||
|
if (signalModal) {
|
||||||
|
console.log('Setting modal display to block');
|
||||||
|
signalModal.style.display = 'block';
|
||||||
|
console.log('Modal display after setting:', signalModal.style.display);
|
||||||
|
} else {
|
||||||
|
console.error('signal-modal element not found!');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function showEditSignalModal(signal) {
|
function showEditSignalModal(signal) {
|
||||||
editingSignalId = signal.signal_id;
|
window.editingSignalId = signal.signal_id;
|
||||||
document.getElementById('modal-title').textContent = 'Edit Protocol Signal';
|
document.getElementById('modal-title').textContent = 'Edit Protocol Signal';
|
||||||
|
|
||||||
// Populate form
|
// Populate form
|
||||||
|
|
@ -137,7 +172,7 @@ function showEditSignalModal(signal) {
|
||||||
|
|
||||||
function closeSignalModal() {
|
function closeSignalModal() {
|
||||||
document.getElementById('signal-modal').style.display = 'none';
|
document.getElementById('signal-modal').style.display = 'none';
|
||||||
editingSignalId = null;
|
window.editingSignalId = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateProtocolFields() {
|
function updateProtocolFields() {
|
||||||
|
|
@ -168,8 +203,8 @@ async function saveSignal(event) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response;
|
let response;
|
||||||
if (editingSignalId) {
|
if (window.editingSignalId) {
|
||||||
response = await fetch(`/api/v1/dashboard/protocol-signals/${editingSignalId}`, {
|
response = await fetch(`/api/v1/dashboard/protocol-signals/${window.editingSignalId}`, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify(formData)
|
body: JSON.stringify(formData)
|
||||||
|
|
@ -185,7 +220,7 @@ async function saveSignal(event) {
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
showSimplifiedAlert(`Protocol signal ${editingSignalId ? 'updated' : 'created'} successfully!`, 'success');
|
showSimplifiedAlert(`Protocol signal ${window.editingSignalId ? 'updated' : 'created'} successfully!`, 'success');
|
||||||
closeSignalModal();
|
closeSignalModal();
|
||||||
loadAllSignals();
|
loadAllSignals();
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -266,21 +301,25 @@ function autoPopulateSignalForm(discoveryData) {
|
||||||
|
|
||||||
if (isModalVisible) {
|
if (isModalVisible) {
|
||||||
clearInterval(waitForModal);
|
clearInterval(waitForModal);
|
||||||
|
console.log('Modal is visible, populating fields...');
|
||||||
populateModalFields(discoveryData);
|
populateModalFields(discoveryData);
|
||||||
}
|
}
|
||||||
}, 50);
|
}, 50);
|
||||||
|
|
||||||
// Timeout after 2 seconds
|
// Timeout after 3 seconds (increased from 2)
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
clearInterval(waitForModal);
|
clearInterval(waitForModal);
|
||||||
const modal = document.getElementById('signal-modal');
|
const modal = document.getElementById('signal-modal');
|
||||||
if (modal && modal.style.display !== 'none') {
|
if (modal && modal.style.display !== 'none') {
|
||||||
|
console.log('Modal opened within timeout, populating fields...');
|
||||||
populateModalFields(discoveryData);
|
populateModalFields(discoveryData);
|
||||||
} else {
|
} else {
|
||||||
console.error('Modal did not open within timeout period');
|
console.error('Modal did not open within timeout period');
|
||||||
|
console.log('Modal element:', modal);
|
||||||
|
console.log('Modal display style:', modal ? modal.style.display : 'no modal found');
|
||||||
showSimplifiedAlert('Could not open signal form. Please try opening it manually.', 'error');
|
showSimplifiedAlert('Could not open signal form. Please try opening it manually.', 'error');
|
||||||
}
|
}
|
||||||
}, 2000);
|
}, 3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
function populateModalFields(discoveryData) {
|
function populateModalFields(discoveryData) {
|
||||||
|
|
@ -330,6 +369,13 @@ function populateModalFields(discoveryData) {
|
||||||
// Utility Functions
|
// Utility Functions
|
||||||
function showSimplifiedAlert(message, type = 'info') {
|
function showSimplifiedAlert(message, type = 'info') {
|
||||||
const alertsDiv = document.getElementById('simplified-alerts');
|
const alertsDiv = document.getElementById('simplified-alerts');
|
||||||
|
|
||||||
|
// Only proceed if the alerts container exists
|
||||||
|
if (!alertsDiv) {
|
||||||
|
console.log(`Alert (${type}): ${message}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const alertDiv = document.createElement('div');
|
const alertDiv = document.createElement('div');
|
||||||
alertDiv.className = `alert ${type === 'error' ? 'error' : 'success'}`;
|
alertDiv.className = `alert ${type === 'error' ? 'error' : 'success'}`;
|
||||||
alertDiv.textContent = message;
|
alertDiv.textContent = message;
|
||||||
|
|
@ -345,8 +391,8 @@ function showSimplifiedAlert(message, type = 'info') {
|
||||||
}, 5000);
|
}, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize
|
// Initialize
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
const signalForm = document.getElementById('signal-form');
|
const signalForm = document.getElementById('signal-form');
|
||||||
if (signalForm) {
|
if (signalForm) {
|
||||||
signalForm.addEventListener('submit', saveSignal);
|
signalForm.addEventListener('submit', saveSignal);
|
||||||
|
|
@ -354,7 +400,11 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
|
||||||
// Load initial data
|
// Load initial data
|
||||||
loadAllSignals();
|
loadAllSignals();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Expose functions to window for discovery integration
|
// Expose functions to window for discovery integration
|
||||||
window.autoPopulateSignalForm = autoPopulateSignalForm;
|
window.autoPopulateSignalForm = autoPopulateSignalForm;
|
||||||
|
window.showAddSignalModal = showAddSignalModal;
|
||||||
|
window.applyFilters = applyFilters;
|
||||||
|
window.closeSignalModal = closeSignalModal;
|
||||||
|
})();
|
||||||
Loading…
Reference in New Issue