feat(calibration): finalize Step 2 Risk & Stops with inline PDF reports and visual validation
This commit is contained in:
@@ -212,7 +212,7 @@ async function validateCalibrationRisk() {
|
||||
async function generateRiskReport() {
|
||||
console.log("[calibration_risk] generateRiskReport() START");
|
||||
|
||||
const payload = buildRiskPayload(); // reutiliza la misma función que validate
|
||||
const payload = buildRiskPayload();
|
||||
|
||||
const res = await fetch("/api/v2/calibration/risk/report", {
|
||||
method: "POST",
|
||||
@@ -220,25 +220,23 @@ async function generateRiskReport() {
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
console.error("Failed to generate report");
|
||||
return;
|
||||
const data = await res.json();
|
||||
|
||||
if (data.url) {
|
||||
// Mostrar visor
|
||||
const viewer = document.getElementById("pdf_viewer_section");
|
||||
const frame = document.getElementById("pdf_frame");
|
||||
|
||||
frame.src = data.url;
|
||||
viewer.classList.remove("d-none");
|
||||
|
||||
// Scroll suave hacia el visor
|
||||
viewer.scrollIntoView({ behavior: "smooth" });
|
||||
} else {
|
||||
alert("Failed to generate report");
|
||||
}
|
||||
|
||||
const blob = await res.blob();
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = "risk_report.pdf";
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
|
||||
window.URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
|
||||
// =================================================
|
||||
// WIZARD NAVIGATION
|
||||
// =================================================
|
||||
@@ -804,6 +802,13 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
document
|
||||
.getElementById("generate_report_btn")
|
||||
?.addEventListener("click", generateRiskReport);
|
||||
|
||||
document
|
||||
.getElementById("close_pdf_btn")
|
||||
?.addEventListener("click", () => {
|
||||
document.getElementById("pdf_viewer_section").classList.add("d-none");
|
||||
document.getElementById("pdf_frame").src = "";
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user