fix clear

This commit is contained in:
larssand
2026-07-06 17:45:39 +02:00
parent da540f81ae
commit b9ca0e1760

View File

@@ -728,23 +728,33 @@ async function refresh() {
}));
async function clearIncidents(status) {
const notice = document.getElementById('incidentNotice');
const label = status ? `${status} incident states` : 'all stored incident states';
const label = status ? `${status} incident states` : 'all incident and finding review states';
if (!confirm(`Clear ${label}? Active evidence can recreate incidents on the next monitor refresh.`)) return;
if (notice) notice.textContent = `Clearing ${label}...`;
try {
const body = status ? {status} : {};
const response = await fetch('/api/incidents/clear', {method:'POST', headers:{'Content-Type':'application/json'}, body:JSON.stringify(body)});
const endpoint = status ? '/api/incidents/clear' : '/api/review-state/clear';
const response = await fetch(endpoint, {method:'POST', headers:{'Content-Type':'application/json'}, body:JSON.stringify(body)});
let payload = {};
try { payload = await response.json(); } catch (_err) {}
if (!response.ok) throw new Error(payload.error || `HTTP ${response.status}`);
if (notice) notice.textContent = `Cleared ${payload.removed || 0} incident state(s). ${payload.remaining || 0} stored state(s) remain.`;
await refresh();
const incidentResult = payload.incidents || payload;
const feedbackResult = payload.feedback || {};
const feedbackText = payload.feedback ? ` Feedback cleared: ${feedbackResult.removed || 0}.` : '';
if (notice) notice.textContent = `Cleared ${incidentResult.removed || 0} incident state(s). ${incidentResult.remaining || 0} stored incident state(s) remain.${feedbackText}`;
if (!status) {
document.getElementById('incidents').innerHTML = '<p class="muted">Stored incident states cleared. New active incidents may appear on the next monitor refresh if evidence still exists.</p>';
document.getElementById('triageQueue').innerHTML = '<p class="muted">Review state cleared. Triage will rebuild from current evidence on the next monitor refresh.</p>';
}
setTimeout(refresh, 500);
} catch (err) {
if (notice) notice.textContent = `Could not clear incidents: ${err.message || err}`;
}
}
document.getElementById('clearResolvedIncidents')?.addEventListener('click', () => clearIncidents('resolved'));
document.getElementById('clearAllIncidents')?.addEventListener('click', () => clearIncidents(''));
const clearResolvedButton = document.getElementById('clearResolvedIncidents');
const clearAllButton = document.getElementById('clearAllIncidents');
if (clearResolvedButton) clearResolvedButton.onclick = () => clearIncidents('resolved');
if (clearAllButton) clearAllButton.onclick = () => clearIncidents('');
document.getElementById('blocks').innerHTML = table(data.block_candidates || [], [
{label:'Source', key:'src_ip', render:r => entityCell(r, 'src_ip')},
{label:'Score', key:'score'},