feat: Implement configurable pump control preprocessing logic #5
|
|
@ -284,14 +284,14 @@ class ProtocolDiscovery {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get station and pump info from form or prompt
|
// Get station, equipment, and data type from our metadata
|
||||||
const stationId = document.getElementById('station-id')?.value || 'station_001';
|
const stationId = this.getDefaultStationId();
|
||||||
const pumpId = document.getElementById('pump-id')?.value || 'pump_001';
|
const equipmentId = this.getDefaultEquipmentId(stationId);
|
||||||
const dataType = document.getElementById('data-type')?.value || 'pressure';
|
const dataTypeId = this.getDefaultDataTypeId();
|
||||||
const dbSource = document.getElementById('db-source')?.value || 'influxdb';
|
const dbSource = 'influxdb'; // Default database source
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/v1/dashboard/discovery/apply/${this.currentScanId}?station_id=${stationId}&pump_id=${pumpId}&data_type=${dataType}&db_source=${dbSource}`, {
|
const response = await fetch(`/api/v1/dashboard/discovery/apply/${this.currentScanId}?station_id=${stationId}&equipment_id=${equipmentId}&data_type_id=${dataTypeId}&db_source=${dbSource}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
|
|
@ -305,8 +305,8 @@ class ProtocolDiscovery {
|
||||||
this.showNotification(`Successfully created ${result.created_mappings.length} protocol mappings from discovery results`, 'success');
|
this.showNotification(`Successfully created ${result.created_mappings.length} protocol mappings from discovery results`, 'success');
|
||||||
|
|
||||||
// Refresh protocol mappings grid
|
// Refresh protocol mappings grid
|
||||||
if (window.protocolMappingGrid) {
|
if (window.loadProtocolMappings) {
|
||||||
window.protocolMappingGrid.loadProtocolMappings();
|
window.loadProtocolMappings();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.showNotification('No protocol mappings were created. Check the discovery results for compatible endpoints.', 'warning');
|
this.showNotification('No protocol mappings were created. Check the discovery results for compatible endpoints.', 'warning');
|
||||||
|
|
@ -366,6 +366,11 @@ class ProtocolDiscovery {
|
||||||
// Create a new protocol mapping ID
|
// Create a new protocol mapping ID
|
||||||
const mappingId = `${endpoint.device_id}_${endpoint.protocol_type}`;
|
const mappingId = `${endpoint.device_id}_${endpoint.protocol_type}`;
|
||||||
|
|
||||||
|
// Get default metadata IDs from our sample metadata
|
||||||
|
const defaultStationId = this.getDefaultStationId();
|
||||||
|
const defaultEquipmentId = this.getDefaultEquipmentId(defaultStationId);
|
||||||
|
const defaultDataTypeId = this.getDefaultDataTypeId();
|
||||||
|
|
||||||
// Set form values (these would be used when creating a new mapping)
|
// Set form values (these would be used when creating a new mapping)
|
||||||
const formData = {
|
const formData = {
|
||||||
mapping_id: mappingId,
|
mapping_id: mappingId,
|
||||||
|
|
@ -374,9 +379,9 @@ class ProtocolDiscovery {
|
||||||
device_name: endpoint.device_name || endpoint.device_id,
|
device_name: endpoint.device_name || endpoint.device_id,
|
||||||
device_address: endpoint.address,
|
device_address: endpoint.address,
|
||||||
device_port: endpoint.port || '',
|
device_port: endpoint.port || '',
|
||||||
station_id: 'station_001', // Default station ID
|
station_id: defaultStationId,
|
||||||
equipment_id: 'equipment_001', // Default equipment ID
|
equipment_id: defaultEquipmentId,
|
||||||
data_type_id: 'datatype_001' // Default data type ID
|
data_type_id: defaultDataTypeId
|
||||||
};
|
};
|
||||||
|
|
||||||
// Store form data for later use
|
// Store form data for later use
|
||||||
|
|
@ -399,25 +404,29 @@ class ProtocolDiscovery {
|
||||||
// Wait a moment for the modal to open, then populate fields
|
// Wait a moment for the modal to open, then populate fields
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
// Find and populate form fields in the modal
|
// Find and populate form fields in the modal
|
||||||
const mappingIdField = document.getElementById('mapping-id');
|
const protocolTypeField = document.getElementById('protocol_type');
|
||||||
const protocolTypeField = document.getElementById('protocol-type');
|
const protocolAddressField = document.getElementById('protocol_address');
|
||||||
const protocolAddressField = document.getElementById('protocol-address');
|
const stationIdField = document.getElementById('station_id');
|
||||||
const deviceNameField = document.getElementById('device-name');
|
const equipmentIdField = document.getElementById('equipment_id');
|
||||||
const deviceAddressField = document.getElementById('device-address');
|
const dataTypeIdField = document.getElementById('data_type_id');
|
||||||
const devicePortField = document.getElementById('device-port');
|
|
||||||
const stationIdField = document.getElementById('station-id');
|
|
||||||
const equipmentIdField = document.getElementById('equipment-id');
|
|
||||||
const dataTypeIdField = document.getElementById('data-type-id');
|
|
||||||
|
|
||||||
if (mappingIdField) mappingIdField.value = formData.mapping_id;
|
|
||||||
if (protocolTypeField) protocolTypeField.value = formData.protocol_type;
|
if (protocolTypeField) protocolTypeField.value = formData.protocol_type;
|
||||||
if (protocolAddressField) protocolAddressField.value = formData.protocol_address;
|
if (protocolAddressField) protocolAddressField.value = formData.protocol_address;
|
||||||
if (deviceNameField) deviceNameField.value = formData.device_name;
|
|
||||||
if (deviceAddressField) deviceAddressField.value = formData.device_address;
|
// Set station, equipment, and data type if they exist in our metadata
|
||||||
if (devicePortField) devicePortField.value = formData.device_port;
|
if (stationIdField && this.isValidStationId(formData.station_id)) {
|
||||||
if (stationIdField) stationIdField.value = formData.station_id;
|
stationIdField.value = formData.station_id;
|
||||||
if (equipmentIdField) equipmentIdField.value = formData.equipment_id;
|
// Trigger equipment dropdown update
|
||||||
if (dataTypeIdField) dataTypeIdField.value = formData.data_type_id;
|
stationIdField.dispatchEvent(new Event('change'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (equipmentIdField && this.isValidEquipmentId(formData.equipment_id)) {
|
||||||
|
equipmentIdField.value = formData.equipment_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dataTypeIdField && this.isValidDataTypeId(formData.data_type_id)) {
|
||||||
|
dataTypeIdField.value = formData.data_type_id;
|
||||||
|
}
|
||||||
|
|
||||||
// Show success message
|
// Show success message
|
||||||
this.showNotification(`Protocol form populated with ${formData.device_name}. Please review and complete any missing information.`, 'success');
|
this.showNotification(`Protocol form populated with ${formData.device_name}. Please review and complete any missing information.`, 'success');
|
||||||
|
|
@ -542,6 +551,75 @@ class ProtocolDiscovery {
|
||||||
}
|
}
|
||||||
}, 5000);
|
}, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get default station ID from available metadata
|
||||||
|
*/
|
||||||
|
getDefaultStationId() {
|
||||||
|
// Try to get the first station from our metadata
|
||||||
|
const stationSelect = document.getElementById('station_id');
|
||||||
|
if (stationSelect && stationSelect.options.length > 1) {
|
||||||
|
return stationSelect.options[1].value; // First actual station (skip "Select Station")
|
||||||
|
}
|
||||||
|
// Fallback to our sample metadata IDs
|
||||||
|
return 'station_main';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get default equipment ID for a station
|
||||||
|
*/
|
||||||
|
getDefaultEquipmentId(stationId) {
|
||||||
|
// Try to get the first equipment for the station
|
||||||
|
const equipmentSelect = document.getElementById('equipment_id');
|
||||||
|
if (equipmentSelect && equipmentSelect.options.length > 1) {
|
||||||
|
return equipmentSelect.options[1].value; // First actual equipment
|
||||||
|
}
|
||||||
|
// Fallback based on station
|
||||||
|
if (stationId === 'station_main') return 'pump_primary';
|
||||||
|
if (stationId === 'station_backup') return 'pump_backup';
|
||||||
|
if (stationId === 'station_control') return 'controller_plc';
|
||||||
|
return 'pump_primary';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get default data type ID
|
||||||
|
*/
|
||||||
|
getDefaultDataTypeId() {
|
||||||
|
// Try to get the first data type from our metadata
|
||||||
|
const dataTypeSelect = document.getElementById('data_type_id');
|
||||||
|
if (dataTypeSelect && dataTypeSelect.options.length > 1) {
|
||||||
|
return dataTypeSelect.options[1].value; // First actual data type
|
||||||
|
}
|
||||||
|
// Fallback to our sample metadata IDs
|
||||||
|
return 'speed_pump';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if station ID exists in our metadata
|
||||||
|
*/
|
||||||
|
isValidStationId(stationId) {
|
||||||
|
const stationSelect = document.getElementById('station_id');
|
||||||
|
if (!stationSelect) return false;
|
||||||
|
return Array.from(stationSelect.options).some(option => option.value === stationId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if equipment ID exists in our metadata
|
||||||
|
*/
|
||||||
|
isValidEquipmentId(equipmentId) {
|
||||||
|
const equipmentSelect = document.getElementById('equipment_id');
|
||||||
|
if (!equipmentSelect) return false;
|
||||||
|
return Array.from(equipmentSelect.options).some(option => option.value === equipmentId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if data type ID exists in our metadata
|
||||||
|
*/
|
||||||
|
isValidDataTypeId(dataTypeId) {
|
||||||
|
const dataTypeSelect = document.getElementById('data_type_id');
|
||||||
|
if (!dataTypeSelect) return false;
|
||||||
|
return Array.from(dataTypeSelect.options).some(option => option.value === dataTypeId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize discovery when DOM is loaded
|
// Initialize discovery when DOM is loaded
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue