UI: close buttons for search/Q&A results, bulk bar above table, pagination (100/page)

This commit is contained in:
Stefano Zini
2026-11-04 15:58:13 +01:00
parent 56c7fe8bd5
commit d3c6816181
2 changed files with 19 additions and 11 deletions
+12 -4
View File
@@ -7,16 +7,18 @@ const fmt=s=>{s=Math.round(s);return String(Math.floor(s/60)).padStart(2,"0")+":
q.onkeydown=e=>{if(e.key=="Enter")srch()};
// Enter in the Q&A box asks the question.
qa.onkeydown=e=>{if(e.key=="Enter")ask()};
// Close button appended after results: clears the input and the result box.
const CLOSE=(i,o)=>`<div><button onclick="${i}.value='';${o}.innerHTML=''">✕ chiudi</button></div>`;
// Q&A: /ask answers from the meeting data. The model may take minutes to load on first use.
async function ask(){if(!qa.value)return;ar.innerHTML="<small>…avvio modelli / risposta (può richiedere qualche minuto)</small>";
const r=await fetch("/ask?q="+encodeURIComponent(qa.value));if(!r.ok){ar.textContent=await r.text();return}const j=await r.json();
// Turn citation markers [n] into links to the matching report section; keep the marker if the source is missing.
ar.innerHTML="<div>"+E(j.answer).replace(/\[(\d+)\]/g,(m,n)=>{const s=j.sources[n-1];return s?`<a href="/report?name=${s.name}#${s.anchor}" target=_blank>[${n}]</a>`:m})+"</div>"+
j.sources.map(s=>`<div><small>[${s.n}] ${E(s.date)} ${E(s.meeting)} — ${E(s.topic)} ${fmt(s.t)} (${s.kind}): ${E(s.text)}</small></div>`).join("")}
j.sources.map(s=>`<div><small>[${s.n}] ${E(s.date)} ${E(s.meeting)} — ${E(s.topic)} ${fmt(s.t)} (${s.kind}): ${E(s.text)}</small></div>`).join("")+CLOSE("qa","ar")}
// Search over speech and screen text (/search).
async function srch(){if(!q.value){sr.innerHTML="";return}const j=await (await fetch("/search?q="+encodeURIComponent(q.value))).json();
// Speech hits: [meeting, seconds, speaker, text]. Screen hits: [meeting, seconds, speaker, text, shot file] and link to the screenshot.
sr.innerHTML=j.speech.map(r=>`<div>${E(r[0])} ${fmt(r[1])} ${E(r[2]||"")}: ${E(r[3])}</div>`).join("")+j.screen.map(r=>`<div>🖥 <a href="/shot?name=${r[0]}&file=shots/${r[4]}" target=_blank>${E(r[0])} ${fmt(r[1])}</a> ${E(r[2]||"")}: ${E(r[3])}</div>`).join("")}
sr.innerHTML=j.speech.map(r=>`<div>${E(r[0])} ${fmt(r[1])} ${E(r[2]||"")}: ${E(r[3])}</div>`).join("")+j.screen.map(r=>`<div>🖥 <a href="/shot?name=${r[0]}&file=shots/${r[4]}" target=_blank>${E(r[0])} ${fmt(r[1])}</a> ${E(r[2]||"")}: ${E(r[3])}</div>`).join("")+CLOSE("q","sr")}
// Start a pipeline run from the chosen step (/run); 409 means it is already running.
async function run(n){const f=document.getElementById("f-"+n).value;const r=await fetch(`/run?name=${n}&from=${f}`,{method:"POST"});if(r.status==409)alert("già in esecuzione");tick()}
// Names of the checked recording rows (.mg checkboxes).
@@ -166,6 +168,9 @@ addEventListener("dragover",e=>{e.preventDefault();document.body.classList.add("
addEventListener("dragleave",e=>{if(!e.relatedTarget)document.body.classList.remove("drag")});
// Drop anywhere on the page: upload the first file.
addEventListener("drop",e=>{e.preventDefault();document.body.classList.remove("drag");const f=e.dataTransfer.files[0];if(f)send(f)});
// Meetings per page and current page index (0-based); goPg changes page and re-renders.
const PS=100;let pg_=0;
function goPg(d){pg_+=d;tick()}
// Refresh the whole UI from /status: header, LLM pickers, table.
async function tick(){try{const j=await (await fetch("/status")).json();ab.disabled=j.ask_blocked;ab.title=j.ask_blocked?"pipeline in corso":"";
// Browser tab title shows the progress of the first running pipeline.
@@ -182,8 +187,11 @@ qs.textContent=j.queue?`rielaborazione: ${j.queue} da completare`:"";
document.querySelectorAll("select[id^=f-]").forEach(s=>sel[s.id]=s.value);
// Table header.
let h="<thead><tr><th>recording<th>status<th>duration<th>speakers<th>MB<th>links<th>actions</tr></thead>";
// One tbody per recording; "running" when the status is done but the process is still alive.
for(const r of j.recs){const st=r.running&&r.status=="done"?"running":r.status;
// Pagination: PS meetings per page; clamp the page if recordings were removed, then draw the pager.
const np=Math.max(1,Math.ceil(j.recs.length/PS));if(pg_>=np)pg_=np-1;
pgr.innerHTML=np>1?`<button ${pg_?"":"disabled"} onclick="goPg(-1)">‹</button><span>pagina ${pg_+1} di ${np} (${j.recs.length} riunioni)</span><button ${pg_<np-1?"":"disabled"} onclick="goPg(1)">›</button>`:"";
// One tbody per recording on the current page; "running" when the status is done but the process is still alive.
for(const r of j.recs.slice(pg_*PS,(pg_+1)*PS)){const st=r.running&&r.status=="done"?"running":r.status;
// Display title, falling back to the upload name.
const nm=r.title||r.upload;
// Main row: checkbox, title and rename buttons; status badge with error text and time since last data.