pdf: white 9pt document-style print CSS, download named after report title; ui tweaks

This commit is contained in:
Stefano Zini
2026-11-05 17:16:46 +01:00
parent bc98e0d004
commit da309ce47f
2 changed files with 21 additions and 5 deletions
+16 -3
View File
@@ -21,7 +21,7 @@ import time
import urllib.request import urllib.request
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from pathlib import Path from pathlib import Path
from urllib.parse import parse_qs, urlparse from urllib.parse import parse_qs, quote, urlparse
# Sibling modules: db (SQLite, paths), llama (model servers), memory (Q&A). # Sibling modules: db (SQLite, paths), llama (model servers), memory (Q&A).
import db import db
@@ -54,7 +54,16 @@ NOPROXY = urllib.request.build_opener(urllib.request.ProxyHandler({}))
# Edge path; %ProgramFiles(x86)% expanded by Windows env. # Edge path; %ProgramFiles(x86)% expanded by Windows env.
EDGE = Path(os.path.expandvars(r"%ProgramFiles(x86)%\Microsoft\Edge\Application\msedge.exe")) EDGE = Path(os.path.expandvars(r"%ProgramFiles(x86)%\Microsoft\Edge\Application\msedge.exe"))
PRINT_CSS = ( PRINT_CSS = (
"@media print{body{max-width:none;padding:0}img,tr{break-inside:avoid}h2,h3{break-after:avoid}}" "@page{margin:15mm}"
"@media print{:root{--bg:#fff;--card:#fff;--soft:#f3f3f3;--line:#ccc}html,body{background:#fff}"
"body{max-width:none;padding:0;font-size:9pt;line-height:1.5}"
"h1{font-size:16pt}h2{font-size:12pt;margin-top:1.6em;border-top:0;padding-top:0}"
"table{font-size:8.5pt;border-radius:0;border:0;border-top:1px solid #999;border-bottom:1px solid #999}"
"td,th{padding:4px 8px}th{background:#eee}"
"#in-breve+ul{border-radius:0;padding:10px 16px 10px 2em}"
"details{border:0;padding:0;margin-top:1em;background:none}summary{display:none}"
"img{border-radius:0;max-width:100%}code{border-radius:0}"
"img,tr{break-inside:avoid}h2,h3{break-after:avoid}}"
) )
# Serializes ask_once: one llama start/stop at a time. # Serializes ask_once: one llama start/stop at a time.
LOCK = threading.Lock() LOCK = threading.Lock()
@@ -876,10 +885,14 @@ class Handler(BaseHTTPRequestHandler):
if file_path is None: if file_path is None:
self._send(b"not found", 404) self._send(b"not found", 404)
else: else:
# File name from the report <title>; filename* carries the UTF-8 form, filename the ASCII fallback.
match = re.search(r"<title>(.*?)</title>", file_path.with_name("report.html").read_text(encoding="utf-8")[:2000])
label = re.sub(r'[\\/:*?"<>|\s]+', " ", match[1] if match else name).strip() or name
ascii_label = label.encode("ascii", "ignore").decode().strip() or name
self._send( self._send(
file_path.read_bytes(), file_path.read_bytes(),
ctype="application/pdf", ctype="application/pdf",
headers=[("Content-Disposition", f'attachment; filename="{name}.pdf"')], headers=[("Content-Disposition", f'attachment; filename="{ascii_label}.pdf"; filename*=UTF-8\'\'{quote(label + ".pdf")}')],
) )
elif parsed.path == "/ask": elif parsed.path == "/ask":
if not params.get("q", "").strip(): if not params.get("q", "").strip():
+5 -2
View File
@@ -77,8 +77,11 @@ const sel={};
// Mini modal with the secondary actions of one recording: rerun from step, drop video, delete. // Mini modal with the secondary actions of one recording: rerun from step, drop video, delete.
function more(name,mb,label,canDrop,title,canRetitle,blocked){ 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>`:"")+ 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>`:"")+
`<button onclick="mclose();reveal('${name}')">📂 mostra su disco</button>`+
(canDrop&&!blocked?`<button onclick="mclose();dropVid('${name}',${mb})">🎞 elimina video</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()} (blocked?"":`<button class=del onclick="mclose();del_('${name}','${label}')">🗑 elimina riunione</button>`)+`<button onclick="mclose()">✕ chiudi</button>`;mdlg.showModal()}
// Ask the server to open the meeting folder in Explorer.
async function reveal(name){const response=await fetch("/reveal?name="+name,{method:"POST"});if(!response.ok)alert(await response.text())}
// Participants: named speakers (unnamed labels shown as-is) with talk time, in the same modal. // 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(); 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>`} 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>`}
@@ -215,7 +218,7 @@ qs.textContent=data.queue?`rielaborazione: ${data.queue} da completare`:"";
// Remember step-select values so they survive the re-render. // Remember step-select values so they survive the re-render.
document.querySelectorAll("select[id^=f-]").forEach(select=>sel[select.id]=select.value); document.querySelectorAll("select[id^=f-]").forEach(select=>sel[select.id]=select.value);
// Table header. // Table header.
let html="<thead><tr><th>riunione<th>stato<th>durata<th>speaker<th>MB<th>azioni</tr></thead>"; let html="<thead><tr><th>riunione<th>stato<th>durata<th>speaker<th>dimensione<th>azioni</tr></thead>";
// Pagination: PS meetings per page; clamp the page if recordings were removed, then draw the pager. // 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; 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>`:""; 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>`:"";
@@ -224,7 +227,7 @@ for(const row of data.recs.slice(pg_*PS,(pg_+1)*PS)){
// Display title, falling back to the upload name. // Display title, falling back to the upload name.
const nm=row.title||row.upload,act=!!(row.prog||row.running||row.status==="queued"); 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. // 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}"><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} 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?row.mb+" 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>`; <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):""; html+=pgo.has(row.name)?progPanel(row):"";
if(open_.has(row.name))html+=await panel(row.name);html+="</tbody>"} if(open_.has(row.name))html+=await panel(row.name);html+="</tbody>"}