π‘οΈ Warracker is an open source, self-hostable warranty tracker to monitor expirations, store receipts, files. You own the data, your rules!
Status page audit: working CSV export, global-view timeline fix (issue #192 follow-up)
Omega (QA)d19c6d789fae
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex a1352fc..5fb4bf6 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1,6 +1,11 @@# Changelog## 1.0.3 - 2026-10-02+- **Status page CSV export:** The Export button on the status dashboard was a placeholder that only showed a "not implemented" toast. It now downloads a CSV of the currently displayed (filtered and sorted) warranties, using the same column layout as the main page export so the file can be re-imported.+ - _Files: `frontend/status.js`_+- **Global-view timeline fix:** The expiration timeline chart always fetched `/api/warranties` (current user only), so in global view it silently omitted other users' warranties. It now builds from the already-loaded view data, matching the rest of the dashboard.+ - _Files: `frontend/status.js`_+### Fixed- **Input validations are now enforced and translated:** three new HTTP 400 validations β product name over 255 chars (was an unhandled DB error β HTTP 500), expiration date before purchase date (was silently accepted), and invalid claim status (was silently coerced) β now return a stable machine-readable `code` (`product_name_too_long`, `expiration_before_purchase`, `invalid_claim_status`; claim-status errors also include `valid_statuses`) alongside the English fallback message. The frontend maps those codes to i18n keys via a new `apiErrorMessage()` helper in `ui.js` (used by the add-warranty form, edit modal, and claims toasts), so error toasts render in the user's language instead of always-English. Two new English keys were added (`messages.product_name_too_long`, `messages.invalid_claim_status`) and machine-translated into all 19 non-English locales with `{{statuses}}` placeholder integrity verified. Also removed the now-unused `safeErrorMessage()` helper from `apiService.js`.- _Files: `backend/warranties_routes.py`, `frontend/js/components/ui.js`, `frontend/js/services/apiService.js`, `frontend/js/components/addWarrantyForm.js`, `frontend/js/components/editModal.js`, `frontend/js/components/claims.js`, `locales/*/translation.json`_diff --git a/frontend/status.js b/frontend/status.jsindex 5958a53..506bc6e 100644--- a/frontend/status.js+++ b/frontend/status.js@@ -568,6 +568,9 @@invoice_path: warranty.invoice_path || null,product_url: warranty.product_url,purchase_price: warranty.purchase_price,+ warranty_duration_years: warranty.warranty_duration_years || 0,+ warranty_duration_months: warranty.warranty_duration_months || 0,+ warranty_duration_days: warranty.warranty_duration_days || 0,vendor: warranty.vendor,model_number: warranty.model_number, // include model number for searchingserial_numbers: warranty.serial_numbers || [],@@ -585,21 +588,34 @@filterAndSortWarranties(); // This will render the table}- function filterAndSortWarranties() {- const tableBody = document.getElementById('recentExpirationsBody');- if (!tableBody) { console.warn("recentExpirationsBody not found for rendering warranties."); return; }-+ function getWarrantyStatusInfo(warranty) {+ const todayForStatus = new Date(); todayForStatus.setHours(0,0,0,0);+ // Archived takes precedence: show as Archived regardless of expiration+ if (warranty.is_archived) {+ return { text: i18next.t('warranties.archived', 'Archived'), className: 'status-archived' };+ }+ if (warranty.is_lifetime) {+ return { text: i18next.t('warranties.lifetime'), className: 'status-lifetime' };+ }+ const expirationDate = new Date(warranty.expiration_date);+ expirationDate.setHours(0,0,0,0);+ if (expirationDate <= todayForStatus) {+ return { text: i18next.t('warranties.expired'), className: 'status-expired' };+ }+ const timeDiff = expirationDate - todayForStatus;+ const daysDiff = Math.ceil(timeDiff / (1000 * 60 * 60 * 24));+ if (daysDiff <= EXPIRING_SOON_DAYS) {+ return { text: i18next.t('warranties.expiring_soon'), className: 'status-expiring' };+ }+ return { text: i18next.t('warranties.active'), className: 'status-active' };+ }++ // Returns the filtered + sorted warranty list currently shown in the table (no DOM writes)+ function getDisplayWarranties() {const currentSearchTerm = searchWarranties && searchWarranties.value ? searchWarranties.value.toLowerCase() : '';const currentStatusValue = statusFilter && statusFilter.value ? statusFilter.value : 'all';-- tableBody.innerHTML = '';- if (!allWarranties || allWarranties.length === 0) {- const colspan = isGlobalView ? 5 : 4;- const noWarrantiesMessage = i18next.t('status.recent_expirations_empty', 'No recently expired or expiring warranties.');- tableBody.innerHTML = `<tr><td colspan="${colspan}" style="text-align:center; padding: 20px;">${noWarrantiesMessage}</td></tr>`;- return;- }+ if (!allWarranties || allWarranties.length === 0) return [];const today = new Date();today.setHours(0,0,0,0); // Normalize today to start of day for consistent comparisons@@ -669,6 +685,24 @@return 0;});+ return displayWarranties;+ }++ function filterAndSortWarranties() {+ const tableBody = document.getElementById('recentExpirationsBody');+ if (!tableBody) { console.warn("recentExpirationsBody not found for rendering warranties."); return; }++ tableBody.innerHTML = '';++ if (!allWarranties || allWarranties.length === 0) {+ const colspan = isGlobalView ? 5 : 4;+ const noWarrantiesMessage = i18next.t('status.recent_expirations_empty', 'No recently expired or expiring warranties.');+ tableBody.innerHTML = `<tr><td colspan="${colspan}" style="text-align:center; padding: 20px;">${noWarrantiesMessage}</td></tr>`;+ return;+ }++ const displayWarranties = getDisplayWarranties();+if (displayWarranties.length === 0) {const colspan = isGlobalView ? 5 : 4;const noMatchMessage = i18next.t('messages.no_results', 'No results found');@@ -680,35 +714,10 @@const row = tableBody.insertRow();row.setAttribute('data-warranty-id', String(warranty.id)); // Ensure ID is string for datasetrow.style.cursor = 'pointer';-- let statusText, statusClass;- const todayForStatus = new Date(); todayForStatus.setHours(0,0,0,0);-- // Archived takes precedence: show as Archived regardless of expiration- if (warranty.is_archived) {- statusText = i18next.t('warranties.archived', 'Archived');- statusClass = 'status-archived';- } else if (warranty.is_lifetime) {- statusText = i18next.t('warranties.lifetime');- statusClass = 'status-lifetime';- } else {- const expirationDate = new Date(warranty.expiration_date);- expirationDate.setHours(0,0,0,0);- if (expirationDate <= todayForStatus) {- statusText = i18next.t('warranties.expired');- statusClass = 'status-expired';- } else {- const timeDiff = expirationDate - todayForStatus;- const daysDiff = Math.ceil(timeDiff / (1000 * 60 * 60 * 24));- if (daysDiff <= EXPIRING_SOON_DAYS) {- statusText = i18next.t('warranties.expiring_soon');- statusClass = 'status-expiring';- } else {- statusText = i18next.t('warranties.active');- statusClass = 'status-active';- }- }- }++ const statusInfo = getWarrantyStatusInfo(warranty);+ const statusText = statusInfo.text;+ const statusClass = statusInfo.className;row.className = statusClass;// Build row HTML based on current view mode@@ -732,6 +741,70 @@});}+ // Export the currently displayed (filtered + sorted) warranties as CSV.+ // Column layout matches the main page export so the file can be re-imported.+ function exportStatusCSV() {+ const displayWarranties = getDisplayWarranties();+ if (!displayWarranties || displayWarranties.length === 0) {+ showToast(i18next.t('messages.no_warranties_to_export', 'No warranties to export'), 'info');+ return;+ }++ const headers = [+ 'ProductName',+ 'PurchaseDate',+ 'IsLifetime',+ 'WarrantyDurationYears',+ 'WarrantyDurationMonths',+ 'WarrantyDurationDays',+ 'ExpirationDate',+ 'Status',+ 'PurchasePrice',+ 'SerialNumber',+ 'ProductURL',+ 'Tags',+ 'Vendor',+ ];+ const escapeField = (field) => `"${String(field).replace(/"/g, '""')}"`;+ let csv = headers.join(',') + '\n';+ displayWarranties.forEach((warranty) => {+ const serials = Array.isArray(warranty.serial_numbers)+ ? warranty.serial_numbers.map(sn => (sn && sn.serial_number) || sn).filter(Boolean).join(', ')+ : '';+ const statusText = getWarrantyStatusInfo(warranty).text;+ const row = [+ warranty.product_name || '',+ warranty.purchase_date ? formatDateYYYYMMDD(new Date(warranty.purchase_date)) : '',+ warranty.is_lifetime ? 'TRUE' : 'FALSE',+ warranty.warranty_duration_years || 0,+ warranty.warranty_duration_months || 0,+ warranty.warranty_duration_days || 0,+ (!warranty.is_lifetime && warranty.expiration_date) ? formatDateYYYYMMDD(new Date(warranty.expiration_date)) : '',+ statusText,+ (warranty.purchase_price !== null && warranty.purchase_price !== undefined && warranty.purchase_price !== '') ? warranty.purchase_price : '',+ serials,+ warranty.product_url || '',+ '', // Tags are not included in the statistics payload+ warranty.vendor || '',+ ];+ csv += row.map(escapeField).join(',') + '\n';+ });++ const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });+ const link = document.createElement('a');+ const url = URL.createObjectURL(blob);+ link.href = url;+ link.download = `warranties_export_${formatDateYYYYMMDD(new Date())}.csv`;+ document.body.appendChild(link);+ link.click();+ document.body.removeChild(link);+ URL.revokeObjectURL(url);+ showToast(+ i18next.t('messages.exported_warranties_successfully', { count: displayWarranties.length }, `Exported ${displayWarranties.length} warranties`),+ 'success'+ );+ }+function getStatusPriority(expirationDateStr, today, isLifetime = false, isArchived = false) {if (isArchived) return -1; // Archived comes first (or last depending on sort direction)if (isLifetime) return 0;@@ -949,31 +1022,10 @@}// --- BEGIN: Expiration Timeline Chart Fix ---- // Instead of using only API timeline, generate a comprehensive timeline from all warranties- let allWarrantiesForTimeline = [];- try {- // Try to fetch all warranties for a complete timeline- const token = window.auth && window.auth.getToken ? window.auth.getToken() : null;- if (token) {- const allWarrantiesResponse = await fetch('/api/warranties', {- headers: {- 'Authorization': `Bearer ${token}`,- 'Content-Type': 'application/json'- }- });- if (allWarrantiesResponse.ok) {- allWarrantiesForTimeline = await allWarrantiesResponse.json();- } else {- console.warn('Could not fetch all warranties for timeline, falling back to data.all_warranties');- allWarrantiesForTimeline = data.all_warranties || [];- }- } else {- allWarrantiesForTimeline = data.all_warranties || [];- }- } catch (err) {- console.error('Error fetching all warranties for timeline:', err);- allWarrantiesForTimeline = data.all_warranties || [];- }+ // Build the timeline from the warranties already loaded for the current+ // view (data.all_warranties). A separate /api/warranties fetch would only+ // ever return the current user's warranties, breaking the global view.+ const allWarrantiesForTimeline = data.all_warranties || [];// Helper: Extract timeline data from all warrantiesfunction extractTimelineData(warranties) {@@ -1380,11 +1432,10 @@filterAndSortWarranties();});}- if (exportBtn) {- exportBtn.addEventListener('click', function() {+ if (exportBtn) {+ exportBtn.addEventListener('click', function() {console.log("Status page export button clicked (status.js IIFE).");- // Placeholder for actual export logic for status page data- showToast('Export for status page table not fully implemented yet.', 'info');+ exportStatusCSV();});}attachSortListeners(); // Call IIFE's attachSortListeners