feat: plateaux d'impression section on job detail — live HA progress, multi-plate tracking
Deploy via Portainer / deploy (push) Successful in 0s

This commit is contained in:
Jo
2026-07-07 12:37:53 +02:00
parent 95b8b0277b
commit 221a0d7b8c
2 changed files with 215 additions and 15 deletions
+173
View File
@@ -250,6 +250,141 @@
</div>
</div>
<!-- ── Plateaux d'impression ────────────────────────────────────────────── -->
{% set plates_done = slots | selectattr('status','in',['done']) | list | length %}
{% set plates_running = slots | selectattr('status','equalto','running') | list | length %}
{% set plates_planned = slots | selectattr('status','in',['planned','running']) | list | length %}
{% set plates_total = slots | rejectattr('status','in',['cancelled']) | list | length %}
{% set missing_plates = [total_plates_needed - plates_total, 0] | max %}
<div class="row g-4 mt-0">
<div class="col-12">
<div class="card">
<div class="card-header py-3 d-flex justify-content-between align-items-center flex-wrap gap-2">
<span><i class="bi bi-layers-half me-2"></i>Plateaux d'impression</span>
<div class="d-flex align-items-center gap-2 flex-wrap">
<!-- Progress pill: X/Y plateaux -->
{% if total_plates_needed > 1 %}
<span class="badge rounded-pill
{% if plates_done >= total_plates_needed %}bg-success
{% elif missing_plates > 0 %}bg-warning text-dark
{% else %}bg-primary{% endif %}"
style="font-size:.8rem">
{{ plates_done }}/{{ total_plates_needed }} terminé{{ 's' if plates_done > 1 else '' }}
</span>
{% endif %}
{% if missing_plates > 0 %}
<span class="badge bg-warning text-dark" style="font-size:.75rem">
<i class="bi bi-exclamation-triangle-fill me-1"></i>{{ missing_plates }} plateau{{ 'x' if missing_plates > 1 else '' }} à planifier
</span>
{% endif %}
<a href="{{ url_for('planning') }}" class="btn btn-sm btn-outline-primary py-0">
<i class="bi bi-calendar-plus me-1"></i>Planning
</a>
</div>
</div>
{% if slots %}
<div class="card-body p-0">
<table class="table table-sm table-hover mb-0">
<thead class="table-light">
<tr>
<th class="small ps-3">#</th>
<th class="small">Début</th>
<th class="small">Machine</th>
<th class="small">Pièces</th>
<th class="small">Statut / Progression</th>
</tr>
</thead>
<tbody>
{% for s in slots %}
{% if s.status != 'cancelled' %}
<tr id="slotRow{{ s.id }}">
<td class="ps-3 text-muted small">{{ loop.index }}</td>
<td class="small" style="white-space:nowrap">
{{ s.planned_start[:16].replace('T',' ') }}
</td>
<td class="small fw-semibold">{{ s.printer_name }}</td>
<td class="small">
{% set ep = s.effective_pieces %}
{% set ig = s.pieces_ignored %}
{% if ig > 0 %}
<span class="text-warning fw-semibold">{{ ep - ig }}/{{ ep }}</span>
<span class="text-muted" style="font-size:.7rem"> ({{ ig }} ignorée{{ 's' if ig > 1 }})</span>
{% else %}
{{ ep }}
{% endif %}
</td>
<td>
{% set sc = {'planned':'secondary','running':'primary','done':'success','failed':'danger'} %}
{% set sl = {'planned':'Planifié','running':'En cours','done':'Terminé','failed':'Échec'} %}
<span class="badge bg-{{ sc.get(s.status,'secondary') }}">{{ sl.get(s.status, s.status) }}</span>
{% if s.status == 'running' and s.ha_entity_prefix %}
<!-- Live HA progress injected by JS -->
<span id="haLive{{ s.id }}" class="ms-2 small text-muted">
<span class="spinner-border spinner-border-sm"></span>
</span>
{% endif %}
{% if s.failure_note %}
<br><span class="text-muted" style="font-size:.72rem">{{ s.failure_note }}</span>
{% endif %}
</td>
</tr>
<!-- HA live progress bar row (hidden until JS fills it) -->
{% if s.status == 'running' and s.ha_entity_prefix %}
<tr id="haBar{{ s.id }}" class="table-primary">
<td colspan="5" class="px-3 py-1">
<div class="progress" style="height:6px;border-radius:3px">
<div id="haBarInner{{ s.id }}" class="progress-bar bg-primary" style="width:0%"></div>
</div>
<div id="haBarInfo{{ s.id }}" class="text-muted mt-1" style="font-size:.72rem"></div>
</td>
</tr>
{% endif %}
{% endif %}
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div class="card-body text-center text-muted py-4 small">
<i class="bi bi-calendar-x fs-3 d-block mb-2"></i>
Aucun créneau planifié pour cette commande.
<br><a href="{{ url_for('planning') }}" class="btn btn-sm btn-outline-primary mt-2">
<i class="bi bi-calendar-plus me-1"></i>Aller au planning
</a>
</div>
{% endif %}
<!-- Global progress bar for multi-plate jobs -->
{% if total_plates_needed > 1 %}
<div class="card-footer py-2 px-3" style="background:#fafafa;border-top:1px solid #f0f0f0">
{% set pct = ((plates_done / total_plates_needed) * 100) | round(0) | int %}
<div class="d-flex justify-content-between align-items-center mb-1">
<small class="text-muted">Progression commande</small>
<small class="fw-semibold">{{ pct }}%</small>
</div>
<div class="progress" style="height:8px;border-radius:4px">
<div class="progress-bar bg-success" style="width:{{ pct }}%"></div>
{% if plates_running > 0 %}
<div class="progress-bar bg-primary progress-bar-striped progress-bar-animated"
style="width:{{ ((plates_running / total_plates_needed) * 100) | round(0) | int }}%"></div>
{% endif %}
</div>
<div class="mt-1 d-flex gap-3" style="font-size:.72rem;color:#6b7280">
<span><i class="bi bi-check-circle-fill text-success me-1"></i>{{ plates_done }} terminé{{ 's' if plates_done > 1 }}</span>
{% if plates_running %}<span><i class="bi bi-arrow-repeat text-primary me-1"></i>{{ plates_running }} en cours</span>{% endif %}
{% set plates_sched = plates_planned - plates_running %}
{% if plates_sched %}<span><i class="bi bi-clock text-secondary me-1"></i>{{ plates_sched }} planifié{{ 's' if plates_sched > 1 }}</span>{% endif %}
{% if missing_plates %}<span class="text-warning"><i class="bi bi-exclamation-triangle-fill me-1"></i>{{ missing_plates }} manquant{{ 's' if missing_plates > 1 }}</span>{% endif %}
</div>
</div>
{% endif %}
</div>
</div>
</div>
<!-- ── Modale viewer 3D ──────────────────────────────────────────────────── -->
<div class="modal fade" id="viewerModal" tabindex="-1">
<div class="modal-dialog modal-xl modal-dialog-centered">
@@ -283,6 +418,44 @@
{% endblock %}
{% block scripts %}
<!-- ── Live HA status for running slots ──────────────────────────────────── -->
{% set running_slots = slots | selectattr('status','equalto','running') | selectattr('ha_entity_prefix') | list %}
{% if running_slots %}
<script>
(async function pollHA() {
const runningPrinters = {
{% for s in running_slots %}
"{{ s.printer_id }}": { slotId: {{ s.id }}, prefix: "{{ s.ha_entity_prefix }}" },
{% endfor %}
};
async function refresh() {
try {
const data = await fetch('/api/ha/status').then(r => r.json());
for (const [printerId, info] of Object.entries(runningPrinters)) {
const p = data[printerId];
if (!p) continue;
const liveEl = document.getElementById('haLive' + info.slotId);
const barEl = document.getElementById('haBarInner' + info.slotId);
const barInfo = document.getElementById('haBarInfo' + info.slotId);
if (!liveEl) continue;
const pct = p.progress || 0;
const layer = p.layer && p.layers_total ? `Couche ${p.layer}/${p.layers_total}` : '';
const fin = p.heure_fin ? `Fin ≈ ${p.heure_fin.slice(11,16)}` : '';
liveEl.innerHTML = `<strong>${pct}%</strong>${layer ? ' · ' + layer : ''}${fin ? ' · ' + fin : ''}`;
if (barEl) barEl.style.width = pct + '%';
if (barInfo) barInfo.textContent = [layer, fin].filter(Boolean).join(' · ');
}
} catch(e) {}
setTimeout(refresh, 30000);
}
refresh();
})();
</script>
{% endif %}
<!-- JSZip pour parser les 3MF Bambu Studio -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
<script type="importmap">