Duriin-API/public/admin/assets/js/intel-predictions.js

61 lines
2.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// intelligence → predictions table
// depends on: app.js, intel-shared.js
let predictionsOffset = 0;
async function loadPredictions() {
const companyId = document.getElementById("i-company").value;
const sort = document.getElementById("i-sort").value;
const params = new URLSearchParams({ limit: PAGE, offset: predictionsOffset });
if (companyId) params.set("company_id", companyId);
if (sort) params.set("sort", sort);
const data = await api(`/admin/api/intelligence/predictions?${params}`);
intelRows = data.rows;
document.getElementById("intel-thead").innerHTML = `
<tr><th>ID</th><th>Company</th><th>Event</th><th>Type</th><th>Direction</th><th>Magnitude</th><th>Timeframe</th><th>Rationale</th><th>Event date</th></tr>`;
document.getElementById("intel-tbody").innerHTML = data.rows.map(r => `
<tr style="cursor:pointer" onclick="openIntelDetail(${r.id}, 'predictions')">
<td style="color:var(--muted-dark); font-size:12px">${r.id}</td>
<td style="white-space:nowrap">${escapeHtml(r.company_name)}</td>
<td style="color:var(--muted-dark); font-size:12px">${r.event_id}</td>
<td><span class="badge null">${escapeHtml(r.type)}</span></td>
<td>${escapeHtml(r.direction || "—")}</td>
<td>${escapeHtml(r.magnitude || "—")}</td>
<td>${escapeHtml(r.timeframe || "—")}</td>
<td><span class="truncate" style="max-width:300px">${escapeHtml(r.rationale || "—")}</span></td>
<td style="color:var(--muted-dark); white-space:nowrap; font-size:12px">${r.event_date ? r.event_date.slice(0,10) : "—"}</td>
</tr>
`).join("");
const total = data.total;
document.getElementById("iPageInfo").textContent =
`${predictionsOffset + 1}${Math.min(predictionsOffset + PAGE, total)} of ${total.toLocaleString()}`;
document.getElementById("iPrevBtn").disabled = predictionsOffset === 0;
document.getElementById("iNextBtn").disabled = predictionsOffset + PAGE >= total;
}
document.addEventListener("DOMContentLoaded", async () => {
document.getElementById("iPrevBtn").onclick = () => {
predictionsOffset = Math.max(0, predictionsOffset - PAGE);
loadPredictions();
};
document.getElementById("iNextBtn").onclick = () => {
predictionsOffset += PAGE;
loadPredictions();
};
document.getElementById("i-filter-btn").onclick = () => {
predictionsOffset = 0;
loadPredictions();
};
const ok = await loadIntelStatsRow();
if (!ok) return;
await loadIntelCompanies();
loadPredictions();
});