/** * Data Analyzer Agent - Specific JavaScript * Uses WorkflowsCore for all shared functionality */ // Initialize data analyzer functionality document.addEventListener('DOMContentLoaded', function() { console.log('Data Analyzer loaded'); // Initialize file upload const fileInput = document.getElementById('dataFile'); if (fileInput) { fileInput.addEventListener('change', handleFileChange); } // Initialize drag and drop const uploadArea = document.querySelector('.file-upload-area'); if (uploadArea && fileInput) { WorkflowsCore.setupDragAndDrop(uploadArea, fileInput); } // Set initial radio selection const firstRadio = document.querySelector('.radio-card'); if (firstRadio && !document.querySelector('.radio-card.selected')) { firstRadio.classList.add('selected'); const input = firstRadio.querySelector('input[type="radio"]'); if (input) input.checked = true; } // Handle form submission const form = document.getElementById('agentForm'); if (form) { form.addEventListener('submit', handleFormSubmission); } }); // Data Analyzer specific functions function selectRadio(value) { // Remove selected class from all cards document.querySelectorAll('.radio-card').forEach(card => { card.classList.remove('selected'); }); // Add selected class to clicked card const selectedCard = document.querySelector(`input[value="${value}"]`).closest('.radio-card'); if (selectedCard) { selectedCard.classList.add('selected'); } // Select the radio button const radioInput = document.getElementById(value); if (radioInput) { radioInput.checked = true; } } function handleFileChange(event) { const file = event.target.files[0]; const uploadArea = document.querySelector('.file-upload-area'); const uploadText = document.querySelector('.upload-text'); if (file) { uploadArea.classList.add('file-selected'); uploadText.innerHTML = `
Analysis completed successfully. Your data has been processed.
'; } if (analysisData.timestamp) { resultsHtml += `Analysis completed: ${new Date(analysisData.timestamp).toLocaleString()}
`; } WorkflowsCore.showResults(resultsHtml, 'Analysis Results'); WorkflowsCore.showToast('✅ Data analysis completed successfully!', 'success'); } function isFormValid() { const fileInput = document.getElementById('dataFile'); const analysisType = document.querySelector('input[name="analysisType"]:checked'); // Clear previous errors WorkflowsCore.clearFieldError('dataFile'); WorkflowsCore.clearFieldError('analysisType'); let isValid = true; if (!fileInput.files || fileInput.files.length === 0) { WorkflowsCore.showFieldError('dataFile', 'Please select a data file'); WorkflowsCore.showToast('Please select a data file', 'error'); isValid = false; } if (!analysisType) { WorkflowsCore.showFieldError('analysisType', 'Please select an analysis type'); WorkflowsCore.showToast('Please select an analysis type', 'error'); isValid = false; } return isValid; }