Add clear DTC codes button to Pi DTC page (FEAT-15)

This commit is contained in:
Mathieu Moran
2026-08-13 16:40:15 -04:00
parent b39faadf58
commit e873db918d
8 changed files with 187 additions and 2 deletions
+27
View File
@@ -14,6 +14,9 @@
<button id="dtc-refresh-btn" class="btn btn-sm btn-secondary">
<i class="fas fa-sync-alt me-1"></i>Refresh
</button>
<button id="dtc-clear-btn" class="btn btn-sm btn-outline-danger">
<i class="fas fa-eraser me-1"></i>Clear codes
</button>
</div>
</div>
@@ -42,6 +45,7 @@
const milEl = document.getElementById('mil-indicator');
const updatedEl = document.getElementById('dtc-updated');
const refreshBtn = document.getElementById('dtc-refresh-btn');
const clearBtn = document.getElementById('dtc-clear-btn');
const body = document.querySelector('#dtc-list [data-data-list-body]');
async function loadDtc() {
@@ -83,6 +87,29 @@
}
refreshBtn.addEventListener('click', loadDtc);
clearBtn.addEventListener('click', async function () {
if (!window.confirm('Clear all DTC codes from the car ECU? This clears the check-engine light unless a fault is still present.')) {
return;
}
clearBtn.disabled = true;
updatedEl.textContent = 'Clearing…';
try {
const r = await fetch('/api/dtc/clear', { method: 'POST' });
const d = await r.json();
if (!r.ok) {
updatedEl.textContent = d.error || 'Clear failed';
return;
}
await loadDtc();
updatedEl.textContent = 'Codes cleared';
} catch (e) {
updatedEl.textContent = 'Clear failed';
} finally {
clearBtn.disabled = false;
}
});
loadDtc();
})();
</script>