Acquisizione: caselle di specchiatura orizzontale e verticale per sorgente
Refs #110 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -220,6 +220,12 @@ PAGINA = r"""<!doctype html>
|
||||
<section class="scheda" id="sezioneParametri">
|
||||
<h2>Parametri camera</h2>
|
||||
<div id="parametri"><div class="nota">-</div></div>
|
||||
<!-- #110: specchiatura per sorgente, applicata dal servizio a ogni frame -->
|
||||
<div class="riga" id="specchiaRiga" style="margin-top:10px">
|
||||
<label style="margin:0 0 6px"><input id="specchiaO" type="checkbox" disabled> Specchia orizzontale</label>
|
||||
<label style="margin:0 0 6px"><input id="specchiaV" type="checkbox" disabled> Specchia verticale</label>
|
||||
</div>
|
||||
<div id="msgSpecchia" class="messaggio"></div>
|
||||
<div class="riga" id="salvaParametriRiga" hidden>
|
||||
<button id="salvaParametri" class="secondario">Salva come predefiniti</button>
|
||||
</div>
|
||||
@@ -470,6 +476,7 @@ function cambioSorgente(salva) {
|
||||
dire("msgElenco", ""); // #91
|
||||
aggiornaStato();
|
||||
caricaParametri();
|
||||
caricaOrientamento(); // #110: specchiatura della nuova sorgente
|
||||
if (era) avviaAnteprima();
|
||||
}
|
||||
|
||||
@@ -793,6 +800,80 @@ async function caricaParametri() {
|
||||
}
|
||||
}
|
||||
|
||||
// #110: specchiatura per sorgente; gen scarta le risposte di una sorgente ormai lasciata, dati = ultimo stato noto del servizio
|
||||
var O = { gen: 0, dati: { orizzontale: false, verticale: false } };
|
||||
|
||||
function caselleSpecchia(attive) { // #110: abilita o disabilita le due caselle
|
||||
$("specchiaO").disabled = $("specchiaV").disabled = !attive;
|
||||
}
|
||||
|
||||
async function caricaOrientamento() { // #110
|
||||
var sorgente = $("sorgente").value;
|
||||
var g = ++O.gen;
|
||||
dire("msgSpecchia", "");
|
||||
O.dati = { orizzontale: false, verticale: false };
|
||||
$("specchiaO").checked = $("specchiaV").checked = false;
|
||||
caselleSpecchia(false); // spente finche' non si sa lo stato (e senza sorgente)
|
||||
if (!sorgente) return;
|
||||
try {
|
||||
var r = await fetch("/camera/orientamento?source=" + encodeURIComponent(sorgente));
|
||||
if (g !== O.gen) return;
|
||||
if (!r.ok) { dire("msgSpecchia", await dettaglio(r), "errore"); return; }
|
||||
var j = await r.json();
|
||||
if (g !== O.gen) return;
|
||||
O.dati = { orizzontale: !!j.orizzontale, verticale: !!j.verticale };
|
||||
$("specchiaO").checked = O.dati.orizzontale;
|
||||
$("specchiaV").checked = O.dati.verticale;
|
||||
caselleSpecchia(true);
|
||||
} catch (e) {
|
||||
if (g === O.gen) dire("msgSpecchia", "Servizio non raggiungibile.", "errore");
|
||||
}
|
||||
}
|
||||
|
||||
async function salvaOrientamento() { // #110: onchange di una casella -> PUT
|
||||
var sorgente = $("sorgente").value;
|
||||
if (!sorgente) return;
|
||||
var g = ++O.gen;
|
||||
var nuovo = { orizzontale: $("specchiaO").checked, verticale: $("specchiaV").checked };
|
||||
caselleSpecchia(false); // durante la PUT niente altri cambi
|
||||
dire("msgSpecchia", "");
|
||||
var rimetti = function () { // #110: casella com'era prima del clic
|
||||
$("specchiaO").checked = O.dati.orizzontale;
|
||||
$("specchiaV").checked = O.dati.verticale;
|
||||
};
|
||||
try {
|
||||
var r = await fetch("/camera/orientamento", {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ source: sorgente, orizzontale: nuovo.orizzontale, verticale: nuovo.verticale })
|
||||
});
|
||||
if (g !== O.gen) return; // sorgente cambiata: ci pensa caricaOrientamento
|
||||
if (!r.ok) {
|
||||
var d = await dettaglio(r);
|
||||
if (g !== O.gen) return;
|
||||
rimetti();
|
||||
caselleSpecchia(true);
|
||||
dire("msgSpecchia", d, "errore");
|
||||
return;
|
||||
}
|
||||
var j = await r.json();
|
||||
if (g !== O.gen) return;
|
||||
O.dati = nuovo;
|
||||
caselleSpecchia(true);
|
||||
if (j.avviso) dire("msgSpecchia", j.avviso, "avviso"); // es. calibrazione da rifare
|
||||
else dire("msgSpecchia", "Specchiatura salvata.", "ok");
|
||||
if (!A.attiva) { // anteprima ferma: un frame solo per vedere l'effetto (se e' attiva, il prossimo esce gia' specchiato)
|
||||
while (A.inVolo) await pausa(50);
|
||||
if (g === O.gen && !A.attiva) unaAnteprima(A.lato);
|
||||
}
|
||||
} catch (e) {
|
||||
if (g !== O.gen) return;
|
||||
rimetti();
|
||||
caselleSpecchia(true);
|
||||
dire("msgSpecchia", "Servizio non raggiungibile.", "errore");
|
||||
}
|
||||
}
|
||||
|
||||
function costruisciParametri(j) {
|
||||
var box = $("parametri");
|
||||
box.textContent = "";
|
||||
@@ -1393,6 +1474,7 @@ $("acquisisci").onclick = calcola;
|
||||
$("salva").onclick = salvaNome;
|
||||
$("nomeCal").onkeydown = function (e) { if (e.key === "Enter") salvaNome(); };
|
||||
$("sorgente").onchange = function () { dire("msgSorgente", ""); cambioSorgente(true); }; // #92
|
||||
$("specchiaO").onchange = $("specchiaV").onchange = salvaOrientamento; // #110
|
||||
scegliTab(memoria("tmf.acq.tab") === "cal" ? "cal" : "acq", false); // #91: tab ricordata
|
||||
caricaSorgenti();
|
||||
</script>
|
||||
|
||||
@@ -52,3 +52,10 @@ def test_localstorage_protetto():
|
||||
# ogni uso di localStorage sta dentro un try
|
||||
for m in re.finditer(r"localStorage[.]", PAGINA):
|
||||
assert "try {" in PAGINA[max(0, m.start() - 200):m.start()]
|
||||
|
||||
|
||||
def test_specchiatura_per_sorgente(): # #110
|
||||
ids = set(re.findall(r'id="([^"]+)"', PAGINA))
|
||||
assert {"specchiaO", "specchiaV", "msgSpecchia"} <= ids
|
||||
assert '"/camera/orientamento' in PAGINA
|
||||
assert "Specchia orizzontale" in PAGINA and "Specchia verticale" in PAGINA
|
||||
|
||||
Reference in New Issue
Block a user