Fix duplicate ID issue and modal field population
- Fix duplicate protocol_type ID by renaming mapping-modal field to mapping_protocol_type - Update populateModalFields to search for fields within modal context instead of globally - Add debugging to show which fields are found in the modal - Ensure protocol type and address fields are properly populated from discovery data
This commit is contained in:
parent
add4952e74
commit
5596f6eaf1
|
|
@ -695,8 +695,8 @@ DASHBOARD_HTML = """
|
||||||
<input type="text" id="mapping_id" name="mapping_id" required>
|
<input type="text" id="mapping_id" name="mapping_id" required>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="protocol_type">Protocol Type:</label>
|
<label for="mapping_protocol_type">Protocol Type:</label>
|
||||||
<select id="protocol_type" name="protocol_type" required onchange="updateProtocolFields()">
|
<select id="mapping_protocol_type" name="protocol_type" required onchange="updateProtocolFields()">
|
||||||
<option value="">Select Protocol</option>
|
<option value="">Select Protocol</option>
|
||||||
<option value="modbus_tcp">Modbus TCP</option>
|
<option value="modbus_tcp">Modbus TCP</option>
|
||||||
<option value="opcua">OPC UA</option>
|
<option value="opcua">OPC UA</option>
|
||||||
|
|
|
||||||
|
|
@ -300,50 +300,54 @@ function populateModalFields(discoveryData) {
|
||||||
|
|
||||||
// Try to find the appropriate form
|
// Try to find the appropriate form
|
||||||
let form = document.getElementById('signal-form');
|
let form = document.getElementById('signal-form');
|
||||||
if (!form) {
|
let modal = document.getElementById('signal-modal');
|
||||||
form = document.getElementById('mapping-form');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!form) {
|
if (!form) {
|
||||||
|
form = document.getElementById('mapping-form');
|
||||||
|
modal = document.getElementById('mapping-modal');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!form || !modal) {
|
||||||
console.warn('No signal or mapping form found - cannot auto-populate');
|
console.warn('No signal or mapping form found - cannot auto-populate');
|
||||||
showSimplifiedAlert('No signal form found - please open the add signal/mapping modal first', 'error');
|
showSimplifiedAlert('No signal form found - please open the add signal/mapping modal first', 'error');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show the modal if it's hidden
|
// Show the modal if it's hidden
|
||||||
const signalModal = document.getElementById('signal-modal');
|
if (modal.style.display === 'none') {
|
||||||
const mappingModal = document.getElementById('mapping-modal');
|
modal.style.display = 'block';
|
||||||
|
console.log('✓ Opened modal');
|
||||||
if (signalModal && signalModal.style.display === 'none') {
|
|
||||||
signalModal.style.display = 'block';
|
|
||||||
console.log('✓ Opened signal modal');
|
|
||||||
} else if (mappingModal && mappingModal.style.display === 'none') {
|
|
||||||
mappingModal.style.display = 'block';
|
|
||||||
console.log('✓ Opened mapping modal');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Find fields within the modal context to avoid duplicate ID issues
|
||||||
|
const modalContent = modal.querySelector('.modal-content');
|
||||||
|
|
||||||
// Debug: Check if fields exist
|
// Debug: Check if fields exist
|
||||||
console.log('Available fields:');
|
console.log('Available fields in modal:');
|
||||||
console.log('- protocol_type:', document.getElementById('protocol_type'));
|
console.log('- protocol_type:', modalContent.querySelector('#protocol_type'));
|
||||||
console.log('- protocol_address:', document.getElementById('protocol_address'));
|
console.log('- mapping_protocol_type:', modalContent.querySelector('#mapping_protocol_type'));
|
||||||
console.log('- db_source:', document.getElementById('db_source'));
|
console.log('- protocol_address:', modalContent.querySelector('#protocol_address'));
|
||||||
|
console.log('- db_source:', modalContent.querySelector('#db_source'));
|
||||||
|
|
||||||
// Populate signal name (try different field names)
|
// Populate signal name (try different field names)
|
||||||
const signalNameField = document.getElementById('signal_name') || document.getElementById('mapping_id');
|
const signalNameField = modalContent.querySelector('#signal_name') || modalContent.querySelector('#mapping_id');
|
||||||
if (signalNameField && discoveryData.signal_name) {
|
if (signalNameField && discoveryData.signal_name) {
|
||||||
signalNameField.value = discoveryData.signal_name;
|
signalNameField.value = discoveryData.signal_name;
|
||||||
console.log('✓ Set signal name to:', discoveryData.signal_name);
|
console.log('✓ Set signal name to:', discoveryData.signal_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Populate tags (only in simplified template)
|
// Populate tags (only in simplified template)
|
||||||
const tagsField = document.getElementById('tags');
|
const tagsField = modalContent.querySelector('#tags');
|
||||||
if (tagsField && discoveryData.tags) {
|
if (tagsField && discoveryData.tags) {
|
||||||
tagsField.value = discoveryData.tags.join(', ');
|
tagsField.value = discoveryData.tags.join(', ');
|
||||||
console.log('✓ Set tags to:', discoveryData.tags);
|
console.log('✓ Set tags to:', discoveryData.tags);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Populate protocol type
|
// Populate protocol type - try both possible IDs
|
||||||
const protocolTypeField = document.getElementById('protocol_type');
|
let protocolTypeField = modalContent.querySelector('#protocol_type');
|
||||||
|
if (!protocolTypeField) {
|
||||||
|
protocolTypeField = modalContent.querySelector('#mapping_protocol_type');
|
||||||
|
}
|
||||||
if (protocolTypeField && discoveryData.protocol_type) {
|
if (protocolTypeField && discoveryData.protocol_type) {
|
||||||
protocolTypeField.value = discoveryData.protocol_type;
|
protocolTypeField.value = discoveryData.protocol_type;
|
||||||
console.log('✓ Set protocol_type to:', discoveryData.protocol_type);
|
console.log('✓ Set protocol_type to:', discoveryData.protocol_type);
|
||||||
|
|
@ -352,14 +356,14 @@ function populateModalFields(discoveryData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Populate protocol address
|
// Populate protocol address
|
||||||
const protocolAddressField = document.getElementById('protocol_address');
|
const protocolAddressField = modalContent.querySelector('#protocol_address');
|
||||||
if (protocolAddressField && discoveryData.protocol_address) {
|
if (protocolAddressField && discoveryData.protocol_address) {
|
||||||
protocolAddressField.value = discoveryData.protocol_address;
|
protocolAddressField.value = discoveryData.protocol_address;
|
||||||
console.log('✓ Set protocol_address to:', discoveryData.protocol_address);
|
console.log('✓ Set protocol_address to:', discoveryData.protocol_address);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Populate database source
|
// Populate database source
|
||||||
const dbSourceField = document.getElementById('db_source');
|
const dbSourceField = modalContent.querySelector('#db_source');
|
||||||
if (dbSourceField && discoveryData.db_source) {
|
if (dbSourceField && discoveryData.db_source) {
|
||||||
dbSourceField.value = discoveryData.db_source;
|
dbSourceField.value = discoveryData.db_source;
|
||||||
console.log('✓ Set db_source to:', discoveryData.db_source);
|
console.log('✓ Set db_source to:', discoveryData.db_source);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue