25f8b4d609
Rotte /maker/api/camera/servizi e /maker/api/camera/sorgenti (url ammesso solo se e' un servizio delle stazioni), sezione «Acquisizione» nell'editor task (servizio, sorgente, analisi impulsiva/in linea) salvata come acquisition_json. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Jbf7qKuxsnAVjxthRy7dnB
71 lines
2.5 KiB
JavaScript
71 lines
2.5 KiB
JavaScript
// «Acquisizione» dell'editor task (#97): camera (servizio + sorgente) e modo di analisi
|
|
// («impulsiva» / «in linea») dei task camera_measure e dxf_compare.
|
|
// Legge /maker/api/camera/servizi e /maker/api/camera/sorgenti?url=. Lo stato scelto sta
|
|
// nel componente padre (editTaskData.acquisition): questo componente carica solo gli elenchi.
|
|
// Uso: x-data="taskAcquisition(() => editTaskData.acquisition, msgs)". Dipende da Alpine.js.
|
|
function taskAcquisition(getAcq, msgs) {
|
|
return {
|
|
msgs: msgs || {},
|
|
servizi: [],
|
|
sources: [],
|
|
loading: false,
|
|
error: '',
|
|
|
|
async init() {
|
|
await this.loadServizi();
|
|
// Task con camera gia' scelta: elenco sorgenti del suo servizio
|
|
const acq = getAcq();
|
|
if (acq && acq.camera_url) await this.loadSources(acq.camera_url);
|
|
},
|
|
|
|
async loadServizi() {
|
|
try {
|
|
const resp = await fetch('/maker/api/camera/servizi');
|
|
if (resp.ok) this.servizi = (await resp.json()).servizi || [];
|
|
} catch (e) { console.error('taskAcquisition servizi', e); }
|
|
},
|
|
|
|
// Servizio salvato nel task ma non piu' fra quelli delle stazioni: resta selezionabile
|
|
serviziConCorrente() {
|
|
const acq = getAcq();
|
|
const out = this.servizi.slice();
|
|
if (acq && acq.camera_url && !out.some(s => s.camera_url === acq.camera_url)) {
|
|
out.push({ camera_url: acq.camera_url, stazioni: [] });
|
|
}
|
|
return out;
|
|
},
|
|
|
|
// Cambio servizio: la sorgente scelta non vale piu'
|
|
async onServizio() {
|
|
const acq = getAcq();
|
|
acq.camera_source = '';
|
|
this.sources = [];
|
|
this.error = '';
|
|
if (acq.camera_url) await this.loadSources(acq.camera_url);
|
|
},
|
|
|
|
async loadSources(url) {
|
|
this.loading = true;
|
|
this.error = '';
|
|
try {
|
|
const resp = await fetch('/maker/api/camera/sorgenti?url=' + encodeURIComponent(url));
|
|
const data = await resp.json().catch(() => ({}));
|
|
if (resp.ok) this.sources = data.sources || [];
|
|
else this.error = data.detail || this.msgs.genericError || '';
|
|
} catch (e) {
|
|
this.error = this.msgs.genericError || String(e);
|
|
} finally { this.loading = false; }
|
|
},
|
|
|
|
// Sorgente salvata ma non piu' elencata dal servizio: resta visibile
|
|
sourcesConCorrente() {
|
|
const acq = getAcq();
|
|
const out = this.sources.slice();
|
|
if (acq && acq.camera_source && !out.some(s => s.name === acq.camera_source)) {
|
|
out.push({ name: acq.camera_source, label: acq.camera_source });
|
|
}
|
|
return out;
|
|
}
|
|
};
|
|
}
|