Click the file select icon to "edit" content.Loading...
'; const start = (currentPage - 1) * itemsPerPage; const pageItems = filteredResults.slice(start, start + itemsPerPage); buildContentTable(pageItems); } catch (error) { console.error('Error fetching page:', error); document.getElementById('content-details').innerHTML = `Error: ${error.message}
`; } } // ===== Table & pagination ===== function buildContentTable(results) { const contentDetailsDiv = document.getElementById('content-details'); const contentSummaryDiv = document.getElementById('content-summary'); if (results.length === 0) { contentDetailsDiv.innerHTML = 'No results found.
'; contentSummaryDiv.innerHTML = ''; document.getElementById('pagination-top').innerHTML = ''; document.getElementById('pagination-bottom').innerHTML = ''; return; } results.sort((a, b) => (b.updated || b.created) - (a.updated || a.created)); let tableHtml = '| Service | Identifier | Metadata | Preview | Size | Created / Updated |
|---|---|---|---|---|---|
| ${result.service} |
|
${generatePreviewHTML(result, userName, identifier)} | ${sizeString} | ${createdString} ${updatedString} |
${startItem}-${endItem} of ${totalResults} results
Total Size: ${formatSize(totalSize)}
`; const paginationHTML = buildPaginationControls(); document.getElementById('pagination-top').innerHTML = paginationHTML; document.getElementById('pagination-bottom').innerHTML = paginationHTML; contentDetailsDiv.innerHTML = tableHtml; initPreviews(); document.querySelectorAll('.clickable-delete').forEach(el => { el.addEventListener('click', function() { deleteContent(this.getAttribute('data-service'), this.getAttribute('data-identifier')); }); }); document.querySelectorAll('.clickable-edit').forEach(el => { el.addEventListener('click', function() { editContent(this.getAttribute('data-service'), this.getAttribute('data-identifier')); }); }); document.querySelectorAll('.clickable-metadata').forEach(el => { el.addEventListener('click', function() { const idx = parseInt(this.getAttribute('data-metadata-index'), 10); if (!isNaN(idx) && idx >= 0) openMetadataDialog(metadataArray[idx]); else alert('No metadata available.'); }); }); addPaginationEventHandlers(); } function buildPaginationControls() { const totalPages = Math.ceil(totalResults / itemsPerPage); if (totalPages <= 1) return ''; let html = ''; if (currentPage > 1) { html += `««`; html += `«`; } else { html += `«««`; } for (let p = 1; p <= totalPages; p++) { html += (p === currentPage) ? `${p}` : `${p}`; } if (currentPage < totalPages) { html += `»`; html += `»»`; } else { html += `»»»`; } return html; } function addPaginationEventHandlers() { document.querySelectorAll('.pagination-link').forEach(link => { link.addEventListener('click', async function() { const newPage = parseInt(this.getAttribute('data-page'), 10); if (!isNaN(newPage)) { showSpinner(); contentPage.style.display = "none"; try { currentPage = newPage; await fetchPage(); } finally { contentPage.style.display = "block"; hideSpinner(); } } }); }); } function formatSize(size) { if (size > (1024*1024*1024*1024)) return (size / (1024*1024*1024*1024)).toFixed(2) + ' TB'; if (size > (1024*1024*1024)) return (size / (1024*1024*1024)).toFixed(2) + ' GB'; if (size > (1024*1024)) return (size / (1024*1024)).toFixed(2) + ' MB'; if (size > 1024) return (size / 1024).toFixed(2) + ' KB'; return (size || 0) + ' B'; } // ===== Preview rendering ===== function generatePreviewHTML(result, userName, identifier) { const safeName = (result.name || userName || '').replace(/"/g, '"'); const safeService = (result.service || '').replace(/"/g, '"'); const safeIdent = (identifier || 'default').replace(/"/g, '"'); return `