Ripristino delle quote già misurate nel ciclo in corso dopo un reload (#40)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-06 11:31:57 +02:00
parent 70e2072b79
commit 1d93eded27
7 changed files with 406 additions and 0 deletions
@@ -1100,6 +1100,7 @@ function taskExecute() {
this.inputStartedAt = Date.now();
// Rejoin whatever production is already open at this station.
await this.loadProductionRun();
await this.loadCurrentCycle();
await this.loadPendingAuthorisation();
// A tablet left to sleep drifts (#37.7): catch the countdown back up to
// the server's own clock, the same source adoptProductionRun already
@@ -1110,6 +1111,42 @@ function taskExecute() {
});
},
/* Quotes already measured in the cycle under way (#40).
A reload, a timer redirect or an auto-logout used to bring every quote back
and measuring them again put duplicates in the SPC statistics. Only inside
a production: outside one there is no cycle, and the screen starts empty as
it always did. */
async loadCurrentCycle() {
if (!this.isMeasureTask || !this.subtasks.length || !this.productionRun) return;
try {
const resp = await fetch(
'{{ url_for("measure.api_current_cycle", task_id=task.id) }}',
);
if (!resp.ok) return;
const data = await resp.json();
const known = new Set(this.subtasks.map(s => s.id));
const restored = (data.measurements || []).filter(m => known.has(m.subtask_id));
if (!restored.length) return;
this.measurements = restored.map(m => {
const st = this.subtasks.find(s => s.id === m.subtask_id);
const nominal = st ? (st.nominal || 0) : 0;
return {
subtask_id: m.subtask_id,
value: m.value,
pass_fail: m.pass_fail,
deviation: m.value - nominal,
};
});
const next = this.subtasks.findIndex(
s => !this.measurements.some(m => m.subtask_id === s.id),
);
this.currentIndex = next !== -1 ? next : this.subtasks.length - 1;
} catch (e) {
// Offline: the screen starts empty, as before.
}
},
/* Is a quote already waiting for the capoturno?
Reloading the page was the simplest way past the old gate. It is not one