Spaces:
Runtime error
Runtime error
Download static/js/upload.js from StrategyForge/PRISM-Marketing-Mix-Intelligence: direct link, hf CLI and curl.
- Browser
- Download file 6.98 kB
-
https://huggingface.co/spaces/StrategyForge/PRISM-Marketing-Mix-Intelligence/resolve/main/static/js/upload.js
- Command line
-
hf download hf://spaces/StrategyForge/PRISM-Marketing-Mix-Intelligence/static/js/upload.js
-
curl -L -o upload.js https://huggingface.co/spaces/StrategyForge/PRISM-Marketing-Mix-Intelligence/resolve/main/static/js/upload.js
6.98 kB
| // ===== Data Upload & Schema ===== | |
| let selectedFile = null; | |
| // Drag & Drop - initialize safely on DOMContentLoaded | |
| document.addEventListener('DOMContentLoaded', () => { | |
| const zone = document.getElementById('uploadZone'); | |
| const fileInput = document.getElementById('fileInput'); | |
| if (zone && fileInput) { | |
| zone.addEventListener('click', (e) => { | |
| // Don't trigger file picker if clicking inside the source selector | |
| if (e.target.closest('.source-selector')) return; | |
| fileInput.click(); | |
| }); | |
| zone.addEventListener('dragover', e => { e.preventDefault(); zone.classList.add('dragover'); }); | |
| zone.addEventListener('dragleave', () => zone.classList.remove('dragover')); | |
| zone.addEventListener('drop', e => { | |
| e.preventDefault(); | |
| zone.classList.remove('dragover'); | |
| if (e.dataTransfer.files.length > 0) selectFile(e.dataTransfer.files[0]); | |
| }); | |
| fileInput.addEventListener('change', e => { | |
| if (e.target.files.length > 0) selectFile(e.target.files[0]); | |
| }); | |
| } | |
| // Load schema (Data Dictionary) | |
| loadSchema(); | |
| }); | |
| function selectFile(file) { | |
| selectedFile = file; | |
| const selector = document.getElementById('sourceSelector'); | |
| if (selector) selector.style.display = 'block'; | |
| const nameEl = document.getElementById('selectedFileName'); | |
| if (nameEl) nameEl.textContent = `${file.name} (${(file.size / 1024).toFixed(1)} KB)`; | |
| } | |
| function cancelUpload() { | |
| selectedFile = null; | |
| const selector = document.getElementById('sourceSelector'); | |
| if (selector) selector.style.display = 'none'; | |
| const vr = document.getElementById('validationResults'); | |
| if (vr) vr.classList.remove('visible'); | |
| const fi = document.getElementById('fileInput'); | |
| if (fi) fi.value = ''; | |
| } | |
| function uploadFile() { | |
| if (!selectedFile) return; | |
| const sourceType = document.getElementById('sourceType').value; | |
| if (!sourceType) { alert('Please select a data source type'); return; } | |
| const btn = document.querySelector('.btn-upload'); | |
| if (btn) { btn.disabled = true; btn.textContent = 'Uploading...'; } | |
| const formData = new FormData(); | |
| formData.append('file', selectedFile); | |
| formData.append('source_type', sourceType); | |
| fetch('/data/api/data/upload-raw', { method: 'POST', body: formData }) | |
| .then(r => r.json()) | |
| .then(data => { | |
| if (btn) { btn.disabled = false; btn.textContent = 'Upload to Raw'; } | |
| if (data.error) { alert(data.error); return; } | |
| showValidationResults(data); | |
| // Refresh the pipeline status to show the new file | |
| if (typeof refreshPipelineStatus === 'function') refreshPipelineStatus(); | |
| }) | |
| .catch(err => { | |
| if (btn) { btn.disabled = false; btn.textContent = 'Upload to Raw'; } | |
| console.error('Upload error:', err); | |
| alert('Upload failed: ' + err.message); | |
| }); | |
| } | |
| function showValidationResults(data) { | |
| const container = document.getElementById('validationResults'); | |
| const checks = document.getElementById('validationChecks'); | |
| if (!container || !checks) return; | |
| container.classList.add('visible'); | |
| let html = ''; | |
| // Show uploaded file info | |
| if (data.saved_as) { | |
| html += ` | |
| <div class="validation-check"> | |
| <div class="check-icon pass">✓</div> | |
| <span class="check-name">File Saved</span> | |
| <span class="check-detail">Saved as <strong>${data.saved_as}</strong> in raw folder</span> | |
| </div>`; | |
| } | |
| // Show validation checks | |
| if (data.checks) { | |
| html += data.checks.map(c => ` | |
| <div class="validation-check"> | |
| <div class="check-icon ${c.status}">${c.status === 'pass' ? '✓' : c.status === 'fail' ? '✗' : c.status === 'warning' ? '!' : 'i'}</div> | |
| <span class="check-name">${c.name}</span> | |
| <span class="check-detail">${c.detail}</span> | |
| </div> | |
| `).join(''); | |
| } | |
| if (data.stats) { | |
| html += ` | |
| <div style="margin-top: 16px; padding: 12px; background: var(--bg-secondary); border-radius: 8px; font-size: 12px; color: var(--text-secondary);"> | |
| <strong style="color: var(--text-primary);">Summary:</strong> ${data.stats.rows.toLocaleString()} rows, ${data.stats.columns} columns, ${data.stats.missing_pct}% missing | |
| </div>`; | |
| } | |
| html += ` | |
| <div style="margin-top: 12px; font-size: 12px; color: var(--text-muted);"> | |
| 💡 Use the <strong>Data Profiler</strong> and <strong>Auto Column Mapper</strong> agents above to process this file through the pipeline. | |
| </div>`; | |
| checks.innerHTML = html; | |
| } | |
| // ===== Data Schema / Data Dictionary ===== | |
| function loadSchema() { | |
| const container = document.getElementById('schemaSections'); | |
| if (!container) return; | |
| fetch('/data/api/data/schema') | |
| .then(r => r.json()) | |
| .then(schema => { | |
| const labels = { | |
| media: 'Media Data', sales: 'Sales Data', consumer_promo: 'Consumer Promo Data', | |
| trade_promo: 'Trade Promo Data', external_factors: 'External Factors Data' | |
| }; | |
| const icons = { | |
| media: '📺', sales: '💰', consumer_promo: '🎯', | |
| trade_promo: '🏪', external_factors: '🌍' | |
| }; | |
| container.innerHTML = Object.entries(schema).map(([key, s]) => ` | |
| <div class="schema-section" onclick="this.classList.toggle('open')"> | |
| <div class="schema-header"> | |
| <h4><span class="schema-icon">${icons[key] || ''}</span> ${labels[key] || key}</h4> | |
| <span class="field-count">${s.required_count} required / ${s.total_count} total fields</span> | |
| </div> | |
| <div class="schema-body"> | |
| <div class="schema-field schema-field-header"> | |
| <span class="field-name">Column Name</span> | |
| <span class="field-type">Data Type</span> | |
| <span class="field-req">Status</span> | |
| </div> | |
| ${s.fields.map(f => ` | |
| <div class="schema-field"> | |
| <span class="field-name">${f.name}</span> | |
| <span class="field-type">${f.type}</span> | |
| <span class="field-req ${f.required ? 'required' : 'optional'}">${f.required ? 'Required' : 'Optional'}</span> | |
| </div>`).join('')} | |
| </div> | |
| </div> | |
| `).join(''); | |
| }) | |
| .catch(err => { | |
| container.innerHTML = '<p class="results-empty">Could not load schema data.</p>'; | |
| console.error('Schema load error:', err); | |
| }); | |
| } | |