Subh775 commited on
Commit
38ddbf2
·
1 Parent(s): c084585

auto-download rework..

Browse files
Files changed (1) hide show
  1. frontend/vehicles.html +27 -29
frontend/vehicles.html CHANGED
@@ -1506,34 +1506,31 @@
1506
  infoRow('Real-time Ratio', d.speed_vs_realtime + 'x', 'Processing speed relative to video playback rate.');
1507
 
1508
  if (d.video_id) {
1509
- loadReports(d.video_id);
1510
-
1511
- // Auto-Download Logic (Respects live toggle state)
1512
- if (document.getElementById('sv-auto-download').classList.contains('active')) {
1513
- const preferredFmt = document.getElementById('sv-report').value; // Get png or pdf
1514
- console.log(`[UrbanFlow] Auto-download triggered for .${preferredFmt}...`);
1515
-
1516
- setTimeout(() => {
1517
- fetch(`/reports_list/${d.video_id}`)
1518
- .then(r => r.json())
1519
- .then(res => {
1520
- // Try to find the file matching the preferred format first
1521
- let targetFile = res.files.find(f => f.endsWith(`.${preferredFmt}`));
1522
- // Fallback to any PDF if preferred format not found
1523
- if (!targetFile) targetFile = res.files.find(f => f.endsWith('.pdf'));
1524
-
1525
- if (targetFile) {
1526
- const link = document.createElement('a');
1527
- link.href = `/reports/${d.video_id}/${targetFile}`;
1528
- link.download = targetFile;
1529
- document.body.appendChild(link);
1530
- link.click();
1531
- document.body.removeChild(link);
1532
- }
1533
- })
1534
- .catch(err => console.error('[UrbanFlow] Auto-download failed:', err));
1535
- }, 3000);
1536
- }
1537
  }
1538
 
1539
  // Show New Analysis button in Settings
@@ -1593,7 +1590,7 @@
1593
  async function loadReports(videoId) {
1594
  const res = await fetch(`/reports/${videoId}`, { method: 'POST' });
1595
  const data = await res.json();
1596
- if (!data.files || !data.files.length) return;
1597
 
1598
  document.getElementById('reports-pending').classList.add('hidden');
1599
  const grid = document.getElementById('reports-grid');
@@ -1649,6 +1646,7 @@
1649
  `;
1650
  grid.appendChild(card);
1651
  });
 
1652
  }
1653
 
1654
  function toggleExportMaster(el) {
 
1506
  infoRow('Real-time Ratio', d.speed_vs_realtime + 'x', 'Processing speed relative to video playback rate.');
1507
 
1508
  if (d.video_id) {
1509
+ loadReports(d.video_id).then(data => {
1510
+ if (!data) return;
1511
+
1512
+ // Auto-Download Logic (Respects live toggle state)
1513
+ if (document.getElementById('sv-auto-download').classList.contains('active')) {
1514
+ const preferredFmt = document.getElementById('sv-report').value;
1515
+ console.log(`[UrbanFlow] Auto-downloading ${preferredFmt} reports...`);
1516
+
1517
+ // Download the primary charts in the user's preferred format
1518
+ data.files.forEach(targetFile => {
1519
+ // We only auto-download the primary KPI charts, not everything
1520
+ const isTarget = targetFile.endsWith(`.${preferredFmt}`) &&
1521
+ (targetFile.includes('congestion') || targetFile.includes('direction') || targetFile.includes('flow'));
1522
+
1523
+ if (isTarget) {
1524
+ const link = document.createElement('a');
1525
+ link.href = `/reports/${d.video_id}/${targetFile}`;
1526
+ link.download = targetFile;
1527
+ document.body.appendChild(link);
1528
+ link.click();
1529
+ document.body.removeChild(link);
1530
+ }
1531
+ });
1532
+ }
1533
+ });
 
 
 
1534
  }
1535
 
1536
  // Show New Analysis button in Settings
 
1590
  async function loadReports(videoId) {
1591
  const res = await fetch(`/reports/${videoId}`, { method: 'POST' });
1592
  const data = await res.json();
1593
+ if (!data.files || !data.files.length) return null;
1594
 
1595
  document.getElementById('reports-pending').classList.add('hidden');
1596
  const grid = document.getElementById('reports-grid');
 
1646
  `;
1647
  grid.appendChild(card);
1648
  });
1649
+ return data;
1650
  }
1651
 
1652
  function toggleExportMaster(el) {