UI: actions menu, title/reprocess dialogs, collapsible progress, pdf download, labels

This commit is contained in:
Stefano Zini
2026-11-05 16:23:02 +01:00
parent 82001d4ffb
commit 23c0a18974
5 changed files with 50 additions and 23 deletions
+33 -19
View File
@@ -33,8 +33,10 @@ fin=true;draw()}
async function srch(){if(!q.value){sr.innerHTML="";return}const results=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=results.speech.map(hit=>`<div>${E(hit[0])} ${fmt(hit[1])} ${E(hit[2]||"")}: ${E(hit[3])}</div>`).join("")+results.screen.map(hit=>`<div>🖥 <a href="/shot?name=${hit[0]}&file=shots/${hit[4]}" target=_blank>${E(hit[0])} ${fmt(hit[1])}</a> ${E(hit[2]||"")}: ${E(hit[3])}</div>`).join("")+CLOSE("q","sr")}
// Start a pipeline run from the chosen step (/run); 409 means it is already running.
async function run(name){const step=document.getElementById("f-"+name).value;const response=await fetch(`/run?name=${name}&from=${step}`,{method:"POST"});if(response.status===409)alert("già in esecuzione");tick()}
// Reprocess dialog: pick the first step, then start the pipeline from it (/run); 409 means it is already running.
let rname="";
function reprocess(name){rname=name;rstep.innerHTML=["audio","transcribe","diarize","speakers","shots","docs","report","memory","render"].map(step=>`<option>${step}`).join("");rdlg.showModal()}
async function run(){const response=await fetch(`/run?name=${rname}&from=${rstep.value}`,{method:"POST"});rdlg.close();if(response.status===409)alert("già in esecuzione");tick()}
// Names of the checked recording rows (.mg checkboxes).
const sel_=()=>[...document.querySelectorAll(".mg:checked")].map(x=>x.value);
// Show the bulk bar only when something is checked, and show the selected count.
@@ -58,9 +60,12 @@ async function mergeSel(){const names=sel_();if(names.length<2)return alert("spu
const open_=new Set();
// Toggle the speakers panel for one recording and re-render.
async function spk(name){editing=false;open_.has(name)?open_.delete(name):open_.add(name);tick()}
// Recordings whose progress panel is expanded (click on the title while processing).
const pgo=new Set();
function togPg(name){pgo.has(name)?pgo.delete(name):pgo.add(name);tick()}
// Speakers panel: diarization label -> person mapping, with a datalist of candidate names.
async function panel(name){const data=await (await fetch("/speakers?name="+name)).json();
return `<tr class=sp><td colspan=7><datalist id="cand-${name}">${data.candidates.map(candidate=>`<option value="${E(candidate)}">`).join("")}</datalist>`+
return `<tr class=sp><td colspan=6><datalist id="cand-${name}">${data.candidates.map(candidate=>`<option value="${E(candidate)}">`).join("")}</datalist>`+
data.rows.map(row=>`<div><b>${E(row.label)}</b> ${fmt(row.talk_s)} <input data-n="${name}" data-l="${E(row.label)}" list="cand-${name}" value="${E(row.person)}"> ${row.source}${row.source==="auto"&&row.overlap_s!=null?" "+Math.round(row.overlap_s)+"s":""}<br><small>${row.samples.map(E).join(" | ")}</small></div>`).join("")+
`<div class=sa><button class=pri onclick="saveSpk('${name}')">✓ Salva nomi</button><button onclick="spk('${name}')">✕ Chiudi</button></div>`}
// Read the label -> person inputs and save them (/speaker_map).
@@ -69,6 +74,15 @@ const response=await fetch("/speaker_map?name="+name,{method:"POST",body:JSON.st
// Recompute the automatic title from the report.
async function retitle(name){const response=await fetch(`/run?name=${name}&from=title`,{method:"POST"});if(!response.ok)alert(await response.text());tick()}
const sel={};
// Mini modal with the secondary actions of one recording: rerun from step, drop video, delete.
function more(name,mb,label,canDrop,title,canRetitle,blocked){
mbody.innerHTML=`<b>${label}</b><button onclick="who('${name}')">👥 partecipanti</button><button onclick="mclose();spk('${name}')">speakers</button><button onclick="mclose();setTitle('${name}','${title}')">✎ modifica titolo</button>`+(canRetitle?`<button onclick="mclose();retitle('${name}')">↻ ricalcola titolo</button>`:"")+(mb?`<button ${blocked?"disabled":""} onclick="mclose();reprocess('${name}')">↻ riprocessa</button>`:"")+
(canDrop&&!blocked?`<button onclick="mclose();dropVid('${name}',${mb})">🎞 elimina video</button>`:"")+
(blocked?"":`<button class=del onclick="mclose();del_('${name}','${label}')">🗑 elimina riunione</button>`)+`<button onclick="mclose()">✕ chiudi</button>`;mdlg.showModal()}
// Participants: named speakers (unnamed labels shown as-is) with talk time, in the same modal.
async function who(name){const data=await (await fetch("/speakers?name="+name)).json();
mbody.innerHTML=`<b>Partecipanti</b>`+(data.rows.map(row=>`<div>${E(row.person||row.label)} <small>${fmt(row.talk_s)}</small></div>`).join("")||"<div>nessun dato</div>")+`<button onclick="mclose()">✕ chiudi</button>`}
const mclose=()=>mdlg.close();
// Delete one recording after confirmation.
async function del_(name,label){if(!confirm(`Eliminare definitivamente "${label}"?
Vengono cancellati registrazione, trascrizione, schermate e report. Non si può annullare.`))return;
@@ -77,9 +91,10 @@ const response=await fetch("/delete?name="+name,{method:"POST"});if(!response.ok
async function dropVid(name,mb){if(!confirm(`Eliminare il file video (${mb} MB)?
Report, trascrizione, audio e schermate restano, ma la riunione non potrà più essere rielaborata. Non si può annullare.`))return;
const response=await fetch("/drop_video?name="+name,{method:"POST"});if(!response.ok)alert(await response.text());tick()}
// Prompt for a new title; empty means automatic. The date suffix is stripped from the default text.
async function setTitle(name,cur){const title=prompt("Titolo della riunione (vuoto = automatico)",cur.replace(/ — \d{4}-\d\d-\d\d.*$/,""));if(title===null)return;
const response=await fetch("/title?name="+name,{method:"POST",body:title});if(!response.ok)alert(await response.text());tick()}
// Title dialog; empty means automatic. The date suffix is stripped from the default text.
let tname="";
function setTitle(name,cur){tname=name;tin.value=cur.replace(/ — \d{4}-\d\d-\d\d.*$/,"");tdlg.showModal();tin.select()}
async function saveTitle(){const response=await fetch("/title?name="+tname,{method:"POST",body:tin.value});tdlg.close();if(!response.ok)alert(await response.text());tick()}
// "mm:ss" or "h:mm:ss" -> seconds.
const sec=str=>str.trim().split(":").reduce((acc,part)=>acc*60+(+part),0);
// Open the preview dialog for recording n; the video is streamed from /video. Optional at = seconds to start playing from (used by the Q&A sources).
@@ -112,9 +127,9 @@ async function setLlm(){const response=await fetch(`/llm?shots=${llm.value}&repo
// Save the "skip screenshots" switch on the server.
async function setSkip(){await fetch("/skip_shots?v="+(skp.checked?1:0),{method:"POST"});tick()}
// Italian labels for pipeline steps.
const LBL={audio:"Audio",transcribing:"Trascrizione",diarizing:"Chi parla",identifying:"Nomi parlanti",shots:"Schermate",docs:"Documentazione",report:"Report",memory:"Memoria"};
const LBL={audio:"Audio",transcribing:"Trascrizione",diarizing:"Riconoscimento voci",identifying:"Assegnazione nomi",shots:"Schermate",docs:"Documentazione",report:"Report",memory:"Memoria"};
// What each step does, shown under the progress bar.
const HOW={audio:"pulizia e normalizzazione dell'audio",transcribing:"Whisper trascrive il parlato",diarizing:"riconoscimento di chi parla",identifying:"abbinamento voci-nomi",shots:"il modello di visione legge ogni schermata condivisa",docs:"ricerca su Confluence e Jira",report:"il modello scrive argomenti, decisioni e azioni",memory:"indicizzazione per la ricerca tra riunioni"};
const HOW={audio:"pulizia e normalizzazione dell'audio",transcribing:"Whisper trascrive il parlato",diarizing:"separazione dei partecipanti in base alla voce",identifying:"associazione di ogni voce al nome del partecipante",shots:"il modello di visione legge ogni schermata condivisa",docs:"ricerca su Confluence e Jira",report:"il modello scrive argomenti, decisioni e azioni",memory:"indicizzazione per la ricerca tra riunioni"};
// Seconds -> "N s", "N min" or "H h MM min".
const dur=seconds=>{if(seconds==null||!isFinite(seconds))return"–";seconds=Math.max(0,Math.round(seconds));if(seconds<60)return seconds+" s";const minutes=Math.round(seconds/60);return minutes<60?minutes+" min":Math.floor(minutes/60)+" h "+String(minutes%60).padStart(2,"0")+" min"};
// Seconds from now -> local HH:MM.
@@ -136,11 +151,11 @@ const idle=prog.idle,cls=act||idle<90?"":idle<300?"warn":"bad";
const tail=act?`ultimo passo completato ${dur(idle)} fa`:idle<90?`attivo · aggiornato ${dur(idle)} fa`:idle<300?`nessun avanzamento da <b>${dur(idle)}</b>: può essere normale (avvio modello, passo lungo)`:`nessuna attività da <b>${dur(idle)}</b>: possibile blocco, controlla il log Prefect o premi stop`;
return `<div class="live ${cls}"><span class=dot></span><span>${txt?txt+" — ":""}${tail}</span></div>`}
// Progress panel for a recording: boot, queued, or running pipeline.
function progPanel(row){const prog=row.prog;
function progPanel(row){const prog=row.prog,stop=`<span class=acts>${row.flow_run_id?`<a class=btn href="http://127.0.0.1:4200/runs/flow-run/${row.flow_run_id}" target=_blank>prefect</a>`:""}<button class=del onclick="stopRun('${row.name}')">■ stop</button></span>`;
// Pipeline starting: the Python environment can take minutes on the first run.
if(!prog&&row.running)return `<tr><td colspan=7><div class=pg><div class=pgh><span><span class=big>…</span> &nbsp;<b>Avvio della pipeline</b> <span class=n>— preparazione dell'ambiente Python (la prima volta scarica le dipendenze: qualche minuto)</span></span></div><div class="bar ind"><i></i></div><div class="live"><span class=dot></span><span>${E(row.boot||"in avvio…")}</span></div></div>`;
if(!prog&&row.running)return `<tr><td colspan=6><div class=pg><div class=pgh><span><span class=big>…</span> &nbsp;<b>Avvio della pipeline</b> <span class=n>— preparazione dell'ambiente Python (la prima volta scarica le dipendenze: qualche minuto)</span></span>${stop}</div><div class="bar ind"><i></i></div><div class="live"><span class=dot></span><span>${E(row.boot||"in avvio…")}</span></div></div>`;
// Queued behind another run, or nothing to show.
if(!prog)return row.status==="queued"?`<tr><td colspan=7><div class=pg><div class=pgh><b>In coda</b><span class=eta>parte appena finisce l'elaborazione in corso</span></div><div class="bar ind"><i></i></div></div>`:"";
if(!prog)return row.status==="queued"?`<tr><td colspan=6><div class=pg><div class=pgh><b>In coda</b><span><span class=eta>parte appena finisce l'elaborazione in corso</span> ${stop}</span></div><div class="bar ind"><i></i></div></div>`:"";
// Overall percent (null if unknown) and the running step.
const pct=prog.pct!=null?Math.round(prog.pct*100):null,cur=prog.plan.find(stage=>stage.state==="run");
// Step chips: skipped / done with duration / running with fraction / pending with estimate.
@@ -148,9 +163,9 @@ const chips=prog.plan.map(stage=>stage.state==="skip"?`<span class="st skip" tit
// Done-of-total counter and step label.
const cnt=prog.total?`${prog.done} di ${prog.total}`:"",step=LBL[prog.step]||prog.step;
// Panel markup: header, progress bars, step chips and live status.
return `<tr><td colspan=7><div class=pg>
return `<tr><td colspan=6><div class=pg>
<div class=pgh><span><span class=big>${pct!=null?pct+"%":"…"}</span> &nbsp;<b>${step}</b> <span class=n>— ${E(prog.note||HOW[prog.step]||"")}</span></span>
<span class=eta>${prog.eta!=null?`fine prevista <b>~${clock(prog.eta)}</b> · mancano <b>${dur(prog.eta)}</b> · `:""}trascorso ${dur(prog.elapsed)}</span></div>
<span><span class=eta>${prog.eta!=null?`fine prevista <b>~${clock(prog.eta)}</b> · mancano <b>${dur(prog.eta)}</b> · `:""}trascorso ${dur(prog.elapsed)}</span> ${stop}</span></div>
<div class="bar${pct==null?" ind":""}"><i style="width:${pct||0}%"></i></div>
<div class=steps>${chips}</div>
<div class="bar thin"><i style="width:${Math.round(prog.frac*100)}%"></i></div>
@@ -200,19 +215,18 @@ qs.textContent=data.queue?`rielaborazione: ${data.queue} da completare`:"";
// Remember step-select values so they survive the re-render.
document.querySelectorAll("select[id^=f-]").forEach(select=>sel[select.id]=select.value);
// Table header.
let html="<thead><tr><th>recording<th>status<th>duration<th>speakers<th>MB<th>links<th>actions</tr></thead>";
let html="<thead><tr><th>riunione<th>stato<th>durata<th>speaker<th>MB<th>azioni</tr></thead>";
// Pagination: PS meetings per page; clamp the page if recordings were removed, then draw the pager.
const pages=Math.max(1,Math.ceil(data.recs.length/PS));if(pg_>=pages)pg_=pages-1;
pgr.innerHTML=pages>1?`<button ${pg_?"":"disabled"} onclick="goPg(-1)">‹</button><span>pagina ${pg_+1} di ${pages} (${data.recs.length} riunioni)</span><button ${pg_<pages-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 row of data.recs.slice(pg_*PS,(pg_+1)*PS)){
// Display title, falling back to the upload name.
const nm=row.title||row.upload;
const nm=row.title||row.upload,act=!!(row.prog||row.running||row.status==="queued");
// Main row: checkbox, title and rename buttons; status badge with error text and time since last data.
html+=`<tbody class=rec><tr class=main><td><input type=checkbox class=mg value="${row.name}">${nm?`<b>${E(nm)}</b><br><small>${row.name}</small>`:row.name} <button class=del title="modifica titolo" onclick="setTitle('${row.name}','${E(row.title||row.upload||"").replace(/'/g,"")}')">✎</button>${row.mb&&row.files.includes("report.html")?`<button class=del title="ricalcola titolo" onclick="retitle('${row.name}')">↻</button>`:""}<td><span class="b ${row.status}" title="${E(row.error)}">${row.status}</span>${row.receiving_age_s!=null&&row.status==="recording"?` <small>${row.receiving_age_s}s ago</small>`:""}${row.error?`<br><small>${E(row.error)}</small>`:""}<td>${row.duration_s?fmt(row.duration_s):""}<td>${row.speakers??""}<td>${row.mb}
<td>${row.files.includes("report.html")?`<a href="/report?name=${row.name}" target=_blank>report</a><a href="/pdf?name=${row.name}" target=_blank>pdf</a>`:""}${row.flow_run_id?`<a href="http://127.0.0.1:4200/runs/flow-run/${row.flow_run_id}" target=_blank>prefect</a>`:""}
<td>${row.mb?`<select id="f-${row.name}">${["audio","transcribe","diarize","speakers","shots","docs","report","memory","render"].map(step=>`<option>${step}`).join("")}</select><button onclick="run('${row.name}')">run</button>`:""}<button onclick="spk('${row.name}')">speakers</button>${row.mb?`<button title="anteprima e ritaglio" onclick="play('${row.name}',${row.duration_s||0},'${E(nm||row.name).replace(/'/g,"")}')">▶ video</button>`:""}${row.mb&&row.status==="done"&&!row.running?`<button title="elimina solo il file video: report, trascrizione e schermate restano, ma non si può più rielaborare" onclick="dropVid('${row.name}',${row.mb})">🎞 elimina video</button>`:""}${row.running||row.status==="queued"?`<button onclick="stopRun('${row.name}')">stop</button>`:`<button class=del title="elimina la riunione" onclick="del_('${row.name}','${E(nm||row.name).replace(/'/g,"")}')">🗑</button>`}`;
html+=progPanel(row);
html+=`<tbody class=rec><tr class=main><td><input type=checkbox class=mg value="${row.name}"><span class="ttl${act?" act":""}"${act?` onclick="togPg('${row.name}')" title="mostra/nascondi avanzamento"`:""}>${nm?`<b>${E(nm)}</b>${act?"<span class=spin></span>":""}<br><small>${row.name}</small>`:row.name+(act?"<span class=spin></span>":"")}</span><td><span class="b ${row.status}" title="${E(row.error)}">${row.status}</span>${row.receiving_age_s!=null&&row.status==="recording"?` <small>${row.receiving_age_s}s ago</small>`:""}${row.error?`<br><small>${E(row.error)}</small>`:""}<td>${row.duration_s?fmt(row.duration_s):""}<td>${row.speakers??""}<td>${row.mb}
<td><div class=acts><a class="btn pri"${row.files.includes("report.html")?` href="/report?name=${row.name}" target=_blank`:""}>📄 report</a><a class=btn${row.files.includes("report.html")?` href="/pdf?name=${row.name}" target=_blank`:""}>pdf</a><button title="anteprima e ritaglio" ${row.mb?"":"disabled"} onclick="play('${row.name}',${row.duration_s||0},'${E(nm||row.name).replace(/'/g,"")}')">▶ video</button><button title="altre azioni" onclick="more('${row.name}',${row.mb||0},'${E(nm||row.name).replace(/'/g,"")}',${!!(row.mb&&row.status==="done"&&!row.running)},'${E(row.title||row.upload||"").replace(/'/g,"")}',${!!(row.mb&&row.files.includes("report.html"))},${!!(row.running||row.status==="queued"||row.status==="recording")})">⋯</button></div>`;
html+=pgo.has(row.name)?progPanel(row):"";
if(open_.has(row.name))html+=await panel(row.name);html+="</tbody>"}
// Re-render only when not editing a speaker field and no table input has focus, so user input is kept.
const ae=document.activeElement;if(!editing&&!(ae&&t.contains(ae)&&/^(INPUT|SELECT)$/.test(ae.tagName))){const ck=[...document.querySelectorAll(".mg:checked")].map(box=>box.value);t.innerHTML=html;for(const id in sel){const element=document.getElementById(id);if(element)element.value=sel[id]}document.querySelectorAll(".mg").forEach(box=>box.checked=ck.includes(box.value));upd()}}catch{/* poll failed: next tick retries */}}