fix clear
This commit is contained in:
@@ -728,23 +728,33 @@ async function refresh() {
|
|||||||
}));
|
}));
|
||||||
async function clearIncidents(status) {
|
async function clearIncidents(status) {
|
||||||
const notice = document.getElementById('incidentNotice');
|
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 (!confirm(`Clear ${label}? Active evidence can recreate incidents on the next monitor refresh.`)) return;
|
||||||
if (notice) notice.textContent = `Clearing ${label}...`;
|
if (notice) notice.textContent = `Clearing ${label}...`;
|
||||||
try {
|
try {
|
||||||
const body = status ? {status} : {};
|
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 = {};
|
let payload = {};
|
||||||
try { payload = await response.json(); } catch (_err) {}
|
try { payload = await response.json(); } catch (_err) {}
|
||||||
if (!response.ok) throw new Error(payload.error || `HTTP ${response.status}`);
|
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.`;
|
const incidentResult = payload.incidents || payload;
|
||||||
await refresh();
|
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) {
|
} catch (err) {
|
||||||
if (notice) notice.textContent = `Could not clear incidents: ${err.message || err}`;
|
if (notice) notice.textContent = `Could not clear incidents: ${err.message || err}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
document.getElementById('clearResolvedIncidents')?.addEventListener('click', () => clearIncidents('resolved'));
|
const clearResolvedButton = document.getElementById('clearResolvedIncidents');
|
||||||
document.getElementById('clearAllIncidents')?.addEventListener('click', () => clearIncidents(''));
|
const clearAllButton = document.getElementById('clearAllIncidents');
|
||||||
|
if (clearResolvedButton) clearResolvedButton.onclick = () => clearIncidents('resolved');
|
||||||
|
if (clearAllButton) clearAllButton.onclick = () => clearIncidents('');
|
||||||
document.getElementById('blocks').innerHTML = table(data.block_candidates || [], [
|
document.getElementById('blocks').innerHTML = table(data.block_candidates || [], [
|
||||||
{label:'Source', key:'src_ip', render:r => entityCell(r, 'src_ip')},
|
{label:'Source', key:'src_ip', render:r => entityCell(r, 'src_ip')},
|
||||||
{label:'Score', key:'score'},
|
{label:'Score', key:'score'},
|
||||||
|
|||||||
Reference in New Issue
Block a user