Skip to content

Commit 8c02df1

Browse files
committed
fix: synchronize download logic between HTML template and JavaScript
- Added explicit JSON struct tags to ExportItem for proper serialization - Updated JavaScript to use correct JSON property names (lowercase) - Synchronized download URL generation logic between static template and dynamic JavaScript - Fixed missing download buttons in export history pagination/filtering This resolves the issue where download buttons were not showing up in the export history when using dynamic loading (pagination/filters).
1 parent 97de033 commit 8c02df1

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

pkg/web/handlers/exports.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ type PaginationData struct {
4343
}
4444

4545
type ExportItem struct {
46-
ID string
47-
Type string
48-
Date time.Time
49-
Status string
50-
Duration string
51-
FileSize string
52-
RecordCount int
53-
Files []string
54-
Error string
46+
ID string `json:"id"`
47+
Type string `json:"type"`
48+
Date time.Time `json:"date"`
49+
Status string `json:"status"`
50+
Duration string `json:"duration"`
51+
FileSize string `json:"fileSize"`
52+
RecordCount int `json:"recordCount"`
53+
Files []string `json:"files"`
54+
Error string `json:"error"`
5555
}
5656

5757
type ExportAPIResponse struct {

web/templates/exports.html

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,8 @@ <h3>No exports found</h3>
520520
'watchlist': '📝 Watchlist'
521521
};
522522

523-
const typeLabel = typeIcons[exportItem.Type] || `📄 ${exportItem.Type}`;
524-
const date = new Date(exportItem.Date).toLocaleString('en-CA', {
523+
const typeLabel = typeIcons[exportItem.type] || `📄 ${exportItem.type}`;
524+
const date = new Date(exportItem.date).toLocaleString('en-CA', {
525525
year: 'numeric',
526526
month: '2-digit',
527527
day: '2-digit',
@@ -530,10 +530,10 @@ <h3>No exports found</h3>
530530
});
531531

532532
let downloadButtons = '';
533-
if (exportItem.Status === 'completed' && exportItem.Files && Array.isArray(exportItem.Files)) {
534-
downloadButtons = exportItem.Files.map(file => {
535-
const downloadUrl = exportItem.ID && exportItem.ID.startsWith('dir_')
536-
? `/download/${exportItem.ID.substring(4)}/${file}`
533+
if (exportItem.status === 'completed' && exportItem.files && Array.isArray(exportItem.files)) {
534+
downloadButtons = exportItem.files.map(file => {
535+
const downloadUrl = exportItem.id && exportItem.id.indexOf('dir_') === 0
536+
? `/download/${exportItem.id.substring(4)}/${file}`
537537
: `/download/${file}`;
538538
const fileName = file.replace(/\.[^/.]+$/, ""); // Remove extension
539539
return `
@@ -543,37 +543,37 @@ <h3>No exports found</h3>
543543
`;
544544
}).join('');
545545

546-
if (exportItem.Files.length > 1) {
546+
if (exportItem.files.length > 1) {
547547
downloadButtons += '<div class="download-all"><small>💡 Tip: Right-click links to save files</small></div>';
548548
}
549549
}
550550

551-
const errorHTML = exportItem.Error ? `
551+
const errorHTML = exportItem.error ? `
552552
<div class="export-error">
553553
<span class="error-icon">❌</span>
554-
<span class="error-message">${exportItem.Error}</span>
554+
<span class="error-message">${exportItem.error}</span>
555555
</div>
556556
` : '';
557557

558558
return `
559-
<div class="export-item" data-type="${exportItem.Type}" data-status="${exportItem.Status}">
559+
<div class="export-item" data-type="${exportItem.type}" data-status="${exportItem.status}">
560560
<div class="export-info">
561561
<div class="export-header">
562562
<h4>${typeLabel}</h4>
563-
<span class="export-status status-indicator ${exportItem.Status}">${exportItem.Status}</span>
563+
<span class="export-status status-indicator ${exportItem.status}">${exportItem.status}</span>
564564
</div>
565565
<div class="export-details">
566566
<span class="export-date">📅 ${date}</span>
567-
${exportItem.Duration ? `<span class="export-duration">⏱️ ${exportItem.Duration}</span>` : ''}
568-
${exportItem.FileSize ? `<span class="export-size">💾 ${exportItem.FileSize}</span>` : ''}
569-
${exportItem.RecordCount ? `<span class="export-records">📊 ${exportItem.RecordCount} records</span>` : ''}
570-
<span class="export-files">📁 ${exportItem.Files ? exportItem.Files.length : 0} file${exportItem.Files && exportItem.Files.length > 1 ? 's' : ''}</span>
567+
${exportItem.duration ? `<span class="export-duration">⏱️ ${exportItem.duration}</span>` : ''}
568+
${exportItem.fileSize ? `<span class="export-size">💾 ${exportItem.fileSize}</span>` : ''}
569+
${exportItem.recordCount ? `<span class="export-records">📊 ${exportItem.recordCount} records</span>` : ''}
570+
<span class="export-files">📁 ${exportItem.files ? exportItem.files.length : 0} file${exportItem.files && exportItem.files.length > 1 ? 's' : ''}</span>
571571
</div>
572572
${errorHTML}
573573
</div>
574574
<div class="export-actions-container">
575575
${downloadButtons}
576-
<button class="btn btn-sm btn-outline delete-btn" data-id="${exportItem.ID}" title="Delete this export">
576+
<button class="btn btn-sm btn-outline delete-btn" data-id="${exportItem.id}" title="Delete this export">
577577
🗑️ Delete
578578
</button>
579579
</div>

0 commit comments

Comments
 (0)