Files
ExportDXF/FabWorks.Api/wwwroot/js/helpers.js
AJ Isaacs 5de40ebafd feat: add delete button to exports list and detail pages
Add DELETE /api/exports/{id} endpoint with cascade delete, trash icon
buttons on both the exports list and export detail pages, and disable
browser caching for static files to prevent stale JS issues.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 09:34:59 -05:00

51 lines
1.5 KiB
JavaScript

function fmtSize(b) {
if (!b) return '0 B';
const k = 1024, s = ['B','KB','MB','GB'];
const i = Math.floor(Math.log(b) / Math.log(k));
return parseFloat((b / Math.pow(k, i)).toFixed(1)) + ' ' + s[i];
}
function fmtDate(d) {
if (!d) return '';
const dt = new Date(d);
return dt.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' }) +
' ' + dt.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
}
function fmtThickness(t) {
if (t == null) return '\u2014';
return `<span style="font-family:var(--font-mono)">${t.toFixed(4)}"</span>`;
}
function esc(s) {
return s ? s.replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;').replace(/'/g,'&#39;') : '';
}
function setPage(title, tag = '') {
document.getElementById('page-title').textContent = title;
document.getElementById('page-tag').textContent = tag;
document.getElementById('page-tag').style.display = tag ? '' : 'none';
}
const api = {
async get(url) {
const r = await fetch(url);
if (!r.ok) throw new Error(`${r.status} ${r.statusText}`);
return r.json();
},
async del(url) {
const r = await fetch(url, { method: 'DELETE' });
if (!r.ok) throw new Error(`${r.status} ${r.statusText}`);
}
};
async function deleteExport(id) {
if (!confirm('Delete this export record? This cannot be undone.')) return;
try {
await api.del(`/api/exports/${id}`);
router.dispatch();
} catch (err) {
alert('Failed to delete: ' + err.message);
}
}