Grotti 3.6.0: Lauf-Identität nach Filament-Pause, robustere Queue, Projekte/Aufträge list-first und API-Polish.
This commit is contained in:
1 parent
d1eb87ba25
commit
c669e51181
53 files changed
+4128
-510
No files matched your search
@@ -4,6 +4,44 @@ Alle Änderungen an Grotti. Format nach [Keep a Changelog](https://keepachangelo
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [3.6.0] – 2026-10-25
|
||||||
|
|
||||||
|
### Neu
|
||||||
|
|
||||||
|
- **Projekte:** Kennzahlen (Läufe, Zeit, Filament, Kosten), Tab Läufe, Einreihen / Alle einreihen, Filter Aktiv/Fertig, Deep-Link `#id`. API: `GET …/laeufe`, `POST …/einreihen`.
|
||||||
|
- **Wand-Cockpit:** Block „Als Nächstes“ — Nochmal, Queue-Hinweis, passende Dateien (Start oder Anpassen unter Dateien).
|
||||||
|
- **Querverlinkung:** Datei/Projekt/Spule/Auftrag/Drucker verlinkt in Protokoll, Bericht, Warteschlange, Aufträge, Material, Statistik (Projektfilter), Dateien.
|
||||||
|
- **API für Apps:** `POST /auth/token`, QR bei Token-Erzeugung, Server-Filter für Dateien/Queue/Spulen (`limit`/`offset`, `X-Total-Count`), `?token=` für Datei-Vorschau und Assets, `/version` mit `api`/`features`, Aktions-Alias `resume`/`cancel`. Doku: `docs/internal/API.md`, `openapi.yaml`.
|
||||||
|
- **Pi:** Umzugsanleitung Windows→Pi, Skript `scripts/pfade_umziehen.py` im `.deb`.
|
||||||
|
- **Protokoll Verbinden:** Verdachtspaare nach Runout manuell zusammenlegen (`POST /laeufe/<id>/verbinden`). Liste zeigt Rollenwechsel, mehrere Spulen und Pausendauer.
|
||||||
|
- **Reparatur:** `scripts/laeufe_reparieren.py` findet Alt-Paare und verwaiste Live-Läufe (Probelauf standardmäßig). Orphan-Übernahme nur bei gleicher Datei und wenn der Live-Lauf wirklich verschwindet; kein Host-Fallback auf fremde offene Drucke.
|
||||||
|
|
||||||
|
### Geändert
|
||||||
|
|
||||||
|
- **Projekte / Aufträge:** Liste zuerst (volle Breite); Formular und Detail nur bei Neu, Auswahl oder Bearbeiten — wie Material. Aufträge: Positionen ohne `prompt()`, Kopf-Button „Neuer Auftrag“.
|
||||||
|
- **Layout:** `.edit-split.is-idle`, Split/Panel ab 1080px einspaltig; Pfad-Ellipsis in Tabellen; Protokoll-Hilfe einklappbar; Queue-Aktionen mit Textlabels; Jetzt-Seite zeigt „Alles erledigt“; Aktivität Drucker-Filter als Select; Statistik-Filter unter „Weitere Filter“; Nav Aufträge = Clipboard-Icon; Mobile-Mehr gruppiert.
|
||||||
|
- **Material-Routing:** PLA ist PLA. Meta, Matte, Silk und die Marke halten die Queue nicht mehr an; liegt die genannte Sorte am Drucker, wird sie weiter bevorzugt. Ein anderer Typ (PETG statt PLA) bleibt ein Wartegrund.
|
||||||
|
- **mcp** auf `2.0.0` gepinnt.
|
||||||
|
- **Lauf-Identität:** Zusammenlegen nur mit Beweis (`print_duration` fortgesetzt + Lücke ≤ 5 s, oder Watcher „druckt weiter“). Leere History-Hüllen werden nicht gespeichert. `sync_history` unter Advisory-Lock; Abzug atomar. Doku: `docs/internal/Lauf-Identitaet.md`.
|
||||||
|
- **Queue `print_active`:** Nur `complete` = fertig. `cancelled`/`standby` werden entprellt; echter Abbruch heißt „Druck abgebrochen“, nicht „Fertig.“. Kein Auto-Retry nach Abbruch. Worker respektiert Abbruch während Upload. `print_queue.run_id` + höchstens ein `running` pro Host.
|
||||||
|
- **Wand Runout:** Hinweis nennt ACE-Platz und verlinkt Material mit vorausgefülltem Drucker/Platz.
|
||||||
|
- **Live-UI:** SSE `queue`/`drucker` aktualisiert Warteschlange und Protokoll.
|
||||||
|
|
||||||
|
### Behoben
|
||||||
|
|
||||||
|
- **Legacy-Kameras-Seite:** totes Template entfernt (Route leitete schon auf die Wand um).
|
||||||
|
- **Laufende Charge bleibt am History-Job:** Kommt die Moonraker-Job-ID, übernimmt dieser Lauf die Nummer. Sie fällt nicht weg, nur weil der Druck noch läuft.
|
||||||
|
- **Alte History-Jobs verbrauchen die Charge von heute:** Eine Filament-Pause öffnet eine zweite Job-ID. Bleibt die ohne Ende und ohne Dauer in der History stehen, hing Grotti sie als neuen Druck an den heutigen Tag und buchte das Filament noch einmal ab. Die Job-ID bleibt am ursprünglichen Lauf, eine leere Hülle überschreibt ihn nicht, und die Charge trägt das Startdatum des Drucks.
|
||||||
|
- **Kontaktverlust spaltet den Druck:** Zwei fehlende Polls melden den Drucker offline, lassen den Lauf aber offen und ziehen nichts ab. Dieselbe Charge läuft weiter, wenn derselbe Auftrag wieder da ist. Erst fertig, Abbruch, Fehler oder ein anderer Auftrag schließt den Lauf.
|
||||||
|
- **Queue bleibt auf „Druckstart kann eine Minute dauern“, während der Drucker längst druckt:** Der Abschluss hat `await_print` erst geprüft, wenn der Drucker wieder frei war, und den laufenden Druck dann als Start-Timeout gewertet.
|
||||||
|
- **Strombericht ohne Düse/Bett nach Pause:** Beim Zusammenlegen zweier History-Jobs bleiben Temperatur- und ED-Proben am Lauf. Vorher wurden die Proben des Folgejobs gelöscht, der Bericht fiel auf die Grundlast zurück.
|
||||||
|
- **Filament-Pause spaltet das Protokoll:** Setzt Anycubic nach dem Fortsetzen eine neue History-Job-ID, bleibt es ein Lauf. Der Abbruch-Teil wird nicht noch einmal als ganzer Druck abgezogen.
|
||||||
|
- **Materialwechsel öffnet trotzdem einen zweiten Auftrag:** Moonraker liefert die History neueste zuerst. Die Fortsetzung kam vor dem abgebrochenen Teil an die Reihe, fand keinen Vorgänger und wurde ein eigener Lauf; der alte Teil wurde als Abbruch abgezogen. Der Abgleich geht jetzt pro Drucker von alt nach neu. Eine eingeklappte Job-ID setzt den laufenden Druck nicht mehr auf „Abgebrochen“ zurück, und der zusammengelegte Lauf hat kein Ende, solange er druckt.
|
||||||
|
- **Fertig vor History bucht doppelt:** Live-Lauf wird geschlossen ohne Abzug; History bucht. Fallback nach 10 min ohne History.
|
||||||
|
- **Abbruch + schnelles Nochmal:** Frischer Neustart (Dauer nahe 0) wird nicht mehr als Filament-Fortsetzung zusammengelegt.
|
||||||
|
- **Alter Lauf auf der neuen Spule:** Der History-Abgleich zieht einen Druck nur von Rollen ab, die vor dem Druckende schon existierten. Die Rolle, die gerade im ACE liegt, bekommt keine alten Jobs.
|
||||||
|
- **Projektfilter leer neben „Wurzel“:** Ein gewähltes Projekt hebt den Ordnerfilter „Wurzel“ auf. Ein Ordner zeigt auch die Dateien in seinen Unterordnern.
|
||||||
|
|
||||||
## [3.5.2] – 2026-10-21
|
## [3.5.2] – 2026-10-21
|
||||||
|
|
||||||
### Geändert
|
### Geändert
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://git.gundel.dev/dg/grotti"><img src="https://img.shields.io/badge/Version-3.5.2-e85d04?style=flat-square" alt="Version 3.5.2"></a>
|
<a href="https://git.gundel.dev/dg/grotti"><img src="https://img.shields.io/badge/Version-3.6.0-e85d04?style=flat-square" alt="Version 3.6.0"></a>
|
||||||
<img src="https://img.shields.io/badge/Python-3.11+-3776AB?style=flat-square&logo=python&logoColor=white" alt="Python 3.11+">
|
<img src="https://img.shields.io/badge/Python-3.11+-3776AB?style=flat-square&logo=python&logoColor=white" alt="Python 3.11+">
|
||||||
<img src="https://img.shields.io/badge/PostgreSQL-14+-4169E1?style=flat-square&logo=postgresql&logoColor=white" alt="PostgreSQL">
|
<img src="https://img.shields.io/badge/PostgreSQL-14+-4169E1?style=flat-square&logo=postgresql&logoColor=white" alt="PostgreSQL">
|
||||||
<img src="https://img.shields.io/badge/Moonraker-Klipper-2ecc71?style=flat-square" alt="Moonraker">
|
<img src="https://img.shields.io/badge/Moonraker-Klipper-2ecc71?style=flat-square" alt="Moonraker">
|
||||||
@@ -115,22 +115,23 @@ Schema-Migrationen laufen beim Start (`grotti/migrations/`). Vor Major-Updates:
|
|||||||
|
|
||||||
## API
|
## API
|
||||||
|
|
||||||
Alles unter `/api/v1`, JSON. Auth: Session oder `Authorization: Bearer grt_…`.
|
Alles unter `/api/v1`, JSON. Auth: Session oder `Authorization: Bearer grt_…` (kein CSRF). Referenz: [`docs/internal/API.md`](docs/internal/API.md), OpenAPI-Skizze [`docs/internal/openapi.yaml`](docs/internal/openapi.yaml).
|
||||||
|
|
||||||
| Methode und Pfad | Zweck |
|
| Methode und Pfad | Zweck |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| `POST /auth/setup`, `/auth/login`, `/auth/logout` | Ersten Admin, Login, Logout |
|
| `POST /auth/setup`, `/auth/login`, `/auth/token`, `/auth/logout` | Admin, Session-Login, App-Token, Logout |
|
||||||
| `GET /me`, `/users`, `/tokens` | Konto, Benutzer (Admin), API-Tokens |
|
| `GET /me`, `/users`, `/tokens` | Konto, Benutzer (Admin), API-Tokens |
|
||||||
| `GET /version` | Version |
|
| `GET /version` | Version, `api`, `features` |
|
||||||
| `GET`/`PATCH /einstellungen`, `POST /telegram/test` | Config und Telegram-Probe |
|
| `GET`/`PATCH /einstellungen`, `POST /telegram/test`, `/ntfy/test` | Config und Push-Probe |
|
||||||
| `GET /drucker?live=1` | Drucker mit Live-Zustand |
|
| `GET /drucker?live=1` | Drucker mit Live-Zustand |
|
||||||
| `POST /drucker/<host>/<aktion>` | Pause, Fortsetzen, Abbrechen, Fehler löschen |
|
| `POST /drucker/<host>/<aktion>` | `pause`, `fortsetzen`/`resume`, `abbrechen`/`cancel` |
|
||||||
| `POST /drucker/<host>/steuern` | Temperatur, Speed, Flow, Lüfter, ACE |
|
| `POST /drucker/<host>/steuern` | Temperatur, Speed, Flow, Lüfter, ACE, `clear_error`, E-Stop |
|
||||||
| `POST /drucker/<host>/abraeumen` | Platte geräumt (`confirm`) |
|
| `POST /drucker/<host>/abraeumen` | Platte geräumt (`confirm`) |
|
||||||
| `GET`/`POST /dateien`, `PATCH`/`DELETE /dateien/<id>` | Bibliothek |
|
| `GET`/`POST /dateien`, `PATCH`/`DELETE /dateien/<id>` | Bibliothek (Filter `family`, `material`, `project_id`, …) |
|
||||||
| `POST /senden`, `GET`/`POST /druck-queue` | Senden und Warteschlange (`confirm`) |
|
| `POST /senden`, `GET`/`POST /druck-queue` | Senden und Warteschlange (`confirm`) |
|
||||||
|
| `GET`/`POST /projekte`, `…/einreihen`, Assets | Projekte |
|
||||||
| `GET /spulen`, `POST /spulen/<id>/einlegen` | Material |
|
| `GET /spulen`, `POST /spulen/<id>/einlegen` | Material |
|
||||||
| `GET /laeufe`, `/statistik`, `/ereignisse` | Protokoll und Aktivität |
|
| `GET /laeufe`, `/statistik`, `/ereignisse`, `/stream` | Protokoll, Statistik, SSE |
|
||||||
|
|
||||||
MCP: `python -m grotti.mcp_server` mit `GROTTI_URL` / `GROTTI_TOKEN` → `docs/internal/MCP.md`.
|
MCP: `python -m grotti.mcp_server` mit `GROTTI_URL` / `GROTTI_TOKEN` → `docs/internal/MCP.md`.
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ Es gibt **kein freies Spulen-Dropdown** beim Start: Grotti nimmt die Rolle(n), d
|
|||||||
|
|
||||||
Während Druck oder Pause die neue Spule unter Material dem Drucker zuweisen und speichern. Grotti schließt den Abschnitt der alten Rolle und öffnet einen neuen — im Druckbericht erscheinen dann zwei Spulenzeilen und Ereignisse. Nur Filament am Gerät laden ohne Zuweisung: Abzug und Protokoll bleiben bei der alten Rolle.
|
Während Druck oder Pause die neue Spule unter Material dem Drucker zuweisen und speichern. Grotti schließt den Abschnitt der alten Rolle und öffnet einen neuen — im Druckbericht erscheinen dann zwei Spulenzeilen und Ereignisse. Nur Filament am Gerät laden ohne Zuweisung: Abzug und Protokoll bleiben bei der alten Rolle.
|
||||||
|
|
||||||
Wenn Moonraker den Druck nach Filament-Pause als neuen History-Job führt, übernimmt Grotti die neu zugewiesene Rolle für den fortgesetzten Teil (Send- und Lauf-Spule werden beim Einlegen aktualisiert).
|
Wenn Moonraker den Druck nach Filament-Pause als neuen History-Job führt, übernimmt Grotti die neu zugewiesene Rolle für den fortgesetzten Teil (Send- und Lauf-Spule werden beim Einlegen aktualisiert). Die beiden Job-IDs bleiben **ein** Protokoll-Lauf, wenn die Druckdauer fortgesetzt wird oder die Wand „druckt weiter“ gesehen hat.
|
||||||
|
|
||||||
Etiketten mit QR: [Material und mehr](Anleitung-Material.md).
|
Etiketten mit QR: [Material und mehr](Anleitung-Material.md).
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ Unter **Dateien → Optionen → ACE-Zuordnung**:
|
|||||||
- Ohne passende Map schreibt der Drucker oft **„cannot parse the file“** und startet nicht
|
- Ohne passende Map schreibt der Drucker oft **„cannot parse the file“** und startet nicht
|
||||||
- Grotti legt die Sidecar `*.gcode.acm` an und schickt sie mit
|
- Grotti legt die Sidecar `*.gcode.acm` an und schickt sie mit
|
||||||
|
|
||||||
Bei **Nächster passender** (kein Drucker gewählt) baut Grotti die Map erst beim Claim aus den Spulen am gewählten Drucker. Passt die Sorte nicht → Wartegrund in der Queue.
|
Bei **Nächster passender** (kein Drucker gewählt) baut Grotti die Map erst beim Claim aus den Spulen am gewählten Drucker. Passt der Typ nicht (PETG statt PLA) → Wartegrund in der Queue. Meta/Matte/Silk halten nicht an; die genannte Sorte wird nur bevorzugt.
|
||||||
|
|
||||||
Externe Spule / keine ACE-Slots: keine `.acm` nötig.
|
Externe Spule / keine ACE-Slots: keine `.acm` nötig.
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ Projekte mit eigenem Ordner: [Projekte](Anleitung-Projekte.md).
|
|||||||
2. **Drucker** wählen — Kacheln zeigen Live-Zustand und eingelegte Rolle. Passt die Maschine nicht, ist die Kachel blass.
|
2. **Drucker** wählen — Kacheln zeigen Live-Zustand und eingelegte Rolle. Passt die Maschine nicht, ist die Kachel blass.
|
||||||
3. **Start:**
|
3. **Start:**
|
||||||
- **Dieser Drucker** — frei und Platte klar → sofort starten; sonst Warteschlange für diesen Drucker
|
- **Dieser Drucker** — frei und Platte klar → sofort starten; sonst Warteschlange für diesen Drucker
|
||||||
- **Nächster passender** — Grotti wählt den nächsten freien Drucker mit passender Sorte (z. B. Sunlu PLA Meta, nicht Matte)
|
- **Nächster passender** — Grotti wählt den nächsten freien Drucker mit passendem Typ (PLA, PETG, …). Die genannte Sorte (Meta, Matte) wird bevorzugt, wenn sie liegt; sonst reicht derselbe Typ.
|
||||||
|
|
||||||
Auswahl merkt sich der Browser (`localStorage`).
|
Auswahl merkt sich der Browser (`localStorage`).
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Einrichtung
|
# Einrichtung
|
||||||
|
|
||||||
Stand **15.10.2026**. Grotti auf dem Haus-PC installieren und den Browser öffnen. Die Drucker brauchen vorher Moonraker (Rinkhals auf Kobra 3 und S1).
|
Stand **24.10.2026**. Grotti auf dem Haus-PC oder Raspberry Pi installieren und den Browser öffnen. Die Drucker brauchen vorher Moonraker (Rinkhals auf Kobra 3 und S1).
|
||||||
|
|
||||||
## Was du brauchst
|
## Was du brauchst
|
||||||
|
|
||||||
@@ -56,8 +56,10 @@ Dann <http://127.0.0.1:8770/> öffnen. Beim ersten Start legst du den Admin-Benu
|
|||||||
|
|
||||||
- Druckstart über die API nur mit `confirm: true` (Dateien-UI: ein Klick).
|
- Druckstart über die API nur mit `confirm: true` (Dateien-UI: ein Klick).
|
||||||
- Keine freie G-code-Konsole; Firmware-Neustart über Grotti ist gesperrt.
|
- Keine freie G-code-Konsole; Firmware-Neustart über Grotti ist gesperrt.
|
||||||
- Benutzer und API-Tokens unter Einstellungen. Für Zugriff aus dem Internet: Reverse Proxy mit TLS, nicht den Entwickler-Server öffentlich freigeben.
|
- Benutzer und API-Tokens unter Einstellungen. App-Kopplung: Token erzeugen und QR scannen, oder `POST /api/v1/auth/token` mit Benutzer/Passwort. Push aufs Handy: **ntfy** (kein FCM). API-Referenz: intern `docs/internal/API.md`.
|
||||||
|
- Für Zugriff aus dem Internet: Reverse Proxy mit TLS, nicht den Entwickler-Server öffentlich freigeben.
|
||||||
- `config.json` und `data/` bleiben lokal, nicht im Git.
|
- `config.json` und `data/` bleiben lokal, nicht im Git.
|
||||||
|
- Raspberry Pi: [Installation auf dem Pi](Anleitung-Installation-Pi.md) (`.deb`, Umzug Windows→Pi).
|
||||||
|
|
||||||
## Weiter
|
## Weiter
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ Telegram: Bot-Token und Chat-ID, pro Ereignisart an/aus, Test-Knopf. **ntfy:** S
|
|||||||
|
|
||||||
## Benutzer und API-Tokens
|
## Benutzer und API-Tokens
|
||||||
|
|
||||||
Unter **Benutzer** (nur Admin) legst du Konten mit Rolle Admin oder Operator an. Unter **API-Tokens** erzeugst du Schlüssel für Home-Automation, App oder MCP — der Klartext erscheint nur einmal (`Authorization: Bearer grt_…`). Ein Shared-`token` in der Config-Datei gilt nicht mehr.
|
Unter **Benutzer** (nur Admin) legst du Konten mit Rolle Admin oder Operator an. Unter **API-Tokens** erzeugst du Schlüssel für Home-Automation, App oder MCP — der Klartext erscheint nur einmal (`Authorization: Bearer grt_…`), dazu ein QR mit Server-URL und Token zum Scannen. Alternativ stellt die App `POST /api/v1/auth/token` mit Benutzer/Passwort aus. Ein Shared-`token` in der Config-Datei gilt nicht mehr.
|
||||||
|
|
||||||
MCP (optional): Token erzeugen, dann `python -m grotti.mcp_server` mit `GROTTI_URL` und `GROTTI_TOKEN`. Für nur Lesen: `GROTTI_MCP_READ_ONLY=1`.
|
MCP (optional): Token erzeugen, dann `python -m grotti.mcp_server` mit `GROTTI_URL` und `GROTTI_TOKEN`. Für nur Lesen: `GROTTI_MCP_READ_ONLY=1`.
|
||||||
|
|
||||||
|
|||||||
@@ -85,8 +85,36 @@ sudo apt purge grotti # zusätzlich /etc/grotti
|
|||||||
# sudo rm -rf /var/lib/grotti
|
# sudo rm -rf /var/lib/grotti
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Umzug Windows → Pi
|
||||||
|
|
||||||
|
1. **Backup auf dem alten Rechner** (Einstellungen → Backup) oder `pg_dump` der PostgreSQL-Datenbank.
|
||||||
|
2. Auf dem Pi Grotti per `.deb` installieren (oben).
|
||||||
|
3. Backup einspielen (Einstellungen → Backup wiederherstellen) **oder** `pg_restore` in die DB `grotti`.
|
||||||
|
4. Slice-Ordner nach `/var/lib/grotti/slice` kopieren (rsync/scp).
|
||||||
|
5. Absolute Windows-Pfade in der DB umschreiben (Dry-Run zuerst):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo -u grotti /opt/grotti/venv/bin/python /opt/grotti/scripts/pfade_umziehen.py \
|
||||||
|
--database-url 'postgresql:///grotti?host=/var/run/postgresql' \
|
||||||
|
--from 'D:/dein/slice' --to /var/lib/grotti/slice
|
||||||
|
# prüfen, dann mit --apply
|
||||||
|
```
|
||||||
|
|
||||||
|
(Alternativ aus dem Repo-Clone mit derselben DB-URL.)
|
||||||
|
|
||||||
|
6. Unter Einstellungen: `watch_dir` = `/var/lib/grotti/slice`, ggf. `fqdn` auf die Pi-URL.
|
||||||
|
7. In Orca „Senden an Grotti“ auf `http://<pi-ip>:8770/` umstellen.
|
||||||
|
8. `sudo systemctl restart grotti` und unter **Dateien → Ordner neu lesen**.
|
||||||
|
|
||||||
|
## Last auf dem Pi
|
||||||
|
|
||||||
|
- Watcher und Toolpath-Cache liegen unter `/var/lib/grotti/`. Bei wenig Speicher Toolpath-Cache-Ordner (`data/toolpath`) gelegentlich leeren.
|
||||||
|
- Wenige SSE-Clients sind unkritisch; viele offene Browser-Tabs mit Kamera-Stream belasten CPU/Netz.
|
||||||
|
- Empfohlen: Pi 4/5 mit SSD oder schneller SD, nicht parallel schwere Builds auf demselben Gerät.
|
||||||
|
|
||||||
## Hinweise
|
## Hinweise
|
||||||
|
|
||||||
- Standard lauscht auf `0.0.0.0:8770` (LAN). Für Internet: Reverse Proxy mit TLS.
|
- Standard lauscht auf `0.0.0.0:8770` (LAN). Für Internet: Reverse Proxy mit TLS.
|
||||||
- Drucker unter **Einstellungen** anlegen (kein vorgefülltes `drucker.json` nötig).
|
- Drucker unter **Einstellungen** anlegen (kein vorgefülltes `drucker.json` nötig).
|
||||||
- Öffentliches `apt install grotti` ohne Datei: kommt mit dem Repo-Server (Phase 2).
|
- Öffentliches `apt install grotti` ohne Datei: kommt mit dem Repo-Server (Phase 2).
|
||||||
|
- `.deb` auf dem Ziel-Pi bauen (`bash packaging/build-deb.sh`), damit arm64-Wheels (`psycopg`, `cryptography`) passen.
|
||||||
@@ -26,9 +26,9 @@ Unter **Aufträge** Kunden, Positionen und Fortschritt. Dateien lassen sich eine
|
|||||||
|
|
||||||
## Protokoll und Statistik
|
## Protokoll und Statistik
|
||||||
|
|
||||||
Abgeschlossene Läufe: Dauer, Ist-Gramm, Kosten, Urteil. Zeile öffnet den **Druckbericht** (Soll/Ist, Spulen, Temperaturverlauf, Kosten-Aufschlüsselung Filament + Strom mit Tortendiagramm, Charge). **Nochmal** startet denselben Job inkl. gespeicherter ACE-Map und Bettnetz-Option.
|
Abgeschlossene Läufe: Dauer, Ist-Gramm, Kosten, Urteil. Zeile öffnet den **Druckbericht** (Soll/Ist, Spulen, Temperaturverlauf, Kosten-Aufschlüsselung Filament + Strom mit Tortendiagramm, Charge). **Nochmal** startet denselben Job inkl. gespeicherter ACE-Map und Bettnetz-Option (nicht während der Druck noch läuft).
|
||||||
|
|
||||||
Nach Filament-Ende: neue Spule unter **Material** dem Drucker/ACE-Platz zuweisen (Ort setzen und speichern — das legt den Rollenwechsel im Lauf an), am Gerät laden, an der Wand **Weiter**. Nur physisch nachlegen reicht nicht. Die Zuweisung gilt auch, wenn Moonraker den Druck nach der Pause als neuen Job zählt.
|
Nach Filament-Ende: neue Spule unter **Material** dem Drucker/ACE-Platz zuweisen (Ort setzen und speichern — das legt den Rollenwechsel im Lauf an), am Gerät laden, an der Wand **Weiter**. Nur physisch nachlegen reicht nicht. Die Zuweisung gilt auch, wenn Moonraker den Druck nach der Pause als neuen Job zählt — Grotti hält das als **einen** Lauf (gleiche Charge). Im Protokoll siehst du bei Rollenwechsel die Spulennamen; falls doch zwei Zeilen stehen, **Läufe holen** oder **Verbinden**.
|
||||||
|
|
||||||
Unter **Statistik** KPIs, Balkendiagramme (Druckzeit je Drucker, Verbrauch je Material), Tabellen und CSV-Export. Zeitraum per Knopf oder Von/Bis.
|
Unter **Statistik** KPIs, Balkendiagramme (Druckzeit je Drucker, Verbrauch je Material), Tabellen und CSV-Export. Zeitraum per Knopf oder Von/Bis.
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Projekte
|
# Projekte
|
||||||
|
|
||||||
Stand **18.10.2026**. Arbeitsmappen unter `/projekte` — getrennt von Kunden-[Aufträgen](Anleitung-Auftraege.md).
|
Stand **24.10.2026**. Arbeitsmappen unter `/projekte` — getrennt von Kunden-[Aufträgen](Anleitung-Auftraege.md).
|
||||||
|
|
||||||
## Wozu
|
## Wozu
|
||||||
|
|
||||||
@@ -16,11 +16,19 @@ Ein **Projekt** bündelt Konstruktion und Druckdateien in einem Ordner unter dem
|
|||||||
|
|
||||||
**Neues Projekt** — Name, Status, optional Ordner (Standard: `Projekte/<Kurzname>`). Mit gesetztem Slice-Ordner legt Grotti den Ordner an.
|
**Neues Projekt** — Name, Status, optional Ordner (Standard: `Projekte/<Kurzname>`). Mit gesetztem Slice-Ordner legt Grotti den Ordner an.
|
||||||
|
|
||||||
G-code und 3MF in diesem Ordner (oder dorthin [verschoben](Anleitung-Dateien.md)) werden dem Projekt zugeordnet und erscheinen in der Druck-Bibliothek.
|
Filter **Aktiv** / **Fertig** / **Alle** in der Liste. G-code und 3MF in diesem Ordner (oder dorthin [verschoben](Anleitung-Dateien.md)) werden dem Projekt zugeordnet und erscheinen in der Druck-Bibliothek.
|
||||||
|
|
||||||
## Weitere Dateien
|
## Detail
|
||||||
|
|
||||||
Im Projekt-Detail: Upload von STEP, STL, PDF, SolidWorks usw. — liegen im selben Ordner, erscheinen **nicht** in der Druck-Bibliothek. Download und Löschen pro Datei.
|
Im Projekt siehst du Kennzahlen (Läufe, Druckzeit, Filament, Kosten) und drei Tabs:
|
||||||
|
|
||||||
|
- **Druckdateien** — Link zur Bibliothek (`?file=` / `?project=`), **Einreihen** pro Datei oder **Alle einreihen** (Warteschlange, mit Bestätigung)
|
||||||
|
- **Läufe** — letzte Drucke mit Link zum Protokoll / Bericht
|
||||||
|
- **Weitere Dateien** — STEP, STL, PDF, SolidWorks usw. (nicht in der Druck-Bibliothek)
|
||||||
|
|
||||||
|
Wenn jede Datei mindestens einmal ok gedruckt wurde, schlägt Grotti vor, den Status auf **fertig** zu setzen.
|
||||||
|
|
||||||
|
Deep-Link: `/projekte#<id>`.
|
||||||
|
|
||||||
## Löschen
|
## Löschen
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Druckerwand
|
# Druckerwand
|
||||||
|
|
||||||
Stand **18.10.2026**. Startseite `/` — eine Karte je Drucker. Klick öffnet das Cockpit.
|
Stand **24.10.2026**. Startseite `/` — eine Karte je Drucker. Klick öffnet das Cockpit.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ Aktionen auf der Karte brauchen oft **zwei Klicks** (erster Klick „scharf“,
|
|||||||
|
|
||||||
| Aktion | Wann |
|
| Aktion | Wann |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| **Pause** / **Weiter** | Während des Drucks; nach Materialwechsel Spule in Grotti an den Drucker hängen, dann **Weiter** |
|
| **Pause** / **Weiter** | Während des Drucks; nach Materialwechsel gelber Hinweis mit ACE-Platz → Link zu Material (Drucker/Platz vorausgefüllt), Speichern, dann **Weiter**. Dieselbe Charge läuft weiter. |
|
||||||
| **Abbrechen** | Druck oder Pause |
|
| **Abbrechen** | Druck oder Pause |
|
||||||
| **Fehler löschen** | Zustand Fehler — räumt den hängenden Fehler, Heizung aus |
|
| **Fehler löschen** | Zustand Fehler — räumt den hängenden Fehler, Heizung aus |
|
||||||
| **Platte geräumt** | Nach Fertig, wenn die Platte wieder frei ist |
|
| **Platte geräumt** | Nach Fertig, wenn die Platte wieder frei ist |
|
||||||
@@ -39,7 +39,8 @@ Inhalt:
|
|||||||
- Status, Temps inkl. Bauraum wo verfügbar, Lüfter
|
- Status, Temps inkl. Bauraum wo verfügbar, Lüfter
|
||||||
- **Steuerung:** Zieltemperaturen, Speed, Flow, Fan — fest vorgegebene Befehle, keine freie Konsole. Mit ACE zusätzlich Trockner (Temp, Dauer, Start/Stopp) und pro bestücktem Platz **an den Drucker** (Sorte und Farbe aus der Grotti-Spule)
|
- **Steuerung:** Zieltemperaturen, Speed, Flow, Fan — fest vorgegebene Befehle, keine freie Konsole. Mit ACE zusätzlich Trockner (Temp, Dauer, Start/Stopp) und pro bestücktem Platz **an den Drucker** (Sorte und Farbe aus der Grotti-Spule)
|
||||||
- **E-Stop** nur bei printing/paused/heating (Zwei-Klick). Danach oft Strom aus/an
|
- **E-Stop** nur bei printing/paused/heating (Zwei-Klick). Danach oft Strom aus/an
|
||||||
- **Verlauf** Temperatur und ED des aktuellen oder letzten Drucks; Link zum Druckbericht (dort Kosten: Filament + Grundlast/Düse/Bett)
|
- **Verlauf** Temperatur und ED des aktuellen oder letzten Drucks; Links zu Datei und Druckbericht (dort Kosten: Filament + Grundlast/Düse/Bett)
|
||||||
|
- **Als Nächstes** (nur wenn der Drucker frei und die Platte quittiert ist): **Nochmal** der letzten Datei, Hinweis zur Warteschlange, passende Dateien nach Familie/Material — Start mit Standardwerten oder **Anpassen…** unter Dateien
|
||||||
- **3D-Pfad** der laufenden oder gewählten Datei; Objekte ausschließen (mit Bestätigung)
|
- **3D-Pfad** der laufenden oder gewählten Datei; Objekte ausschließen (mit Bestätigung)
|
||||||
- **Bettnetz**-Heatmap, wenn vorhanden
|
- **Bettnetz**-Heatmap, wenn vorhanden
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
# Grotti HTTP-API (`/api/v1`)
|
||||||
|
|
||||||
|
Stand für Android/App-Clients und Integrationen. Nutzer-Anleitungen bleiben unter `docs/Anleitung-*.md`.
|
||||||
|
|
||||||
|
## Auth
|
||||||
|
|
||||||
|
| Weg | Header / Cookie | CSRF |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| Session | Cookie nach `POST /auth/login` | `X-CSRF-Token` bei mutierenden API-Calls |
|
||||||
|
| Bearer | `Authorization: Bearer grt_…` | nicht nötig |
|
||||||
|
|
||||||
|
**Token ausstellen**
|
||||||
|
|
||||||
|
- Eingeloggt: `POST /tokens` `{name, role?}` → Klartext einmalig in `token`
|
||||||
|
- Ohne Session (App): `POST /auth/token` `{username, password, device_name?, role?}` → `201` mit `token` + `user` (Rate-Limit wie Login)
|
||||||
|
|
||||||
|
Öffentlich ohne Login: `/auth/status`, `/auth/login`, `/auth/token`, `/auth/setup`, `/version`.
|
||||||
|
|
||||||
|
Rollen: `operator` ≤ `admin`. Admin-only u. a. Benutzer, Backup, volle Einstellungen, Drucker anlegen.
|
||||||
|
|
||||||
|
**Medien mit Query-Token** (nur GET): `?token=grt_…` für Kamera, Live-Vorschau, Datei-Vorschau (`/dateien/<id>/vorschau`), Projekt-Assets.
|
||||||
|
|
||||||
|
## Fehler
|
||||||
|
|
||||||
|
```json
|
||||||
|
{"error": "Text", "code": "kurzcode"}
|
||||||
|
```
|
||||||
|
|
||||||
|
HTTP-Status: 400/401/403/404/409/429/503. Bild-Endpunkte liefern bei fehlendem Bild ebenfalls dieses JSON (nicht nur leeren 404).
|
||||||
|
|
||||||
|
## Pagination
|
||||||
|
|
||||||
|
Listen akzeptieren `limit` / `offset` wo sinnvoll. Antwort bleibt ein **JSON-Array**; Gesamtzahl im Header `X-Total-Count`.
|
||||||
|
|
||||||
|
Ohne `limit` liefern `/dateien` und `/spulen` die volle Liste (Web-UI).
|
||||||
|
|
||||||
|
## Bestätigung
|
||||||
|
|
||||||
|
Mutierende Druckaktionen brauchen oft `"confirm": true`:
|
||||||
|
|
||||||
|
- `POST /senden`, `POST /druck-queue`, `POST /ablauf`
|
||||||
|
- `POST /projekte/<id>/einreihen`, `POST /auftraege/<id>/einreihen`
|
||||||
|
- `POST /drucker/<host>/abraeumen`
|
||||||
|
- `steuern` mit `emergency_stop`, `clear_error`, `exclude_object`
|
||||||
|
|
||||||
|
## Server-Info
|
||||||
|
|
||||||
|
`GET /version` → `{name, version, api: 1, features: [...]}`.
|
||||||
|
|
||||||
|
## SSE Live
|
||||||
|
|
||||||
|
`GET /stream` (Session-Cookie oder Bearer). Events:
|
||||||
|
|
||||||
|
| Event | Bedeutung |
|
||||||
|
| --- | --- |
|
||||||
|
| `ping` | Keepalive (~15 s), Payload `{}` |
|
||||||
|
| `drucker` | Live-Zustand der Drucker geändert |
|
||||||
|
| `queue` | Druckwarteschlange geändert |
|
||||||
|
| `senden` | Sende-Auftrag geändert |
|
||||||
|
| `ereignis` | Neues Ereignis / Aktivität |
|
||||||
|
| `aufgaben` | Offene Aufgaben (Platte …) |
|
||||||
|
|
||||||
|
Ohne Stream: Client pollt `/drucker?live=1`, `/jetzt`, `/druck-queue`.
|
||||||
|
|
||||||
|
## Push an Geräte
|
||||||
|
|
||||||
|
Grotti sendet **kein** FCM. Empfohlen: **ntfy** (Topic unter Einstellungen). Die App kann denselben Topic abonnieren; Secrets (ntfy-Token) bleiben serverseitig.
|
||||||
|
|
||||||
|
## Wichtige Ressourcen
|
||||||
|
|
||||||
|
| Bereich | Pfade |
|
||||||
|
| --- | --- |
|
||||||
|
| Drucker | `GET /drucker?live=1`, `POST /drucker/<host>/pause\|fortsetzen\|abbrechen` (Alias `resume`/`cancel`), `…/steuern`, `…/abraeumen` |
|
||||||
|
| Dateien | `GET /dateien?family=&material=&project_id=&host=&q=&limit=&offset=`, Upload multipart, `…/vorschau`, `…/pfad` |
|
||||||
|
| Senden / Queue | `POST /senden`, `GET /senden-zuletzt?host=&file_id=`, `GET\|POST /druck-queue?host=&status=`, `POST /ablauf` |
|
||||||
|
| Projekte | `GET\|POST /projekte`, `GET /projekte/<id>`, `…/laeufe`, `POST …/einreihen`, Assets |
|
||||||
|
| Aufträge | `GET\|POST /auftraege`, Positionen, `…/einreihen` |
|
||||||
|
| Material | `GET /spulen?aktiv=1`, Akte, Einlegen |
|
||||||
|
| Protokoll | `GET /laeufe`, `GET /laeufe/<id>`, `GET /statistik?project_id=` |
|
||||||
|
| Kamera | `GET /kamera?host=`, `…/stream` |
|
||||||
|
|
||||||
|
Pfadnamen sind überwiegend **deutsch**. Aktionen: deutsch + englische Alias für Pause/Resume/Cancel.
|
||||||
|
|
||||||
|
## MCP
|
||||||
|
|
||||||
|
`python -m grotti.mcp_server` nutzt dieselbe REST-API (Teilmenge). Siehe `docs/internal/MCP.md`.
|
||||||
@@ -134,6 +134,16 @@ Ohne Map: Rinkhals füllt oft Identity T0→Platz0 … — deshalb Grotti bei ei
|
|||||||
| Slots anzeigen | Moonraker `mmu` (Rinkhals) | `mmu_ace.py` |
|
| Slots anzeigen | Moonraker `mmu` (Rinkhals) | `mmu_ace.py` |
|
||||||
| Kein Firmware-Restart | abgelehnt | Rinkhals #32, `patch_klipper_restart` |
|
| Kein Firmware-Restart | abgelehnt | Rinkhals #32, `patch_klipper_restart` |
|
||||||
|
|
||||||
|
## History nach Filament-Pause
|
||||||
|
|
||||||
|
Runout, Rolle tauschen, Fortsetzen: Anycubic schließt den History-Job als `cancelled` und öffnet eine neue Job-ID. Beobachtet am 2026-10-25 auf Kobra 3 A1 (`000040` → `000041`):
|
||||||
|
|
||||||
|
- Der neue `start_time` liegt etwa 0,04 s nach dem `end_time` des alten.
|
||||||
|
- `print_duration` und `total_duration` sind an beiden Einträgen gleich und laufen weiter. Der Zähler beginnt nicht bei 0.
|
||||||
|
- `/server/history/list` liefert neueste zuerst. Grotti sortiert pro Drucker nach `start_time`, sonst kommt die Fortsetzung vor ihrem Vorgänger dran (`jobs.history_in_order`).
|
||||||
|
- Nach dem Zusammenlegen hängt die alte Job-ID in `run_jobs` am Lauf. `store.history_job_retired` überspringt sie, sonst schreibt sie `cancelled` zurück.
|
||||||
|
- Zusammenlegen nur mit Beweis: `print_duration` fortgesetzt und Lücke ≤ 5 s, oder Watcher `paused→printing` (`docs/internal/Lauf-Identitaet.md`).
|
||||||
|
|
||||||
## Offene Grenzen
|
## Offene Grenzen
|
||||||
|
|
||||||
- Quellcode von **gkapi** (Task-State-Machine, exakte 10101-Bedingungen) ist nicht öffentlich.
|
- Quellcode von **gkapi** (Task-State-Machine, exakte 10101-Bedingungen) ist nicht öffentlich.
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
# Lauf-Identität: ein physischer Druck = ein Lauf
|
||||||
|
|
||||||
|
## Regel
|
||||||
|
|
||||||
|
Zusammengelegt wird nur mit **Beweis**, nicht nur wegen Zeit und Dateiname:
|
||||||
|
|
||||||
|
1. Der neue Moonraker-Job hat `print_duration` ≥ Dauer des Vorgängers − 30 s, und die Lücke `end→start` ist höchstens 5 s (Anycubic setzt `end_time` erst beim Fortsetzen).
|
||||||
|
2. Oder der Watcher hat `paused → printing` bei gleicher Datei gesehen (`watcher_resume`, `printers.active_run_id`).
|
||||||
|
|
||||||
|
Ein Neustart mit `print_duration` ≤ 60 s wird nie zusammengelegt.
|
||||||
|
|
||||||
|
## Pfade
|
||||||
|
|
||||||
|
| Pfad | Datei |
|
||||||
|
| --- | --- |
|
||||||
|
| Beweis | `jobs.is_filament_resume` |
|
||||||
|
| Fold | `jobs.fold_filament_resume` |
|
||||||
|
| Abgleich | `jobs.sync_history` (Advisory-Lock) |
|
||||||
|
| Job-Aliase | `run_jobs` + `history_job_retired` |
|
||||||
|
| Leere Hülle | übersprungen in `_sync_one_job` |
|
||||||
|
| Live-Abzug | erst History; Fallback nach 10 min (`LIVE_DEDUCT_FALLBACK_S`) |
|
||||||
|
| Manuell | `POST /api/v1/laeufe/<id>/verbinden` |
|
||||||
|
|
||||||
|
## Queue
|
||||||
|
|
||||||
|
In `print_active` heißt nur `complete` fertig. `cancelled`/`standby` werden entprellt (`TERMINAL_CONFIRM_HITS`). Echter Abbruch → Status `cancelled`, nicht „Fertig.“.
|
||||||
|
|
||||||
|
## Reparatur
|
||||||
|
|
||||||
|
`scripts/laeufe_reparieren.py` (Probelauf standardmäßig, `--apply` nach Freigabe).
|
||||||
|
Verwaiste `live:`-Läufe nur an offenen History-Jobs **derselben Datei**; `adopt_live_run` greift geschlossene Live-Läufe nur ≤ 2 h.
|
||||||
@@ -27,7 +27,7 @@ Jedes Ereignis landet in `events` und auf der Seite `/aktivitaet`. Telegram ist
|
|||||||
| `fertig` | Watcher, `printing`→`complete` | nein, Platte unter „Aufgaben“ | an |
|
| `fertig` | Watcher, `printing`→`complete` | nein, Platte unter „Aufgaben“ | an |
|
||||||
| `fehler` | Watcher, Zustand `error` | ja | an |
|
| `fehler` | Watcher, Zustand `error` | ja | an |
|
||||||
| `abbruch` | Watcher, `printing`/`paused`→`cancelled`/`standby` | ja | wie `fehler` |
|
| `abbruch` | Watcher, `printing`/`paused`→`cancelled`/`standby` | ja | wie `fehler` |
|
||||||
| `offline` | Watcher, ≥2 Polls weg; auch „wieder erreichbar“ | ja | an |
|
| `offline` | Watcher, ≥2 Polls weg; auch „wieder erreichbar“. Beendet den Lauf nicht und zieht nichts ab — der letzte Druckzustand bleibt gemerkt | ja | an |
|
||||||
| `spule` | Watcher, Rest unter Job-Gewicht | ja | an |
|
| `spule` | Watcher, Rest unter Job-Gewicht | ja | an |
|
||||||
| `queue` | Dispatcher: Queue-Fehler, Ablauf gestoppt | ja | an |
|
| `queue` | Dispatcher: Queue-Fehler, Ablauf gestoppt | ja | an |
|
||||||
| `start` | Watcher: Druck startet, Pause, Fortsetzen | nein | aus |
|
| `start` | Watcher: Druck startet, Pause, Fortsetzen | nein | aus |
|
||||||
|
|||||||
@@ -6,5 +6,8 @@ Nutzer-Handbuch: `docs/Anleitung-*.md`.
|
|||||||
|
|
||||||
| Datei | Inhalt |
|
| Datei | Inhalt |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
|
| [API.md](API.md) | HTTP-API für App/Integrationen (Auth, confirm, SSE, Filter) |
|
||||||
|
| [openapi.yaml](openapi.yaml) | OpenAPI-Skizze (Client-Generator) |
|
||||||
|
| [MCP.md](MCP.md) | MCP-Server und Tool-Ablauf |
|
||||||
| [Makros-Kobra.md](Makros-Kobra.md) | G-code/Makros Kobra S1 und 3: Nicht-tun, Vanilla-Alltag, ACE, LeviQ/Wipe |
|
| [Makros-Kobra.md](Makros-Kobra.md) | G-code/Makros Kobra S1 und 3: Nicht-tun, Vanilla-Alltag, ACE, LeviQ/Wipe |
|
||||||
| [Anycubic-Stack.md](Anycubic-Stack.md) | GoKlipper, MQTT-Start/Stop, ACE-Kanäle |
|
| [Anycubic-Stack.md](Anycubic-Stack.md) | GoKlipper, MQTT-Start/Stop, ACE-Kanäle |
|
||||||
@@ -0,0 +1,180 @@
|
|||||||
|
openapi: 3.0.3
|
||||||
|
info:
|
||||||
|
title: Grotti API
|
||||||
|
version: "1"
|
||||||
|
description: |
|
||||||
|
JSON unter /api/v1. Auth: Session-Cookie oder Bearer grt_….
|
||||||
|
Mutierende Session-Calls brauchen Header X-CSRF-Token.
|
||||||
|
Siehe docs/internal/API.md.
|
||||||
|
servers:
|
||||||
|
- url: /api/v1
|
||||||
|
paths:
|
||||||
|
/version:
|
||||||
|
get:
|
||||||
|
summary: Server-Info
|
||||||
|
security: []
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: name, version, api, features
|
||||||
|
/auth/login:
|
||||||
|
post:
|
||||||
|
summary: Session-Login
|
||||||
|
security: []
|
||||||
|
requestBody:
|
||||||
|
required: true
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
required: [username, password]
|
||||||
|
properties:
|
||||||
|
username: { type: string }
|
||||||
|
password: { type: string }
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: user + csrf
|
||||||
|
/auth/token:
|
||||||
|
post:
|
||||||
|
summary: Passwort → API-Token (App)
|
||||||
|
security: []
|
||||||
|
requestBody:
|
||||||
|
required: true
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
required: [username, password]
|
||||||
|
properties:
|
||||||
|
username: { type: string }
|
||||||
|
password: { type: string }
|
||||||
|
device_name: { type: string }
|
||||||
|
role: { type: string, enum: [operator, admin] }
|
||||||
|
responses:
|
||||||
|
"201":
|
||||||
|
description: token (einmalig) + user
|
||||||
|
/drucker:
|
||||||
|
get:
|
||||||
|
summary: Druckerliste
|
||||||
|
parameters:
|
||||||
|
- name: live
|
||||||
|
in: query
|
||||||
|
schema: { type: integer, enum: [0, 1] }
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: Array Drucker
|
||||||
|
/drucker/{host}/{action}:
|
||||||
|
post:
|
||||||
|
summary: Pause / Fortsetzen / Abbrechen
|
||||||
|
parameters:
|
||||||
|
- name: host
|
||||||
|
in: path
|
||||||
|
required: true
|
||||||
|
schema: { type: string }
|
||||||
|
- name: action
|
||||||
|
in: path
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
enum: [pause, fortsetzen, abbrechen, resume, cancel]
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
/dateien:
|
||||||
|
get:
|
||||||
|
summary: Bibliothek
|
||||||
|
parameters:
|
||||||
|
- { name: family, in: query, schema: { type: string } }
|
||||||
|
- { name: material, in: query, schema: { type: string } }
|
||||||
|
- { name: project_id, in: query, schema: { type: integer } }
|
||||||
|
- { name: host, in: query, schema: { type: string } }
|
||||||
|
- { name: q, in: query, schema: { type: string } }
|
||||||
|
- { name: limit, in: query, schema: { type: integer } }
|
||||||
|
- { name: offset, in: query, schema: { type: integer } }
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: Array Dateien; Header X-Total-Count
|
||||||
|
headers:
|
||||||
|
X-Total-Count:
|
||||||
|
schema: { type: integer }
|
||||||
|
/senden:
|
||||||
|
post:
|
||||||
|
summary: Druck starten oder einreihen
|
||||||
|
requestBody:
|
||||||
|
required: true
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
required: [file_id, confirm]
|
||||||
|
properties:
|
||||||
|
file_id: { type: integer }
|
||||||
|
hosts: { type: array, items: { type: string } }
|
||||||
|
confirm: { type: boolean }
|
||||||
|
when_free: { type: boolean }
|
||||||
|
ace_maps: { type: object }
|
||||||
|
bed_leveling: { type: boolean }
|
||||||
|
responses:
|
||||||
|
"202":
|
||||||
|
description: jobs
|
||||||
|
/druck-queue:
|
||||||
|
get:
|
||||||
|
summary: Warteschlange
|
||||||
|
parameters:
|
||||||
|
- { name: host, in: query, schema: { type: string } }
|
||||||
|
- { name: status, in: query, schema: { type: string } }
|
||||||
|
- { name: limit, in: query, schema: { type: integer } }
|
||||||
|
- { name: offset, in: query, schema: { type: integer } }
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: Array; X-Total-Count
|
||||||
|
post:
|
||||||
|
summary: Einreihen
|
||||||
|
requestBody:
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
required: [file_id, confirm]
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: Queue-Eintrag
|
||||||
|
/projekte/{id}/einreihen:
|
||||||
|
post:
|
||||||
|
summary: Projektdateien einreihen
|
||||||
|
parameters:
|
||||||
|
- name: id
|
||||||
|
in: path
|
||||||
|
required: true
|
||||||
|
schema: { type: integer }
|
||||||
|
requestBody:
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
required: [confirm]
|
||||||
|
properties:
|
||||||
|
confirm: { type: boolean }
|
||||||
|
file_ids: { type: array, items: { type: integer } }
|
||||||
|
menge: { type: integer }
|
||||||
|
responses:
|
||||||
|
"201":
|
||||||
|
description: jobs
|
||||||
|
/stream:
|
||||||
|
get:
|
||||||
|
summary: SSE Live-Events
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: text/event-stream (drucker, queue, senden, ereignis, ping)
|
||||||
|
components:
|
||||||
|
securitySchemes:
|
||||||
|
bearerAuth:
|
||||||
|
type: http
|
||||||
|
scheme: bearer
|
||||||
|
bearerFormat: grt_
|
||||||
|
cookieAuth:
|
||||||
|
type: apiKey
|
||||||
|
in: cookie
|
||||||
|
name: session
|
||||||
|
security:
|
||||||
|
- bearerAuth: []
|
||||||
|
- cookieAuth: []
|
||||||
@@ -45,7 +45,10 @@ def _yesterday_stats(conn):
|
|||||||
|
|
||||||
def build_text(conn, watcher_latest=None, printers=None):
|
def build_text(conn, watcher_latest=None, printers=None):
|
||||||
stats = _yesterday_stats(conn)
|
stats = _yesterday_stats(conn)
|
||||||
waiting = len([j for j in store.list_print_queue(conn, limit=200) if j.get("status") == "waiting"])
|
waiting = len([
|
||||||
|
j for j in store.list_print_queue(conn, limit=200)["items"]
|
||||||
|
if j.get("status") == "waiting"
|
||||||
|
])
|
||||||
eta = jetzt_mod.farm_eta([
|
eta = jetzt_mod.farm_eta([
|
||||||
{"remain": (live or {}).get("remain") or 0}
|
{"remain": (live or {}).get("remain") or 0}
|
||||||
for live in (watcher_latest or [])
|
for live in (watcher_latest or [])
|
||||||
|
|||||||
+1
-1
@@ -111,7 +111,7 @@ def build(conn, watcher_latest, printers=None, send_jobs=None):
|
|||||||
"SELECT DISTINCT host FROM print_queue WHERE status = 'running'"
|
"SELECT DISTINCT host FROM print_queue WHERE status = 'running'"
|
||||||
).fetchall()
|
).fetchall()
|
||||||
}
|
}
|
||||||
queue = store.list_print_queue(conn, limit=80)
|
queue = store.list_print_queue(conn, limit=80)["items"]
|
||||||
waiting = [j for j in queue if j.get("status") == "waiting"]
|
waiting = [j for j in queue if j.get("status") == "waiting"]
|
||||||
errors = [j for j in queue if j.get("status") == "error"]
|
errors = [j for j in queue if j.get("status") == "error"]
|
||||||
running_q = [j for j in queue if j.get("status") == "running"]
|
running_q = [j for j in queue if j.get("status") == "running"]
|
||||||
|
|||||||
+464
-37
@@ -5,7 +5,7 @@ import urllib.error
|
|||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
from grotti import acm, catalog, eject, library, moonraker, store, usage
|
from grotti import acm, catalog, eject, library, logutil, moonraker, store, usage
|
||||||
from grotti.cost import energy_cost
|
from grotti.cost import energy_cost
|
||||||
from grotti.errors import GrottiError
|
from grotti.errors import GrottiError
|
||||||
from grotti.parse import content_has_ace_trailer, prepare_rinkhals_gcode
|
from grotti.parse import content_has_ace_trailer, prepare_rinkhals_gcode
|
||||||
@@ -39,12 +39,12 @@ def _ace_map_of(sent):
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
def _targets_from_ace(conn, host, ace):
|
def _targets_from_ace(conn, host, ace, ended_at=None):
|
||||||
targets = []
|
targets = []
|
||||||
for item in ace:
|
for item in ace:
|
||||||
slot = int(item["ams_index"]) + 1
|
slot = int(item["ams_index"]) + 1
|
||||||
row = store.spool_at_slot(conn, host, slot)
|
row = store.spool_at_slot(conn, host, slot)
|
||||||
if row:
|
if row and _spool_valid_for_end(row, ended_at):
|
||||||
targets.append(row)
|
targets.append(row)
|
||||||
return targets
|
return targets
|
||||||
|
|
||||||
@@ -55,6 +55,380 @@ def unix_to_dt(value):
|
|||||||
return datetime.fromtimestamp(float(value), timezone.utc)
|
return datetime.fromtimestamp(float(value), timezone.utc)
|
||||||
|
|
||||||
|
|
||||||
|
# Anycubic schließt bei Filament-Pause den History-Job (cancelled) und öffnet
|
||||||
|
# beim Fortsetzen eine neue Job-ID. Zusammengelegt wird nur mit Beweis:
|
||||||
|
# print_duration läuft weiter und die Lücke ist klein, oder der Watcher
|
||||||
|
# hat paused→printing gesehen. Ein Neustart mit Dauer nahe 0 bleibt getrennt.
|
||||||
|
RESUME_GAP_S = 5
|
||||||
|
RESUME_DURATION_TOL_S = 30
|
||||||
|
RESUME_FRESH_MAX_S = 60
|
||||||
|
# Abwärtskompatibel für alte Aufrufe / Docs.
|
||||||
|
RESUME_JOIN_S = RESUME_GAP_S
|
||||||
|
LIVE_DEDUCT_FALLBACK_S = 600
|
||||||
|
SYNC_LOCK_KEY = 748291053
|
||||||
|
|
||||||
|
|
||||||
|
def _as_utc(value):
|
||||||
|
if value is None:
|
||||||
|
return None
|
||||||
|
if getattr(value, "tzinfo", None) is None:
|
||||||
|
return value.replace(tzinfo=timezone.utc)
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
def history_shell_is_empty(run_or_job):
|
||||||
|
"""History-Job ohne Ende und ohne Dauer. Nie als eigenen Lauf speichern."""
|
||||||
|
if not run_or_job:
|
||||||
|
return False
|
||||||
|
duration = float(
|
||||||
|
run_or_job.get("duration_s")
|
||||||
|
or run_or_job.get("print_duration")
|
||||||
|
or run_or_job.get("total_duration")
|
||||||
|
or 0
|
||||||
|
)
|
||||||
|
ended = run_or_job.get("ended_at") or run_or_job.get("end_time")
|
||||||
|
return duration <= 0 and not ended
|
||||||
|
|
||||||
|
|
||||||
|
def is_filament_resume(
|
||||||
|
prev_end,
|
||||||
|
new_start,
|
||||||
|
prev_duration_s=None,
|
||||||
|
new_duration_s=None,
|
||||||
|
watcher_resume=False,
|
||||||
|
gap_s=RESUME_GAP_S,
|
||||||
|
):
|
||||||
|
"""True nur mit Beweis: Dauer fortgesetzt + kleine Lücke, oder Watcher-Signal.
|
||||||
|
|
||||||
|
Aufruf mit zwei Zeitpunkten (alt): nur Lücke — gilt nicht mehr als Resume.
|
||||||
|
"""
|
||||||
|
prev_end = _as_utc(prev_end)
|
||||||
|
new_start = _as_utc(new_start)
|
||||||
|
if prev_end is None or new_start is None:
|
||||||
|
return False
|
||||||
|
gap = (new_start - prev_end).total_seconds()
|
||||||
|
if not (-30 <= gap <= max(float(gap_s), RESUME_GAP_S)):
|
||||||
|
# Watcher-Signal: Lücke darf länger sein (Pause vor dem Resume-Ende).
|
||||||
|
if not watcher_resume or gap > 24 * 3600 or gap < -30:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
if watcher_resume:
|
||||||
|
return True
|
||||||
|
# Zwei-Argument-Aufruf (Tests/alt): ohne Dauer kein Beweis → kein Resume.
|
||||||
|
if prev_duration_s is None and new_duration_s is None:
|
||||||
|
return False
|
||||||
|
prev_d = float(prev_duration_s or 0)
|
||||||
|
new_d = float(new_duration_s or 0)
|
||||||
|
# Frischer Neustart: Dauer beginnt nahe 0 — nie zusammenlegen.
|
||||||
|
if new_d <= RESUME_FRESH_MAX_S:
|
||||||
|
return False
|
||||||
|
if new_d < max(0.0, prev_d - RESUME_DURATION_TOL_S):
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def undo_deduction(conn, run):
|
||||||
|
"""Spulenabzug eines Laufs zurücknehmen. Abschnitte bleiben."""
|
||||||
|
if not run or not run.get("deducted"):
|
||||||
|
return False
|
||||||
|
rows = conn.execute(
|
||||||
|
"SELECT spool_id, weight_g FROM run_spools WHERE run_id = %s",
|
||||||
|
(run["id"],),
|
||||||
|
).fetchall()
|
||||||
|
for row in rows:
|
||||||
|
grams = float(row["weight_g"] or 0)
|
||||||
|
if grams and row["spool_id"]:
|
||||||
|
conn.execute(
|
||||||
|
"UPDATE spools SET remaining_g = remaining_g + %s WHERE id = %s",
|
||||||
|
(grams, row["spool_id"]),
|
||||||
|
)
|
||||||
|
conn.execute("DELETE FROM run_spools WHERE run_id = %s", (run["id"],))
|
||||||
|
conn.execute(
|
||||||
|
"UPDATE runs SET deducted = false, filament_cost = 0 WHERE id = %s",
|
||||||
|
(run["id"],),
|
||||||
|
)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def fold_filament_resume(
|
||||||
|
conn,
|
||||||
|
host,
|
||||||
|
filename,
|
||||||
|
job_id,
|
||||||
|
start_dt,
|
||||||
|
print_duration_s=0,
|
||||||
|
watcher_resume=False,
|
||||||
|
):
|
||||||
|
"""Fortsetzung nach Filament-Pause auf den bestehenden Lauf legen.
|
||||||
|
|
||||||
|
Gibt die Lauf-ID zurück, deren moonraker_job_id jetzt job_id ist.
|
||||||
|
Leere Hüllen (Dauer 0, kein Ende) werden vorher übersprungen — nicht hier.
|
||||||
|
"""
|
||||||
|
pred = store.find_resume_predecessor(
|
||||||
|
conn, host, filename, job_id, start_dt, watcher_resume=watcher_resume
|
||||||
|
)
|
||||||
|
if not pred:
|
||||||
|
return None
|
||||||
|
if not is_filament_resume(
|
||||||
|
pred.get("ended_at"),
|
||||||
|
start_dt,
|
||||||
|
prev_duration_s=pred.get("duration_s"),
|
||||||
|
new_duration_s=print_duration_s,
|
||||||
|
watcher_resume=watcher_resume,
|
||||||
|
):
|
||||||
|
return None
|
||||||
|
other = conn.execute(
|
||||||
|
"""
|
||||||
|
SELECT * FROM runs
|
||||||
|
WHERE printer_host = %s AND moonraker_job_id = %s AND id <> %s
|
||||||
|
""",
|
||||||
|
(host, str(job_id), pred["id"]),
|
||||||
|
).fetchone()
|
||||||
|
store.remember_run_job(conn, host, pred.get("moonraker_job_id"), pred["id"], replace=True)
|
||||||
|
undo_deduction(conn, pred)
|
||||||
|
kept = None
|
||||||
|
if other:
|
||||||
|
undo_deduction(conn, other)
|
||||||
|
conn.execute(
|
||||||
|
"UPDATE events SET run_id = %s WHERE run_id = %s",
|
||||||
|
(pred["id"], other["id"]),
|
||||||
|
)
|
||||||
|
if not (pred.get("verdict") or "").strip() and (other.get("verdict") or "").strip():
|
||||||
|
conn.execute(
|
||||||
|
"""
|
||||||
|
UPDATE runs
|
||||||
|
SET verdict = %s, verdict_reason = %s, pieces_ok = %s, pieces_bad = %s
|
||||||
|
WHERE id = %s
|
||||||
|
""",
|
||||||
|
(
|
||||||
|
other.get("verdict") or "",
|
||||||
|
other.get("verdict_reason") or "",
|
||||||
|
other.get("pieces_ok") or 0,
|
||||||
|
other.get("pieces_bad") or 0,
|
||||||
|
pred["id"],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
kept = {
|
||||||
|
"state": other.get("state") or "completed",
|
||||||
|
"ended_at": other.get("ended_at"),
|
||||||
|
"duration_s": float(other.get("duration_s") or 0),
|
||||||
|
"weight_used_g": float(other.get("weight_used_g") or 0),
|
||||||
|
"weight_source": other.get("weight_source") or "",
|
||||||
|
"filament_used_mm": float(other.get("filament_used_mm") or 0),
|
||||||
|
"filament_total_mm": float(other.get("filament_total_mm") or 0),
|
||||||
|
"progress_last": float(other.get("progress_last") or 0),
|
||||||
|
}
|
||||||
|
for table in ("run_samples", "run_segments"):
|
||||||
|
conn.execute(
|
||||||
|
"UPDATE %s SET run_id = %%s WHERE run_id = %%s" % table,
|
||||||
|
(pred["id"], other["id"]),
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
conn.execute(
|
||||||
|
"""
|
||||||
|
DELETE FROM run_labels AS src
|
||||||
|
WHERE src.run_id = %s
|
||||||
|
AND EXISTS (
|
||||||
|
SELECT 1 FROM run_labels AS dst
|
||||||
|
WHERE dst.run_id = %s AND dst.object_name = src.object_name
|
||||||
|
)
|
||||||
|
""",
|
||||||
|
(other["id"], pred["id"]),
|
||||||
|
)
|
||||||
|
conn.execute(
|
||||||
|
"UPDATE run_labels SET run_id = %s WHERE run_id = %s",
|
||||||
|
(pred["id"], other["id"]),
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
logutil.get("grotti.jobs").warning(
|
||||||
|
"Etiketten von Lauf %s nicht übernommen.", other["id"]
|
||||||
|
)
|
||||||
|
conn.execute("DELETE FROM run_spools WHERE run_id = %s", (other["id"],))
|
||||||
|
store.move_run_jobs(conn, host, other["id"], pred["id"])
|
||||||
|
# Job-ID freigeben, sonst Unique (printer_host, moonraker_job_id) beim Pred.
|
||||||
|
conn.execute(
|
||||||
|
"UPDATE runs SET moonraker_job_id = %s WHERE id = %s",
|
||||||
|
("live:merged:%s" % other["id"], other["id"]),
|
||||||
|
)
|
||||||
|
conn.execute("DELETE FROM runs WHERE id = %s", (other["id"],))
|
||||||
|
# Der Druck läuft weiter. Das Ende kommt vom Folgejob.
|
||||||
|
conn.execute(
|
||||||
|
"""
|
||||||
|
UPDATE runs
|
||||||
|
SET moonraker_job_id = %s,
|
||||||
|
ended_at = NULL,
|
||||||
|
state = CASE
|
||||||
|
WHEN %s IN ('in_progress', 'printing', 'paused') THEN %s
|
||||||
|
WHEN state IN ('cancelled', 'interrupted', 'error') THEN 'in_progress'
|
||||||
|
ELSE state
|
||||||
|
END
|
||||||
|
WHERE id = %s
|
||||||
|
""",
|
||||||
|
(
|
||||||
|
str(job_id),
|
||||||
|
(kept or {}).get("state") or "in_progress",
|
||||||
|
(kept or {}).get("state") or "in_progress",
|
||||||
|
pred["id"],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
store.remember_run_job(conn, host, job_id, pred["id"], replace=True)
|
||||||
|
store.set_printer_active_run(conn, host, pred["id"])
|
||||||
|
if kept and kept.get("ended_at"):
|
||||||
|
conn.execute(
|
||||||
|
"""
|
||||||
|
UPDATE runs SET
|
||||||
|
state = %s,
|
||||||
|
ended_at = COALESCE(%s, ended_at),
|
||||||
|
duration_s = GREATEST(COALESCE(duration_s, 0), %s),
|
||||||
|
weight_used_g = GREATEST(COALESCE(weight_used_g, 0), %s),
|
||||||
|
weight_source = CASE WHEN %s <> '' THEN %s ELSE weight_source END,
|
||||||
|
filament_used_mm = GREATEST(COALESCE(filament_used_mm, 0), %s),
|
||||||
|
filament_total_mm = CASE WHEN %s > 0 THEN %s ELSE filament_total_mm END,
|
||||||
|
progress_last = GREATEST(COALESCE(progress_last, 0), %s),
|
||||||
|
deducted = false
|
||||||
|
WHERE id = %s
|
||||||
|
""",
|
||||||
|
(
|
||||||
|
kept["state"],
|
||||||
|
kept["ended_at"],
|
||||||
|
kept["duration_s"],
|
||||||
|
kept["weight_used_g"],
|
||||||
|
kept["weight_source"],
|
||||||
|
kept["weight_source"],
|
||||||
|
kept["filament_used_mm"],
|
||||||
|
kept["filament_total_mm"],
|
||||||
|
kept["filament_total_mm"],
|
||||||
|
kept["progress_last"],
|
||||||
|
pred["id"],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
elif print_duration_s:
|
||||||
|
conn.execute(
|
||||||
|
"""
|
||||||
|
UPDATE runs
|
||||||
|
SET duration_s = GREATEST(COALESCE(duration_s, 0), %s),
|
||||||
|
deducted = false
|
||||||
|
WHERE id = %s
|
||||||
|
""",
|
||||||
|
(float(print_duration_s), pred["id"]),
|
||||||
|
)
|
||||||
|
return pred["id"]
|
||||||
|
|
||||||
|
|
||||||
|
def history_in_order(items):
|
||||||
|
"""Älteste zuerst. Der abgebrochene Teil muss stehen, bevor die Fortsetzung kommt."""
|
||||||
|
return sorted(
|
||||||
|
items or [],
|
||||||
|
key=lambda job: (float(job.get("start_time") or 0), str(job.get("job_id") or "")),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def manual_merge_runs(conn, keep_id, absorb_id, confirm=False):
|
||||||
|
"""Zwei Läufe manuell verbinden. keep überlebt, absorb wird übernommen."""
|
||||||
|
if not confirm:
|
||||||
|
raise GrottiError("Verbinden braucht eine Bestätigung.", "bestaetigung")
|
||||||
|
keep = store.get_run_row(conn, keep_id)
|
||||||
|
absorb = store.get_run_row(conn, absorb_id)
|
||||||
|
if not keep or not absorb:
|
||||||
|
raise GrottiError("Der Lauf fehlt.", "lauf", 404)
|
||||||
|
if keep["id"] == absorb["id"]:
|
||||||
|
raise GrottiError("Gleicher Lauf.", "lauf")
|
||||||
|
if (keep.get("printer_host") or "") != (absorb.get("printer_host") or ""):
|
||||||
|
raise GrottiError("Nur Läufe desselben Druckers.", "drucker")
|
||||||
|
if (keep.get("filename") or "") != (absorb.get("filename") or ""):
|
||||||
|
raise GrottiError("Nur Läufe derselben Datei.", "datei")
|
||||||
|
# Früherer Start bleibt der überlebende Lauf.
|
||||||
|
if keep.get("started_at") and absorb.get("started_at") and absorb["started_at"] < keep["started_at"]:
|
||||||
|
keep, absorb = absorb, keep
|
||||||
|
host = keep["printer_host"]
|
||||||
|
undo_deduction(conn, keep)
|
||||||
|
undo_deduction(conn, absorb)
|
||||||
|
snapshot = {
|
||||||
|
"keep_id": keep["id"],
|
||||||
|
"absorb_id": absorb["id"],
|
||||||
|
"absorb_job_id": absorb.get("moonraker_job_id"),
|
||||||
|
}
|
||||||
|
for table in ("run_samples", "run_segments", "run_spools", "events"):
|
||||||
|
conn.execute(
|
||||||
|
"UPDATE %s SET run_id = %%s WHERE run_id = %%s" % table,
|
||||||
|
(keep["id"], absorb["id"]),
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
conn.execute(
|
||||||
|
"""
|
||||||
|
DELETE FROM run_labels AS src
|
||||||
|
WHERE src.run_id = %s
|
||||||
|
AND EXISTS (
|
||||||
|
SELECT 1 FROM run_labels AS dst
|
||||||
|
WHERE dst.run_id = %s AND dst.object_name = src.object_name
|
||||||
|
)
|
||||||
|
""",
|
||||||
|
(absorb["id"], keep["id"]),
|
||||||
|
)
|
||||||
|
conn.execute(
|
||||||
|
"UPDATE run_labels SET run_id = %s WHERE run_id = %s",
|
||||||
|
(keep["id"], absorb["id"]),
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
store.move_run_jobs(conn, host, absorb["id"], keep["id"])
|
||||||
|
job_id = absorb.get("moonraker_job_id") or keep.get("moonraker_job_id")
|
||||||
|
if job_id and not str(job_id).startswith("live:"):
|
||||||
|
store.remember_run_job(conn, host, job_id, keep["id"], replace=True)
|
||||||
|
# Job-ID am absorb freigeben, sonst Unique beim UPDATE auf keep.
|
||||||
|
conn.execute(
|
||||||
|
"UPDATE runs SET moonraker_job_id = %s WHERE id = %s",
|
||||||
|
("live:merged:%s" % absorb["id"], absorb["id"]),
|
||||||
|
)
|
||||||
|
absorb_terminal = (absorb.get("state") or "") in TERMINAL
|
||||||
|
keep_open = (keep.get("state") or "") in ("in_progress", "printing", "paused")
|
||||||
|
new_state = absorb["state"] if absorb_terminal and not keep_open else (
|
||||||
|
absorb["state"] if not keep_open else keep["state"]
|
||||||
|
)
|
||||||
|
if keep_open or (absorb.get("state") or "") in ("in_progress", "printing", "paused"):
|
||||||
|
new_state = absorb["state"] if (absorb.get("state") or "") in ("in_progress", "printing", "paused") else "in_progress"
|
||||||
|
ended = None
|
||||||
|
else:
|
||||||
|
ended = absorb.get("ended_at") or keep.get("ended_at")
|
||||||
|
conn.execute(
|
||||||
|
"""
|
||||||
|
UPDATE runs SET
|
||||||
|
moonraker_job_id = COALESCE(NULLIF(%s, ''), moonraker_job_id),
|
||||||
|
state = %s,
|
||||||
|
ended_at = %s,
|
||||||
|
duration_s = GREATEST(COALESCE(duration_s, 0), COALESCE(%s, 0)),
|
||||||
|
weight_used_g = GREATEST(COALESCE(weight_used_g, 0), COALESCE(%s, 0)),
|
||||||
|
filament_used_mm = GREATEST(COALESCE(filament_used_mm, 0), COALESCE(%s, 0)),
|
||||||
|
progress_last = GREATEST(COALESCE(progress_last, 0), COALESCE(%s, 0)),
|
||||||
|
deducted = false
|
||||||
|
WHERE id = %s
|
||||||
|
""",
|
||||||
|
(
|
||||||
|
str(job_id or ""),
|
||||||
|
new_state,
|
||||||
|
ended,
|
||||||
|
float(absorb.get("duration_s") or 0),
|
||||||
|
float(absorb.get("weight_used_g") or 0),
|
||||||
|
float(absorb.get("filament_used_mm") or 0),
|
||||||
|
float(absorb.get("progress_last") or 0),
|
||||||
|
keep["id"],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
conn.execute(
|
||||||
|
"UPDATE print_queue SET run_id = %s WHERE run_id = %s",
|
||||||
|
(keep["id"], absorb["id"]),
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
conn.execute("DELETE FROM runs WHERE id = %s", (absorb["id"],))
|
||||||
|
store.set_printer_active_run(
|
||||||
|
conn, host, keep["id"] if new_state in ("in_progress", "printing", "paused") else None
|
||||||
|
)
|
||||||
|
fresh = store.get_run_row(conn, keep["id"])
|
||||||
|
return {"run": store.run_out(fresh), "undo": snapshot}
|
||||||
|
|
||||||
|
|
||||||
def choose_spool(conn, host, material, hinted_id, ended_at=None):
|
def choose_spool(conn, host, material, hinted_id, ended_at=None):
|
||||||
"""Spule für History-Abzug. Ohne Hint nur Rollen, die vor Druckende existierten."""
|
"""Spule für History-Abzug. Ohne Hint nur Rollen, die vor Druckende existierten."""
|
||||||
at_host = [
|
at_host = [
|
||||||
@@ -196,12 +570,13 @@ def apply_deduction(conn, run, energy, metadata=None):
|
|||||||
|
|
||||||
store.close_open_segments(conn, run["id"], None, run.get("filament_used_mm") or 0)
|
store.close_open_segments(conn, run["id"], None, run.get("filament_used_mm") or 0)
|
||||||
segments = store.list_run_segments(conn, run["id"])
|
segments = store.list_run_segments(conn, run["id"])
|
||||||
|
ended = run.get("ended_at")
|
||||||
|
|
||||||
entries = []
|
entries = []
|
||||||
targets = _targets_from_ace(conn, run["printer_host"], ace) if ace else []
|
targets = _targets_from_ace(conn, run["printer_host"], ace, ended_at=ended) if ace else []
|
||||||
if not targets and run.get("spool_id"):
|
if not targets and run.get("spool_id"):
|
||||||
spool = store.get_spool_row(conn, run["spool_id"])
|
spool = store.get_spool_row(conn, run["spool_id"])
|
||||||
if spool:
|
if spool and _spool_valid_for_end(spool, ended):
|
||||||
targets = [spool]
|
targets = [spool]
|
||||||
# Abschnitte ohne ACE-Map: externe Rollen nacheinander
|
# Abschnitte ohne ACE-Map: externe Rollen nacheinander
|
||||||
if segments and not ace:
|
if segments and not ace:
|
||||||
@@ -291,8 +666,10 @@ def apply_deduction(conn, run, energy, metadata=None):
|
|||||||
filament = sum(item["cost"] for item in entries)
|
filament = sum(item["cost"] for item in entries)
|
||||||
samples = store.list_run_samples(conn, run["id"])
|
samples = store.list_run_samples(conn, run["id"])
|
||||||
power = energy_cost(run["duration_s"], energy, samples)
|
power = energy_cost(run["duration_s"], energy, samples)
|
||||||
# run_spools vor deducted=true, sonst bleibt die Akte leer bei Abbruch dazwischen
|
weight_source = source or (
|
||||||
store.replace_run_spools(conn, run["id"], entries)
|
"estimate" if any(e["is_estimate"] for e in entries) else "measured"
|
||||||
|
)
|
||||||
|
# Zuerst deducted=true — nur der Gewinner schreibt Akte und zieht ab.
|
||||||
marked = store.mark_deducted(
|
marked = store.mark_deducted(
|
||||||
conn,
|
conn,
|
||||||
run["id"],
|
run["id"],
|
||||||
@@ -300,11 +677,11 @@ def apply_deduction(conn, run, energy, metadata=None):
|
|||||||
filament,
|
filament,
|
||||||
power,
|
power,
|
||||||
weight_used_g=used_total,
|
weight_used_g=used_total,
|
||||||
weight_source=source or ("estimate" if any(e["is_estimate"] for e in entries) else "measured"),
|
weight_source=weight_source,
|
||||||
)
|
)
|
||||||
if not marked:
|
if not marked:
|
||||||
store.replace_run_spools(conn, run["id"], [])
|
|
||||||
return False
|
return False
|
||||||
|
store.replace_run_spools(conn, run["id"], entries)
|
||||||
for item in entries:
|
for item in entries:
|
||||||
store.deduct_spool(conn, item["spool_id"], item["weight_g"])
|
store.deduct_spool(conn, item["spool_id"], item["weight_g"])
|
||||||
store.ensure_run_chargen(conn, run["id"], used_total)
|
store.ensure_run_chargen(conn, run["id"], used_total)
|
||||||
@@ -318,28 +695,40 @@ def apply_deduction(conn, run, energy, metadata=None):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def sync_history(conn, cfg):
|
def _sync_one_job(conn, cfg, printer, job, watcher_resume=False):
|
||||||
printers = store.list_printers(conn)
|
"""Einen History-Job verarbeiten. Gibt 1 zurück wenn abgezogen wurde."""
|
||||||
|
|
||||||
def fetch(printer):
|
|
||||||
return printer, moonraker.history(printer["host"])
|
|
||||||
|
|
||||||
with ThreadPoolExecutor(max_workers=max(1, len(printers))) as pool:
|
|
||||||
fetched = list(pool.map(fetch, printers))
|
|
||||||
collected = []
|
|
||||||
for printer, items in fetched:
|
|
||||||
for job in items:
|
|
||||||
collected.append((printer, job))
|
|
||||||
deducted = 0
|
|
||||||
for printer, job in collected:
|
|
||||||
job_id = str(job.get("job_id") or "")
|
job_id = str(job.get("job_id") or "")
|
||||||
if not job_id or str(job_id).startswith("live:"):
|
if not job_id or str(job_id).startswith("live:"):
|
||||||
continue
|
return 0
|
||||||
filename = job.get("filename") or ""
|
filename = job.get("filename") or ""
|
||||||
|
start_dt = unix_to_dt(job.get("start_time"))
|
||||||
|
end_dt = unix_to_dt(job.get("end_time"))
|
||||||
|
duration_s = float(job.get("print_duration") or job.get("total_duration") or 0)
|
||||||
|
state = job.get("status") or ""
|
||||||
|
# Leere Hülle: nie speichern. Sobald Dauer da ist, gilt die Beweis-Regel.
|
||||||
|
if history_shell_is_empty({
|
||||||
|
"duration_s": duration_s,
|
||||||
|
"ended_at": end_dt,
|
||||||
|
"print_duration": duration_s,
|
||||||
|
"end_time": end_dt,
|
||||||
|
}) and state not in TERMINAL:
|
||||||
|
return 0
|
||||||
|
if store.history_job_already_folded(conn, printer["host"], filename, job_id, end_dt):
|
||||||
|
return 0
|
||||||
|
if store.history_job_retired(conn, printer["host"], job_id):
|
||||||
|
return 0
|
||||||
|
fold_filament_resume(
|
||||||
|
conn,
|
||||||
|
printer["host"],
|
||||||
|
filename,
|
||||||
|
job_id,
|
||||||
|
start_dt,
|
||||||
|
print_duration_s=duration_s,
|
||||||
|
watcher_resume=watcher_resume,
|
||||||
|
)
|
||||||
metadata = job.get("metadata") or {}
|
metadata = job.get("metadata") or {}
|
||||||
planned = weight_of(metadata)
|
planned = weight_of(metadata)
|
||||||
material = material_of(metadata)
|
material = material_of(metadata)
|
||||||
state = job.get("status") or ""
|
|
||||||
used_mm = usage.filament_used_mm(job)
|
used_mm = usage.filament_used_mm(job)
|
||||||
total_mm = usage.filament_total_mm(metadata, job)
|
total_mm = usage.filament_total_mm(metadata, job)
|
||||||
estimated = float(metadata.get("estimated_time") or 0)
|
estimated = float(metadata.get("estimated_time") or 0)
|
||||||
@@ -348,8 +737,7 @@ def sync_history(conn, cfg):
|
|||||||
file_id = (sent or {}).get("file_id") or (known or {}).get("id")
|
file_id = (sent or {}).get("file_id") or (known or {}).get("id")
|
||||||
project_id = (sent or {}).get("project_id") or (known or {}).get("project_id")
|
project_id = (sent or {}).get("project_id") or (known or {}).get("project_id")
|
||||||
hinted = (sent or {}).get("spool_id") or (known or {}).get("spool_id")
|
hinted = (sent or {}).get("spool_id") or (known or {}).get("spool_id")
|
||||||
ended_at = unix_to_dt(job.get("end_time"))
|
ended_at = end_dt
|
||||||
# Ohne Send-Eintrag keine Rate — sonst zieht eine neue Spule alle alten Jobs ab.
|
|
||||||
if not sent and not hinted:
|
if not sent and not hinted:
|
||||||
spool = None
|
spool = None
|
||||||
else:
|
else:
|
||||||
@@ -370,7 +758,7 @@ def sync_history(conn, cfg):
|
|||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
objects = []
|
objects = []
|
||||||
used_g, source = usage.resolve_used_grams(
|
used_g, source = usage.resolve_used_grams(
|
||||||
planned, used_mm, total_mm, progress, state, job.get("print_duration") or 0
|
planned, used_mm, total_mm, progress, state, duration_s
|
||||||
)
|
)
|
||||||
row = store.upsert_run(conn, {
|
row = store.upsert_run(conn, {
|
||||||
"printer_host": printer["host"],
|
"printer_host": printer["host"],
|
||||||
@@ -380,9 +768,9 @@ def sync_history(conn, cfg):
|
|||||||
"project_id": project_id,
|
"project_id": project_id,
|
||||||
"spool_id": spool["id"] if spool else None,
|
"spool_id": spool["id"] if spool else None,
|
||||||
"state": state,
|
"state": state,
|
||||||
"started_at": unix_to_dt(job.get("start_time")),
|
"started_at": start_dt,
|
||||||
"ended_at": unix_to_dt(job.get("end_time")),
|
"ended_at": ended_at,
|
||||||
"duration_s": float(job.get("print_duration") or job.get("total_duration") or 0),
|
"duration_s": duration_s,
|
||||||
"weight_g": planned,
|
"weight_g": planned,
|
||||||
"weight_planned_g": planned,
|
"weight_planned_g": planned,
|
||||||
"weight_used_g": used_g,
|
"weight_used_g": used_g,
|
||||||
@@ -391,26 +779,65 @@ def sync_history(conn, cfg):
|
|||||||
"filament_total_mm": total_mm,
|
"filament_total_mm": total_mm,
|
||||||
"progress_last": progress,
|
"progress_last": progress,
|
||||||
"estimated_s": estimated,
|
"estimated_s": estimated,
|
||||||
"energy_cost": energy_cost(job.get("print_duration") or job.get("total_duration") or 0, cfg["energy"]),
|
"energy_cost": energy_cost(duration_s, cfg["energy"]),
|
||||||
"moonraker_job_id": job_id,
|
"moonraker_job_id": job_id,
|
||||||
"needs_spool": bool(terminal and used_g > 0 and not spool),
|
"needs_spool": bool(terminal and used_g > 0 and not spool),
|
||||||
"material_type": material,
|
"material_type": material,
|
||||||
"message": (job.get("message") or "") if state == "error" else "",
|
"message": (job.get("message") or "") if state == "error" else "",
|
||||||
"objects": objects,
|
"objects": objects,
|
||||||
})
|
})
|
||||||
# Live sofort auf History hängen — auch solange noch in_progress (eine Protokoll-Zeile)
|
|
||||||
store.adopt_live_run(conn, printer["host"], filename, row["id"])
|
store.adopt_live_run(conn, printer["host"], filename, row["id"])
|
||||||
row = store.get_run_row(conn, row["id"])
|
row = store.get_run_row(conn, row["id"])
|
||||||
if terminal:
|
if not terminal:
|
||||||
# Nachzug nicht während eines neuen Live-Drucks — sonst „Platte belegt“ zu Unrecht
|
store.set_printer_active_run(conn, printer["host"], row["id"])
|
||||||
|
else:
|
||||||
active = store.find_live_run(conn, printer["host"])
|
active = store.find_live_run(conn, printer["host"])
|
||||||
if not active:
|
if not active:
|
||||||
ended = row.get("ended_at") or unix_to_dt(job.get("end_time"))
|
ended = row.get("ended_at") or ended_at
|
||||||
store.ensure_bed_after_print(
|
store.ensure_bed_after_print(
|
||||||
conn, printer["host"], ended_at=ended, message=filename or state
|
conn, printer["host"], ended_at=ended, message=filename or state
|
||||||
)
|
)
|
||||||
|
store.set_printer_active_run(conn, printer["host"], None)
|
||||||
if apply_deduction(conn, row, cfg["energy"], metadata=metadata):
|
if apply_deduction(conn, row, cfg["energy"], metadata=metadata):
|
||||||
deducted += 1
|
return 1
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def deduct_stale_live_runs(conn, cfg, older_than_s=LIVE_DEDUCT_FALLBACK_S):
|
||||||
|
"""Live-Läufe ohne History nach Frist abziehen (Fertig-Pfad ohne History)."""
|
||||||
|
rows = store.list_stale_live_runs(conn, older_than_s=older_than_s)
|
||||||
|
n = 0
|
||||||
|
for row in rows:
|
||||||
|
if apply_deduction(conn, row, cfg["energy"]):
|
||||||
|
n += 1
|
||||||
|
return n
|
||||||
|
|
||||||
|
|
||||||
|
def sync_history(conn, cfg, host=None, watcher_resume=False):
|
||||||
|
"""History abgleichen. Serialisiert über Session-Advisory-Lock."""
|
||||||
|
printers = store.list_printers(conn)
|
||||||
|
if host:
|
||||||
|
printers = [p for p in printers if p.get("host") == host]
|
||||||
|
|
||||||
|
def fetch(printer):
|
||||||
|
return printer, moonraker.history(printer["host"])
|
||||||
|
|
||||||
|
with ThreadPoolExecutor(max_workers=max(1, len(printers) or 1)) as pool:
|
||||||
|
fetched = list(pool.map(fetch, printers)) if printers else []
|
||||||
|
collected = []
|
||||||
|
for printer, items in fetched:
|
||||||
|
for job in history_in_order(items):
|
||||||
|
collected.append((printer, job))
|
||||||
|
deducted = 0
|
||||||
|
conn.execute("SELECT pg_advisory_lock(%s)", (SYNC_LOCK_KEY,))
|
||||||
|
try:
|
||||||
|
for printer, job in collected:
|
||||||
|
deducted += _sync_one_job(
|
||||||
|
conn, cfg, printer, job, watcher_resume=watcher_resume
|
||||||
|
)
|
||||||
|
deducted += deduct_stale_live_runs(conn, cfg)
|
||||||
|
finally:
|
||||||
|
conn.execute("SELECT pg_advisory_unlock(%s)", (SYNC_LOCK_KEY,))
|
||||||
return {"gelesen": len(collected), "abgezogen": deducted}
|
return {"gelesen": len(collected), "abgezogen": deducted}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
-- Jede Moonraker-Job-ID bleibt einem Lauf zugeordnet, auch nach dem Zusammenlegen.
|
||||||
|
CREATE TABLE IF NOT EXISTS run_jobs (
|
||||||
|
printer_host text NOT NULL,
|
||||||
|
job_id text NOT NULL,
|
||||||
|
run_id bigint NOT NULL REFERENCES runs (id) ON DELETE CASCADE,
|
||||||
|
PRIMARY KEY (printer_host, job_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS run_jobs_run ON run_jobs (run_id);
|
||||||
|
|
||||||
|
INSERT INTO run_jobs (printer_host, job_id, run_id)
|
||||||
|
SELECT printer_host, moonraker_job_id, id
|
||||||
|
FROM runs
|
||||||
|
WHERE moonraker_job_id <> ''
|
||||||
|
AND moonraker_job_id NOT LIKE 'live:%'
|
||||||
|
ON CONFLICT DO NOTHING;
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
-- Last active run per printer (survives Grotti restart during pause)
|
||||||
|
ALTER TABLE printers
|
||||||
|
ADD COLUMN IF NOT EXISTS active_run_id bigint REFERENCES runs (id) ON DELETE SET NULL;
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS printers_active_run ON printers (active_run_id)
|
||||||
|
WHERE active_run_id IS NOT NULL;
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
-- Queue item points at the run it started. At most one running job per host.
|
||||||
|
ALTER TABLE print_queue
|
||||||
|
ADD COLUMN IF NOT EXISTS run_id bigint REFERENCES runs (id) ON DELETE SET NULL;
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS print_queue_run ON print_queue (run_id)
|
||||||
|
WHERE run_id IS NOT NULL;
|
||||||
|
|
||||||
|
CREATE UNIQUE INDEX IF NOT EXISTS print_queue_one_running_per_host
|
||||||
|
ON print_queue (host)
|
||||||
|
WHERE status = 'running' AND host <> '';
|
||||||
+164
-20
@@ -34,6 +34,9 @@ PRINT_START_TIMEOUT_S = 600
|
|||||||
# Nach erfolgreichem Senden ist die Phase await_print — dort gilt das nicht,
|
# Nach erfolgreichem Senden ist die Phase await_print — dort gilt das nicht,
|
||||||
# sonst wird ein noch anlaufender Druck als „Neustart“ neu eingereiht.
|
# sonst wird ein noch anlaufender Druck als „Neustart“ neu eingereiht.
|
||||||
SIMPLE_START_STUCK_S = 45
|
SIMPLE_START_STUCK_S = 45
|
||||||
|
# Anycubic meldet kurz cancelled/standby bei LeviQ und Filament-Resume.
|
||||||
|
TERMINAL_CONFIRM_HITS = 3
|
||||||
|
AWAIT_CANCEL_HITS = 3
|
||||||
|
|
||||||
|
|
||||||
def _ablauf_needs_motors(item):
|
def _ablauf_needs_motors(item):
|
||||||
@@ -151,10 +154,20 @@ class PrintQueueDispatcher:
|
|||||||
def _auto_retry_enabled(self):
|
def _auto_retry_enabled(self):
|
||||||
return bool((self.cfg or {}).get("auto_retry", True))
|
return bool((self.cfg or {}).get("auto_retry", True))
|
||||||
|
|
||||||
|
def _retryable_message(self, message):
|
||||||
|
text = (message or "").lower()
|
||||||
|
if "abgebrochen" in text:
|
||||||
|
return False
|
||||||
|
if "druck abgebrochen" in text:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
def _try_auto_retry(self, conn, item, message):
|
def _try_auto_retry(self, conn, item, message):
|
||||||
"""Ein automatischer Neuversuch; sonst False."""
|
"""Ein automatischer Neuversuch; sonst False. Nicht nach Abbruch."""
|
||||||
if not self._auto_retry_enabled():
|
if not self._auto_retry_enabled():
|
||||||
return False
|
return False
|
||||||
|
if not self._retryable_message(message):
|
||||||
|
return False
|
||||||
retries = int(item.get("retry_count") or 0)
|
retries = int(item.get("retry_count") or 0)
|
||||||
if retries >= 1:
|
if retries >= 1:
|
||||||
return False
|
return False
|
||||||
@@ -172,6 +185,23 @@ class PrintQueueDispatcher:
|
|||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def _terminal_hits(self, item_id, kind="end"):
|
||||||
|
key = "%s:%s" % (item_id, kind)
|
||||||
|
if not hasattr(self, "_term_hits"):
|
||||||
|
self._term_hits = {}
|
||||||
|
self._term_hits[key] = self._term_hits.get(key, 0) + 1
|
||||||
|
return self._term_hits[key]
|
||||||
|
|
||||||
|
def _clear_terminal_hits(self, item_id, kind=None):
|
||||||
|
if not hasattr(self, "_term_hits"):
|
||||||
|
return
|
||||||
|
if kind:
|
||||||
|
self._term_hits.pop("%s:%s" % (item_id, kind), None)
|
||||||
|
return
|
||||||
|
for key in list(self._term_hits):
|
||||||
|
if key.startswith("%s:" % item_id):
|
||||||
|
self._term_hits.pop(key, None)
|
||||||
|
|
||||||
def _fail_stuck_simple_start(self, conn, item, printer):
|
def _fail_stuck_simple_start(self, conn, item, printer):
|
||||||
host = printer["host"]
|
host = printer["host"]
|
||||||
msg = "Start abgebrochen (Neustart)"
|
msg = "Start abgebrochen (Neustart)"
|
||||||
@@ -277,6 +307,13 @@ class PrintQueueDispatcher:
|
|||||||
lives[host] = live
|
lives[host] = live
|
||||||
state = (live.get("state") or "").lower()
|
state = (live.get("state") or "").lower()
|
||||||
if state in BUSY:
|
if state in BUSY:
|
||||||
|
# Laufenden Einfach-Druck mitziehen. Sonst bleibt await_print
|
||||||
|
# stehen, bis der Drucker frei ist — und der Start gilt als Timeout,
|
||||||
|
# obwohl er längst druckt.
|
||||||
|
running = store.running_print_on_host(conn, host)
|
||||||
|
if running and not _has_ablauf(running):
|
||||||
|
self._advance_simple(conn, running, printer, live)
|
||||||
|
conn.commit()
|
||||||
continue
|
continue
|
||||||
if state not in FREE:
|
if state not in FREE:
|
||||||
continue
|
continue
|
||||||
@@ -418,26 +455,31 @@ class PrintQueueDispatcher:
|
|||||||
bed_leveling=bed_leveling,
|
bed_leveling=bed_leveling,
|
||||||
)
|
)
|
||||||
name = (result or {}).get("filename") or ""
|
name = (result or {}).get("filename") or ""
|
||||||
|
# Abbruch während Upload: Status nicht überschreiben, Druck stoppen.
|
||||||
|
current = store.get_print_queue_row(wconn, item_id)
|
||||||
|
if current and (current.get("status") or "") in ("cancelled", "dismissed"):
|
||||||
|
try:
|
||||||
|
moonraker.command(host, "cancel")
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
return
|
||||||
oid = item.get("order_item_id")
|
oid = item.get("order_item_id")
|
||||||
if oid:
|
if oid:
|
||||||
from grotti import orders
|
from grotti import orders
|
||||||
|
|
||||||
orders.attach_order_item_to_live_run(wconn, host, name, oid)
|
orders.attach_order_item_to_live_run(wconn, host, name, oid)
|
||||||
# await_print: Datei ist raus, Drucker meldet printing oft erst
|
live_run = store.find_active_run(wconn, host, name)
|
||||||
# nach einer Minute. Nicht bei starting lassen — sonst gilt nach
|
fields = {
|
||||||
# 45 s der Neustart-Retry und der zweite Start trifft „druckt schon“.
|
|
||||||
store.update_print_queue(
|
|
||||||
wconn,
|
|
||||||
item_id,
|
|
||||||
{
|
|
||||||
"status": "running",
|
"status": "running",
|
||||||
"message": "Datei ist auf %s. Druckstart kann etwa eine Minute dauern."
|
"message": "Datei ist auf %s. Druckstart kann etwa eine Minute dauern."
|
||||||
% printer_copy["name"],
|
% printer_copy["name"],
|
||||||
"host": host,
|
"host": host,
|
||||||
"phase": "await_print",
|
"phase": "await_print",
|
||||||
"phase_started_at": "now",
|
"phase_started_at": "now",
|
||||||
},
|
}
|
||||||
)
|
if live_run:
|
||||||
|
fields["run_id"] = live_run["id"]
|
||||||
|
store.update_print_queue(wconn, item_id, fields)
|
||||||
self._event(
|
self._event(
|
||||||
wconn,
|
wconn,
|
||||||
host,
|
host,
|
||||||
@@ -493,6 +535,7 @@ class PrintQueueDispatcher:
|
|||||||
state = (live.get("state") or "").lower()
|
state = (live.get("state") or "").lower()
|
||||||
if phase in ("starting", "await_print"):
|
if phase in ("starting", "await_print"):
|
||||||
if state in ("printing", "paused", "heating") or live.get("print_active"):
|
if state in ("printing", "paused", "heating") or live.get("print_active"):
|
||||||
|
self._clear_terminal_hits(item["id"])
|
||||||
store.update_print_queue(
|
store.update_print_queue(
|
||||||
conn,
|
conn,
|
||||||
item["id"],
|
item["id"],
|
||||||
@@ -503,6 +546,21 @@ class PrintQueueDispatcher:
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
if phase == "await_print" and state == "cancelled":
|
||||||
|
hits = self._terminal_hits(item["id"], "await_cancel")
|
||||||
|
if hits >= AWAIT_CANCEL_HITS:
|
||||||
|
self._clear_terminal_hits(item["id"])
|
||||||
|
store.update_print_queue(
|
||||||
|
conn,
|
||||||
|
item["id"],
|
||||||
|
{
|
||||||
|
"status": "error",
|
||||||
|
"message": "Druck abgebrochen.",
|
||||||
|
"phase": "",
|
||||||
|
"phase_started_at": None,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
return
|
||||||
if phase == "await_print" and self._print_start_timed_out(item):
|
if phase == "await_print" and self._print_start_timed_out(item):
|
||||||
store.update_print_queue(
|
store.update_print_queue(
|
||||||
conn,
|
conn,
|
||||||
@@ -521,6 +579,7 @@ class PrintQueueDispatcher:
|
|||||||
if phase != "print_active":
|
if phase != "print_active":
|
||||||
return
|
return
|
||||||
if state in ("printing", "paused", "heating"):
|
if state in ("printing", "paused", "heating"):
|
||||||
|
self._clear_terminal_hits(item["id"])
|
||||||
return
|
return
|
||||||
if state == "error":
|
if state == "error":
|
||||||
store.update_print_queue(
|
store.update_print_queue(
|
||||||
@@ -534,7 +593,9 @@ class PrintQueueDispatcher:
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
if state in FREE or state in ("complete", "cancelled"):
|
# Nur complete = fertig. cancelled/standby erst nach Entprellen.
|
||||||
|
if state == "complete":
|
||||||
|
self._clear_terminal_hits(item["id"])
|
||||||
store.update_print_queue(
|
store.update_print_queue(
|
||||||
conn,
|
conn,
|
||||||
item["id"],
|
item["id"],
|
||||||
@@ -553,6 +614,61 @@ class PrintQueueDispatcher:
|
|||||||
"%s fertig: %s" % (printer["name"], item.get("filename") or "Druck"),
|
"%s fertig: %s" % (printer["name"], item.get("filename") or "Druck"),
|
||||||
item.get("filename") or "",
|
item.get("filename") or "",
|
||||||
)
|
)
|
||||||
|
return
|
||||||
|
if state in ("cancelled", "standby"):
|
||||||
|
hits = self._terminal_hits(item["id"], "end")
|
||||||
|
if hits < TERMINAL_CONFIRM_HITS:
|
||||||
|
return
|
||||||
|
live2 = live
|
||||||
|
try:
|
||||||
|
live2 = moonraker.query(printer["host"])
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
state2 = (live2.get("state") or "").lower()
|
||||||
|
if state2 in ("printing", "paused", "heating") or live2.get("print_active"):
|
||||||
|
self._clear_terminal_hits(item["id"])
|
||||||
|
return
|
||||||
|
self._clear_terminal_hits(item["id"])
|
||||||
|
if state2 == "complete":
|
||||||
|
store.update_print_queue(
|
||||||
|
conn,
|
||||||
|
item["id"],
|
||||||
|
{
|
||||||
|
"status": "done",
|
||||||
|
"message": "Fertig.",
|
||||||
|
"phase": "",
|
||||||
|
"phase_started_at": None,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
self._event(
|
||||||
|
conn,
|
||||||
|
printer["host"],
|
||||||
|
printer["name"],
|
||||||
|
"fertig",
|
||||||
|
"%s fertig: %s" % (printer["name"], item.get("filename") or "Druck"),
|
||||||
|
item.get("filename") or "",
|
||||||
|
)
|
||||||
|
return
|
||||||
|
# Echter Abbruch — nicht „Fertig.“ und kein Auto-Retry.
|
||||||
|
store.update_print_queue(
|
||||||
|
conn,
|
||||||
|
item["id"],
|
||||||
|
{
|
||||||
|
"status": "cancelled",
|
||||||
|
"message": "Druck abgebrochen.",
|
||||||
|
"phase": "",
|
||||||
|
"phase_started_at": None,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
self._event(
|
||||||
|
conn,
|
||||||
|
printer["host"],
|
||||||
|
printer["name"],
|
||||||
|
"abbruch",
|
||||||
|
"%s: Druck abgebrochen (%s)"
|
||||||
|
% (printer["name"], item.get("filename") or "ohne Datei"),
|
||||||
|
item.get("filename") or "",
|
||||||
|
)
|
||||||
|
|
||||||
def _begin_ablauf(self, conn, item, printer, live):
|
def _begin_ablauf(self, conn, item, printer, live):
|
||||||
try:
|
try:
|
||||||
@@ -790,9 +906,31 @@ class PrintQueueDispatcher:
|
|||||||
live.get("message") or "Druckerfehler während des Drucks.",
|
live.get("message") or "Druckerfehler während des Drucks.",
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
# Erst weiter, wenn der Job wirklich gelaufen ist — sonst Race
|
# Nur complete = Druckende. standby/cancelled entprellen (Filament-Resume).
|
||||||
# (noch standby/complete vom vorherigen Auftrag).
|
if phase == "print_active" and state == "complete":
|
||||||
if phase == "print_active" and state in ("complete", "standby"):
|
self._clear_terminal_hits(item["id"])
|
||||||
|
self._next_step(conn, item, printer, live)
|
||||||
|
return
|
||||||
|
if phase == "print_active" and state in ("cancelled", "standby"):
|
||||||
|
hits = self._terminal_hits(item["id"], "ablauf_end")
|
||||||
|
if hits < TERMINAL_CONFIRM_HITS:
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
live = moonraker.query(printer["host"])
|
||||||
|
state = (live.get("state") or "").lower()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
if state in ("printing", "paused", "heating") or live.get("print_active"):
|
||||||
|
self._clear_terminal_hits(item["id"])
|
||||||
|
return
|
||||||
|
self._clear_terminal_hits(item["id"])
|
||||||
|
if state == "complete":
|
||||||
|
self._next_step(conn, item, printer, live)
|
||||||
|
return
|
||||||
|
if state == "cancelled":
|
||||||
|
self._fail_ablauf(conn, item, printer, "Druck abgebrochen.")
|
||||||
|
return
|
||||||
|
# standby nach Entprellen: Job wirklich zu Ende
|
||||||
self._next_step(conn, item, printer, live)
|
self._next_step(conn, item, printer, live)
|
||||||
return
|
return
|
||||||
# Idle schon während des Drucks verlängern — sonst greift M84/Default zu früh.
|
# Idle schon während des Drucks verlängern — sonst greift M84/Default zu früh.
|
||||||
@@ -912,16 +1050,22 @@ class PrintQueueDispatcher:
|
|||||||
)
|
)
|
||||||
name = (result or {}).get("filename") or ""
|
name = (result or {}).get("filename") or ""
|
||||||
row = store.get_print_queue_row(wconn, item_id) or item
|
row = store.get_print_queue_row(wconn, item_id) or item
|
||||||
store.update_print_queue(
|
if (row.get("status") or "") in ("cancelled", "dismissed"):
|
||||||
wconn,
|
try:
|
||||||
item_id,
|
moonraker.command(printer_copy["host"], "cancel")
|
||||||
{
|
except Exception:
|
||||||
|
pass
|
||||||
|
return
|
||||||
|
fields = {
|
||||||
"phase": "printing",
|
"phase": "printing",
|
||||||
"phase_started_at": "now",
|
"phase_started_at": "now",
|
||||||
"file_id": step_copy["file_id"],
|
"file_id": step_copy["file_id"],
|
||||||
"message": self._ablauf_message(row, "druckt %s" % name),
|
"message": self._ablauf_message(row, "druckt %s" % name),
|
||||||
},
|
}
|
||||||
)
|
live_run = store.find_active_run(wconn, printer_copy["host"], name)
|
||||||
|
if live_run:
|
||||||
|
fields["run_id"] = live_run["id"]
|
||||||
|
store.update_print_queue(wconn, item_id, fields)
|
||||||
self._step_event(wconn, row, printer_copy, "druckt %s" % name)
|
self._step_event(wconn, row, printer_copy, "druckt %s" % name)
|
||||||
wconn.commit()
|
wconn.commit()
|
||||||
except GrottiError as exc:
|
except GrottiError as exc:
|
||||||
|
|||||||
+803
-55
File diff suppressed because it is too large.
Load diff
+1
-1
@@ -1,3 +1,3 @@
|
|||||||
"""Version von Grotti (SemVer). Bei jeder Änderung CHANGELOG.md mitführen."""
|
"""Version von Grotti (SemVer). Bei jeder Änderung CHANGELOG.md mitführen."""
|
||||||
|
|
||||||
__version__ = "3.5.2"
|
__version__ = "3.6.0"
|
||||||
+136
-57
@@ -16,6 +16,21 @@ SAMPLE_EVERY_S = 30
|
|||||||
SAMPLE_HEAT_S = 10
|
SAMPLE_HEAT_S = 10
|
||||||
|
|
||||||
|
|
||||||
|
def contact_gap_keeps_run(prev_filename, next_filename, next_state):
|
||||||
|
"""Nach einem Kontaktverlust bleibt der Lauf, solange kein anderer Auftrag läuft.
|
||||||
|
|
||||||
|
Ein Timeout ist kein Druckende. Ohne Dateiname gibt es keinen Beweis
|
||||||
|
für einen Wechsel, der offene Lauf bleibt.
|
||||||
|
"""
|
||||||
|
if next_state not in ("printing", "paused"):
|
||||||
|
return False
|
||||||
|
prev_filename = prev_filename or ""
|
||||||
|
next_filename = next_filename or ""
|
||||||
|
if not prev_filename or not next_filename:
|
||||||
|
return True
|
||||||
|
return prev_filename == next_filename
|
||||||
|
|
||||||
|
|
||||||
class StateWatcher:
|
class StateWatcher:
|
||||||
def __init__(self, database_url, cfg, interval=10):
|
def __init__(self, database_url, cfg, interval=10):
|
||||||
self.database_url = database_url
|
self.database_url = database_url
|
||||||
@@ -23,6 +38,7 @@ class StateWatcher:
|
|||||||
self.interval = max(5, int(interval))
|
self.interval = max(5, int(interval))
|
||||||
self._prev = {}
|
self._prev = {}
|
||||||
self._offline_hits = {}
|
self._offline_hits = {}
|
||||||
|
self._cancel_hits = {}
|
||||||
self.latest = []
|
self.latest = []
|
||||||
self._lock = threading.Lock()
|
self._lock = threading.Lock()
|
||||||
self._updated_at = 0.0
|
self._updated_at = 0.0
|
||||||
@@ -95,41 +111,36 @@ class StateWatcher:
|
|||||||
if offline:
|
if offline:
|
||||||
hits = self._offline_hits.get(host, 0) + 1
|
hits = self._offline_hits.get(host, 0) + 1
|
||||||
self._offline_hits[host] = hits
|
self._offline_hits[host] = hits
|
||||||
if hits >= 2 and not prev_offline:
|
# Ein Aussetzer ist noch kein Offline. Erst der zweite Poll.
|
||||||
|
if hits < 2:
|
||||||
|
return
|
||||||
|
if not prev_offline:
|
||||||
self._emit(conn, host, name, "offline", "%s ist offline." % name, filename)
|
self._emit(conn, host, name, "offline", "%s ist offline." % name, filename)
|
||||||
# Nach Crash/Shutdown (503/gklib) bleibt sonst „druckt“ im Protokoll.
|
# Kontakt weg ist kein Druckende. Der letzte echte Zustand bleibt
|
||||||
if hits >= 2:
|
# gemerkt, damit fertig/Abbruch/Fehler beim nächsten Poll greifen.
|
||||||
dangling = store.find_live_run(conn, host)
|
remembered = prev_state if prev_state and prev_state != "offline" else ""
|
||||||
if dangling:
|
self._prev[host] = {
|
||||||
closed = store.complete_open_run(
|
"state": remembered,
|
||||||
conn, dangling["id"], state="interrupted"
|
"offline": True,
|
||||||
)
|
"heating": bool(prev.get("heating")),
|
||||||
if closed:
|
"filename": prev.get("filename") or filename or "",
|
||||||
label = dangling.get("filename") or filename or "offline"
|
"spool_warn": bool(prev.get("spool_warn")) if remembered == "printing" else False,
|
||||||
self._emit(
|
"run_id": prev.get("run_id"),
|
||||||
conn,
|
}
|
||||||
host,
|
|
||||||
name,
|
|
||||||
"abbruch",
|
|
||||||
"%s: Druck unterbrochen (Drucker offline)." % name,
|
|
||||||
label,
|
|
||||||
closed["id"],
|
|
||||||
)
|
|
||||||
try:
|
|
||||||
from grotti import jobs
|
|
||||||
|
|
||||||
jobs.apply_deduction(conn, closed, self.cfg["energy"])
|
|
||||||
except Exception as exc:
|
|
||||||
log.warning("Watcher Abzug offline %s: %s", host, exc)
|
|
||||||
self._prev[host] = {"state": "offline", "offline": True, "filename": filename}
|
|
||||||
return
|
return
|
||||||
|
|
||||||
self._offline_hits[host] = 0
|
self._offline_hits[host] = 0
|
||||||
|
file_changed = False
|
||||||
|
if prev_offline and state in ("printing", "paused"):
|
||||||
|
file_changed = self._release_replaced_run(conn, host, name, filename)
|
||||||
starting = (
|
starting = (
|
||||||
|
(
|
||||||
bool(prev_state)
|
bool(prev_state)
|
||||||
and prev_state not in ("printing", "paused")
|
and prev_state not in ("printing", "paused")
|
||||||
and state == "printing"
|
and state == "printing"
|
||||||
)
|
)
|
||||||
|
or (file_changed and state == "printing")
|
||||||
|
)
|
||||||
if starting:
|
if starting:
|
||||||
# Aufheiz-Proben behalten: Live-Lauf gleicher Datei nicht verwerfen
|
# Aufheiz-Proben behalten: Live-Lauf gleicher Datei nicht verwerfen
|
||||||
keep = None
|
keep = None
|
||||||
@@ -154,9 +165,21 @@ class StateWatcher:
|
|||||||
force = starting or (heating and not prev.get("heating"))
|
force = starting or (heating and not prev.get("heating"))
|
||||||
run = self._track_print(conn, host, name, filename, live, state, force_sample=force)
|
run = self._track_print(conn, host, name, filename, live, state, force_sample=force)
|
||||||
run_id = run["id"] if run else None
|
run_id = run["id"] if run else None
|
||||||
|
if run_id:
|
||||||
|
store.set_printer_active_run(conn, host, run_id)
|
||||||
|
|
||||||
|
if state not in ("cancelled", "standby"):
|
||||||
|
self._cancel_hits[host] = 0
|
||||||
|
|
||||||
if prev_offline:
|
if prev_offline:
|
||||||
self._emit(conn, host, name, "offline", "%s ist wieder erreichbar." % name, filename, run_id)
|
self._emit(conn, host, name, "offline", "%s ist wieder erreichbar." % name, filename, run_id)
|
||||||
|
if file_changed and state == "printing":
|
||||||
|
self._emit(
|
||||||
|
conn, host, name, "start",
|
||||||
|
"%s druckt %s" % (name, filename or "einen Auftrag"),
|
||||||
|
filename, run_id,
|
||||||
|
)
|
||||||
|
self._ensure_start_segment(conn, host, filename, live, run_id)
|
||||||
elif starting:
|
elif starting:
|
||||||
self._emit(
|
self._emit(
|
||||||
conn, host, name, "start",
|
conn, host, name, "start",
|
||||||
@@ -177,9 +200,16 @@ class StateWatcher:
|
|||||||
self._emit(conn, host, name, "start", "%s pausiert." % name, filename, run_id)
|
self._emit(conn, host, name, "start", "%s pausiert." % name, filename, run_id)
|
||||||
elif prev_state == "paused" and state == "printing":
|
elif prev_state == "paused" and state == "printing":
|
||||||
self._emit(conn, host, name, "start", "%s druckt weiter." % name, filename, run_id)
|
self._emit(conn, host, name, "start", "%s druckt weiter." % name, filename, run_id)
|
||||||
|
try:
|
||||||
|
jobs.sync_history(conn, self.cfg, host=host, watcher_resume=True)
|
||||||
|
except Exception as exc:
|
||||||
|
log.warning("Watcher Abgleich Resume %s: %s", host, exc)
|
||||||
|
# Nach Fold: aktiven History-Lauf weiter tracken.
|
||||||
|
open_run = store.find_active_run(conn, host, filename)
|
||||||
|
if open_run:
|
||||||
|
run_id = open_run["id"]
|
||||||
|
store.set_printer_active_run(conn, host, run_id)
|
||||||
elif prev_state == "printing" and state == "complete":
|
elif prev_state == "printing" and state == "complete":
|
||||||
# Live-Übergang: immer belegen (ensure_bed_after_print ohne Endzeit
|
|
||||||
# würde nach Quittierung eines älteren Drucks stehen bleiben).
|
|
||||||
store.set_bed_needs_clear(conn, host, True, filename or "fertig")
|
store.set_bed_needs_clear(conn, host, True, filename or "fertig")
|
||||||
self._emit(
|
self._emit(
|
||||||
conn,
|
conn,
|
||||||
@@ -191,32 +221,41 @@ class StateWatcher:
|
|||||||
run_id or (prev.get("run_id")),
|
run_id or (prev.get("run_id")),
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
from grotti import jobs
|
jobs.sync_history(conn, self.cfg, host=host)
|
||||||
|
|
||||||
jobs.sync_history(conn, self.cfg)
|
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
log.warning("Watcher Abgleich %s: %s", host, exc)
|
log.warning("Watcher Abgleich %s: %s", host, exc)
|
||||||
# History oft ohne Endzeit (interrupted) — Live trotzdem schließen.
|
# Live schließen ohne Abzug — History bucht; Fallback nach Frist.
|
||||||
dangling = store.find_live_run(conn, host)
|
dangling = store.find_live_run(conn, host)
|
||||||
if dangling:
|
if dangling:
|
||||||
closed = store.complete_open_run(conn, dangling["id"], state="completed")
|
store.complete_open_run(conn, dangling["id"], state="completed")
|
||||||
if closed:
|
store.set_printer_active_run(conn, host, None)
|
||||||
try:
|
|
||||||
from grotti import jobs
|
|
||||||
|
|
||||||
jobs.apply_deduction(conn, closed, self.cfg["energy"])
|
|
||||||
except Exception as exc:
|
|
||||||
log.warning("Watcher Abzug %s: %s", host, exc)
|
|
||||||
elif state in ("cancelled", "standby"):
|
elif state in ("cancelled", "standby"):
|
||||||
# Live-Lauf schließen: normaler Abbruch, oder nach Offline/Neustart
|
|
||||||
# (prev wird „offline“, der Übergang paused→standby geht sonst verloren).
|
|
||||||
dangling = store.find_live_run(conn, host)
|
dangling = store.find_live_run(conn, host)
|
||||||
from_active = prev_state in ("printing", "paused")
|
from_active = prev_state in ("printing", "paused")
|
||||||
recover = bool(dangling) and (prev_offline or not prev_state)
|
recover = bool(dangling) and (prev_offline or not prev_state)
|
||||||
if from_active or recover:
|
hits = self._cancel_hits.get(host, 0) + 1
|
||||||
|
self._cancel_hits[host] = hits
|
||||||
|
# Anycubic flackert kurz cancelled/standby während Pause/Resume —
|
||||||
|
# erst nach 3 Polls aufgeben. Nach Offline-Lücke sofort.
|
||||||
|
need_hits = 1 if recover else 3
|
||||||
|
if (from_active or recover) and hits >= need_hits:
|
||||||
file_label = filename or (dangling or {}).get("filename") or state
|
file_label = filename or (dangling or {}).get("filename") or state
|
||||||
|
try:
|
||||||
|
jobs.sync_history(conn, self.cfg, host=host)
|
||||||
|
except Exception as exc:
|
||||||
|
log.warning("Watcher Abgleich %s: %s", host, exc)
|
||||||
|
# Nach Sync evtl. schon Fortsetzung — dann nicht aufgeben.
|
||||||
|
still = store.find_live_run(conn, host) or store.find_open_history_run(
|
||||||
|
conn, host, filename or (dangling or {}).get("filename") or ""
|
||||||
|
)
|
||||||
|
if still and (still.get("state") or "") in ("in_progress", "printing", "paused"):
|
||||||
|
self._cancel_hits[host] = 0
|
||||||
|
run_id = still["id"]
|
||||||
|
store.set_printer_active_run(conn, host, run_id)
|
||||||
|
else:
|
||||||
store.set_bed_needs_clear(conn, host, True, file_label)
|
store.set_bed_needs_clear(conn, host, True, file_label)
|
||||||
store.abandon_live_runs(conn, host)
|
store.abandon_live_runs(conn, host)
|
||||||
|
store.set_printer_active_run(conn, host, None)
|
||||||
self._emit(
|
self._emit(
|
||||||
conn,
|
conn,
|
||||||
host,
|
host,
|
||||||
@@ -228,16 +267,26 @@ class StateWatcher:
|
|||||||
file_label if file_label != state else "",
|
file_label if file_label != state else "",
|
||||||
run_id or prev.get("run_id") or (dangling or {}).get("id"),
|
run_id or prev.get("run_id") or (dangling or {}).get("id"),
|
||||||
)
|
)
|
||||||
try:
|
# prev-Zustand behalten, bis die Hits reichen.
|
||||||
from grotti import jobs
|
if hits < 3 and from_active:
|
||||||
|
self._prev[host] = {
|
||||||
jobs.sync_history(conn, self.cfg)
|
"state": prev_state,
|
||||||
except Exception as exc:
|
"offline": False,
|
||||||
log.warning("Watcher Abgleich %s: %s", host, exc)
|
"heating": heating,
|
||||||
|
"filename": prev.get("filename") or filename,
|
||||||
|
"spool_warn": bool(prev.get("spool_warn")),
|
||||||
|
"run_id": run_id or prev.get("run_id"),
|
||||||
|
}
|
||||||
|
return
|
||||||
elif state == "error" and prev_state != "error":
|
elif state == "error" and prev_state != "error":
|
||||||
if prev_state == "printing" or prev_state == "paused":
|
if prev_state == "printing" or prev_state == "paused":
|
||||||
store.set_bed_needs_clear(conn, host, True, filename or "Fehler")
|
store.set_bed_needs_clear(conn, host, True, filename or "Fehler")
|
||||||
|
try:
|
||||||
|
jobs.sync_history(conn, self.cfg, host=host)
|
||||||
|
except Exception as exc:
|
||||||
|
log.warning("Watcher Abgleich %s: %s", host, exc)
|
||||||
store.abandon_live_runs(conn, host)
|
store.abandon_live_runs(conn, host)
|
||||||
|
store.set_printer_active_run(conn, host, None)
|
||||||
msg = (live.get("message") or "").strip()
|
msg = (live.get("message") or "").strip()
|
||||||
if not msg or msg.lower() in ("error", "fehler"):
|
if not msg or msg.lower() in ("error", "fehler"):
|
||||||
msg = "Ursache unbekannt — in Mainsail prüfen"
|
msg = "Ursache unbekannt — in Mainsail prüfen"
|
||||||
@@ -251,18 +300,10 @@ class StateWatcher:
|
|||||||
filename,
|
filename,
|
||||||
run_id or prev.get("run_id"),
|
run_id or prev.get("run_id"),
|
||||||
)
|
)
|
||||||
try:
|
|
||||||
from grotti import jobs
|
|
||||||
|
|
||||||
jobs.sync_history(conn, self.cfg)
|
|
||||||
except Exception as exc:
|
|
||||||
log.warning("Watcher Abgleich %s: %s", host, exc)
|
|
||||||
elif state == "error":
|
elif state == "error":
|
||||||
if (live.get("nozzle_target") or 0) > 0 or (live.get("bed_target") or 0) > 0:
|
if (live.get("nozzle_target") or 0) > 0 or (live.get("bed_target") or 0) > 0:
|
||||||
self._cool_heaters(host)
|
self._cool_heaters(host)
|
||||||
elif state == "complete" and (not prev_state or prev_offline):
|
elif state == "complete" and (not prev_state or prev_offline):
|
||||||
# Erster Blick nach Neustart: nur mit Endzeit des letzten Laufs,
|
|
||||||
# sonst wird bereits Quittiertes wieder „Platte belegt“.
|
|
||||||
ended = conn.execute(
|
ended = conn.execute(
|
||||||
"""
|
"""
|
||||||
SELECT ended_at FROM runs
|
SELECT ended_at FROM runs
|
||||||
@@ -280,6 +321,10 @@ class StateWatcher:
|
|||||||
ended_at=ended["ended_at"] if ended else None,
|
ended_at=ended["ended_at"] if ended else None,
|
||||||
message=filename or "fertig",
|
message=filename or "fertig",
|
||||||
)
|
)
|
||||||
|
try:
|
||||||
|
jobs.sync_history(conn, self.cfg, host=host)
|
||||||
|
except Exception as exc:
|
||||||
|
log.warning("Watcher Abgleich %s: %s", host, exc)
|
||||||
|
|
||||||
spool_warn = bool(prev.get("spool_warn"))
|
spool_warn = bool(prev.get("spool_warn"))
|
||||||
if state == "printing" and not spool_warn:
|
if state == "printing" and not spool_warn:
|
||||||
@@ -294,6 +339,40 @@ class StateWatcher:
|
|||||||
"run_id": run_id or (prev.get("run_id") if state in ("printing", "paused") or heating else None),
|
"run_id": run_id or (prev.get("run_id") if state in ("printing", "paused") or heating else None),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def _release_replaced_run(self, conn, host, name, filename):
|
||||||
|
"""Anderer Auftrag nach der Lücke: den offenen Lauf loslassen.
|
||||||
|
|
||||||
|
History zuerst, damit Proben am echten Job hängen. Bleibt der alte
|
||||||
|
Live-Lauf, wird er beendet ohne Abzug — der History-Abgleich bucht
|
||||||
|
das Filament, sobald der Job da ist.
|
||||||
|
"""
|
||||||
|
existing = store.find_live_run(conn, host)
|
||||||
|
if not existing:
|
||||||
|
return False
|
||||||
|
if contact_gap_keeps_run(existing.get("filename") or "", filename, "printing"):
|
||||||
|
return False
|
||||||
|
try:
|
||||||
|
jobs.sync_history(conn, self.cfg)
|
||||||
|
except Exception as exc:
|
||||||
|
log.warning("Watcher Abgleich nach Offline %s: %s", host, exc)
|
||||||
|
existing = store.find_live_run(conn, host)
|
||||||
|
if not existing:
|
||||||
|
return True
|
||||||
|
if contact_gap_keeps_run(existing.get("filename") or "", filename, "printing"):
|
||||||
|
return False
|
||||||
|
label = existing.get("filename") or "ohne Datei"
|
||||||
|
store.abandon_live_runs(conn, host)
|
||||||
|
self._emit(
|
||||||
|
conn,
|
||||||
|
host,
|
||||||
|
name,
|
||||||
|
"abbruch",
|
||||||
|
"%s: Druck unterbrochen (%s)" % (name, label),
|
||||||
|
label,
|
||||||
|
existing["id"],
|
||||||
|
)
|
||||||
|
return True
|
||||||
|
|
||||||
def _should_sample(self, conn, host, live, state):
|
def _should_sample(self, conn, host, live, state):
|
||||||
"""Proben bei Druck/Pause und beim Aufheizen mit Bezug zu einem Auftrag."""
|
"""Proben bei Druck/Pause und beim Aufheizen mit Bezug zu einem Auftrag."""
|
||||||
if state in ("printing", "paused"):
|
if state in ("printing", "paused"):
|
||||||
|
|||||||
@@ -37,6 +37,12 @@ rsync -a --delete \
|
|||||||
cp "$ROOT/server.py" "$STAGE/usr/lib/grotti/server.py"
|
cp "$ROOT/server.py" "$STAGE/usr/lib/grotti/server.py"
|
||||||
cp "$ROOT/requirements.txt" "$STAGE/usr/lib/grotti/requirements.txt"
|
cp "$ROOT/requirements.txt" "$STAGE/usr/lib/grotti/requirements.txt"
|
||||||
cp "$ROOT/config.example.json" "$STAGE/usr/lib/grotti/config.example.json"
|
cp "$ROOT/config.example.json" "$STAGE/usr/lib/grotti/config.example.json"
|
||||||
|
mkdir -p "$STAGE/usr/lib/grotti/scripts"
|
||||||
|
cp "$ROOT/scripts/pfade_umziehen.py" "$STAGE/usr/lib/grotti/scripts/pfade_umziehen.py"
|
||||||
|
# Symlink-Pfad für die Anleitung
|
||||||
|
mkdir -p "$STAGE/opt/grotti"
|
||||||
|
ln -sfn /usr/lib/grotti/scripts "$STAGE/opt/grotti/scripts"
|
||||||
|
ln -sfn /usr/lib/grotti/venv "$STAGE/opt/grotti/venv"
|
||||||
echo '[]' > "$STAGE/usr/lib/grotti/drucker.json"
|
echo '[]' > "$STAGE/usr/lib/grotti/drucker.json"
|
||||||
cp "$ROOT/packaging/config.pi.json" "$STAGE/usr/share/grotti/config.pi.json"
|
cp "$ROOT/packaging/config.pi.json" "$STAGE/usr/share/grotti/config.pi.json"
|
||||||
cp "$ROOT/packaging/config.pi.json" "$STAGE/etc/grotti/config.json"
|
cp "$ROOT/packaging/config.pi.json" "$STAGE/etc/grotti/config.json"
|
||||||
|
|||||||
+1
-1
@@ -4,5 +4,5 @@ psycopg-pool==3.3.3
|
|||||||
paho-mqtt==2.1.0
|
paho-mqtt==2.1.0
|
||||||
cryptography==50.0.2
|
cryptography==50.0.2
|
||||||
markdown==3.11.1
|
markdown==3.11.1
|
||||||
mcp>=1.2
|
mcp==2.0.0
|
||||||
waitress==3.0.2
|
waitress==3.0.2
|
||||||
@@ -0,0 +1,136 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Alt-Paare und verwaiste Live-Läufe finden. Standard: Probelauf.
|
||||||
|
|
||||||
|
python scripts/laeufe_reparieren.py
|
||||||
|
python scripts/laeufe_reparieren.py --apply
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
ROOT = Path(__file__).resolve().parents[1]
|
||||||
|
sys.path.insert(0, str(ROOT))
|
||||||
|
|
||||||
|
from grotti import jobs, store # noqa: E402
|
||||||
|
from grotti.config import load # noqa: E402
|
||||||
|
from grotti.db import connect, prepare # noqa: E402
|
||||||
|
|
||||||
|
|
||||||
|
def find_pairs(conn):
|
||||||
|
return conn.execute(
|
||||||
|
"""
|
||||||
|
SELECT a.id AS pred_id, b.id AS succ_id,
|
||||||
|
a.printer_host, a.filename,
|
||||||
|
a.state AS pred_state, b.state AS succ_state,
|
||||||
|
a.duration_s AS pred_dur, b.duration_s AS succ_dur,
|
||||||
|
a.ended_at, b.started_at,
|
||||||
|
a.deducted AS pred_deducted, b.deducted AS succ_deducted,
|
||||||
|
a.chargen_nr AS pred_chargen, b.chargen_nr AS succ_chargen
|
||||||
|
FROM runs a
|
||||||
|
JOIN runs b
|
||||||
|
ON a.printer_host = b.printer_host
|
||||||
|
AND a.filename = b.filename
|
||||||
|
AND a.id <> b.id
|
||||||
|
AND b.started_at BETWEEN a.ended_at - interval '30 seconds'
|
||||||
|
AND a.ended_at + interval '5 seconds'
|
||||||
|
WHERE a.state IN ('cancelled', 'interrupted', 'error')
|
||||||
|
AND a.ended_at IS NOT NULL
|
||||||
|
AND a.moonraker_job_id NOT LIKE 'live:%%'
|
||||||
|
AND b.moonraker_job_id NOT LIKE 'live:%%'
|
||||||
|
AND COALESCE(b.duration_s, 0) > 60
|
||||||
|
AND COALESCE(b.duration_s, 0) >= COALESCE(a.duration_s, 0) - 30
|
||||||
|
ORDER BY a.ended_at DESC
|
||||||
|
"""
|
||||||
|
).fetchall()
|
||||||
|
|
||||||
|
|
||||||
|
def find_orphan_live(conn):
|
||||||
|
return conn.execute(
|
||||||
|
"""
|
||||||
|
SELECT id, printer_host, filename, state, started_at, ended_at, duration_s, chargen_nr
|
||||||
|
FROM runs
|
||||||
|
WHERE moonraker_job_id LIKE 'live:%%'
|
||||||
|
AND state IN ('interrupted', 'completed', 'cancelled')
|
||||||
|
ORDER BY COALESCE(ended_at, started_at) DESC
|
||||||
|
LIMIT 100
|
||||||
|
"""
|
||||||
|
).fetchall()
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser(description="Läufe nach Filament-Resume reparieren")
|
||||||
|
parser.add_argument("--apply", action="store_true", help="Wirklich zusammenlegen")
|
||||||
|
args = parser.parse_args()
|
||||||
|
cfg = load()
|
||||||
|
prepare(cfg["database_url"])
|
||||||
|
with connect(cfg["database_url"]) as conn:
|
||||||
|
pairs = find_pairs(conn)
|
||||||
|
orphans = find_orphan_live(conn)
|
||||||
|
print("=== Verdachtspaare (Beweis: Dauer fortgesetzt, Lücke ≤ 5 s) ===")
|
||||||
|
for row in pairs:
|
||||||
|
print(json.dumps({k: str(v) for k, v in dict(row).items()}, ensure_ascii=False))
|
||||||
|
print("%d Paare" % len(pairs))
|
||||||
|
print("=== Verwaiste live:-Läufe ===")
|
||||||
|
for row in orphans:
|
||||||
|
print(json.dumps({k: str(v) for k, v in dict(row).items()}, ensure_ascii=False))
|
||||||
|
print("%d orphan" % len(orphans))
|
||||||
|
if not args.apply:
|
||||||
|
print("Probelauf. Mit --apply werden Paare verbunden.")
|
||||||
|
conn.rollback()
|
||||||
|
return
|
||||||
|
merged = 0
|
||||||
|
for row in pairs:
|
||||||
|
try:
|
||||||
|
jobs.manual_merge_runs(
|
||||||
|
conn, row["pred_id"], row["succ_id"], confirm=True
|
||||||
|
)
|
||||||
|
merged += 1
|
||||||
|
print("verbunden", row["pred_id"], "+", row["succ_id"])
|
||||||
|
except Exception as exc:
|
||||||
|
print("Fehler", row["pred_id"], row["succ_id"], exc)
|
||||||
|
conn.rollback()
|
||||||
|
# Orphans nur an History derselben Datei hängen (kein Host-Fallback).
|
||||||
|
# adopt_live_run nimmt geschlossene live: nur ≤ 2 h — ältere bleiben liegen.
|
||||||
|
cleaned = 0
|
||||||
|
skipped = 0
|
||||||
|
for row in orphans:
|
||||||
|
fname = (row.get("filename") or "").strip()
|
||||||
|
if not fname:
|
||||||
|
skipped += 1
|
||||||
|
continue
|
||||||
|
hist = conn.execute(
|
||||||
|
"""
|
||||||
|
SELECT * FROM runs
|
||||||
|
WHERE printer_host = %s
|
||||||
|
AND filename = %s
|
||||||
|
AND moonraker_job_id NOT LIKE 'live:%%'
|
||||||
|
AND state IN ('in_progress', 'printing', 'paused')
|
||||||
|
ORDER BY id DESC
|
||||||
|
LIMIT 1
|
||||||
|
""",
|
||||||
|
(row["printer_host"], fname),
|
||||||
|
).fetchone()
|
||||||
|
if not hist:
|
||||||
|
skipped += 1
|
||||||
|
continue
|
||||||
|
store.adopt_live_run(conn, row["printer_host"], fname, hist["id"])
|
||||||
|
still = conn.execute(
|
||||||
|
"SELECT 1 FROM runs WHERE id = %s", (row["id"],)
|
||||||
|
).fetchone()
|
||||||
|
if still:
|
||||||
|
skipped += 1
|
||||||
|
else:
|
||||||
|
cleaned += 1
|
||||||
|
conn.commit()
|
||||||
|
print(
|
||||||
|
"verbunden=%d orphan_adopted=%d orphan_skipped=%d"
|
||||||
|
% (merged, cleaned, skipped)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Absolute Windows-Pfade in files.stored_path und projects.folder auf Linux umschreiben.
|
||||||
|
|
||||||
|
Beispiel (Dry-Run):
|
||||||
|
python scripts/pfade_umziehen.py \\
|
||||||
|
--database-url postgresql:///grotti?host=/var/run/postgresql \\
|
||||||
|
--from "D:/Projekte/3DP/Slice" --to /var/lib/grotti/slice
|
||||||
|
|
||||||
|
Ohne --apply nur Anzeige. Mit --apply werden die Zeilen geschrieben.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
ROOT = Path(__file__).resolve().parents[1]
|
||||||
|
if str(ROOT) not in sys.path:
|
||||||
|
sys.path.insert(0, str(ROOT))
|
||||||
|
|
||||||
|
|
||||||
|
def normalize_slash(path: str) -> str:
|
||||||
|
return (path or "").replace("\\", "/").rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
def rewrite(value: str, old: str, new: str) -> str | None:
|
||||||
|
if not value:
|
||||||
|
return None
|
||||||
|
cur = value.replace("\\", "/")
|
||||||
|
old_n = normalize_slash(old)
|
||||||
|
new_n = normalize_slash(new)
|
||||||
|
# case-insensitive für Windows-Laufwerke
|
||||||
|
if cur.lower().startswith(old_n.lower()):
|
||||||
|
rest = cur[len(old_n) :]
|
||||||
|
if rest and not rest.startswith("/"):
|
||||||
|
rest = "/" + rest
|
||||||
|
return new_n + rest
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> int:
|
||||||
|
parser = argparse.ArgumentParser(description="Slice-Pfade Windows → Linux umschreiben")
|
||||||
|
parser.add_argument("--database-url", required=True)
|
||||||
|
parser.add_argument("--from", dest="old", required=True, help="Alter Prefix (Windows)")
|
||||||
|
parser.add_argument("--to", dest="new", required=True, help="Neuer Prefix (Linux)")
|
||||||
|
parser.add_argument("--apply", action="store_true", help="Wirklich schreiben")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
import psycopg
|
||||||
|
from psycopg.rows import dict_row
|
||||||
|
|
||||||
|
old = args.old
|
||||||
|
new = args.new
|
||||||
|
changed_files = 0
|
||||||
|
changed_projects = 0
|
||||||
|
|
||||||
|
with psycopg.connect(args.database_url, row_factory=dict_row) as conn:
|
||||||
|
files = conn.execute("SELECT id, stored_path FROM files ORDER BY id").fetchall()
|
||||||
|
for row in files:
|
||||||
|
nxt = rewrite(row["stored_path"] or "", old, new)
|
||||||
|
if nxt is None or nxt == row["stored_path"]:
|
||||||
|
continue
|
||||||
|
changed_files += 1
|
||||||
|
print("file %s: %s → %s" % (row["id"], row["stored_path"], nxt))
|
||||||
|
if args.apply:
|
||||||
|
conn.execute("UPDATE files SET stored_path = %s WHERE id = %s", (nxt, row["id"]))
|
||||||
|
|
||||||
|
projects = conn.execute("SELECT id, folder FROM projects ORDER BY id").fetchall()
|
||||||
|
for row in projects:
|
||||||
|
folder = row["folder"] or ""
|
||||||
|
# folder ist relativ — nur absolute Reste bereinigen
|
||||||
|
nxt = rewrite(folder, old, new)
|
||||||
|
if nxt is None:
|
||||||
|
continue
|
||||||
|
# relativ zum neuen Slice-Root speichern, falls möglich
|
||||||
|
new_n = normalize_slash(new)
|
||||||
|
if nxt.lower().startswith(new_n.lower()):
|
||||||
|
rel = nxt[len(new_n) :].lstrip("/")
|
||||||
|
nxt = rel
|
||||||
|
changed_projects += 1
|
||||||
|
print("project %s: %s → %s" % (row["id"], folder, nxt))
|
||||||
|
if args.apply:
|
||||||
|
conn.execute("UPDATE projects SET folder = %s WHERE id = %s", (nxt, row["id"]))
|
||||||
|
|
||||||
|
if args.apply:
|
||||||
|
conn.commit()
|
||||||
|
print("Geschrieben: %s Dateien, %s Projekte." % (changed_files, changed_projects))
|
||||||
|
else:
|
||||||
|
print(
|
||||||
|
"Dry-Run: %s Dateien, %s Projekte würden sich ändern. Mit --apply ausführen."
|
||||||
|
% (changed_files, changed_projects)
|
||||||
|
)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
raise SystemExit(main())
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
"""Leere History-Hülle, Resume-Beweis und Chargen-Tag."""
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
from datetime import date, datetime, timedelta, timezone
|
||||||
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
|
from grotti.jobs import (
|
||||||
|
history_in_order,
|
||||||
|
history_shell_is_empty,
|
||||||
|
is_filament_resume,
|
||||||
|
)
|
||||||
|
from grotti.store import chargen_day, history_job_retired
|
||||||
|
|
||||||
|
|
||||||
|
class HistoryShellTests(unittest.TestCase):
|
||||||
|
def test_pause_shell_is_empty(self):
|
||||||
|
self.assertTrue(history_shell_is_empty({"duration_s": 0, "ended_at": None}))
|
||||||
|
|
||||||
|
def test_recorded_cancel_is_not_a_shell(self):
|
||||||
|
self.assertFalse(history_shell_is_empty({
|
||||||
|
"duration_s": 653,
|
||||||
|
"ended_at": datetime(2026, 10, 18, 13, 18, tzinfo=timezone.utc),
|
||||||
|
}))
|
||||||
|
|
||||||
|
def test_missing_row_is_not_a_shell(self):
|
||||||
|
self.assertFalse(history_shell_is_empty(None))
|
||||||
|
|
||||||
|
|
||||||
|
class FilamentResumeProofTests(unittest.TestCase):
|
||||||
|
def test_duration_continued_with_tiny_gap(self):
|
||||||
|
# 2026-10-25 Kobra 3 A1: 000040 → 000041, 0,04 s Lücke, gleiche print_duration
|
||||||
|
end = datetime(2026, 10, 25, 5, 48, 27, 569483, tzinfo=timezone.utc)
|
||||||
|
start = end + timedelta(milliseconds=40)
|
||||||
|
self.assertTrue(is_filament_resume(
|
||||||
|
end, start, prev_duration_s=11711, new_duration_s=11711
|
||||||
|
))
|
||||||
|
|
||||||
|
def test_fresh_restart_after_cancel_is_not_resume(self):
|
||||||
|
# Lauf 27941: 8 s abgebrochen, 45 s später Neustart mit Dauer ~0
|
||||||
|
end = datetime(2026, 10, 24, 11, 46, 8, tzinfo=timezone.utc)
|
||||||
|
start = end + timedelta(seconds=45)
|
||||||
|
self.assertFalse(is_filament_resume(
|
||||||
|
end, start, prev_duration_s=8, new_duration_s=5
|
||||||
|
))
|
||||||
|
|
||||||
|
def test_two_arg_call_without_proof_is_false(self):
|
||||||
|
end = datetime(2026, 10, 21, 19, 32, 20, tzinfo=timezone.utc)
|
||||||
|
start = end + timedelta(milliseconds=40)
|
||||||
|
self.assertFalse(is_filament_resume(end, start))
|
||||||
|
|
||||||
|
def test_watcher_signal_allows_longer_gap(self):
|
||||||
|
end = datetime(2026, 10, 25, 1, 0, 0, tzinfo=timezone.utc)
|
||||||
|
start = end + timedelta(hours=4)
|
||||||
|
self.assertTrue(is_filament_resume(
|
||||||
|
end, start, prev_duration_s=1000, new_duration_s=1000, watcher_resume=True
|
||||||
|
))
|
||||||
|
|
||||||
|
def test_duration_reset_is_not_resume(self):
|
||||||
|
end = datetime(2026, 10, 25, 5, 48, 27, tzinfo=timezone.utc)
|
||||||
|
start = end + timedelta(milliseconds=40)
|
||||||
|
self.assertFalse(is_filament_resume(
|
||||||
|
end, start, prev_duration_s=11711, new_duration_s=12
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
|
class HistoryOrderTests(unittest.TestCase):
|
||||||
|
def test_cancelled_part_before_resume(self):
|
||||||
|
items = [
|
||||||
|
{"job_id": "000041", "start_time": 1792907307.607},
|
||||||
|
{"job_id": "000040", "start_time": 1792879062.392},
|
||||||
|
]
|
||||||
|
self.assertEqual([j["job_id"] for j in history_in_order(items)], ["000040", "000041"])
|
||||||
|
|
||||||
|
def test_missing_start_first(self):
|
||||||
|
items = [{"job_id": "b", "start_time": 5}, {"job_id": "a"}]
|
||||||
|
self.assertEqual([j["job_id"] for j in history_in_order(items)], ["a", "b"])
|
||||||
|
|
||||||
|
|
||||||
|
class HistoryJobRetiredTests(unittest.TestCase):
|
||||||
|
def _conn(self, row):
|
||||||
|
conn = MagicMock()
|
||||||
|
conn.execute.return_value.fetchone.return_value = row
|
||||||
|
return conn
|
||||||
|
|
||||||
|
def test_folded_predecessor_is_retired(self):
|
||||||
|
conn = self._conn({"moonraker_job_id": "000041"})
|
||||||
|
self.assertTrue(history_job_retired(conn, "h", "000040"))
|
||||||
|
|
||||||
|
def test_own_job_is_not_retired(self):
|
||||||
|
conn = self._conn({"moonraker_job_id": "000041"})
|
||||||
|
self.assertFalse(history_job_retired(conn, "h", "000041"))
|
||||||
|
|
||||||
|
def test_unknown_job_is_not_retired(self):
|
||||||
|
self.assertFalse(history_job_retired(self._conn(None), "h", "000042"))
|
||||||
|
|
||||||
|
|
||||||
|
class ChargenDayTests(unittest.TestCase):
|
||||||
|
def test_old_print_keeps_its_day(self):
|
||||||
|
started = datetime(2026, 10, 18, 13, 4, 16, tzinfo=timezone.utc)
|
||||||
|
self.assertEqual(chargen_day(started, today=date(2026, 10, 24)), date(2026, 10, 18))
|
||||||
|
|
||||||
|
def test_without_start_uses_today(self):
|
||||||
|
self.assertEqual(chargen_day(None, today=date(2026, 10, 24)), date(2026, 10, 24))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
@@ -69,6 +69,16 @@ class ChooseSpoolTests(unittest.TestCase):
|
|||||||
):
|
):
|
||||||
self.assertEqual(jobs.resolve_tracking_spool(conn, "h", 4), 14)
|
self.assertEqual(jobs.resolve_tracking_spool(conn, "h", 4), 14)
|
||||||
|
|
||||||
|
def test_ace_target_skips_spool_created_after_end(self):
|
||||||
|
end = datetime(2026, 10, 15, 22, 0, tzinfo=timezone.utc)
|
||||||
|
future = {"id": 18, "created_at": end + timedelta(days=6)}
|
||||||
|
conn = MagicMock()
|
||||||
|
with patch("grotti.jobs.store.spool_at_slot", return_value=future):
|
||||||
|
self.assertEqual(
|
||||||
|
jobs._targets_from_ace(conn, "h", [{"ams_index": 3}], ended_at=end),
|
||||||
|
[],
|
||||||
|
)
|
||||||
|
|
||||||
def test_spool_valid_for_end_naive(self):
|
def test_spool_valid_for_end_naive(self):
|
||||||
end = datetime(2026, 10, 1, 12, 0, tzinfo=timezone.utc)
|
end = datetime(2026, 10, 1, 12, 0, tzinfo=timezone.utc)
|
||||||
spool = {"created_at": datetime(2026, 9, 1, 12, 0)}
|
spool = {"created_at": datetime(2026, 9, 1, 12, 0)}
|
||||||
|
|||||||
@@ -53,13 +53,29 @@ class MatchSpoolsTests(unittest.TestCase):
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
def test_base_sunlu_pla_matches_plain_pla_not_meta(self):
|
def test_base_sunlu_pla_matches_any_pla(self):
|
||||||
need = {"profile": "Sunlu PLA", "material_type": "pla", "color": "", "paint_index": 0}
|
need = {"profile": "Sunlu PLA", "material_type": "pla", "color": "", "paint_index": 0}
|
||||||
matched = store._match_spools_for_need(need, self.have)
|
matched = store._match_spools_for_need(need, self.have)
|
||||||
ids = {m["spool_id"] for m in matched}
|
ids = {m["spool_id"] for m in matched}
|
||||||
self.assertEqual(ids, {3}) # Eryone PLA; Meta/Matte nicht
|
self.assertEqual(ids, {1, 2, 3})
|
||||||
|
|
||||||
def test_pla_lite_hex_matches_plain_pla(self):
|
def test_base_pla_matches_matte_alone(self):
|
||||||
|
need = {"profile": "Sunlu PLA", "material_type": "pla", "color": "#f2a900", "paint_index": 0}
|
||||||
|
have = [self.have[1]]
|
||||||
|
matched = store._match_spools_for_need(need, have)
|
||||||
|
self.assertEqual([m["spool_id"] for m in matched], [2])
|
||||||
|
|
||||||
|
def test_meta_falls_back_to_any_pla(self):
|
||||||
|
need = {"profile": "Sunlu PLA Meta", "material_type": "pla", "color": "", "paint_index": 0}
|
||||||
|
have = [self.have[1]]
|
||||||
|
matched = store._match_spools_for_need(need, have)
|
||||||
|
self.assertEqual([m["spool_id"] for m in matched], [2])
|
||||||
|
|
||||||
|
def test_petg_does_not_match_pla(self):
|
||||||
|
need = {"profile": "Sunlu PETG", "material_type": "petg", "color": "", "paint_index": 0}
|
||||||
|
self.assertEqual(store._match_spools_for_need(need, self.have), [])
|
||||||
|
|
||||||
|
def test_pla_lite_hex_matches_any_pla(self):
|
||||||
# Orca: Profil „Eryone PLA Lite“, Farbe #26A69A — Lager: Eryone/Sunlu PLA „Grau“
|
# Orca: Profil „Eryone PLA Lite“, Farbe #26A69A — Lager: Eryone/Sunlu PLA „Grau“
|
||||||
need = {
|
need = {
|
||||||
"profile": "Eryone PLA Lite",
|
"profile": "Eryone PLA Lite",
|
||||||
@@ -86,7 +102,7 @@ class MatchSpoolsTests(unittest.TestCase):
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
matched = store._match_spools_for_need(need, have)
|
matched = store._match_spools_for_need(need, have)
|
||||||
self.assertEqual({m["spool_id"] for m in matched}, {15})
|
self.assertEqual({m["spool_id"] for m in matched}, {15, 1})
|
||||||
|
|
||||||
def test_picks_meta_not_matte(self):
|
def test_picks_meta_not_matte(self):
|
||||||
need = {"profile": "Sunlu PLA Meta", "material_type": "pla", "color": "", "paint_index": 0}
|
need = {"profile": "Sunlu PLA Meta", "material_type": "pla", "color": "", "paint_index": 0}
|
||||||
|
|||||||
@@ -8,7 +8,15 @@ from unittest import mock
|
|||||||
ROOT = Path(__file__).resolve().parents[1]
|
ROOT = Path(__file__).resolve().parents[1]
|
||||||
sys.path.insert(0, str(ROOT))
|
sys.path.insert(0, str(ROOT))
|
||||||
|
|
||||||
from grotti.print_queue import PRINT_START_TIMEOUT_S, PrintQueueDispatcher, _cool_wait_text
|
from datetime import datetime, timedelta, timezone
|
||||||
|
|
||||||
|
from grotti.jobs import is_filament_resume
|
||||||
|
from grotti.print_queue import (
|
||||||
|
PRINT_START_TIMEOUT_S,
|
||||||
|
TERMINAL_CONFIRM_HITS,
|
||||||
|
PrintQueueDispatcher,
|
||||||
|
_cool_wait_text,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class CoolTextTests(unittest.TestCase):
|
class CoolTextTests(unittest.TestCase):
|
||||||
@@ -20,9 +28,26 @@ class CoolTextTests(unittest.TestCase):
|
|||||||
self.assertNotIn(" · ", text)
|
self.assertNotIn(" · ", text)
|
||||||
|
|
||||||
|
|
||||||
|
class FilamentResumeTests(unittest.TestCase):
|
||||||
|
def test_same_moment_with_duration_is_resume(self):
|
||||||
|
end = datetime(2026, 10, 21, 19, 32, 20, tzinfo=timezone.utc)
|
||||||
|
start = end + timedelta(milliseconds=40)
|
||||||
|
self.assertTrue(is_filament_resume(
|
||||||
|
end, start, prev_duration_s=500, new_duration_s=520
|
||||||
|
))
|
||||||
|
|
||||||
|
def test_later_reprint_is_not_resume(self):
|
||||||
|
end = datetime(2026, 10, 21, 19, 32, 20, tzinfo=timezone.utc)
|
||||||
|
start = end + timedelta(minutes=10)
|
||||||
|
self.assertFalse(is_filament_resume(
|
||||||
|
end, start, prev_duration_s=500, new_duration_s=10
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
class DispatcherHelpers(unittest.TestCase):
|
class DispatcherHelpers(unittest.TestCase):
|
||||||
def test_timeout_constant(self):
|
def test_timeout_constant(self):
|
||||||
self.assertGreaterEqual(PRINT_START_TIMEOUT_S, 300)
|
self.assertGreaterEqual(PRINT_START_TIMEOUT_S, 300)
|
||||||
|
self.assertGreaterEqual(TERMINAL_CONFIRM_HITS, 2)
|
||||||
|
|
||||||
def test_worker_busy_empty(self):
|
def test_worker_busy_empty(self):
|
||||||
d = PrintQueueDispatcher("postgresql://x", {}, watcher=None)
|
d = PrintQueueDispatcher("postgresql://x", {}, watcher=None)
|
||||||
@@ -34,6 +59,21 @@ class DispatcherHelpers(unittest.TestCase):
|
|||||||
d.cfg = {"auto_queue": False}
|
d.cfg = {"auto_queue": False}
|
||||||
self.assertFalse(d._auto_enabled())
|
self.assertFalse(d._auto_enabled())
|
||||||
|
|
||||||
|
def test_no_retry_after_abort(self):
|
||||||
|
d = PrintQueueDispatcher("postgresql://x", {}, watcher=None)
|
||||||
|
self.assertFalse(d._retryable_message("Druck abgebrochen."))
|
||||||
|
self.assertTrue(d._retryable_message("Start-Timeout"))
|
||||||
|
|
||||||
|
def test_advance_simple_ignores_single_cancelled(self):
|
||||||
|
d = PrintQueueDispatcher("postgresql://x", {}, watcher=None)
|
||||||
|
item = {"id": 1, "phase": "print_active", "filename": "a.gcode"}
|
||||||
|
printer = {"host": "h", "name": "P"}
|
||||||
|
live = {"state": "cancelled", "print_active": False}
|
||||||
|
with mock.patch("grotti.print_queue.store.update_print_queue") as upd:
|
||||||
|
d._advance_simple(mock.Mock(), item, printer, live)
|
||||||
|
upd.assert_not_called()
|
||||||
|
self.assertEqual(d._term_hits.get("1:end"), 1)
|
||||||
|
|
||||||
|
|
||||||
class ResolveSpoolTests(unittest.TestCase):
|
class ResolveSpoolTests(unittest.TestCase):
|
||||||
def test_material_match(self):
|
def test_material_match(self):
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
"""Szenarien für einen physischen Druck = ein Lauf (ohne DB, mit Mocks)."""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import unittest
|
||||||
|
from datetime import datetime, timedelta, timezone
|
||||||
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
|
from grotti import jobs
|
||||||
|
|
||||||
|
|
||||||
|
class SyncOneJobShellTests(unittest.TestCase):
|
||||||
|
def test_empty_shell_skipped(self):
|
||||||
|
conn = MagicMock()
|
||||||
|
printer = {"host": "h", "name": "P"}
|
||||||
|
job = {
|
||||||
|
"job_id": "000041",
|
||||||
|
"filename": "a.gcode",
|
||||||
|
"status": "in_progress",
|
||||||
|
"start_time": 1000,
|
||||||
|
"end_time": None,
|
||||||
|
"print_duration": 0,
|
||||||
|
"total_duration": 0,
|
||||||
|
"metadata": {},
|
||||||
|
}
|
||||||
|
self.assertEqual(jobs._sync_one_job(conn, {"energy": {}}, printer, job), 0)
|
||||||
|
conn.execute.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
|
class FoldProofIntegrationLike(unittest.TestCase):
|
||||||
|
def test_fold_requires_duration_proof(self):
|
||||||
|
end = datetime(2026, 10, 25, 5, 48, 27, tzinfo=timezone.utc)
|
||||||
|
start = end + timedelta(milliseconds=40)
|
||||||
|
pred = {
|
||||||
|
"id": 1,
|
||||||
|
"ended_at": end,
|
||||||
|
"duration_s": 11711,
|
||||||
|
"moonraker_job_id": "000040",
|
||||||
|
"verdict": "",
|
||||||
|
}
|
||||||
|
conn = MagicMock()
|
||||||
|
conn.execute.return_value.fetchone.return_value = None
|
||||||
|
with patch("grotti.jobs.store.find_resume_predecessor", return_value=pred), \
|
||||||
|
patch("grotti.jobs.store.remember_run_job"), \
|
||||||
|
patch("grotti.jobs.store.move_run_jobs"), \
|
||||||
|
patch("grotti.jobs.store.set_printer_active_run"), \
|
||||||
|
patch("grotti.jobs.undo_deduction"):
|
||||||
|
# Frischer Neustart (Dauer 12) — kein Fold
|
||||||
|
self.assertIsNone(jobs.fold_filament_resume(
|
||||||
|
conn, "h", "a.gcode", "000041", start, print_duration_s=12
|
||||||
|
))
|
||||||
|
# Fortgesetzte Dauer — Fold
|
||||||
|
self.assertEqual(
|
||||||
|
jobs.fold_filament_resume(
|
||||||
|
conn, "h", "a.gcode", "000041", start, print_duration_s=11711
|
||||||
|
),
|
||||||
|
1,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@unittest.skipUnless(os.environ.get("GROTTI_TEST_DB"), "GROTTI_TEST_DB nicht gesetzt")
|
||||||
|
class LiveDbScenarios(unittest.TestCase):
|
||||||
|
"""Gegen echte Test-DB: GROTTI_TEST_DB=postgresql://…"""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
import psycopg
|
||||||
|
from psycopg.rows import dict_row
|
||||||
|
|
||||||
|
self.conn = psycopg.connect(os.environ["GROTTI_TEST_DB"], row_factory=dict_row)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self.conn.rollback()
|
||||||
|
self.conn.close()
|
||||||
|
|
||||||
|
def test_connection(self):
|
||||||
|
self.assertTrue(self.conn.execute("SELECT 1").fetchone())
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
@@ -0,0 +1,142 @@
|
|||||||
|
"""Kontaktverlust beendet einen Druck nicht."""
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
|
from grotti.watcher import StateWatcher, contact_gap_keeps_run
|
||||||
|
|
||||||
|
HOST = "10.10.1.88"
|
||||||
|
FILE = "boden_PETG_0.2_2h15m.gcode"
|
||||||
|
|
||||||
|
|
||||||
|
class ContactGapTests(unittest.TestCase):
|
||||||
|
def test_same_file_stays(self):
|
||||||
|
self.assertTrue(contact_gap_keeps_run(FILE, FILE, "printing"))
|
||||||
|
self.assertTrue(contact_gap_keeps_run(FILE, FILE, "paused"))
|
||||||
|
|
||||||
|
def test_other_file_does_not_stay(self):
|
||||||
|
self.assertFalse(contact_gap_keeps_run(FILE, "andere.gcode", "printing"))
|
||||||
|
|
||||||
|
def test_terminal_state_does_not_stay(self):
|
||||||
|
self.assertFalse(contact_gap_keeps_run(FILE, FILE, "standby"))
|
||||||
|
self.assertFalse(contact_gap_keeps_run(FILE, FILE, "complete"))
|
||||||
|
self.assertFalse(contact_gap_keeps_run(FILE, FILE, "error"))
|
||||||
|
|
||||||
|
def test_missing_name_is_not_a_change(self):
|
||||||
|
self.assertTrue(contact_gap_keeps_run("", FILE, "printing"))
|
||||||
|
self.assertTrue(contact_gap_keeps_run(FILE, "", "paused"))
|
||||||
|
|
||||||
|
|
||||||
|
class WatcherOfflineTests(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.watcher = StateWatcher("postgresql://x", {})
|
||||||
|
self.watcher._prev[HOST] = {
|
||||||
|
"state": "printing",
|
||||||
|
"offline": False,
|
||||||
|
"filename": FILE,
|
||||||
|
"run_id": 42,
|
||||||
|
}
|
||||||
|
|
||||||
|
def test_two_misses_keep_the_run(self):
|
||||||
|
live = {
|
||||||
|
"host": HOST,
|
||||||
|
"name": "Kobra S1",
|
||||||
|
"state": "offline",
|
||||||
|
"ok": False,
|
||||||
|
"filename": "",
|
||||||
|
}
|
||||||
|
with mock.patch.object(self.watcher, "_emit") as emit, \
|
||||||
|
mock.patch("grotti.watcher.store.complete_open_run") as close, \
|
||||||
|
mock.patch("grotti.watcher.jobs.apply_deduction") as deduct:
|
||||||
|
self.watcher._one(mock.Mock(), live)
|
||||||
|
self.watcher._one(mock.Mock(), live)
|
||||||
|
close.assert_not_called()
|
||||||
|
deduct.assert_not_called()
|
||||||
|
remembered = self.watcher._prev[HOST]
|
||||||
|
self.assertEqual(remembered["state"], "printing")
|
||||||
|
self.assertTrue(remembered["offline"])
|
||||||
|
self.assertEqual(remembered["run_id"], 42)
|
||||||
|
self.assertEqual(remembered["filename"], FILE)
|
||||||
|
self.assertEqual([call.args[3] for call in emit.call_args_list], ["offline"])
|
||||||
|
|
||||||
|
def test_same_print_after_gap_is_the_same_run(self):
|
||||||
|
self.watcher._prev[HOST]["offline"] = True
|
||||||
|
live = {
|
||||||
|
"host": HOST,
|
||||||
|
"name": "Kobra S1",
|
||||||
|
"state": "printing",
|
||||||
|
"ok": True,
|
||||||
|
"filename": FILE,
|
||||||
|
"weight": 0,
|
||||||
|
}
|
||||||
|
run = {"id": 42, "filename": FILE}
|
||||||
|
with mock.patch.object(self.watcher, "_emit") as emit, \
|
||||||
|
mock.patch.object(self.watcher, "_track_print", return_value=run) as track, \
|
||||||
|
mock.patch.object(self.watcher, "_check_spool", return_value=False), \
|
||||||
|
mock.patch("grotti.watcher.store.find_live_run", return_value=run), \
|
||||||
|
mock.patch("grotti.watcher.store.abandon_live_runs") as abandon, \
|
||||||
|
mock.patch("grotti.watcher.store.complete_open_run") as close, \
|
||||||
|
mock.patch("grotti.watcher.jobs.sync_history") as sync, \
|
||||||
|
mock.patch("grotti.watcher.jobs.apply_deduction") as deduct:
|
||||||
|
self.watcher._one(mock.Mock(), live)
|
||||||
|
close.assert_not_called()
|
||||||
|
deduct.assert_not_called()
|
||||||
|
abandon.assert_not_called()
|
||||||
|
sync.assert_not_called()
|
||||||
|
track.assert_called_once()
|
||||||
|
self.assertEqual([call.args[3] for call in emit.call_args_list], ["offline"])
|
||||||
|
self.assertIn("wieder erreichbar", emit.call_args_list[0].args[4])
|
||||||
|
self.assertEqual(self.watcher._prev[HOST]["state"], "printing")
|
||||||
|
self.assertFalse(self.watcher._prev[HOST]["offline"])
|
||||||
|
|
||||||
|
def test_standby_after_gap_closes(self):
|
||||||
|
self.watcher._prev[HOST]["offline"] = True
|
||||||
|
live = {
|
||||||
|
"host": HOST,
|
||||||
|
"name": "Kobra S1",
|
||||||
|
"state": "standby",
|
||||||
|
"ok": True,
|
||||||
|
"filename": "",
|
||||||
|
}
|
||||||
|
run = {"id": 42, "filename": FILE}
|
||||||
|
with mock.patch.object(self.watcher, "_emit") as emit, \
|
||||||
|
mock.patch.object(self.watcher, "_track_print", return_value=None), \
|
||||||
|
mock.patch.object(self.watcher, "_check_spool", return_value=False), \
|
||||||
|
mock.patch("grotti.watcher.store.find_live_run", return_value=run), \
|
||||||
|
mock.patch("grotti.watcher.store.running_print_on_host", return_value=None), \
|
||||||
|
mock.patch("grotti.watcher.store.abandon_live_runs") as abandon, \
|
||||||
|
mock.patch("grotti.watcher.store.set_bed_needs_clear"), \
|
||||||
|
mock.patch("grotti.watcher.jobs.sync_history") as sync:
|
||||||
|
self.watcher._one(mock.Mock(), live)
|
||||||
|
abandon.assert_called_once()
|
||||||
|
sync.assert_called_once()
|
||||||
|
self.assertIn("abbruch", [call.args[3] for call in emit.call_args_list])
|
||||||
|
|
||||||
|
def test_other_file_after_gap_releases_the_old_run(self):
|
||||||
|
self.watcher._prev[HOST]["offline"] = True
|
||||||
|
live = {
|
||||||
|
"host": HOST,
|
||||||
|
"name": "Kobra S1",
|
||||||
|
"state": "printing",
|
||||||
|
"ok": True,
|
||||||
|
"filename": "andere.gcode",
|
||||||
|
"weight": 0,
|
||||||
|
}
|
||||||
|
old = {"id": 42, "filename": FILE}
|
||||||
|
new = {"id": 99, "filename": "andere.gcode"}
|
||||||
|
with mock.patch.object(self.watcher, "_emit") as emit, \
|
||||||
|
mock.patch.object(self.watcher, "_track_print", return_value=new), \
|
||||||
|
mock.patch.object(self.watcher, "_ensure_start_segment"), \
|
||||||
|
mock.patch.object(self.watcher, "_check_spool", return_value=False), \
|
||||||
|
mock.patch("grotti.watcher.store.find_live_run", side_effect=[old, old, None]), \
|
||||||
|
mock.patch("grotti.watcher.store.abandon_live_runs") as abandon, \
|
||||||
|
mock.patch("grotti.watcher.jobs.sync_history") as sync:
|
||||||
|
self.watcher._one(mock.Mock(), live)
|
||||||
|
sync.assert_called_once()
|
||||||
|
self.assertGreaterEqual(abandon.call_count, 1)
|
||||||
|
kinds = [call.args[3] for call in emit.call_args_list]
|
||||||
|
self.assertEqual(kinds, ["abbruch", "offline", "start"])
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
+235
-18
@@ -48,6 +48,8 @@ TOKEN_QUERY_PATHS = (
|
|||||||
"/api/v1/kamera",
|
"/api/v1/kamera",
|
||||||
"/api/v1/kamera/stream",
|
"/api/v1/kamera/stream",
|
||||||
"/api/v1/vorschau",
|
"/api/v1/vorschau",
|
||||||
|
"/api/v1/dateien/",
|
||||||
|
"/api/v1/projekte/",
|
||||||
)
|
)
|
||||||
STEER_ACTIONS = {
|
STEER_ACTIONS = {
|
||||||
"nozzle", "bed", "speed", "flow", "fan", "emergency_stop", "clear_error",
|
"nozzle", "bed", "speed", "flow", "fan", "emergency_stop", "clear_error",
|
||||||
@@ -99,6 +101,7 @@ def create_app(cfg):
|
|||||||
"/setup",
|
"/setup",
|
||||||
"/api/v1/auth/status",
|
"/api/v1/auth/status",
|
||||||
"/api/v1/auth/login",
|
"/api/v1/auth/login",
|
||||||
|
"/api/v1/auth/token",
|
||||||
"/api/v1/auth/setup",
|
"/api/v1/auth/setup",
|
||||||
"/api/v1/version",
|
"/api/v1/version",
|
||||||
}
|
}
|
||||||
@@ -454,6 +457,39 @@ def create_app(cfg):
|
|||||||
store.add_event(conn(), "", "", "auth", "Login %s" % row["username"])
|
store.add_event(conn(), "", "", "auth", "Login %s" % row["username"])
|
||||||
return jsonify({"user": grotti_auth.public_user(row), "csrf": session["csrf"]})
|
return jsonify({"user": grotti_auth.public_user(row), "csrf": session["csrf"]})
|
||||||
|
|
||||||
|
@app.post("/api/v1/auth/token")
|
||||||
|
def auth_token():
|
||||||
|
"""Passwort → API-Token (für Android/App). Keine Session, Rate-Limit wie Login."""
|
||||||
|
if store.user_count(conn()) == 0:
|
||||||
|
raise GrottiError("Zuerst Admin anlegen.", "setup", 503)
|
||||||
|
key = request.remote_addr or "unknown"
|
||||||
|
if not grotti_auth.login_rate_ok(key):
|
||||||
|
raise GrottiError("Zu viele Versuche. Bitte warten.", "rate", 429)
|
||||||
|
data = body()
|
||||||
|
username = (data.get("username") or "").strip()
|
||||||
|
password = data.get("password") or ""
|
||||||
|
device = (data.get("device_name") or data.get("name") or "App").strip()[:80] or "App"
|
||||||
|
row = store.get_user_by_name(conn(), username)
|
||||||
|
if not row or not row.get("active") or not grotti_auth.verify_password(row["password_hash"], password):
|
||||||
|
grotti_auth.login_rate_hit(key)
|
||||||
|
raise GrottiError("Benutzer oder Passwort falsch.", "auth", 401)
|
||||||
|
store.touch_user_login(conn(), row["id"])
|
||||||
|
raw = grotti_auth.new_api_token()
|
||||||
|
role = grotti_auth.clamp_token_role(row["role"], data.get("role"))
|
||||||
|
token_row = store.create_api_token(
|
||||||
|
conn(),
|
||||||
|
row["id"],
|
||||||
|
device,
|
||||||
|
grotti_auth.hash_token(raw),
|
||||||
|
grotti_auth.token_prefix(raw),
|
||||||
|
role,
|
||||||
|
)
|
||||||
|
store.add_event(conn(), "", "", "auth", "Token „%s“ für %s" % (device, row["username"]))
|
||||||
|
item = grotti_auth.public_token(token_row)
|
||||||
|
item["token"] = raw
|
||||||
|
item["user"] = grotti_auth.public_user(row)
|
||||||
|
return jsonify(item), 201
|
||||||
|
|
||||||
@app.post("/api/v1/auth/logout")
|
@app.post("/api/v1/auth/logout")
|
||||||
def auth_logout():
|
def auth_logout():
|
||||||
session.clear()
|
session.clear()
|
||||||
@@ -811,7 +847,22 @@ def create_app(cfg):
|
|||||||
|
|
||||||
@app.get("/api/v1/version")
|
@app.get("/api/v1/version")
|
||||||
def version_info():
|
def version_info():
|
||||||
return jsonify({"version": __version__})
|
return jsonify({
|
||||||
|
"name": "Grotti",
|
||||||
|
"version": __version__,
|
||||||
|
"api": 1,
|
||||||
|
"features": [
|
||||||
|
"auth_token",
|
||||||
|
"sse",
|
||||||
|
"queue",
|
||||||
|
"projects",
|
||||||
|
"orders",
|
||||||
|
"spools",
|
||||||
|
"camera",
|
||||||
|
"confirm",
|
||||||
|
"ntfy",
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
@app.get("/api/v1/einstellungen")
|
@app.get("/api/v1/einstellungen")
|
||||||
def settings():
|
def settings():
|
||||||
@@ -969,6 +1020,8 @@ def create_app(cfg):
|
|||||||
@app.post("/api/v1/drucker/<host>/<action>")
|
@app.post("/api/v1/drucker/<host>/<action>")
|
||||||
def printer_action(host, action):
|
def printer_action(host, action):
|
||||||
require_host(host)
|
require_host(host)
|
||||||
|
aliases = {"resume": "fortsetzen", "cancel": "abbrechen"}
|
||||||
|
action = aliases.get(action, action)
|
||||||
if action not in ("pause", "fortsetzen", "abbrechen"):
|
if action not in ("pause", "fortsetzen", "abbrechen"):
|
||||||
raise GrottiError("Unbekannter Befehl.", "befehl")
|
raise GrottiError("Unbekannter Befehl.", "befehl")
|
||||||
return jsonify(jobs.control(conn(), host, action))
|
return jsonify(jobs.control(conn(), host, action))
|
||||||
@@ -989,7 +1042,7 @@ def create_app(cfg):
|
|||||||
host = require_host(request.args.get("host", ""))
|
host = require_host(request.args.get("host", ""))
|
||||||
image = moonraker.camera_image(host)
|
image = moonraker.camera_image(host)
|
||||||
if not image:
|
if not image:
|
||||||
abort(404)
|
raise GrottiError("Kein Kamerabild.", "kamera", 404)
|
||||||
return image[1], 200, {"Content-Type": image[0], "Cache-Control": "no-store"}
|
return image[1], 200, {"Content-Type": image[0], "Cache-Control": "no-store"}
|
||||||
|
|
||||||
@app.get("/api/v1/kamera/stream")
|
@app.get("/api/v1/kamera/stream")
|
||||||
@@ -1048,7 +1101,8 @@ def create_app(cfg):
|
|||||||
|
|
||||||
@app.get("/api/v1/projekte")
|
@app.get("/api/v1/projekte")
|
||||||
def project_list():
|
def project_list():
|
||||||
return jsonify(store.list_projects(conn()))
|
status = (request.args.get("status") or "").strip() or None
|
||||||
|
return jsonify(store.list_projects(conn(), status=status))
|
||||||
|
|
||||||
@app.post("/api/v1/projekte")
|
@app.post("/api/v1/projekte")
|
||||||
def project_create():
|
def project_create():
|
||||||
@@ -1083,11 +1137,83 @@ def create_app(cfg):
|
|||||||
|
|
||||||
@app.get("/api/v1/projekte/<int:project_id>")
|
@app.get("/api/v1/projekte/<int:project_id>")
|
||||||
def project_get(project_id):
|
def project_get(project_id):
|
||||||
row = store.get_project(conn(), project_id)
|
row = store.get_project(conn(), project_id, watch_dir=cfg.get("watch_dir"))
|
||||||
if not row:
|
if not row:
|
||||||
raise GrottiError("Das Projekt fehlt.", "projekt", 404)
|
raise GrottiError("Das Projekt fehlt.", "projekt", 404)
|
||||||
|
# Status „druckt“, wenn ein Lauf aktiv ist (nur Anzeige — kein Auto-Write ohne Wunsch)
|
||||||
return jsonify(row)
|
return jsonify(row)
|
||||||
|
|
||||||
|
@app.get("/api/v1/projekte/<int:project_id>/laeufe")
|
||||||
|
def project_runs(project_id):
|
||||||
|
if not store.get_project(conn(), project_id):
|
||||||
|
raise GrottiError("Das Projekt fehlt.", "projekt", 404)
|
||||||
|
try:
|
||||||
|
limit = max(1, min(200, int(request.args.get("limit") or 40)))
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
limit = 40
|
||||||
|
try:
|
||||||
|
offset = max(0, int(request.args.get("offset") or 0))
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
offset = 0
|
||||||
|
data = store.list_project_runs(conn(), project_id, limit=limit, offset=offset)
|
||||||
|
resp = jsonify(data["items"])
|
||||||
|
resp.headers["X-Total-Count"] = str(data["total"])
|
||||||
|
return resp
|
||||||
|
|
||||||
|
@app.post("/api/v1/projekte/<int:project_id>/einreihen")
|
||||||
|
def project_einreihen(project_id):
|
||||||
|
data = body()
|
||||||
|
if not bool(data.get("confirm")):
|
||||||
|
raise GrottiError("Bestätigung fehlt.", "bestaetigung")
|
||||||
|
project = store.get_project(conn(), project_id, watch_dir=cfg.get("watch_dir"))
|
||||||
|
if not project:
|
||||||
|
raise GrottiError("Das Projekt fehlt.", "projekt", 404)
|
||||||
|
wanted = data.get("file_ids")
|
||||||
|
if isinstance(wanted, list) and wanted:
|
||||||
|
try:
|
||||||
|
wanted_ids = {int(x) for x in wanted}
|
||||||
|
except (TypeError, ValueError) as exc:
|
||||||
|
raise GrottiError("Ungültige Datei-IDs.", "datei") from exc
|
||||||
|
files = [f for f in (project.get("files") or []) if f["id"] in wanted_ids]
|
||||||
|
else:
|
||||||
|
files = list(project.get("files") or [])
|
||||||
|
if not files:
|
||||||
|
raise GrottiError("Keine Druckdateien zum Einreihen.", "datei")
|
||||||
|
try:
|
||||||
|
menge = max(1, min(50, int(data.get("menge") or 1)))
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
menge = 1
|
||||||
|
try:
|
||||||
|
priority = int(data.get("priority", 100))
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
priority = 100
|
||||||
|
host = optional_host(data.get("host") or "")
|
||||||
|
if host:
|
||||||
|
require_host(host)
|
||||||
|
bed = bool(data.get("bed_leveling"))
|
||||||
|
override = bool(data.get("override_machine"))
|
||||||
|
created = []
|
||||||
|
for file_row in files:
|
||||||
|
family = (data.get("family") or file_row.get("printer_family") or "").strip()
|
||||||
|
for _ in range(menge):
|
||||||
|
created.append(
|
||||||
|
store.enqueue_print(
|
||||||
|
conn(),
|
||||||
|
file_row["id"],
|
||||||
|
host,
|
||||||
|
family if not host else "",
|
||||||
|
priority,
|
||||||
|
optional_id(data.get("spool_id")),
|
||||||
|
data.get("ace_map") if isinstance(data.get("ace_map"), list) else [],
|
||||||
|
bed,
|
||||||
|
override,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
# Status auf „druckt“ heben, wenn noch Idee/bereit
|
||||||
|
if project.get("status") in ("idee", "bereit"):
|
||||||
|
store.update_project(conn(), project_id, {"status": "druckt"})
|
||||||
|
return jsonify({"jobs": created, "count": len(created)}), 201
|
||||||
|
|
||||||
@app.patch("/api/v1/projekte/<int:project_id>")
|
@app.patch("/api/v1/projekte/<int:project_id>")
|
||||||
def project_patch(project_id):
|
def project_patch(project_id):
|
||||||
data = body()
|
data = body()
|
||||||
@@ -1182,7 +1308,39 @@ def create_app(cfg):
|
|||||||
@app.get("/api/v1/dateien")
|
@app.get("/api/v1/dateien")
|
||||||
def file_list():
|
def file_list():
|
||||||
library.sync_watch(conn(), cfg, force=False)
|
library.sync_watch(conn(), cfg, force=False)
|
||||||
return jsonify(store.list_files(conn(), watch_dir=cfg.get("watch_dir")))
|
family = (request.args.get("family") or "").strip()
|
||||||
|
material = (request.args.get("material") or "").strip()
|
||||||
|
q = (request.args.get("q") or "").strip()
|
||||||
|
host = optional_host(request.args.get("host") or "")
|
||||||
|
project_id = optional_id(request.args.get("project_id") or request.args.get("project"))
|
||||||
|
limit_raw = request.args.get("limit")
|
||||||
|
offset_raw = request.args.get("offset")
|
||||||
|
limit = None
|
||||||
|
offset = 0
|
||||||
|
if limit_raw is not None and str(limit_raw).strip() != "":
|
||||||
|
try:
|
||||||
|
limit = max(1, min(500, int(limit_raw)))
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
limit = 40
|
||||||
|
if offset_raw is not None:
|
||||||
|
try:
|
||||||
|
offset = max(0, int(offset_raw))
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
offset = 0
|
||||||
|
data = store.list_files(
|
||||||
|
conn(),
|
||||||
|
watch_dir=cfg.get("watch_dir"),
|
||||||
|
family=family,
|
||||||
|
material=material,
|
||||||
|
project_id=project_id,
|
||||||
|
q=q,
|
||||||
|
host=host,
|
||||||
|
limit=limit,
|
||||||
|
offset=offset,
|
||||||
|
)
|
||||||
|
resp = jsonify(data["items"])
|
||||||
|
resp.headers["X-Total-Count"] = str(data["total"])
|
||||||
|
return resp
|
||||||
|
|
||||||
@app.post("/api/v1/dateien/<int:file_id>/meta")
|
@app.post("/api/v1/dateien/<int:file_id>/meta")
|
||||||
def file_meta_refresh(file_id):
|
def file_meta_refresh(file_id):
|
||||||
@@ -1267,10 +1425,10 @@ def create_app(cfg):
|
|||||||
def file_preview(file_id):
|
def file_preview(file_id):
|
||||||
row = store.get_file_row(conn(), file_id)
|
row = store.get_file_row(conn(), file_id)
|
||||||
if not row:
|
if not row:
|
||||||
abort(404)
|
raise GrottiError("Vorschau fehlt.", "vorschau", 404)
|
||||||
png = library.preview_png(row, conn=conn(), data_dir=cfg["data_dir"])
|
png = library.preview_png(row, conn=conn(), data_dir=cfg["data_dir"])
|
||||||
if not png:
|
if not png:
|
||||||
abort(404)
|
raise GrottiError("Vorschau fehlt.", "vorschau", 404)
|
||||||
return png, 200, {"Content-Type": "image/png", "Cache-Control": "private, max-age=300"}
|
return png, 200, {"Content-Type": "image/png", "Cache-Control": "private, max-age=300"}
|
||||||
|
|
||||||
@app.get("/api/v1/dateien/<int:file_id>/pfad")
|
@app.get("/api/v1/dateien/<int:file_id>/pfad")
|
||||||
@@ -1411,9 +1569,12 @@ def create_app(cfg):
|
|||||||
file_id = int(request.args.get("file_id") or 0)
|
file_id = int(request.args.get("file_id") or 0)
|
||||||
except (TypeError, ValueError):
|
except (TypeError, ValueError):
|
||||||
file_id = 0
|
file_id = 0
|
||||||
if not host or not file_id:
|
if not host:
|
||||||
raise GrottiError("Host und Datei nötig.", "senden")
|
raise GrottiError("Host nötig.", "senden")
|
||||||
|
if file_id:
|
||||||
row = store.latest_send_for_file(conn(), host, file_id)
|
row = store.latest_send_for_file(conn(), host, file_id)
|
||||||
|
else:
|
||||||
|
row = store.latest_send_for_host(conn(), host)
|
||||||
if not row:
|
if not row:
|
||||||
return jsonify(None)
|
return jsonify(None)
|
||||||
return jsonify(row)
|
return jsonify(row)
|
||||||
@@ -1508,7 +1669,18 @@ def create_app(cfg):
|
|||||||
limit = max(1, min(200, int(request.args.get("limit") or 40)))
|
limit = max(1, min(200, int(request.args.get("limit") or 40)))
|
||||||
except (TypeError, ValueError):
|
except (TypeError, ValueError):
|
||||||
limit = 40
|
limit = 40
|
||||||
return jsonify(store.list_print_queue(conn(), limit=limit))
|
try:
|
||||||
|
offset = max(0, int(request.args.get("offset") or 0))
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
offset = 0
|
||||||
|
host = optional_host(request.args.get("host") or "")
|
||||||
|
status = (request.args.get("status") or "").strip()
|
||||||
|
data = store.list_print_queue(
|
||||||
|
conn(), limit=limit, offset=offset, host=host, status=status
|
||||||
|
)
|
||||||
|
resp = jsonify(data["items"])
|
||||||
|
resp.headers["X-Total-Count"] = str(data["total"])
|
||||||
|
return resp
|
||||||
|
|
||||||
@app.get("/api/v1/laeuft")
|
@app.get("/api/v1/laeuft")
|
||||||
def running_now():
|
def running_now():
|
||||||
@@ -1590,7 +1762,10 @@ def create_app(cfg):
|
|||||||
for item in running:
|
for item in running:
|
||||||
rem = float(item.get("remain") or 0)
|
rem = float(item.get("remain") or 0)
|
||||||
item["free_at"] = jetzt_mod._iso_remain(rem) if rem > 0 else None
|
item["free_at"] = jetzt_mod._iso_remain(rem) if rem > 0 else None
|
||||||
waiting = [j for j in store.list_print_queue(conn(), limit=80) if j.get("status") == "waiting"]
|
waiting = [
|
||||||
|
j for j in store.list_print_queue(conn(), limit=80)["items"]
|
||||||
|
if j.get("status") == "waiting"
|
||||||
|
]
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"running": running,
|
"running": running,
|
||||||
"waiting_count": len(waiting),
|
"waiting_count": len(waiting),
|
||||||
@@ -1694,15 +1869,14 @@ def create_app(cfg):
|
|||||||
except ValueError as exc:
|
except ValueError as exc:
|
||||||
raise GrottiError(str(exc), "urteil") from exc
|
raise GrottiError(str(exc), "urteil") from exc
|
||||||
run_json = store.set_verdict(c, run_row["id"], verdict, reason, ok_n, bad_n)
|
run_json = store.set_verdict(c, run_row["id"], verdict, reason, ok_n, bad_n)
|
||||||
# Live-Lauf schließen: Moonraker-History bleibt oft ohne Endzeit hängen,
|
# Live-Lauf schließen ohne Abzug — History bucht; Fallback nach Frist.
|
||||||
# sonst bleibt der Druck im Protokoll ewig „in_progress“ trotz Urteil.
|
|
||||||
if run_row and (run_row.get("state") or "") in ("in_progress", "printing", "paused"):
|
if run_row and (run_row.get("state") or "") in ("in_progress", "printing", "paused"):
|
||||||
closed = store.complete_open_run(c, run_row["id"], state="completed")
|
closed = store.complete_open_run(c, run_row["id"], state="completed")
|
||||||
if closed:
|
if closed:
|
||||||
try:
|
try:
|
||||||
jobs.apply_deduction(c, closed, cfg["energy"])
|
jobs.sync_history(c, cfg, host=host)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
log.warning("Abräumen Abzug %s: %s", host, exc)
|
log.warning("Abräumen Abgleich %s: %s", host, exc)
|
||||||
row = store.get_run_row(c, closed["id"]) or closed
|
row = store.get_run_row(c, closed["id"]) or closed
|
||||||
run_json = store.run_out(row)
|
run_json = store.run_out(row)
|
||||||
reprint = None
|
reprint = None
|
||||||
@@ -2196,7 +2370,28 @@ def create_app(cfg):
|
|||||||
|
|
||||||
@app.get("/api/v1/spulen")
|
@app.get("/api/v1/spulen")
|
||||||
def spool_list():
|
def spool_list():
|
||||||
return jsonify(store.list_spools(conn()))
|
aktiv_raw = (request.args.get("aktiv") or "").strip().lower()
|
||||||
|
aktiv = None
|
||||||
|
if aktiv_raw in ("1", "true", "yes"):
|
||||||
|
aktiv = True
|
||||||
|
elif aktiv_raw in ("0", "false", "no"):
|
||||||
|
aktiv = False
|
||||||
|
limit_raw = request.args.get("limit")
|
||||||
|
limit = None
|
||||||
|
offset = 0
|
||||||
|
if limit_raw is not None and str(limit_raw).strip() != "":
|
||||||
|
try:
|
||||||
|
limit = max(1, min(500, int(limit_raw)))
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
limit = 100
|
||||||
|
try:
|
||||||
|
offset = max(0, int(request.args.get("offset") or 0))
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
offset = 0
|
||||||
|
data = store.list_spools(conn(), aktiv=aktiv, limit=limit, offset=offset)
|
||||||
|
resp = jsonify(data["items"])
|
||||||
|
resp.headers["X-Total-Count"] = str(data["total"])
|
||||||
|
return resp
|
||||||
|
|
||||||
@app.get("/api/v1/spulen/by-code/<path:code>")
|
@app.get("/api/v1/spulen/by-code/<path:code>")
|
||||||
def spool_by_code(code):
|
def spool_by_code(code):
|
||||||
@@ -2495,8 +2690,18 @@ def create_app(cfg):
|
|||||||
run = store.run_out(row)
|
run = store.run_out(row)
|
||||||
if run.get("chargen_nr") and run.get("objects"):
|
if run.get("chargen_nr") and run.get("objects"):
|
||||||
store.ensure_run_labels(conn(), run_id, run.get("objects") or [], qty=1)
|
store.ensure_run_labels(conn(), run_id, run.get("objects") or [], qty=1)
|
||||||
|
if run.get("order_item_id") and not run.get("order_id"):
|
||||||
|
oi = conn().execute(
|
||||||
|
"SELECT order_id FROM order_items WHERE id = %s",
|
||||||
|
(run["order_item_id"],),
|
||||||
|
).fetchone()
|
||||||
|
if oi:
|
||||||
|
run["order_id"] = oi["order_id"]
|
||||||
file_row = store.get_file_row(conn(), run["file_id"]) if run.get("file_id") else None
|
file_row = store.get_file_row(conn(), run["file_id"]) if run.get("file_id") else None
|
||||||
project = store.get_project(conn(), run["project_id"]) if run.get("project_id") else None
|
project = (
|
||||||
|
store.get_project(conn(), run["project_id"], watch_dir=cfg.get("watch_dir"))
|
||||||
|
if run.get("project_id") else None
|
||||||
|
)
|
||||||
samples = store.list_run_samples(conn(), run_id)
|
samples = store.list_run_samples(conn(), run_id)
|
||||||
from grotti.cost import energy_estimate
|
from grotti.cost import energy_estimate
|
||||||
|
|
||||||
@@ -2512,7 +2717,7 @@ def create_app(cfg):
|
|||||||
"samples": samples,
|
"samples": samples,
|
||||||
"labels": store.list_run_labels(conn(), run_id),
|
"labels": store.list_run_labels(conn(), run_id),
|
||||||
"events": store.list_run_events(conn(), run_id),
|
"events": store.list_run_events(conn(), run_id),
|
||||||
"file": store.file_out(file_row) if file_row else None,
|
"file": store.file_out(file_row, watch_dir=cfg.get("watch_dir")) if file_row else None,
|
||||||
"project": project,
|
"project": project,
|
||||||
"energy": energy,
|
"energy": energy,
|
||||||
})
|
})
|
||||||
@@ -2522,6 +2727,18 @@ def create_app(cfg):
|
|||||||
library.sync_watch(conn(), cfg, force=False)
|
library.sync_watch(conn(), cfg, force=False)
|
||||||
return jsonify(jobs.sync_history(conn(), cfg))
|
return jsonify(jobs.sync_history(conn(), cfg))
|
||||||
|
|
||||||
|
@app.post("/api/v1/laeufe/<int:run_id>/verbinden")
|
||||||
|
def run_merge(run_id):
|
||||||
|
"""Zwei Protokoll-Zeilen desselben physischen Drucks verbinden (admin)."""
|
||||||
|
require_role("admin")
|
||||||
|
data = body()
|
||||||
|
other = int(data.get("other_id") or data.get("mit") or 0)
|
||||||
|
if not other:
|
||||||
|
raise GrottiError("other_id fehlt.", "lauf")
|
||||||
|
return jsonify(jobs.manual_merge_runs(
|
||||||
|
conn(), run_id, other, confirm=bool(data.get("confirm"))
|
||||||
|
))
|
||||||
|
|
||||||
@app.patch("/api/v1/laeufe/<int:run_id>")
|
@app.patch("/api/v1/laeufe/<int:run_id>")
|
||||||
def run_patch(run_id):
|
def run_patch(run_id):
|
||||||
data = body()
|
data = body()
|
||||||
|
|||||||
+177
-4
@@ -396,6 +396,9 @@ body.shelf [data-role="hero"] { font-size: 1.35rem; }
|
|||||||
min-width: 0;
|
min-width: 0;
|
||||||
}
|
}
|
||||||
.live-page {
|
.live-page {
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: auto;
|
||||||
|
|
||||||
max-width: 36rem;
|
max-width: 36rem;
|
||||||
}
|
}
|
||||||
.jetzt-eta {
|
.jetzt-eta {
|
||||||
@@ -548,7 +551,16 @@ button.warn:hover { background: var(--st-error-soft); filter: none; }
|
|||||||
background: rgba(255, 255, 255, 0.025);
|
background: rgba(255, 255, 255, 0.025);
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
.queue-box.is-empty { display: none; }
|
.live-pop .queue-box.is-empty { display: none; }
|
||||||
|
.live-page .queue-box.is-empty { display: block; }
|
||||||
|
.queue-empty {
|
||||||
|
list-style: none;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0.85rem 0.7rem 1rem;
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: var(--t-sm);
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
.queue-box[open] { border-color: var(--line); }
|
.queue-box[open] { border-color: var(--line); }
|
||||||
.run-stack {
|
.run-stack {
|
||||||
flex: none;
|
flex: none;
|
||||||
@@ -613,6 +625,8 @@ h2.queue-title { font-size: var(--t-xs); }
|
|||||||
}
|
}
|
||||||
.icon-btn:hover { color: var(--ink); background: rgba(255, 255, 255, 0.06); filter: none; }
|
.icon-btn:hover { color: var(--ink); background: rgba(255, 255, 255, 0.06); filter: none; }
|
||||||
.icon-btn.danger:hover { color: var(--st-error); background: var(--st-error-soft); }
|
.icon-btn.danger:hover { color: var(--st-error); background: var(--st-error-soft); }
|
||||||
|
.ghost.tiny-btn.danger { color: var(--st-error); }
|
||||||
|
.ghost.tiny-btn.danger:hover { background: var(--st-error-soft); }
|
||||||
.queue-list { list-style: none; margin: 0; padding: 0 0.4rem 0.45rem; display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.35rem; }
|
.queue-list { list-style: none; margin: 0; padding: 0 0.4rem 0.45rem; display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.35rem; }
|
||||||
.queue-list > li { min-width: 0; }
|
.queue-list > li { min-width: 0; }
|
||||||
.queue-empty {
|
.queue-empty {
|
||||||
@@ -895,6 +909,22 @@ h2 { font-size: 0.95rem; margin: 0 0 0.65rem; letter-spacing: -0.02em; font-weig
|
|||||||
flex: 0 1 auto;
|
flex: 0 1 auto;
|
||||||
width: auto;
|
width: auto;
|
||||||
}
|
}
|
||||||
|
.stat-more {
|
||||||
|
border: 1px solid var(--line);
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 0.35rem 0.65rem 0.55rem;
|
||||||
|
background: rgba(255, 255, 255, 0.02);
|
||||||
|
}
|
||||||
|
.stat-more > summary {
|
||||||
|
list-style: none;
|
||||||
|
cursor: pointer;
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: var(--t-sm);
|
||||||
|
font-weight: 650;
|
||||||
|
padding: 0.25rem 0;
|
||||||
|
}
|
||||||
|
.stat-more > summary::-webkit-details-marker { display: none; }
|
||||||
|
.stat-more[open] > summary { margin-bottom: 0.45rem; }
|
||||||
.stat-filters {
|
.stat-filters {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
@@ -1328,6 +1358,15 @@ article.printer {
|
|||||||
}
|
}
|
||||||
main > .card { margin-bottom: 0.85rem; }
|
main > .card { margin-bottom: 0.85rem; }
|
||||||
.split { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); gap: 1rem; align-items: start; }
|
.split { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); gap: 1rem; align-items: start; }
|
||||||
|
.edit-split { grid-template-columns: minmax(0, 1.15fr) minmax(18rem, 0.95fr); }
|
||||||
|
.edit-split.is-idle { grid-template-columns: 1fr; }
|
||||||
|
.edit-panel { position: sticky; top: calc(var(--topbar-h) + 0.75rem); }
|
||||||
|
.cell-path {
|
||||||
|
max-width: 14rem;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.55rem 0.75rem; }
|
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.55rem 0.75rem; }
|
||||||
.field { display: grid; gap: 0.28rem; min-width: 0; }
|
.field { display: grid; gap: 0.28rem; min-width: 0; }
|
||||||
.field > label, .field-label {
|
.field > label, .field-label {
|
||||||
@@ -2291,6 +2330,45 @@ body.desk-on main {
|
|||||||
.strip.stopped .strip-actions button.ghost { color: #fecaca; border-color: rgba(248, 113, 113, 0.4); }
|
.strip.stopped .strip-actions button.ghost { color: #fecaca; border-color: rgba(248, 113, 113, 0.4); }
|
||||||
.waiting-note { font-size: var(--t-xs); color: var(--muted); display: flex; align-items: center; gap: 0.35rem; }
|
.waiting-note { font-size: var(--t-xs); color: var(--muted); display: flex; align-items: center; gap: 0.35rem; }
|
||||||
.waiting-note b { color: var(--accent); }
|
.waiting-note b { color: var(--accent); }
|
||||||
|
.desk-next {
|
||||||
|
margin-top: 0.65rem;
|
||||||
|
padding: 0.55rem 0.6rem;
|
||||||
|
border: 1px solid var(--line);
|
||||||
|
border-radius: var(--radius-sm);
|
||||||
|
background: rgba(255, 255, 255, 0.02);
|
||||||
|
display: grid;
|
||||||
|
gap: 0.45rem;
|
||||||
|
}
|
||||||
|
.desk-next-head {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.35rem;
|
||||||
|
font-weight: 650;
|
||||||
|
font-size: var(--t-sm);
|
||||||
|
}
|
||||||
|
.desk-next-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.35rem;
|
||||||
|
}
|
||||||
|
.desk-next-row .grow {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.05rem;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
.desk-next-row .grow span,
|
||||||
|
.desk-next-row .grow b {
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.desk-next-files {
|
||||||
|
display: grid;
|
||||||
|
gap: 0.3rem;
|
||||||
|
padding-top: 0.25rem;
|
||||||
|
border-top: 1px solid var(--line);
|
||||||
|
}
|
||||||
|
|
||||||
.segmented {
|
.segmented {
|
||||||
display: inline-grid;
|
display: inline-grid;
|
||||||
@@ -2461,7 +2539,7 @@ article.machine.flash { animation: flash 2s var(--ease); }
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0.35rem 0.5rem;
|
padding: 0.35rem 0.5rem;
|
||||||
}
|
}
|
||||||
@media (min-width: 1100px) {
|
@media (min-width: 1280px) {
|
||||||
.lib-tools { flex-wrap: nowrap; }
|
.lib-tools { flex-wrap: nowrap; }
|
||||||
.lib-tools .search-wrap { max-width: 12rem; }
|
.lib-tools .search-wrap { max-width: 12rem; }
|
||||||
}
|
}
|
||||||
@@ -2638,11 +2716,49 @@ label.button:hover { background: rgba(255, 255, 255, 0.04); }
|
|||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
color: inherit;
|
color: inherit;
|
||||||
}
|
}
|
||||||
.proj-file { flex-direction: column; align-items: flex-start; gap: 0.15rem; }
|
.proj-file { flex-direction: column; align-items: flex-start; gap: 0.15rem; flex: 1 1 auto; min-width: 0; }
|
||||||
.proj-file:hover, .proj-asset:hover { border-color: var(--line-strong); }
|
.proj-file:hover, .proj-asset:hover { border-color: var(--line-strong); }
|
||||||
.proj-asset a { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
|
.proj-asset a { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
|
||||||
.proj-asset .tiny { flex: none; color: var(--muted); }
|
.proj-asset .tiny { flex: none; color: var(--muted); }
|
||||||
|
.proj-stats {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(5.5rem, 1fr));
|
||||||
|
gap: 0.45rem;
|
||||||
|
margin: 0.75rem 0 0.35rem;
|
||||||
|
}
|
||||||
|
.proj-stat {
|
||||||
|
padding: 0.45rem 0.55rem;
|
||||||
|
border: 1px solid var(--line);
|
||||||
|
border-radius: var(--radius-sm);
|
||||||
|
background: rgba(255, 255, 255, 0.02);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.1rem;
|
||||||
|
}
|
||||||
|
.proj-stat strong { font-size: var(--t-sm); }
|
||||||
|
.proj-file-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.45rem;
|
||||||
|
}
|
||||||
|
.proj-file-row .ghost { flex: none; }
|
||||||
|
.focus-flash {
|
||||||
|
outline: 2px solid var(--accent);
|
||||||
|
outline-offset: 2px;
|
||||||
|
border-radius: var(--radius-sm);
|
||||||
|
animation: focus-flash-fade 2.4s var(--ease) forwards;
|
||||||
|
}
|
||||||
|
@keyframes focus-flash-fade {
|
||||||
|
0% { outline-color: var(--accent); }
|
||||||
|
70% { outline-color: var(--accent); }
|
||||||
|
100% { outline-color: transparent; }
|
||||||
|
}
|
||||||
|
|
||||||
|
a.lib-proj {
|
||||||
|
color: var(--accent);
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
a.lib-proj:hover { text-decoration: underline; }
|
||||||
.lib-card { position: relative; transition: box-shadow 0.2s var(--ease); }
|
.lib-card { position: relative; transition: box-shadow 0.2s var(--ease); }
|
||||||
.lib-card.drop { box-shadow: 0 0 0 2px var(--accent), var(--shadow); }
|
.lib-card.drop { box-shadow: 0 0 0 2px var(--accent), var(--shadow); }
|
||||||
.drop-hint { margin: 0.6rem 0 0; font-size: var(--t-xs); color: var(--faint); text-align: center; }
|
.drop-hint { margin: 0.6rem 0 0; font-size: var(--t-xs); color: var(--faint); text-align: center; }
|
||||||
@@ -2790,11 +2906,17 @@ label.button:hover { background: rgba(255, 255, 255, 0.04); }
|
|||||||
@media (max-width: 1080px) {
|
@media (max-width: 1080px) {
|
||||||
.send-layout { grid-template-columns: 1fr; }
|
.send-layout { grid-template-columns: 1fr; }
|
||||||
.send-panel { position: static; }
|
.send-panel { position: static; }
|
||||||
|
.split, .edit-split, .mat-split { grid-template-columns: 1fr; }
|
||||||
|
.edit-panel, .mat-form { position: static; }
|
||||||
.doc-layout { grid-template-columns: 1fr; }
|
.doc-layout { grid-template-columns: 1fr; }
|
||||||
.doc-toc { position: static; display: flex; flex-wrap: wrap; gap: 0.3rem; padding-bottom: 0.9rem; border-bottom: 1px solid var(--line); }
|
.doc-toc { position: static; display: flex; flex-wrap: wrap; gap: 0.3rem; padding-bottom: 0.9rem; border-bottom: 1px solid var(--line); }
|
||||||
.doc-toc p { display: none; }
|
.doc-toc p { display: none; }
|
||||||
.doc-toc a { border: 1px solid var(--line-strong); border-radius: 99px; padding: 0.22rem 0.65rem; font-size: var(--t-xs); }
|
.doc-toc a { border: 1px solid var(--line-strong); border-radius: 99px; padding: 0.22rem 0.65rem; font-size: var(--t-xs); }
|
||||||
.doc-toc a.on { border-radius: 99px; border-color: rgba(249, 115, 22, 0.55); }
|
.doc-toc a.on { border-radius: 99px; border-color: rgba(249, 115, 22, 0.55); }
|
||||||
|
.proto-table th:nth-child(4),
|
||||||
|
.proto-table th:nth-child(5),
|
||||||
|
.proto-table td:nth-child(4),
|
||||||
|
.proto-table td:nth-child(5) { display: none; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 960px) {
|
@media (max-width: 960px) {
|
||||||
@@ -2832,7 +2954,11 @@ label.button:hover { background: rgba(255, 255, 255, 0.04); }
|
|||||||
.send-panel, .doc-toc { top: 1rem; }
|
.send-panel, .doc-toc { top: 1rem; }
|
||||||
.sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
|
.sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
|
||||||
.live-bar { display: none; }
|
.live-bar { display: none; }
|
||||||
.split, .grid-2 { grid-template-columns: 1fr; }
|
.grid-2 { grid-template-columns: 1fr; }
|
||||||
|
.proto-table th:nth-child(6),
|
||||||
|
.proto-table th:nth-child(8),
|
||||||
|
.proto-table td:nth-child(6),
|
||||||
|
.proto-table td.proto-spool { display: none; }
|
||||||
.fleet { grid-template-columns: 1fr; }
|
.fleet { grid-template-columns: 1fr; }
|
||||||
main { padding: 1rem 0.85rem 2rem; }
|
main { padding: 1rem 0.85rem 2rem; }
|
||||||
.hero-main { font-size: 1.4rem; }
|
.hero-main { font-size: 1.4rem; }
|
||||||
@@ -3049,6 +3175,16 @@ ul.plain li:last-child { border-bottom: 0; }
|
|||||||
gap: 0.35rem;
|
gap: 0.35rem;
|
||||||
margin-bottom: 0.75rem;
|
margin-bottom: 0.75rem;
|
||||||
}
|
}
|
||||||
|
.mobile-more-sheet .nav-label {
|
||||||
|
margin: 0.45rem 0 0.1rem;
|
||||||
|
padding: 0 0.25rem;
|
||||||
|
font-size: var(--t-xs);
|
||||||
|
color: var(--faint);
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.04em;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
.mobile-more-sheet .nav-label:first-child { margin-top: 0; }
|
||||||
.mobile-more-sheet a {
|
.mobile-more-sheet a {
|
||||||
display: block;
|
display: block;
|
||||||
padding: 0.65rem 0.75rem;
|
padding: 0.65rem 0.75rem;
|
||||||
@@ -3480,6 +3616,36 @@ td .cell-file {
|
|||||||
margin-top: 0.15rem;
|
margin-top: 0.15rem;
|
||||||
opacity: 0.85;
|
opacity: 0.85;
|
||||||
}
|
}
|
||||||
|
.proto-table td.proto-file .warn-text {
|
||||||
|
color: var(--warn, #b45309);
|
||||||
|
margin-top: 0.2rem;
|
||||||
|
}
|
||||||
|
.proto-actions {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.25rem;
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
.proto-help {
|
||||||
|
margin: 0.35rem 0 0;
|
||||||
|
max-width: 36rem;
|
||||||
|
}
|
||||||
|
.proto-help summary {
|
||||||
|
cursor: pointer;
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
.proto-help p { margin: 0.35rem 0 0; color: var(--muted); }
|
||||||
|
.sr-only {
|
||||||
|
position: absolute;
|
||||||
|
width: 1px;
|
||||||
|
height: 1px;
|
||||||
|
padding: 0;
|
||||||
|
margin: -1px;
|
||||||
|
overflow: hidden;
|
||||||
|
clip: rect(0, 0, 0, 0);
|
||||||
|
white-space: nowrap;
|
||||||
|
border: 0;
|
||||||
|
}
|
||||||
.proto-table td.proto-spool {
|
.proto-table td.proto-spool {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
@@ -3493,6 +3659,13 @@ td.actions-cell {
|
|||||||
text-align: right;
|
text-align: right;
|
||||||
}
|
}
|
||||||
td.actions-cell .icon-btn { vertical-align: middle; }
|
td.actions-cell .icon-btn { vertical-align: middle; }
|
||||||
|
td.actions-cell .act-label { margin-left: 0.15rem; font-size: var(--t-xs); }
|
||||||
|
td.actions-cell .ghost.tiny-btn.with-label {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.2rem;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
button.is-busy { position: relative; color: transparent !important; pointer-events: none; }
|
button.is-busy { position: relative; color: transparent !important; pointer-events: none; }
|
||||||
button.is-busy::after {
|
button.is-busy::after {
|
||||||
|
|||||||
@@ -374,6 +374,56 @@ function renderPager(el, state, onPage) {
|
|||||||
el.querySelector(".pager-next").onclick = () => onPage(s.page + 1);
|
el.querySelector(".pager-next").onclick = () => onPage(s.page + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Einheitliche Querverlinkung zwischen Seiten.
|
||||||
|
* @param {"datei"|"projekt"|"spule"|"auftrag"|"lauf"|"drucker"} kind
|
||||||
|
* @param {string|number} id
|
||||||
|
* @param {string} [label]
|
||||||
|
* @returns {string} HTML-Anker oder escaped Text
|
||||||
|
*/
|
||||||
|
function linkTo(kind, id, label) {
|
||||||
|
const text = escapeHtml(label == null || label === "" ? String(id ?? "") : String(label));
|
||||||
|
if (id == null || id === "") return text;
|
||||||
|
const enc = encodeURIComponent(String(id));
|
||||||
|
let href = "";
|
||||||
|
switch (kind) {
|
||||||
|
case "datei":
|
||||||
|
href = "/dateien?file=" + enc;
|
||||||
|
break;
|
||||||
|
case "projekt":
|
||||||
|
href = "/projekte#" + enc;
|
||||||
|
break;
|
||||||
|
case "spule":
|
||||||
|
href = "/material?spule=" + enc;
|
||||||
|
break;
|
||||||
|
case "auftrag":
|
||||||
|
href = "/auftraege#" + enc;
|
||||||
|
break;
|
||||||
|
case "lauf":
|
||||||
|
href = "/protokoll/" + enc;
|
||||||
|
break;
|
||||||
|
case "drucker":
|
||||||
|
href = "/#" + enc;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
return '<a href="' + href + '">' + text + "</a>";
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Hash/Query-Fokus: Element hervorheben und scrollen. */
|
||||||
|
function focusById(id, opts) {
|
||||||
|
if (!id) return null;
|
||||||
|
const el = document.getElementById(id) || document.querySelector('[data-id="' + CSS.escape(String(id)) + '"]');
|
||||||
|
if (!el) return null;
|
||||||
|
el.classList.add("focus-flash");
|
||||||
|
el.scrollIntoView({ behavior: (opts && opts.behavior) || "smooth", block: "center" });
|
||||||
|
setTimeout(() => el.classList.remove("focus-flash"), 2400);
|
||||||
|
return el;
|
||||||
|
}
|
||||||
|
|
||||||
window.DEFAULT_PAGE_SIZE = DEFAULT_PAGE_SIZE;
|
window.DEFAULT_PAGE_SIZE = DEFAULT_PAGE_SIZE;
|
||||||
window.pageSlice = pageSlice;
|
window.pageSlice = pageSlice;
|
||||||
window.renderPager = renderPager;
|
window.renderPager = renderPager;
|
||||||
|
window.linkTo = linkTo;
|
||||||
|
window.focusById = focusById;
|
||||||
@@ -14,5 +14,5 @@
|
|||||||
<section class="queue-box" data-box="alerts" id="alert-box" hidden>
|
<section class="queue-box" data-box="alerts" id="alert-box" hidden>
|
||||||
<h2 class="queue-title"><svg class="ico title-ico"><use href="#i-bell"/></svg><span class="grow">Meldungen</span><span class="count bad" id="alert-count">0</span></h2>
|
<h2 class="queue-title"><svg class="ico title-ico"><use href="#i-bell"/></svg><span class="grow">Meldungen</span><span class="count bad" id="alert-count">0</span></h2>
|
||||||
<ul class="queue-list" id="alert-list"></ul>
|
<ul class="queue-list" id="alert-list"></ul>
|
||||||
<div class="queue-foot"><button type="button" class="ghost tiny-btn" id="events-clear">gelesen</button> <a href="/aktivitaet">alle →</a></div>
|
<div class="queue-foot"><button type="button" class="ghost tiny-btn" id="events-clear">Meldungen gelesen</button> <a href="/aktivitaet">alle →</a></div>
|
||||||
</section>
|
</section>
|
||||||
@@ -19,7 +19,14 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="toolbar" id="f-kind" role="group" aria-label="Art"></div>
|
<div class="toolbar" id="f-kind" role="group" aria-label="Art"></div>
|
||||||
<div class="toolbar" id="f-host" role="group" aria-label="Drucker"></div>
|
<div class="toolbar" aria-label="Drucker">
|
||||||
|
<label class="field inline" for="f-host">
|
||||||
|
<span class="sr-only">Drucker</span>
|
||||||
|
<select id="f-host" title="Drucker">
|
||||||
|
<option value="">Alle Drucker</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
<p id="tl-note" class="tiny"></p>
|
<p id="tl-note" class="tiny"></p>
|
||||||
<div class="timeline" id="timeline">
|
<div class="timeline" id="timeline">
|
||||||
@@ -67,11 +74,13 @@ function renderFilters() {
|
|||||||
KINDS.map(([k, label]) =>
|
KINDS.map(([k, label]) =>
|
||||||
`<button type="button" class="fchip ${filter.kinds.has(k) ? "on" : ""}" data-kind="${k}"><span class="tl-dot ${k}"></span>${label}</button>`
|
`<button type="button" class="fchip ${filter.kinds.has(k) ? "on" : ""}" data-kind="${k}"><span class="tl-dot ${k}"></span>${label}</button>`
|
||||||
).join("");
|
).join("");
|
||||||
document.getElementById("f-host").innerHTML =
|
const hostSel = document.getElementById("f-host");
|
||||||
`<button type="button" class="fchip ${filter.host ? "" : "on"}" data-host="">Alle Drucker</button>` +
|
const cur = filter.host;
|
||||||
|
hostSel.innerHTML = '<option value="">Alle Drucker</option>' +
|
||||||
printers.map((p) =>
|
printers.map((p) =>
|
||||||
`<button type="button" class="fchip ${filter.host === p.host ? "on" : ""}" data-host="${escapeHtml(p.host)}">${escapeHtml(p.name)}</button>`
|
`<option value="${escapeHtml(p.host)}">${escapeHtml(p.name)}</option>`
|
||||||
).join("");
|
).join("");
|
||||||
|
if ([...hostSel.options].some((o) => o.value === cur)) hostSel.value = cur;
|
||||||
}
|
}
|
||||||
|
|
||||||
function sinceIso() {
|
function sinceIso() {
|
||||||
@@ -165,8 +174,6 @@ document.addEventListener("click", (e) => {
|
|||||||
if (!k) filter.kinds.clear();
|
if (!k) filter.kinds.clear();
|
||||||
else if (filter.kinds.has(k)) filter.kinds.delete(k);
|
else if (filter.kinds.has(k)) filter.kinds.delete(k);
|
||||||
else filter.kinds.add(k);
|
else filter.kinds.add(k);
|
||||||
} else if (e.target.closest("#f-host [data-host]")) {
|
|
||||||
filter.host = e.target.closest("[data-host]").dataset.host;
|
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -175,6 +182,13 @@ document.addEventListener("click", (e) => {
|
|||||||
load();
|
load();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.getElementById("f-host").addEventListener("change", () => {
|
||||||
|
filter.host = document.getElementById("f-host").value || "";
|
||||||
|
syncUrl();
|
||||||
|
renderFilters();
|
||||||
|
load();
|
||||||
|
});
|
||||||
|
|
||||||
document.getElementById("tl-refresh").addEventListener("click", load);
|
document.getElementById("tl-refresh").addEventListener("click", load);
|
||||||
document.getElementById("tl-read").addEventListener("click", async () => {
|
document.getElementById("tl-read").addEventListener("click", async () => {
|
||||||
await api("/ereignisse/gelesen", { method: "POST", json: {} });
|
await api("/ereignisse/gelesen", { method: "POST", json: {} });
|
||||||
|
|||||||
+196
-55
@@ -7,9 +7,10 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
<a class="ghost" id="lieferschein-link" href="#" hidden target="_blank" rel="noopener">Lieferschein</a>
|
<a class="ghost" id="lieferschein-link" href="#" hidden target="_blank" rel="noopener">Lieferschein</a>
|
||||||
|
<button type="button" class="btn-primary" id="order-new-head"><svg class="ico"><use href="#i-plus"/></svg>Neuer Auftrag</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="split">
|
<div class="split edit-split is-idle" id="order-layout">
|
||||||
<section class="card">
|
<section class="card">
|
||||||
<div class="field inline">
|
<div class="field inline">
|
||||||
<label for="filter-status">Status</label>
|
<label for="filter-status">Status</label>
|
||||||
@@ -32,9 +33,14 @@
|
|||||||
<div class="pager" id="order-pager" hidden></div>
|
<div class="pager" id="order-pager" hidden></div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<section class="card">
|
<section class="card edit-panel" id="order-panel" hidden>
|
||||||
|
<div class="mat-form-head">
|
||||||
<h2 id="order-title">Neuer Auftrag</h2>
|
<h2 id="order-title">Neuer Auftrag</h2>
|
||||||
<form id="order-form">
|
<button type="button" class="ghost tiny-btn" id="order-edit-btn" hidden>Bearbeiten</button>
|
||||||
|
<button type="button" class="icon-btn" id="order-close" title="Schließen" aria-label="Schließen"></button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form id="order-form" hidden>
|
||||||
<input id="order-id" type="hidden">
|
<input id="order-id" type="hidden">
|
||||||
<div class="field"><label for="order-title-in">Titel</label><input id="order-title-in" required></div>
|
<div class="field"><label for="order-title-in">Titel</label><input id="order-title-in" required></div>
|
||||||
<div class="grid-2">
|
<div class="grid-2">
|
||||||
@@ -57,13 +63,16 @@
|
|||||||
<div class="field"><label for="order-notes">Notiz</label><textarea id="order-notes"></textarea></div>
|
<div class="field"><label for="order-notes">Notiz</label><textarea id="order-notes"></textarea></div>
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
<button type="submit" class="btn-primary">Speichern</button>
|
<button type="submit" class="btn-primary">Speichern</button>
|
||||||
<button type="button" class="ghost" id="order-new">Neu</button>
|
<button type="button" class="ghost" id="order-cancel-edit" hidden>Abbrechen</button>
|
||||||
<button type="button" class="btn-danger" id="order-delete" hidden>Löschen</button>
|
<button type="button" class="btn-danger" id="order-delete" hidden>Löschen</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<p id="order-note" class="tiny"></p>
|
<p id="order-note" class="tiny"></p>
|
||||||
|
|
||||||
|
<div id="order-detail" hidden>
|
||||||
<p class="tiny" id="order-progress"></p>
|
<p class="tiny" id="order-progress"></p>
|
||||||
<p class="tiny" id="order-actuals"></p>
|
<p class="tiny" id="order-actuals"></p>
|
||||||
|
<p class="tiny" id="order-notes-view"></p>
|
||||||
|
|
||||||
<h2 class="section-gap">Positionen</h2>
|
<h2 class="section-gap">Positionen</h2>
|
||||||
<div class="table-wrap">
|
<div class="table-wrap">
|
||||||
@@ -72,6 +81,20 @@
|
|||||||
<tbody id="item-rows"></tbody>
|
<tbody id="item-rows"></tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<form id="item-edit-form" class="section-gap card" hidden style="padding:0.75rem;margin-top:0.75rem">
|
||||||
|
<input type="hidden" id="item-edit-id">
|
||||||
|
<h3 style="margin:0 0 0.5rem;font-size:0.95rem">Position ändern</h3>
|
||||||
|
<div class="grid-2">
|
||||||
|
<div class="field"><label for="item-edit-qty">Stück</label><input id="item-edit-qty" type="number" min="1" step="1" value="1"></div>
|
||||||
|
<div class="field"><label for="item-edit-price">Preis/Stk €</label><input id="item-edit-price" type="number" min="0" step="0.01" value="0"></div>
|
||||||
|
</div>
|
||||||
|
<div class="actions">
|
||||||
|
<button type="submit" class="btn-primary">Speichern</button>
|
||||||
|
<button type="button" class="ghost" id="item-edit-cancel">Abbrechen</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
<form id="item-form" class="section-gap">
|
<form id="item-form" class="section-gap">
|
||||||
<div class="grid-2">
|
<div class="grid-2">
|
||||||
<div class="field"><label for="item-file">Datei</label><select id="item-file"><option value="">—</option></select></div>
|
<div class="field"><label for="item-file">Datei</label><select id="item-file"><option value="">—</option></select></div>
|
||||||
@@ -94,6 +117,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</details>
|
</details>
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -107,6 +131,43 @@ let orders = [];
|
|||||||
let customers = [];
|
let customers = [];
|
||||||
let files = [];
|
let files = [];
|
||||||
let current = null;
|
let current = null;
|
||||||
|
/** idle | create | view | edit */
|
||||||
|
let panelMode = "idle";
|
||||||
|
let orderPage = 1;
|
||||||
|
|
||||||
|
document.getElementById("order-close").innerHTML = icon("x");
|
||||||
|
|
||||||
|
function openPanel() {
|
||||||
|
document.getElementById("order-panel").hidden = false;
|
||||||
|
document.getElementById("order-layout").classList.remove("is-idle");
|
||||||
|
document.getElementById("order-panel").scrollIntoView({ block: "nearest", behavior: "smooth" });
|
||||||
|
}
|
||||||
|
|
||||||
|
function closePanel() {
|
||||||
|
panelMode = "idle";
|
||||||
|
current = null;
|
||||||
|
document.getElementById("order-panel").hidden = true;
|
||||||
|
document.getElementById("order-layout").classList.add("is-idle");
|
||||||
|
document.getElementById("order-form").hidden = true;
|
||||||
|
document.getElementById("order-detail").hidden = true;
|
||||||
|
document.getElementById("order-edit-btn").hidden = true;
|
||||||
|
document.getElementById("order-cancel-edit").hidden = true;
|
||||||
|
document.getElementById("order-delete").hidden = true;
|
||||||
|
document.getElementById("lieferschein-link").hidden = true;
|
||||||
|
document.getElementById("item-edit-form").hidden = true;
|
||||||
|
document.getElementById("order-note").textContent = "";
|
||||||
|
history.replaceState(null, "", location.pathname);
|
||||||
|
renderList();
|
||||||
|
}
|
||||||
|
|
||||||
|
function setFormValues(order) {
|
||||||
|
document.getElementById("order-id").value = order ? order.id : "";
|
||||||
|
document.getElementById("order-title-in").value = order ? order.title : "";
|
||||||
|
document.getElementById("order-status").value = order ? order.status : "idee";
|
||||||
|
document.getElementById("order-due").value = order && order.due_at ? order.due_at.slice(0, 10) : "";
|
||||||
|
document.getElementById("order-customer").value = order && order.customer_id ? order.customer_id : "";
|
||||||
|
document.getElementById("order-notes").value = order ? (order.notes || "") : "";
|
||||||
|
}
|
||||||
|
|
||||||
function fillCustomers() {
|
function fillCustomers() {
|
||||||
const sel = document.getElementById("order-customer");
|
const sel = document.getElementById("order-customer");
|
||||||
@@ -146,27 +207,64 @@ function paintActuals(order) {
|
|||||||
el.textContent = bits.join(" · ");
|
el.textContent = bits.join(" · ");
|
||||||
}
|
}
|
||||||
|
|
||||||
function fillOrder(order) {
|
function showCreate() {
|
||||||
|
panelMode = "create";
|
||||||
|
current = null;
|
||||||
|
setFormValues(null);
|
||||||
|
document.getElementById("order-title").textContent = "Neuer Auftrag";
|
||||||
|
document.getElementById("order-form").hidden = false;
|
||||||
|
document.getElementById("order-detail").hidden = true;
|
||||||
|
document.getElementById("order-edit-btn").hidden = true;
|
||||||
|
document.getElementById("order-cancel-edit").hidden = true;
|
||||||
|
document.getElementById("order-delete").hidden = true;
|
||||||
|
document.getElementById("lieferschein-link").hidden = true;
|
||||||
|
document.getElementById("order-note").textContent = "";
|
||||||
|
document.getElementById("item-edit-form").hidden = true;
|
||||||
|
history.replaceState(null, "", location.pathname);
|
||||||
|
openPanel();
|
||||||
|
renderList();
|
||||||
|
document.getElementById("order-title-in").focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
function showView(order) {
|
||||||
|
panelMode = "view";
|
||||||
current = order;
|
current = order;
|
||||||
document.getElementById("order-id").value = order ? order.id : "";
|
setFormValues(order);
|
||||||
document.getElementById("order-title-in").value = order ? order.title : "";
|
document.getElementById("order-title").textContent = order.title || "Auftrag";
|
||||||
document.getElementById("order-status").value = order ? order.status : "idee";
|
document.getElementById("order-form").hidden = true;
|
||||||
document.getElementById("order-due").value = order && order.due_at ? order.due_at.slice(0, 10) : "";
|
document.getElementById("order-detail").hidden = false;
|
||||||
document.getElementById("order-customer").value = order && order.customer_id ? order.customer_id : "";
|
document.getElementById("order-edit-btn").hidden = false;
|
||||||
document.getElementById("order-notes").value = order ? order.notes : "";
|
document.getElementById("order-cancel-edit").hidden = true;
|
||||||
document.getElementById("order-title").textContent = order ? order.title : "Neuer Auftrag";
|
document.getElementById("order-delete").hidden = true;
|
||||||
document.getElementById("order-delete").hidden = !order;
|
document.getElementById("item-edit-form").hidden = true;
|
||||||
const link = document.getElementById("lieferschein-link");
|
const link = document.getElementById("lieferschein-link");
|
||||||
if (order) {
|
|
||||||
link.href = "/auftraege/" + order.id + "/lieferschein";
|
link.href = "/auftraege/" + order.id + "/lieferschein";
|
||||||
link.hidden = false;
|
link.hidden = false;
|
||||||
} else {
|
history.replaceState(null, "", "#" + order.id);
|
||||||
link.hidden = true;
|
const prog = order.progress;
|
||||||
}
|
|
||||||
const prog = order && order.progress;
|
|
||||||
document.getElementById("order-progress").textContent = prog ? "Fortschritt: " + prog.label : "";
|
document.getElementById("order-progress").textContent = prog ? "Fortschritt: " + prog.label : "";
|
||||||
paintActuals(order || {});
|
paintActuals(order);
|
||||||
renderItems(order && order.items ? order.items : []);
|
const notes = (order.notes || "").trim();
|
||||||
|
document.getElementById("order-notes-view").textContent = notes ? "Notiz: " + notes : "";
|
||||||
|
renderItems(order.items || []);
|
||||||
|
openPanel();
|
||||||
|
renderList();
|
||||||
|
}
|
||||||
|
|
||||||
|
function showEdit(order) {
|
||||||
|
panelMode = "edit";
|
||||||
|
current = order;
|
||||||
|
setFormValues(order);
|
||||||
|
document.getElementById("order-title").textContent = "Bearbeiten";
|
||||||
|
document.getElementById("order-form").hidden = false;
|
||||||
|
document.getElementById("order-detail").hidden = true;
|
||||||
|
document.getElementById("order-edit-btn").hidden = true;
|
||||||
|
document.getElementById("order-cancel-edit").hidden = false;
|
||||||
|
document.getElementById("order-delete").hidden = false;
|
||||||
|
document.getElementById("item-edit-form").hidden = true;
|
||||||
|
openPanel();
|
||||||
|
renderList();
|
||||||
|
document.getElementById("order-title-in").focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderItems(items) {
|
function renderItems(items) {
|
||||||
@@ -179,7 +277,11 @@ function renderItems(items) {
|
|||||||
items.forEach((item) => {
|
items.forEach((item) => {
|
||||||
const tr = document.createElement("tr");
|
const tr = document.createElement("tr");
|
||||||
tr.innerHTML = "<td></td><td class=\"num\"></td><td class=\"num\"></td><td class=\"actions\"></td>";
|
tr.innerHTML = "<td></td><td class=\"num\"></td><td class=\"num\"></td><td class=\"actions\"></td>";
|
||||||
tr.children[0].textContent = item.file_name || ("#" + (item.file_id || "—"));
|
if (item.file_id) {
|
||||||
|
tr.children[0].innerHTML = linkTo("datei", item.file_id, item.file_name || ("#" + item.file_id));
|
||||||
|
} else {
|
||||||
|
tr.children[0].textContent = item.file_name || "—";
|
||||||
|
}
|
||||||
tr.children[1].textContent = item.qty;
|
tr.children[1].textContent = item.qty;
|
||||||
tr.children[2].textContent = item.done_ok + (item.done_bad ? " (−" + item.done_bad + ")" : "");
|
tr.children[2].textContent = item.done_ok + (item.done_bad ? " (−" + item.done_bad + ")" : "");
|
||||||
const tools = document.createElement("div");
|
const tools = document.createElement("div");
|
||||||
@@ -194,7 +296,7 @@ function renderItems(items) {
|
|||||||
edit.type = "button";
|
edit.type = "button";
|
||||||
edit.className = "ghost tiny-btn";
|
edit.className = "ghost tiny-btn";
|
||||||
edit.textContent = "Ändern";
|
edit.textContent = "Ändern";
|
||||||
edit.addEventListener("click", () => editItem(item));
|
edit.addEventListener("click", () => beginEditItem(item));
|
||||||
const del = document.createElement("button");
|
const del = document.createElement("button");
|
||||||
del.type = "button";
|
del.type = "button";
|
||||||
del.className = "btn-danger tiny-btn";
|
del.className = "btn-danger tiny-btn";
|
||||||
@@ -204,7 +306,7 @@ function renderItems(items) {
|
|||||||
await api("/auftraege/positionen/" + item.id, { method: "DELETE" });
|
await api("/auftraege/positionen/" + item.id, { method: "DELETE" });
|
||||||
toast("Position gelöscht.");
|
toast("Position gelöscht.");
|
||||||
const full = await api("/auftraege/" + current.id);
|
const full = await api("/auftraege/" + current.id);
|
||||||
fillOrder(full);
|
showView(full);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
tools.append(btn, edit, del);
|
tools.append(btn, edit, del);
|
||||||
@@ -213,22 +315,12 @@ function renderItems(items) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function editItem(item) {
|
function beginEditItem(item) {
|
||||||
const qty = prompt("Stückzahl", String(item.qty || 1));
|
document.getElementById("item-edit-id").value = item.id;
|
||||||
if (qty == null) return;
|
document.getElementById("item-edit-qty").value = item.qty || 1;
|
||||||
const price = prompt("Preis/Stk €", String(item.unit_price || 0));
|
document.getElementById("item-edit-price").value = item.unit_price || 0;
|
||||||
if (price == null) return;
|
document.getElementById("item-edit-form").hidden = false;
|
||||||
try {
|
document.getElementById("item-edit-qty").focus();
|
||||||
await api("/auftraege/positionen/" + item.id, {
|
|
||||||
method: "PATCH",
|
|
||||||
json: { qty: Number(qty) || 1, unit_price: Number(price) || 0 },
|
|
||||||
});
|
|
||||||
const full = await api("/auftraege/" + current.id);
|
|
||||||
fillOrder(full);
|
|
||||||
toast("Position gespeichert.");
|
|
||||||
} catch (error) {
|
|
||||||
showNote("order-note", error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function einreihen(itemId) {
|
async function einreihen(itemId) {
|
||||||
@@ -240,42 +332,40 @@ async function einreihen(itemId) {
|
|||||||
});
|
});
|
||||||
toast("In Warteschlange.");
|
toast("In Warteschlange.");
|
||||||
const full = await api("/auftraege/" + current.id);
|
const full = await api("/auftraege/" + current.id);
|
||||||
fillOrder(full);
|
showView(full);
|
||||||
await loadList();
|
await loadList();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showNote("order-note", error);
|
showNote("order-note", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let orderPage = 1;
|
|
||||||
|
|
||||||
function renderList() {
|
function renderList() {
|
||||||
const body = document.getElementById("order-rows");
|
const body = document.getElementById("order-rows");
|
||||||
body.innerHTML = "";
|
body.innerHTML = "";
|
||||||
const pager = document.getElementById("order-pager");
|
const pager = document.getElementById("order-pager");
|
||||||
if (!orders.length) {
|
if (!orders.length) {
|
||||||
body.innerHTML = '<tr><td colspan="3" class="empty"><div class="empty-state"><p>Noch kein Auftrag.</p><p><button type="button" class="ghost" id="order-empty-new">Ersten Auftrag anlegen →</button></p></div></td></tr>';
|
body.innerHTML = '<tr><td colspan="3" class="empty"><div class="empty-state"><p>Noch kein Auftrag.</p><p><button type="button" class="btn-primary" id="order-empty-new">Ersten Auftrag anlegen</button></p></div></td></tr>';
|
||||||
document.getElementById("order-empty-new")?.addEventListener("click", () => fillOrder(null));
|
document.getElementById("order-empty-new")?.addEventListener("click", showCreate);
|
||||||
renderPager(pager, null, () => {});
|
renderPager(pager, null, () => {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const selected = document.getElementById("order-id").value;
|
const selected = current ? String(current.id) : "";
|
||||||
const paged = pageSlice(orders, orderPage, DEFAULT_PAGE_SIZE);
|
const paged = pageSlice(orders, orderPage, DEFAULT_PAGE_SIZE);
|
||||||
orderPage = paged.page;
|
orderPage = paged.page;
|
||||||
paged.items.forEach((order) => {
|
paged.items.forEach((order) => {
|
||||||
const tr = document.createElement("tr");
|
const tr = document.createElement("tr");
|
||||||
tr.className = "pick" + (selected && String(order.id) === selected ? " on" : "");
|
tr.className = "pick" + (selected && String(order.id) === selected ? " on" : "");
|
||||||
tr.innerHTML = "<td></td><td></td><td></td>";
|
tr.innerHTML = "<td></td><td></td><td class=\"cell-path\"></td>";
|
||||||
tr.children[0].textContent = order.title;
|
tr.children[0].textContent = order.title;
|
||||||
const st = order.status || "";
|
const st = order.status || "";
|
||||||
const chipState = st === "druckt" ? "printing" : (st === "fertig" || st === "geliefert" || st === "bezahlt") ? "done" : st === "bestaetigt" ? "waiting" : "idle";
|
const chipState = st === "druckt" ? "printing" : (st === "fertig" || st === "geliefert" || st === "bezahlt") ? "done" : st === "bestaetigt" ? "waiting" : "idle";
|
||||||
tr.children[1].innerHTML = chipHtml(chipState, STATUS_LABEL[st] || st);
|
tr.children[1].innerHTML = chipHtml(chipState, STATUS_LABEL[st] || st);
|
||||||
tr.children[2].textContent = (order.progress && order.progress.label) || "";
|
tr.children[2].textContent = (order.progress && order.progress.label) || "";
|
||||||
|
tr.children[2].title = (order.progress && order.progress.label) || "";
|
||||||
tr.addEventListener("click", async () => {
|
tr.addEventListener("click", async () => {
|
||||||
try {
|
try {
|
||||||
const full = await api("/auftraege/" + order.id);
|
const full = await api("/auftraege/" + order.id);
|
||||||
fillOrder(full);
|
showView(full);
|
||||||
renderList();
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showNote("order-note", error);
|
showNote("order-note", error);
|
||||||
}
|
}
|
||||||
@@ -304,11 +394,28 @@ async function loadBase() {
|
|||||||
fillCustomers();
|
fillCustomers();
|
||||||
fillFiles();
|
fillFiles();
|
||||||
await loadList();
|
await loadList();
|
||||||
fillOrder(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById("filter-status").addEventListener("change", () => loadList().catch((e) => showNote("order-note", e)));
|
document.getElementById("filter-status").addEventListener("change", () => loadList().catch((e) => showNote("order-note", e)));
|
||||||
|
|
||||||
|
document.getElementById("order-new-head").addEventListener("click", showCreate);
|
||||||
|
document.getElementById("order-close").addEventListener("click", closePanel);
|
||||||
|
document.getElementById("order-edit-btn").addEventListener("click", () => {
|
||||||
|
if (current) showEdit(current);
|
||||||
|
});
|
||||||
|
document.getElementById("order-cancel-edit").addEventListener("click", async () => {
|
||||||
|
if (!current) {
|
||||||
|
closePanel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const full = await api("/auftraege/" + current.id);
|
||||||
|
showView(full);
|
||||||
|
} catch (error) {
|
||||||
|
showNote("order-note", error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
document.getElementById("order-form").addEventListener("submit", async (event) => {
|
document.getElementById("order-form").addEventListener("submit", async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const id = document.getElementById("order-id").value;
|
const id = document.getElementById("order-id").value;
|
||||||
@@ -324,22 +431,22 @@ document.getElementById("order-form").addEventListener("submit", async (event) =
|
|||||||
? await api("/auftraege/" + id, { method: "PATCH", json: payload })
|
? await api("/auftraege/" + id, { method: "PATCH", json: payload })
|
||||||
: await api("/auftraege", { method: "POST", json: payload });
|
: await api("/auftraege", { method: "POST", json: payload });
|
||||||
showNote("order-note", null);
|
showNote("order-note", null);
|
||||||
document.getElementById("order-note").textContent = "Gespeichert.";
|
toast("Gespeichert.", "good");
|
||||||
await loadList();
|
await loadList();
|
||||||
fillOrder(saved);
|
const full = await api("/auftraege/" + saved.id);
|
||||||
|
showView(full);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showNote("order-note", error);
|
showNote("order-note", error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById("order-new").addEventListener("click", () => fillOrder(null));
|
|
||||||
document.getElementById("order-delete").addEventListener("click", (event) => {
|
document.getElementById("order-delete").addEventListener("click", (event) => {
|
||||||
const id = document.getElementById("order-id").value;
|
const id = document.getElementById("order-id").value;
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
armButton(event.currentTarget, "Auftrag wirklich löschen?", async () => {
|
armButton(event.currentTarget, "Auftrag wirklich löschen?", async () => {
|
||||||
await api("/auftraege/" + id, { method: "DELETE" });
|
await api("/auftraege/" + id, { method: "DELETE" });
|
||||||
toast("Gelöscht.");
|
toast("Gelöscht.");
|
||||||
fillOrder(null);
|
closePanel();
|
||||||
loadList();
|
loadList();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -359,12 +466,36 @@ document.getElementById("item-form").addEventListener("submit", async (event) =>
|
|||||||
try {
|
try {
|
||||||
await api("/auftraege/" + current.id + "/positionen", { method: "POST", json: payload });
|
await api("/auftraege/" + current.id + "/positionen", { method: "POST", json: payload });
|
||||||
const full = await api("/auftraege/" + current.id);
|
const full = await api("/auftraege/" + current.id);
|
||||||
fillOrder(full);
|
showView(full);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showNote("order-note", error);
|
showNote("order-note", error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.getElementById("item-edit-form").addEventListener("submit", async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
if (!current) return;
|
||||||
|
const itemId = document.getElementById("item-edit-id").value;
|
||||||
|
try {
|
||||||
|
await api("/auftraege/positionen/" + itemId, {
|
||||||
|
method: "PATCH",
|
||||||
|
json: {
|
||||||
|
qty: Number(document.getElementById("item-edit-qty").value) || 1,
|
||||||
|
unit_price: Number(document.getElementById("item-edit-price").value) || 0,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
document.getElementById("item-edit-form").hidden = true;
|
||||||
|
const full = await api("/auftraege/" + current.id);
|
||||||
|
showView(full);
|
||||||
|
toast("Position gespeichert.");
|
||||||
|
} catch (error) {
|
||||||
|
showNote("order-note", error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
document.getElementById("item-edit-cancel").addEventListener("click", () => {
|
||||||
|
document.getElementById("item-edit-form").hidden = true;
|
||||||
|
});
|
||||||
|
|
||||||
document.getElementById("customer-form").addEventListener("submit", async (event) => {
|
document.getElementById("customer-form").addEventListener("submit", async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const id = document.getElementById("cust-id").value;
|
const id = document.getElementById("cust-id").value;
|
||||||
@@ -421,6 +552,16 @@ document.getElementById("cust-delete").addEventListener("click", (event) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
loadBase().catch((error) => showNote("order-note", error));
|
loadBase().then(async () => {
|
||||||
|
const hash = (location.hash || "").replace(/^#/, "");
|
||||||
|
if (hash && /^\d+$/.test(hash)) {
|
||||||
|
try {
|
||||||
|
const full = await api("/auftraege/" + hash);
|
||||||
|
showView(full);
|
||||||
|
} catch (error) {
|
||||||
|
showNote("order-note", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).catch((error) => showNote("order-note", error));
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -110,9 +110,14 @@ function costBreakdownHtml(energy, filamentCost) {
|
|||||||
function render(data) {
|
function render(data) {
|
||||||
const run = data.run;
|
const run = data.run;
|
||||||
const name = (run.filename || "").split("/").pop() || "ohne Datei";
|
const name = (run.filename || "").split("/").pop() || "ohne Datei";
|
||||||
document.getElementById("bericht-sub").textContent =
|
const subBits = [
|
||||||
(run.printer_name || run.printer_host) + " · " + name
|
run.printer_host
|
||||||
+ (run.chargen_nr ? " · " + run.chargen_nr : "");
|
? linkTo("drucker", run.printer_host, run.printer_name || run.printer_host)
|
||||||
|
: escapeHtml(run.printer_name || ""),
|
||||||
|
run.file_id ? linkTo("datei", run.file_id, name) : escapeHtml(name),
|
||||||
|
run.chargen_nr ? escapeHtml(run.chargen_nr) : "",
|
||||||
|
].filter(Boolean);
|
||||||
|
document.getElementById("bericht-sub").innerHTML = subBits.join(" · ");
|
||||||
|
|
||||||
const planned = Number(run.weight_planned_g) || 0;
|
const planned = Number(run.weight_planned_g) || 0;
|
||||||
const used = Number(run.weight_used_g) || 0;
|
const used = Number(run.weight_used_g) || 0;
|
||||||
@@ -128,7 +133,7 @@ function render(data) {
|
|||||||
|
|
||||||
const spoolRows = (data.spools || []).map((s) => `
|
const spoolRows = (data.spools || []).map((s) => `
|
||||||
<tr>
|
<tr>
|
||||||
<td>${escapeHtml(s.name)}${s.ace_slot ? " · ACE " + s.ace_slot : ""}</td>
|
<td>${s.spool_id ? linkTo("spule", s.spool_id, s.name) : escapeHtml(s.name)}${s.ace_slot ? " · ACE " + s.ace_slot : ""}</td>
|
||||||
<td>${escapeHtml(s.material_type || "")}</td>
|
<td>${escapeHtml(s.material_type || "")}</td>
|
||||||
<td class="num">${grams(s.weight_planned_g)}</td>
|
<td class="num">${grams(s.weight_planned_g)}</td>
|
||||||
<td class="num">${grams(s.weight_g)}${s.is_estimate ? ' <span class="tag">Schätzwert</span>' : ""}</td>
|
<td class="num">${grams(s.weight_g)}${s.is_estimate ? ' <span class="tag">Schätzwert</span>' : ""}</td>
|
||||||
@@ -161,7 +166,8 @@ function render(data) {
|
|||||||
<p>Kosten <b>${euro(cost)}</b> (Filament ${euro(run.filament_cost)} · Strom ${euro(energyEuro)}${energyHint ? " · " + energyHint : ""})${run.cost_per_part != null ? " · <b>" + euro(run.cost_per_part) + "</b>/Teil" : ""}</p>
|
<p>Kosten <b>${euro(cost)}</b> (Filament ${euro(run.filament_cost)} · Strom ${euro(energyEuro)}${energyHint ? " · " + energyHint : ""})${run.cost_per_part != null ? " · <b>" + euro(run.cost_per_part) + "</b>/Teil" : ""}</p>
|
||||||
${run.pieces_ok || run.pieces_bad ? `<p>Stück <b>${run.pieces_ok || 0}</b> gut${run.pieces_bad ? " · " + run.pieces_bad + " schlecht" : ""}</p>` : ""}
|
${run.pieces_ok || run.pieces_bad ? `<p>Stück <b>${run.pieces_ok || 0}</b> gut${run.pieces_bad ? " · " + run.pieces_bad + " schlecht" : ""}</p>` : ""}
|
||||||
${run.message ? "<p class=\"msg\">" + escapeHtml(run.message) + "</p>" : ""}
|
${run.message ? "<p class=\"msg\">" + escapeHtml(run.message) + "</p>" : ""}
|
||||||
${data.project ? "<p class=\"tiny\">Projekt: " + escapeHtml(data.project.name) + "</p>" : ""}
|
${data.project ? "<p class=\"tiny\">Projekt: " + linkTo("projekt", data.project.id, data.project.name) + "</p>" : ""}
|
||||||
|
${run.order_id ? "<p class=\"tiny\">Auftrag: " + linkTo("auftrag", run.order_id, "#" + run.order_id) + "</p>" : ""}
|
||||||
</div>
|
</div>
|
||||||
${costBreakdownHtml(energy, run.filament_cost)}
|
${costBreakdownHtml(energy, run.filament_cost)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -604,6 +604,20 @@ function folderLabel(folder) {
|
|||||||
return "Wurzel";
|
return "Wurzel";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function folderMatches(fileFolder, selected) {
|
||||||
|
if (!selected) return true;
|
||||||
|
if (selected === "root") return !fileFolder;
|
||||||
|
if (!fileFolder) return false;
|
||||||
|
return fileFolder === selected || fileFolder.startsWith(selected + "/");
|
||||||
|
}
|
||||||
|
|
||||||
|
function releaseRootForProject() {
|
||||||
|
const project = document.getElementById("file-filter-project").value;
|
||||||
|
const folder = document.getElementById("file-filter-folder");
|
||||||
|
if (!folder || !project || project === "none" || folder.value !== "root") return;
|
||||||
|
folder.value = "";
|
||||||
|
}
|
||||||
|
|
||||||
function saveLibMemory() {
|
function saveLibMemory() {
|
||||||
try {
|
try {
|
||||||
localStorage.setItem(LIB_KEY, JSON.stringify({
|
localStorage.setItem(LIB_KEY, JSON.stringify({
|
||||||
@@ -650,8 +664,7 @@ function filteredFiles() {
|
|||||||
const types = ((file.filaments) || []).map((f) => f.type).filter(Boolean);
|
const types = ((file.filaments) || []).map((f) => f.type).filter(Boolean);
|
||||||
if (!types.includes(material)) return false;
|
if (!types.includes(material)) return false;
|
||||||
}
|
}
|
||||||
if (folder === "root" && folderKey(file)) return false;
|
if (!folderMatches(folderKey(file), folder)) return false;
|
||||||
if (folder && folder !== "root" && folderKey(file) !== folder) return false;
|
|
||||||
if (!q) return true;
|
if (!q) return true;
|
||||||
const hay = [
|
const hay = [
|
||||||
file.name || "",
|
file.name || "",
|
||||||
@@ -809,10 +822,13 @@ function alwaysMeta(file, project) {
|
|||||||
file.weight_g ? grams(file.weight_g) : "",
|
file.weight_g ? grams(file.weight_g) : "",
|
||||||
layerHeightText(file),
|
layerHeightText(file),
|
||||||
families[file.printer_family] || "",
|
families[file.printer_family] || "",
|
||||||
project ? project.name : "",
|
|
||||||
];
|
];
|
||||||
if (!file.weight_g && !file.estimated_s) bits.push(sizeText(file.size_bytes));
|
if (!file.weight_g && !file.estimated_s) bits.push(sizeText(file.size_bytes));
|
||||||
return bits.filter(Boolean).map((t) => `<span>${escapeHtml(t)}</span>`).join("") + swatchesHtml(file);
|
const spans = bits.filter(Boolean).map((t) => `<span>${escapeHtml(t)}</span>`);
|
||||||
|
if (project) {
|
||||||
|
spans.push(`<a class="lib-proj" href="/projekte#${encodeURIComponent(project.id)}" onclick="event.stopPropagation()">${escapeHtml(project.name)}</a>`);
|
||||||
|
}
|
||||||
|
return spans.join("") + swatchesHtml(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
function detailMeta(file) {
|
function detailMeta(file) {
|
||||||
@@ -1154,6 +1170,12 @@ async function load() {
|
|||||||
fillProjectFilter();
|
fillProjectFilter();
|
||||||
fillMaterialFilter();
|
fillMaterialFilter();
|
||||||
fillFolderFilter();
|
fillFolderFilter();
|
||||||
|
const deepProject = new URLSearchParams(location.search).get("project");
|
||||||
|
if (deepProject) {
|
||||||
|
const pf = document.getElementById("file-filter-project");
|
||||||
|
if (pf && [...pf.options].some((o) => o.value === deepProject)) pf.value = deepProject;
|
||||||
|
}
|
||||||
|
releaseRootForProject();
|
||||||
renderLibrary();
|
renderLibrary();
|
||||||
renderTabs();
|
renderTabs();
|
||||||
refreshFlow();
|
refreshFlow();
|
||||||
@@ -1689,6 +1711,7 @@ document.getElementById("lib-list").addEventListener("keydown", (event) => {
|
|||||||
const node = document.getElementById(id);
|
const node = document.getElementById(id);
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
const onChange = () => {
|
const onChange = () => {
|
||||||
|
if (id === "file-filter-project") releaseRootForProject();
|
||||||
libPage = 1;
|
libPage = 1;
|
||||||
saveLibMemory();
|
saveLibMemory();
|
||||||
renderLibrary();
|
renderLibrary();
|
||||||
|
|||||||
@@ -257,6 +257,10 @@
|
|||||||
</form>
|
</form>
|
||||||
<p id="token-note"></p>
|
<p id="token-note"></p>
|
||||||
<p class="ok" id="token-once" hidden></p>
|
<p class="ok" id="token-once" hidden></p>
|
||||||
|
<div id="token-qr-wrap" hidden style="margin-top:0.75rem">
|
||||||
|
<p class="tiny">App-Kopplung — QR mit Server-URL und Token (nur jetzt):</p>
|
||||||
|
<canvas id="token-qr" width="180" height="180" aria-label="QR-Code"></canvas>
|
||||||
|
</div>
|
||||||
<p class="hint" id="legacy-token-hint" hidden>In der Config steht noch ein Shared-<code>token</code> — der wird seit 3.1 nicht mehr akzeptiert. Bitte leeren und API-Tokens (<code>grt_…</code>) nutzen.</p>
|
<p class="hint" id="legacy-token-hint" hidden>In der Config steht noch ein Shared-<code>token</code> — der wird seit 3.1 nicht mehr akzeptiert. Bitte leeren und API-Tokens (<code>grt_…</code>) nutzen.</p>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -293,6 +297,7 @@
|
|||||||
</dialog>
|
</dialog>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block script %}
|
{% block script %}
|
||||||
|
<script src="{{ url_for('static', filename='qrcode.min.js') }}?v=1"></script>
|
||||||
<script>
|
<script>
|
||||||
const families = { kobra_3: "Kobra 3", kobra_s1: "Kobra S1", "": "—" };
|
const families = { kobra_3: "Kobra 3", kobra_s1: "Kobra S1", "": "—" };
|
||||||
const isAdmin = document.querySelector('meta[name="user-role"]')?.content === "admin";
|
const isAdmin = document.querySelector('meta[name="user-role"]')?.content === "admin";
|
||||||
@@ -543,7 +548,9 @@ document.getElementById("user-add")?.addEventListener("submit", async (event) =>
|
|||||||
document.getElementById("token-add").addEventListener("submit", async (event) => {
|
document.getElementById("token-add").addEventListener("submit", async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const once = document.getElementById("token-once");
|
const once = document.getElementById("token-once");
|
||||||
|
const qrWrap = document.getElementById("token-qr-wrap");
|
||||||
once.hidden = true;
|
once.hidden = true;
|
||||||
|
if (qrWrap) qrWrap.hidden = true;
|
||||||
try {
|
try {
|
||||||
const out = await api("/tokens", {
|
const out = await api("/tokens", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -555,8 +562,20 @@ document.getElementById("token-add").addEventListener("submit", async (event) =>
|
|||||||
document.getElementById("token-add").reset();
|
document.getElementById("token-add").reset();
|
||||||
once.hidden = false;
|
once.hidden = false;
|
||||||
once.textContent = "Token (nur jetzt sichtbar): " + out.token;
|
once.textContent = "Token (nur jetzt sichtbar): " + out.token;
|
||||||
showNote("token-note", null, "Token erzeugt — jetzt kopieren.");
|
showNote("token-note", null, "Token erzeugt — jetzt kopieren oder QR scannen.");
|
||||||
loadTokens();
|
loadTokens();
|
||||||
|
if (out.token && window.QRCode && qrWrap) {
|
||||||
|
const canvas = document.getElementById("token-qr");
|
||||||
|
const payload = JSON.stringify({
|
||||||
|
url: location.origin,
|
||||||
|
token: out.token,
|
||||||
|
name: "Grotti",
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
QRCode.toCanvas(canvas, payload, { width: 180, margin: 1, errorCorrectionLevel: "M" });
|
||||||
|
qrWrap.hidden = false;
|
||||||
|
} catch (error) { /* QR optional */ }
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showNote("token-note", error);
|
showNote("token-note", error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,136 +0,0 @@
|
|||||||
{% extends "layout.html" %}
|
|
||||||
{% block body %}
|
|
||||||
<div class="page-head">
|
|
||||||
<div>
|
|
||||||
<h1>Kameras</h1>
|
|
||||||
<p class="tiny">Livebilder aller Drucker.</p>
|
|
||||||
</div>
|
|
||||||
<div class="page-head-side">
|
|
||||||
<label class="field cam-mode-field">
|
|
||||||
<span class="tiny">Bild</span>
|
|
||||||
<select id="cam-mode" title="Kamera-Modus">
|
|
||||||
<option value="snapshot">Snapshot</option>
|
|
||||||
<option value="stream">Stream</option>
|
|
||||||
</select>
|
|
||||||
</label>
|
|
||||||
<span id="when"></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="camera-grid" id="grid"></div>
|
|
||||||
{% endblock %}
|
|
||||||
{% block script %}
|
|
||||||
<script>
|
|
||||||
const tiles = new Map();
|
|
||||||
|
|
||||||
(function initCamMode() {
|
|
||||||
const sel = document.getElementById("cam-mode");
|
|
||||||
if (!sel || typeof cameraMode !== "function") return;
|
|
||||||
sel.value = cameraMode();
|
|
||||||
sel.addEventListener("change", () => {
|
|
||||||
setCameraMode(sel.value);
|
|
||||||
for (const tile of tiles.values()) {
|
|
||||||
const img = tile.querySelector('[data-role="cam"]');
|
|
||||||
if (img) img.dataset.srcKey = "";
|
|
||||||
}
|
|
||||||
refresh().catch(() => {});
|
|
||||||
});
|
|
||||||
window.addEventListener("grotti-camera-mode", () => {
|
|
||||||
sel.value = cameraMode();
|
|
||||||
});
|
|
||||||
})();
|
|
||||||
|
|
||||||
function metaLine(printer) {
|
|
||||||
const state = shownState(printer);
|
|
||||||
const busy = state === "printing" || state === "paused";
|
|
||||||
const bits = [chipHtml(state, STATE_LABELS[state] || state)];
|
|
||||||
if (busy) {
|
|
||||||
const pct = Math.round((printer.progress || 0) * 100);
|
|
||||||
bits.push(pct + " %");
|
|
||||||
const eta = finishClock(printer.remain);
|
|
||||||
if (eta) bits.push("fertig " + eta);
|
|
||||||
else if (hours(printer.remain)) bits.push("Rest " + hours(printer.remain));
|
|
||||||
}
|
|
||||||
const job = (printer.filename || "").replace(/\.gcode$/i, "").replace(/^(\d+-)+/, "");
|
|
||||||
if (busy && job) bits.push(escapeHtml(job));
|
|
||||||
return bits.join(" · ");
|
|
||||||
}
|
|
||||||
|
|
||||||
function ensureTile(printer) {
|
|
||||||
let tile = tiles.get(printer.host);
|
|
||||||
if (tile) return tile;
|
|
||||||
tile = document.createElement("figure");
|
|
||||||
tile.className = "camera-tile";
|
|
||||||
tile.dataset.host = printer.host;
|
|
||||||
tile.innerHTML = `
|
|
||||||
<figcaption>
|
|
||||||
<span class="cam-name"></span>
|
|
||||||
<span class="host"></span>
|
|
||||||
</figcaption>
|
|
||||||
<p class="cam-meta tiny"></p>
|
|
||||||
<div class="cam-stage">
|
|
||||||
<img alt="" data-role="cam" hidden>
|
|
||||||
<p class="cam-empty" data-role="cam-empty">${icon("camera")}<span>Keine Kamera</span></p>
|
|
||||||
</div>
|
|
||||||
<a class="ghost cam-open" href="/#${encodeURIComponent(printer.host)}">Cockpit</a>`;
|
|
||||||
tiles.set(printer.host, tile);
|
|
||||||
document.getElementById("grid").appendChild(tile);
|
|
||||||
return tile;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function refresh() {
|
|
||||||
const printers = await api("/drucker?live=1");
|
|
||||||
document.getElementById("when").textContent = new Date().toLocaleTimeString("de-DE", { hour: "2-digit", minute: "2-digit" });
|
|
||||||
const grid = document.getElementById("grid");
|
|
||||||
if (!printers.length) {
|
|
||||||
tiles.clear();
|
|
||||||
grid.innerHTML = `<div class="empty-state">${icon("camera", "lg")}<p>Noch keine Drucker.</p><a href="/einstellungen">Zu den Einstellungen</a></div>`;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (grid.querySelector(".empty-state")) grid.innerHTML = "";
|
|
||||||
const streaming = cameraMode() === "stream";
|
|
||||||
const seen = new Set();
|
|
||||||
for (const printer of printers) {
|
|
||||||
seen.add(printer.host);
|
|
||||||
const tile = ensureTile(printer);
|
|
||||||
const state = shownState(printer);
|
|
||||||
tile.className = "camera-tile " + state + (streaming ? " stream" : "");
|
|
||||||
tile.querySelector(".cam-name").textContent = printer.name;
|
|
||||||
tile.querySelector(".host").textContent = printer.host;
|
|
||||||
tile.querySelector(".cam-meta").innerHTML = metaLine(printer);
|
|
||||||
tile.querySelector(".cam-open").href = "/#" + encodeURIComponent(printer.host);
|
|
||||||
const img = tile.querySelector('[data-role="cam"]');
|
|
||||||
const empty = tile.querySelector('[data-role="cam-empty"]');
|
|
||||||
if (!printer.camera || printer.has_camera === false) {
|
|
||||||
img.removeAttribute("src");
|
|
||||||
img.hidden = true;
|
|
||||||
empty.hidden = false;
|
|
||||||
empty.innerHTML = icon("camera") + "<span>Keine Kamera</span>";
|
|
||||||
img.dataset.srcKey = "";
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
img.alt = "Kamera " + printer.name;
|
|
||||||
const next = cameraUrl(printer, streaming ? 0 : 2000);
|
|
||||||
if (img.dataset.srcKey === next) continue;
|
|
||||||
img.dataset.srcKey = next;
|
|
||||||
img.onerror = () => {
|
|
||||||
img.hidden = true;
|
|
||||||
empty.hidden = false;
|
|
||||||
empty.innerHTML = icon("camera") + "<span>Keine Kamera</span>";
|
|
||||||
};
|
|
||||||
img.onload = () => {
|
|
||||||
img.hidden = false;
|
|
||||||
empty.hidden = true;
|
|
||||||
};
|
|
||||||
img.src = next;
|
|
||||||
}
|
|
||||||
for (const [host, tile] of [...tiles.entries()]) {
|
|
||||||
if (!seen.has(host)) {
|
|
||||||
tile.remove();
|
|
||||||
tiles.delete(host);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
refresh().catch((error) => console.error(error));
|
|
||||||
setInterval(() => refresh().catch(() => {}), 5000);
|
|
||||||
</script>
|
|
||||||
{% endblock %}
|
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
<link rel="icon" type="image/png" sizes="32x32" href="{{ url_for('static', filename='brand/favicon-32.png') }}">
|
<link rel="icon" type="image/png" sizes="32x32" href="{{ url_for('static', filename='brand/favicon-32.png') }}">
|
||||||
<link rel="icon" type="image/png" sizes="512x512" href="{{ url_for('static', filename='brand/favicon.png') }}">
|
<link rel="icon" type="image/png" sizes="512x512" href="{{ url_for('static', filename='brand/favicon.png') }}">
|
||||||
<link rel="apple-touch-icon" href="{{ url_for('static', filename='brand/apple-touch-icon.png') }}">
|
<link rel="apple-touch-icon" href="{{ url_for('static', filename='brand/apple-touch-icon.png') }}">
|
||||||
<link rel="stylesheet" href="{{ url_for('static', filename='grotti.css') }}?v=70">
|
<link rel="stylesheet" href="{{ url_for('static', filename='grotti.css') }}?v=73">
|
||||||
<link rel="manifest" href="{{ url_for('static', filename='manifest.webmanifest') }}">
|
<link rel="manifest" href="{{ url_for('static', filename='manifest.webmanifest') }}">
|
||||||
<meta name="theme-color" content="#0a0a0c" id="theme-color-meta">
|
<meta name="theme-color" content="#0a0a0c" id="theme-color-meta">
|
||||||
<script>
|
<script>
|
||||||
@@ -82,7 +82,7 @@
|
|||||||
<a href="/" class="{{ 'on' if page == 'wand' else '' }}" title="Drucker"><svg class="ico"><use href="#i-printer"/></svg><span>Drucker</span></a>
|
<a href="/" class="{{ 'on' if page == 'wand' else '' }}" title="Drucker"><svg class="ico"><use href="#i-printer"/></svg><span>Drucker</span></a>
|
||||||
<a href="/dateien" class="{{ 'on' if page == 'dateien' else '' }} nav-desk" title="Dateien"><svg class="ico"><use href="#i-file"/></svg><span>Dateien</span></a>
|
<a href="/dateien" class="{{ 'on' if page == 'dateien' else '' }} nav-desk" title="Dateien"><svg class="ico"><use href="#i-file"/></svg><span>Dateien</span></a>
|
||||||
<a href="/warteschlange" class="{{ 'on' if page == 'warteschlange' else '' }}" title="Warteschlange"><svg class="ico"><use href="#i-queue"/></svg><span>Warteschlange</span></a>
|
<a href="/warteschlange" class="{{ 'on' if page == 'warteschlange' else '' }}" title="Warteschlange"><svg class="ico"><use href="#i-queue"/></svg><span>Warteschlange</span></a>
|
||||||
<a href="/auftraege" class="{{ 'on' if page == 'auftraege' else '' }} nav-desk" title="Aufträge"><svg class="ico"><use href="#i-folder"/></svg><span>Aufträge</span></a>
|
<a href="/auftraege" class="{{ 'on' if page == 'auftraege' else '' }} nav-desk" title="Aufträge"><svg class="ico"><use href="#i-clipboard"/></svg><span>Aufträge</span></a>
|
||||||
<span class="nav-label nav-desk">Rückschau</span>
|
<span class="nav-label nav-desk">Rückschau</span>
|
||||||
<a href="/protokoll" class="{{ 'on' if page == 'protokoll' or page == 'bericht' else '' }} nav-desk" title="Protokoll"><svg class="ico"><use href="#i-list"/></svg><span>Protokoll</span></a>
|
<a href="/protokoll" class="{{ 'on' if page == 'protokoll' or page == 'bericht' else '' }} nav-desk" title="Protokoll"><svg class="ico"><use href="#i-list"/></svg><span>Protokoll</span></a>
|
||||||
<a href="/statistik" class="{{ 'on' if page == 'statistik' else '' }} nav-desk" title="Statistik"><svg class="ico"><use href="#i-chart"/></svg><span>Statistik</span></a>
|
<a href="/statistik" class="{{ 'on' if page == 'statistik' else '' }} nav-desk" title="Statistik"><svg class="ico"><use href="#i-chart"/></svg><span>Statistik</span></a>
|
||||||
@@ -138,11 +138,14 @@
|
|||||||
</nav>
|
</nav>
|
||||||
<dialog id="mobile-more-sheet" class="mobile-more-sheet">
|
<dialog id="mobile-more-sheet" class="mobile-more-sheet">
|
||||||
<nav aria-label="Weitere Seiten">
|
<nav aria-label="Weitere Seiten">
|
||||||
|
<p class="nav-label">Live</p>
|
||||||
<a href="/auftraege">Aufträge</a>
|
<a href="/auftraege">Aufträge</a>
|
||||||
<a href="/projekte">Projekte</a>
|
<p class="nav-label">Rückschau</p>
|
||||||
<a href="/protokoll">Protokoll</a>
|
<a href="/protokoll">Protokoll</a>
|
||||||
<a href="/statistik">Statistik</a>
|
<a href="/statistik">Statistik</a>
|
||||||
<a href="/aktivitaet">Aktivität</a>
|
<a href="/aktivitaet">Aktivität</a>
|
||||||
|
<p class="nav-label">Verwalten</p>
|
||||||
|
<a href="/projekte">Projekte</a>
|
||||||
<a href="/material">Material</a>
|
<a href="/material">Material</a>
|
||||||
<a href="/wartung">Wartung</a>
|
<a href="/wartung">Wartung</a>
|
||||||
<a href="/einstellungen">Einstellungen</a>
|
<a href="/einstellungen">Einstellungen</a>
|
||||||
@@ -466,7 +469,12 @@ async function refreshJetzt() {
|
|||||||
}
|
}
|
||||||
if (jetztBox) {
|
if (jetztBox) {
|
||||||
jetztBox.classList.toggle("is-empty", !actionItems.length);
|
jetztBox.classList.toggle("is-empty", !actionItems.length);
|
||||||
setListHtml(document.getElementById("jetzt-list"), actionItems.map(actionItemHtml).join(""));
|
const jetztList = document.getElementById("jetzt-list");
|
||||||
|
if (!actionItems.length) {
|
||||||
|
setListHtml(jetztList, '<li class="queue-empty">Alles erledigt — nichts zu tun.</li>');
|
||||||
|
} else {
|
||||||
|
setListHtml(jetztList, actionItems.map(actionItemHtml).join(""));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const runBox = document.getElementById("run-box");
|
const runBox = document.getElementById("run-box");
|
||||||
@@ -607,13 +615,17 @@ refreshJetzt();
|
|||||||
(function liveUpdates() {
|
(function liveUpdates() {
|
||||||
let streamLive = false;
|
let streamLive = false;
|
||||||
const sseKinds = {
|
const sseKinds = {
|
||||||
queue: () => refreshJetzt(),
|
queue: () => {
|
||||||
|
refreshJetzt();
|
||||||
|
if (typeof window.onQueueChanged === "function") window.onQueueChanged();
|
||||||
|
},
|
||||||
senden: () => refreshJetzt(),
|
senden: () => refreshJetzt(),
|
||||||
ereignis: () => refreshJetzt(),
|
ereignis: () => refreshJetzt(),
|
||||||
aufgaben: () => refreshJetzt(),
|
aufgaben: () => refreshJetzt(),
|
||||||
drucker: () => {
|
drucker: () => {
|
||||||
refreshJetzt();
|
refreshJetzt();
|
||||||
if (typeof window.onDruckerLive === "function") window.onDruckerLive();
|
if (typeof window.onDruckerLive === "function") window.onDruckerLive();
|
||||||
|
if (typeof window.onQueueChanged === "function") window.onQueueChanged();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -524,8 +524,13 @@ async function loadAkte(spoolId) {
|
|||||||
const charge = run.chargen_nr
|
const charge = run.chargen_nr
|
||||||
? '<a class="tag akte-charge" href="' + href + '">' + escapeHtml(run.chargen_nr) + "</a>"
|
? '<a class="tag akte-charge" href="' + href + '">' + escapeHtml(run.chargen_nr) + "</a>"
|
||||||
: '<span class="akte-charge tiny">—</span>';
|
: '<span class="akte-charge tiny">—</span>';
|
||||||
const file = '<a class="akte-file" href="' + href + '" title="' + escapeHtml((run.filename || "").split("/").pop() || "") + '">'
|
const fileName = akteFile(run.filename);
|
||||||
+ escapeHtml(akteFile(run.filename)) + "</a>";
|
const file = run.file_id
|
||||||
|
? '<a class="akte-file" href="/dateien?file=' + encodeURIComponent(run.file_id) + '" title="' + escapeHtml((run.filename || "").split("/").pop() || "") + '">'
|
||||||
|
+ escapeHtml(fileName) + "</a>"
|
||||||
|
+ ' <a class="tiny" href="' + href + '">Lauf</a>'
|
||||||
|
: '<a class="akte-file" href="' + href + '" title="' + escapeHtml((run.filename || "").split("/").pop() || "") + '">'
|
||||||
|
+ escapeHtml(fileName) + "</a>";
|
||||||
const gramsTxt = grams(run.spool_weight_g) + (run.spool_is_estimate ? " ≈" : "");
|
const gramsTxt = grams(run.spool_weight_g) + (run.spool_is_estimate ? " ≈" : "");
|
||||||
return '<div class="akte-run">'
|
return '<div class="akte-run">'
|
||||||
+ '<span class="akte-when tiny">' + escapeHtml(akteWhen(run.started_at)) + "</span>"
|
+ '<span class="akte-when tiny">' + escapeHtml(akteWhen(run.started_at)) + "</span>"
|
||||||
@@ -1115,11 +1120,24 @@ load().then(() => {
|
|||||||
closeSpoolPanel();
|
closeSpoolPanel();
|
||||||
closeSortenPanel();
|
closeSortenPanel();
|
||||||
const params = new URLSearchParams(location.search);
|
const params = new URLSearchParams(location.search);
|
||||||
const spoolId = params.get("spool");
|
const spoolId = params.get("spule") || params.get("spool");
|
||||||
|
const hostHint = params.get("host") || "";
|
||||||
|
const slotHint = params.get("slot") || "";
|
||||||
if (spoolId) {
|
if (spoolId) {
|
||||||
const spool = spools.find((row) => String(row.id) === spoolId);
|
const spool = spools.find((row) => String(row.id) === spoolId);
|
||||||
if (spool) fill(spool);
|
if (spool) {
|
||||||
else openByCode(spoolId);
|
fill(spool);
|
||||||
|
focusById("spool-id") || document.getElementById("spool-name")?.scrollIntoView({ behavior: "smooth", block: "center" });
|
||||||
|
} else openByCode(spoolId);
|
||||||
|
} else if (hostHint) {
|
||||||
|
document.getElementById("spool-panel")?.removeAttribute("hidden");
|
||||||
|
document.getElementById("spool-new")?.click?.();
|
||||||
|
const hostField = document.getElementById("spool-printer");
|
||||||
|
if (hostField) hostField.value = hostHint;
|
||||||
|
const slotField = document.getElementById("spool-slot");
|
||||||
|
if (slotField && slotHint) slotField.value = String(slotHint);
|
||||||
|
document.getElementById("spool-name")?.scrollIntoView({ behavior: "smooth", block: "center" });
|
||||||
|
toast("Drucker und Platz vorausgefüllt — Rolle wählen und speichern.");
|
||||||
}
|
}
|
||||||
}).catch((error) => showNote("spool-note", error));
|
}).catch((error) => showNote("spool-note", error));
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
+339
-50
@@ -6,11 +6,16 @@
|
|||||||
<p class="tiny">Arbeitsmappen mit Ordner unter dem Slice-Pfad — G-code und Konstruktionsdaten.</p>
|
<p class="tiny">Arbeitsmappen mit Ordner unter dem Slice-Pfad — G-code und Konstruktionsdaten.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
|
<div class="seg" id="proj-filter" role="group" aria-label="Filter">
|
||||||
|
<button type="button" class="on" data-filter="aktiv">Aktiv</button>
|
||||||
|
<button type="button" data-filter="fertig">Fertig</button>
|
||||||
|
<button type="button" data-filter="">Alle</button>
|
||||||
|
</div>
|
||||||
<button type="button" class="btn-primary" id="proj-new"><svg class="ico"><use href="#i-plus"/></svg>Neues Projekt</button>
|
<button type="button" class="btn-primary" id="proj-new"><svg class="ico"><use href="#i-plus"/></svg>Neues Projekt</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="split">
|
<div class="split edit-split is-idle" id="proj-layout">
|
||||||
<section class="card">
|
<section class="card">
|
||||||
<div class="card-head lib-head">
|
<div class="card-head lib-head">
|
||||||
<svg class="ico head-ico"><use href="#i-folder"/></svg>
|
<svg class="ico head-ico"><use href="#i-folder"/></svg>
|
||||||
@@ -19,16 +24,21 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="table-wrap">
|
<div class="table-wrap">
|
||||||
<table>
|
<table>
|
||||||
<thead><tr><th>Name</th><th>Status</th><th>Ordner</th><th class="num">Dateien</th></tr></thead>
|
<thead><tr><th>Name</th><th>Status</th><th>Ordner</th><th class="num">Dateien</th><th class="num">Kosten</th></tr></thead>
|
||||||
<tbody id="proj-rows"></tbody>
|
<tbody id="proj-rows"></tbody>
|
||||||
</table>
|
</table>
|
||||||
<div class="pager" id="proj-pager" hidden></div>
|
<div class="pager" id="proj-pager" hidden></div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="card" id="proj-panel">
|
<section class="card edit-panel" id="proj-panel" hidden>
|
||||||
|
<div class="mat-form-head">
|
||||||
<h2 id="proj-title">Neues Projekt</h2>
|
<h2 id="proj-title">Neues Projekt</h2>
|
||||||
<form id="proj-form" novalidate>
|
<button type="button" class="ghost tiny-btn" id="proj-edit-btn" hidden>Bearbeiten</button>
|
||||||
|
<button type="button" class="icon-btn" id="proj-close" title="Schließen" aria-label="Schließen"></button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form id="proj-form" novalidate hidden>
|
||||||
<input id="proj-id" type="hidden">
|
<input id="proj-id" type="hidden">
|
||||||
<div class="field"><label for="proj-name">Name</label><input id="proj-name" required autocomplete="off"></div>
|
<div class="field"><label for="proj-name">Name</label><input id="proj-name" required autocomplete="off"></div>
|
||||||
<div class="grid-2">
|
<div class="grid-2">
|
||||||
@@ -36,9 +46,9 @@
|
|||||||
<label for="proj-status">Status</label>
|
<label for="proj-status">Status</label>
|
||||||
<select id="proj-status">
|
<select id="proj-status">
|
||||||
<option value="idee">Idee</option>
|
<option value="idee">Idee</option>
|
||||||
<option value="bereit">bereit</option>
|
<option value="bereit">Bereit</option>
|
||||||
<option value="druckt">druckt</option>
|
<option value="druckt">Druckt</option>
|
||||||
<option value="fertig">fertig</option>
|
<option value="fertig">Fertig</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
@@ -50,17 +60,39 @@
|
|||||||
<div class="field"><label for="proj-notes">Notiz</label><textarea id="proj-notes" rows="3"></textarea></div>
|
<div class="field"><label for="proj-notes">Notiz</label><textarea id="proj-notes" rows="3"></textarea></div>
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
<button type="submit" class="btn-primary" id="proj-save">Speichern</button>
|
<button type="submit" class="btn-primary" id="proj-save">Speichern</button>
|
||||||
<a class="ghost" id="proj-files-link" href="/dateien" hidden>Dateien</a>
|
<button type="button" class="ghost" id="proj-cancel-edit" hidden>Abbrechen</button>
|
||||||
<button type="button" class="warn" id="proj-delete" hidden><svg class="ico"><use href="#i-trash"/></svg>Löschen</button>
|
<button type="button" class="warn" id="proj-delete" hidden><svg class="ico"><use href="#i-trash"/></svg>Löschen</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<p id="proj-note" class="tiny"></p>
|
<p id="proj-note" class="tiny"></p>
|
||||||
|
|
||||||
<div id="proj-detail" hidden>
|
<div id="proj-detail" hidden>
|
||||||
<h3 class="section-gap">Druckdateien</h3>
|
<div class="actions" style="margin-bottom:0.5rem">
|
||||||
<div id="proj-gcodes" class="proj-file-list"></div>
|
<a class="ghost" id="proj-files-link" href="/dateien" hidden>Dateien</a>
|
||||||
|
</div>
|
||||||
|
<div id="proj-stats" class="proj-stats"></div>
|
||||||
|
<p id="proj-suggest" class="tiny" hidden></p>
|
||||||
|
<p id="proj-meta" class="tiny"></p>
|
||||||
|
|
||||||
<h3 class="section-gap">Weitere Dateien</h3>
|
<div class="seg" id="proj-tabs" role="tablist" style="margin:0.75rem 0">
|
||||||
|
<button type="button" class="on" data-tab="files">Druckdateien</button>
|
||||||
|
<button type="button" data-tab="runs">Läufe</button>
|
||||||
|
<button type="button" data-tab="assets">Weitere Dateien</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="proj-tab-files">
|
||||||
|
<div class="actions" style="margin-bottom:0.5rem">
|
||||||
|
<button type="button" class="btn-primary" id="proj-enqueue-all" hidden>Alle einreihen</button>
|
||||||
|
</div>
|
||||||
|
<div id="proj-gcodes" class="proj-file-list"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="proj-tab-runs" hidden>
|
||||||
|
<div id="proj-runs" class="proj-file-list"></div>
|
||||||
|
<div class="pager" id="proj-runs-pager" hidden></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="proj-tab-assets" hidden>
|
||||||
<p class="tiny">STEP, STL, PDF, SolidWorks usw. im Projektordner — nicht in der Druck-Bibliothek.</p>
|
<p class="tiny">STEP, STL, PDF, SolidWorks usw. im Projektordner — nicht in der Druck-Bibliothek.</p>
|
||||||
<div class="actions" style="margin-bottom:0.5rem">
|
<div class="actions" style="margin-bottom:0.5rem">
|
||||||
<label class="button ghost" for="proj-asset-file"><svg class="ico"><use href="#i-upload"/></svg>Hochladen</label>
|
<label class="button ghost" for="proj-asset-file"><svg class="ico"><use href="#i-upload"/></svg>Hochladen</label>
|
||||||
@@ -68,57 +100,124 @@
|
|||||||
</div>
|
</div>
|
||||||
<div id="proj-assets" class="proj-file-list"></div>
|
<div id="proj-assets" class="proj-file-list"></div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block script %}
|
{% block script %}
|
||||||
<script>
|
<script>
|
||||||
const STATUS_LABEL = { idee: "Idee", bereit: "bereit", druckt: "druckt", fertig: "fertig" };
|
const STATUS_LABEL = { idee: "Idee", bereit: "Bereit", druckt: "Druckt", fertig: "Fertig" };
|
||||||
let projects = [];
|
let projects = [];
|
||||||
let selectedId = null;
|
let selectedId = null;
|
||||||
|
let listFilter = "aktiv";
|
||||||
|
let detailTab = "files";
|
||||||
|
let runsPage = 0;
|
||||||
|
let runsTotal = 0;
|
||||||
|
const RUNS_PAGE = 20;
|
||||||
|
/** idle | create | view | edit */
|
||||||
|
let panelMode = "idle";
|
||||||
|
let folderTouched = false;
|
||||||
|
let projPage = 1;
|
||||||
|
|
||||||
function fillBlank() {
|
document.getElementById("proj-close").innerHTML = icon("x");
|
||||||
|
|
||||||
|
function openPanel() {
|
||||||
|
document.getElementById("proj-panel").hidden = false;
|
||||||
|
document.getElementById("proj-layout").classList.remove("is-idle");
|
||||||
|
document.getElementById("proj-panel").scrollIntoView({ block: "nearest", behavior: "smooth" });
|
||||||
|
}
|
||||||
|
|
||||||
|
function closePanel() {
|
||||||
|
panelMode = "idle";
|
||||||
selectedId = null;
|
selectedId = null;
|
||||||
document.getElementById("proj-id").value = "";
|
document.getElementById("proj-panel").hidden = true;
|
||||||
document.getElementById("proj-name").value = "";
|
document.getElementById("proj-layout").classList.add("is-idle");
|
||||||
document.getElementById("proj-status").value = "idee";
|
document.getElementById("proj-form").hidden = true;
|
||||||
document.getElementById("proj-folder").value = "";
|
document.getElementById("proj-detail").hidden = true;
|
||||||
document.getElementById("proj-notes").value = "";
|
document.getElementById("proj-edit-btn").hidden = true;
|
||||||
document.getElementById("proj-title").textContent = "Neues Projekt";
|
document.getElementById("proj-cancel-edit").hidden = true;
|
||||||
document.getElementById("proj-delete").hidden = true;
|
document.getElementById("proj-delete").hidden = true;
|
||||||
document.getElementById("proj-files-link").hidden = true;
|
document.getElementById("proj-files-link").hidden = true;
|
||||||
document.getElementById("proj-detail").hidden = true;
|
|
||||||
document.getElementById("proj-note").textContent = "";
|
document.getElementById("proj-note").textContent = "";
|
||||||
|
document.getElementById("proj-enqueue-all").hidden = true;
|
||||||
|
history.replaceState(null, "", location.pathname);
|
||||||
renderList();
|
renderList();
|
||||||
}
|
}
|
||||||
|
|
||||||
function fill(project) {
|
function setFormValues(project) {
|
||||||
|
document.getElementById("proj-id").value = project ? project.id : "";
|
||||||
|
document.getElementById("proj-name").value = project ? (project.name || "") : "";
|
||||||
|
document.getElementById("proj-status").value = project ? (project.status || "idee") : "idee";
|
||||||
|
document.getElementById("proj-folder").value = project ? (project.folder || "") : "";
|
||||||
|
document.getElementById("proj-notes").value = project ? (project.notes || "") : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
function showCreate() {
|
||||||
|
panelMode = "create";
|
||||||
|
selectedId = null;
|
||||||
|
folderTouched = false;
|
||||||
|
setFormValues(null);
|
||||||
|
document.getElementById("proj-title").textContent = "Neues Projekt";
|
||||||
|
document.getElementById("proj-form").hidden = false;
|
||||||
|
document.getElementById("proj-detail").hidden = true;
|
||||||
|
document.getElementById("proj-edit-btn").hidden = true;
|
||||||
|
document.getElementById("proj-cancel-edit").hidden = true;
|
||||||
|
document.getElementById("proj-delete").hidden = true;
|
||||||
|
document.getElementById("proj-files-link").hidden = true;
|
||||||
|
document.getElementById("proj-note").textContent = "";
|
||||||
|
document.getElementById("proj-enqueue-all").hidden = true;
|
||||||
|
openPanel();
|
||||||
|
renderList();
|
||||||
|
document.getElementById("proj-name").focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
function showView(project) {
|
||||||
|
panelMode = "view";
|
||||||
selectedId = project.id;
|
selectedId = project.id;
|
||||||
document.getElementById("proj-id").value = project.id;
|
setFormValues(project);
|
||||||
document.getElementById("proj-name").value = project.name || "";
|
|
||||||
document.getElementById("proj-status").value = project.status || "idee";
|
|
||||||
document.getElementById("proj-folder").value = project.folder || "";
|
|
||||||
document.getElementById("proj-notes").value = project.notes || "";
|
|
||||||
document.getElementById("proj-title").textContent = project.name || "Projekt";
|
document.getElementById("proj-title").textContent = project.name || "Projekt";
|
||||||
document.getElementById("proj-delete").hidden = false;
|
document.getElementById("proj-form").hidden = true;
|
||||||
|
document.getElementById("proj-detail").hidden = false;
|
||||||
|
document.getElementById("proj-edit-btn").hidden = false;
|
||||||
|
document.getElementById("proj-cancel-edit").hidden = true;
|
||||||
|
document.getElementById("proj-delete").hidden = true;
|
||||||
const link = document.getElementById("proj-files-link");
|
const link = document.getElementById("proj-files-link");
|
||||||
link.hidden = false;
|
link.hidden = false;
|
||||||
link.href = "/dateien";
|
link.href = "/dateien?project=" + encodeURIComponent(project.id);
|
||||||
document.getElementById("proj-detail").hidden = false;
|
|
||||||
document.getElementById("proj-note").textContent = "";
|
document.getElementById("proj-note").textContent = "";
|
||||||
|
openPanel();
|
||||||
renderList();
|
renderList();
|
||||||
renderDetail(project);
|
renderDetail(project);
|
||||||
}
|
}
|
||||||
|
|
||||||
let projPage = 1;
|
function showEdit(project) {
|
||||||
|
panelMode = "edit";
|
||||||
|
selectedId = project.id;
|
||||||
|
folderTouched = true;
|
||||||
|
setFormValues(project);
|
||||||
|
document.getElementById("proj-title").textContent = "Bearbeiten";
|
||||||
|
document.getElementById("proj-form").hidden = false;
|
||||||
|
document.getElementById("proj-detail").hidden = true;
|
||||||
|
document.getElementById("proj-edit-btn").hidden = true;
|
||||||
|
document.getElementById("proj-cancel-edit").hidden = false;
|
||||||
|
document.getElementById("proj-delete").hidden = false;
|
||||||
|
document.getElementById("proj-files-link").hidden = true;
|
||||||
|
openPanel();
|
||||||
|
renderList();
|
||||||
|
document.getElementById("proj-name").focus();
|
||||||
|
}
|
||||||
|
|
||||||
function renderList() {
|
function renderList() {
|
||||||
const body = document.getElementById("proj-rows");
|
const body = document.getElementById("proj-rows");
|
||||||
const pager = document.getElementById("proj-pager");
|
const pager = document.getElementById("proj-pager");
|
||||||
document.getElementById("proj-count").textContent = String(projects.length);
|
document.getElementById("proj-count").textContent = String(projects.length);
|
||||||
if (!projects.length) {
|
if (!projects.length) {
|
||||||
body.innerHTML = '<tr><td class="empty" colspan="4"><div class="empty-state">' + icon("folder") + "<p>Noch kein Projekt.</p></div></td></tr>";
|
body.innerHTML = '<tr><td class="empty" colspan="5"><div class="empty-state">' + icon("folder")
|
||||||
|
+ "<p>Noch kein Projekt.</p>"
|
||||||
|
+ '<p><button type="button" class="btn-primary" id="proj-empty-new">Erstes Projekt anlegen</button></p>'
|
||||||
|
+ "</div></td></tr>";
|
||||||
|
document.getElementById("proj-empty-new")?.addEventListener("click", showCreate);
|
||||||
renderPager(pager, null, () => {});
|
renderPager(pager, null, () => {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -128,12 +227,16 @@ function renderList() {
|
|||||||
paged.items.forEach((project) => {
|
paged.items.forEach((project) => {
|
||||||
const tr = document.createElement("tr");
|
const tr = document.createElement("tr");
|
||||||
tr.className = "pick" + (String(project.id) === String(selectedId) ? " on" : "");
|
tr.className = "pick" + (String(project.id) === String(selectedId) ? " on" : "");
|
||||||
tr.innerHTML = "<td></td><td></td><td></td><td class=\"num\"></td>";
|
tr.innerHTML = "<td></td><td></td><td class=\"cell-path\"></td><td class=\"num\"></td><td class=\"num\"></td>";
|
||||||
tr.children[0].textContent = project.name;
|
tr.children[0].textContent = project.name;
|
||||||
tr.children[1].textContent = STATUS_LABEL[project.status] || project.status || "";
|
let status = STATUS_LABEL[project.status] || project.status || "";
|
||||||
|
if ((project.stats || {}).active_count > 0) status = STATUS_LABEL.druckt;
|
||||||
|
tr.children[1].textContent = status;
|
||||||
tr.children[2].textContent = project.folder || "—";
|
tr.children[2].textContent = project.folder || "—";
|
||||||
tr.children[2].title = project.folder || "";
|
tr.children[2].title = project.folder || "";
|
||||||
tr.children[3].textContent = String(project.file_count ?? (project.files || []).length);
|
tr.children[3].textContent = String(project.file_count ?? (project.files || []).length);
|
||||||
|
const cost = (project.stats || {}).cost;
|
||||||
|
tr.children[4].textContent = cost ? euro(cost) : "—";
|
||||||
tr.addEventListener("click", () => openProject(project.id));
|
tr.addEventListener("click", () => openProject(project.id));
|
||||||
body.appendChild(tr);
|
body.appendChild(tr);
|
||||||
});
|
});
|
||||||
@@ -143,20 +246,122 @@ function renderList() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setTab(tab) {
|
||||||
|
detailTab = tab;
|
||||||
|
document.querySelectorAll("#proj-tabs [data-tab]").forEach((btn) => {
|
||||||
|
btn.classList.toggle("on", btn.dataset.tab === tab);
|
||||||
|
});
|
||||||
|
document.getElementById("proj-tab-files").hidden = tab !== "files";
|
||||||
|
document.getElementById("proj-tab-runs").hidden = tab !== "runs";
|
||||||
|
document.getElementById("proj-tab-assets").hidden = tab !== "assets";
|
||||||
|
if (tab === "runs" && selectedId) loadRuns(selectedId, 0);
|
||||||
|
if (tab === "assets" && selectedId) loadAssets(selectedId);
|
||||||
|
}
|
||||||
|
|
||||||
function renderDetail(project) {
|
function renderDetail(project) {
|
||||||
const gcodes = document.getElementById("proj-gcodes");
|
const stats = project.stats || {};
|
||||||
|
const statsEl = document.getElementById("proj-stats");
|
||||||
|
const chips = [
|
||||||
|
[stats.run_count || 0, "Läufe"],
|
||||||
|
[hours(stats.duration_s) || "0 min", "Zeit"],
|
||||||
|
[grams(stats.weight_g || 0), "Filament"],
|
||||||
|
[euro(stats.cost || 0), "Kosten"],
|
||||||
|
];
|
||||||
|
if (stats.files_total) {
|
||||||
|
chips.push([stats.files_ok + "/" + stats.files_total, "Dateien ok"]);
|
||||||
|
}
|
||||||
|
statsEl.innerHTML = chips.map(([v, l]) =>
|
||||||
|
`<div class="proj-stat"><strong>${escapeHtml(String(v))}</strong><span class="tiny">${escapeHtml(l)}</span></div>`
|
||||||
|
).join("");
|
||||||
|
|
||||||
|
const meta = [];
|
||||||
|
if (project.folder) meta.push(project.folder);
|
||||||
|
if (project.created_at) meta.push("Angelegt " + formatDateTime(project.created_at));
|
||||||
|
if (stats.last_run) {
|
||||||
|
meta.push("Zuletzt " + formatDateTime(stats.last_run.started_at) + " · " + (stats.last_run.filename || ""));
|
||||||
|
}
|
||||||
|
document.getElementById("proj-meta").textContent = meta.join(" · ");
|
||||||
|
|
||||||
|
const suggest = document.getElementById("proj-suggest");
|
||||||
|
if (stats.suggest_fertig) {
|
||||||
|
suggest.hidden = false;
|
||||||
|
suggest.innerHTML = 'Alle Dateien mindestens einmal ok gedruckt. <button type="button" class="ghost" id="proj-mark-fertig">Als fertig markieren?</button>';
|
||||||
|
document.getElementById("proj-mark-fertig")?.addEventListener("click", async () => {
|
||||||
|
try {
|
||||||
|
await api("/projekte/" + project.id, { method: "PATCH", json: { status: "fertig" } });
|
||||||
|
toast("Projekt als fertig markiert.", "good");
|
||||||
|
await load();
|
||||||
|
await openProject(project.id);
|
||||||
|
} catch (error) {
|
||||||
|
showNote("proj-note", error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
suggest.hidden = true;
|
||||||
|
suggest.textContent = "";
|
||||||
|
}
|
||||||
|
|
||||||
const files = project.files || [];
|
const files = project.files || [];
|
||||||
|
document.getElementById("proj-enqueue-all").hidden = !files.length;
|
||||||
|
const gcodes = document.getElementById("proj-gcodes");
|
||||||
if (!files.length) {
|
if (!files.length) {
|
||||||
gcodes.innerHTML = '<p class="tiny">Keine G-code/3MF-Dateien verknüpft. Dateien in den Projektordner legen oder unter Dateien verschieben.</p>';
|
gcodes.innerHTML = '<p class="tiny">Keine G-code/3MF-Dateien verknüpft. Dateien in den Projektordner legen oder unter Dateien verschieben.</p>';
|
||||||
} else {
|
} else {
|
||||||
gcodes.innerHTML = files.map((file) => {
|
gcodes.innerHTML = files.map((file) => {
|
||||||
const mats = (file.filaments || []).map((f) => f.type || f.material_type || f.name || "").filter(Boolean);
|
const mats = (file.filaments || []).map((f) => f.type || f.material_type || f.name || "").filter(Boolean);
|
||||||
const mat = [...new Set(mats)].join(" / ");
|
const mat = [...new Set(mats)].join(" / ");
|
||||||
const meta = [mat, file.weight_g ? Math.round(file.weight_g) + " g" : ""].filter(Boolean).join(" · ");
|
const metaBits = [
|
||||||
return `<a class="proj-file" href="/dateien">${escapeHtml(file.name)}<span class="tiny">${escapeHtml(meta)}</span></a>`;
|
mat,
|
||||||
|
file.weight_g ? Math.round(file.weight_g) + " g" : "",
|
||||||
|
file.printed ? file.printed + "× gedruckt" : "noch nie",
|
||||||
|
file.queued ? file.queued + " in Queue" : "",
|
||||||
|
file.ok_once ? "ok" : "",
|
||||||
|
].filter(Boolean).join(" · ");
|
||||||
|
const href = "/dateien?file=" + encodeURIComponent(file.id) + "&project=" + encodeURIComponent(project.id);
|
||||||
|
return `<div class="proj-file-row">
|
||||||
|
<a class="proj-file" href="${escapeHtml(href)}">${escapeHtml(file.name)}<span class="tiny">${escapeHtml(metaBits)}</span></a>
|
||||||
|
<button type="button" class="ghost" data-enqueue="${file.id}">Einreihen</button>
|
||||||
|
</div>`;
|
||||||
}).join("");
|
}).join("");
|
||||||
}
|
}
|
||||||
loadAssets(project.id);
|
setTab(detailTab);
|
||||||
|
if (detailTab === "assets") loadAssets(project.id);
|
||||||
|
if (detailTab === "runs") loadRuns(project.id, runsPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadRuns(projectId, offset) {
|
||||||
|
const box = document.getElementById("proj-runs");
|
||||||
|
const pager = document.getElementById("proj-runs-pager");
|
||||||
|
runsPage = Math.max(0, offset || 0);
|
||||||
|
try {
|
||||||
|
const resp = await fetch(withToken("/api/v1/projekte/" + projectId + "/laeufe?limit=" + RUNS_PAGE + "&offset=" + runsPage), {
|
||||||
|
credentials: "same-origin",
|
||||||
|
headers: { Accept: "application/json" },
|
||||||
|
});
|
||||||
|
if (!resp.ok) throw new Error("Läufe laden fehlgeschlagen.");
|
||||||
|
const rows = await resp.json();
|
||||||
|
runsTotal = Number(resp.headers.get("X-Total-Count") || rows.length);
|
||||||
|
if (!rows.length) {
|
||||||
|
box.innerHTML = '<p class="tiny">Noch keine Läufe.</p>';
|
||||||
|
pager.hidden = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
box.innerHTML = rows.map((run) => {
|
||||||
|
const state = (window.RUN_STATES && RUN_STATES[run.state]) || run.state || "";
|
||||||
|
const cost = Number(run.filament_cost || 0) + Number(run.energy_cost || 0);
|
||||||
|
const meta = [state, hours(run.duration_s), cost ? euro(cost) : "", formatDateTime(run.started_at)].filter(Boolean).join(" · ");
|
||||||
|
return `<a class="proj-file" href="/protokoll/${run.id}">${escapeHtml(run.filename || "Lauf #" + run.id)}<span class="tiny">${escapeHtml(meta)}</span></a>`;
|
||||||
|
}).join("");
|
||||||
|
const pages = Math.max(1, Math.ceil(runsTotal / RUNS_PAGE));
|
||||||
|
const page = Math.floor(runsPage / RUNS_PAGE) + 1;
|
||||||
|
renderPager(pager, {
|
||||||
|
items: rows, page, pages, total: runsTotal, pageSize: RUNS_PAGE,
|
||||||
|
from: runsTotal ? runsPage + 1 : 0,
|
||||||
|
to: Math.min(runsPage + rows.length, runsTotal),
|
||||||
|
}, (p) => loadRuns(projectId, (p - 1) * RUNS_PAGE));
|
||||||
|
} catch (error) {
|
||||||
|
box.innerHTML = '<p class="tiny">' + escapeHtml(error.message || String(error)) + "</p>";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadAssets(projectId) {
|
async function loadAssets(projectId) {
|
||||||
@@ -187,32 +392,80 @@ function sizeText(bytes) {
|
|||||||
return (n / (1024 * 1024)).toFixed(1).replace(".", ",") + " MB";
|
return (n / (1024 * 1024)).toFixed(1).replace(".", ",") + " MB";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function enqueueFiles(projectId, fileIds) {
|
||||||
|
const payload = { confirm: true };
|
||||||
|
if (fileIds && fileIds.length) payload.file_ids = fileIds;
|
||||||
|
const out = await api("/projekte/" + projectId + "/einreihen", { method: "POST", json: payload });
|
||||||
|
toast((out.count || 0) + " in die Warteschlange.", "good");
|
||||||
|
await openProject(projectId);
|
||||||
|
}
|
||||||
|
|
||||||
async function openProject(id) {
|
async function openProject(id) {
|
||||||
try {
|
try {
|
||||||
const row = await api("/projekte/" + id);
|
const row = await api("/projekte/" + id);
|
||||||
fill(row);
|
showView(row);
|
||||||
|
history.replaceState(null, "", "#" + id);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showNote("proj-note", error);
|
showNote("proj-note", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function load() {
|
async function load() {
|
||||||
projects = await api("/projekte");
|
const q = listFilter ? ("?status=" + encodeURIComponent(listFilter)) : "";
|
||||||
|
projects = await api("/projekte" + q);
|
||||||
renderList();
|
renderList();
|
||||||
if (selectedId) {
|
if (selectedId && (panelMode === "view" || panelMode === "edit")) {
|
||||||
const still = projects.find((p) => String(p.id) === String(selectedId));
|
const still = projects.find((p) => String(p.id) === String(selectedId));
|
||||||
if (still) await openProject(selectedId);
|
if (still) {
|
||||||
else fillBlank();
|
if (panelMode === "edit") {
|
||||||
|
const row = await api("/projekte/" + selectedId);
|
||||||
|
showEdit(row);
|
||||||
|
} else {
|
||||||
|
await openProject(selectedId);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
closePanel();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let folderTouched = false;
|
document.getElementById("proj-filter").addEventListener("click", (event) => {
|
||||||
|
const btn = event.target.closest("[data-filter]");
|
||||||
|
if (!btn) return;
|
||||||
|
listFilter = btn.dataset.filter || "";
|
||||||
|
document.querySelectorAll("#proj-filter [data-filter]").forEach((b) => b.classList.toggle("on", b === btn));
|
||||||
|
projPage = 1;
|
||||||
|
load().catch((error) => showNote("proj-note", error));
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById("proj-tabs").addEventListener("click", (event) => {
|
||||||
|
const btn = event.target.closest("[data-tab]");
|
||||||
|
if (!btn) return;
|
||||||
|
setTab(btn.dataset.tab);
|
||||||
|
});
|
||||||
|
|
||||||
document.getElementById("proj-new").addEventListener("click", () => {
|
document.getElementById("proj-new").addEventListener("click", () => {
|
||||||
folderTouched = false;
|
history.replaceState(null, "", location.pathname);
|
||||||
fillBlank();
|
showCreate();
|
||||||
document.getElementById("proj-name").focus();
|
|
||||||
});
|
});
|
||||||
|
document.getElementById("proj-close").addEventListener("click", closePanel);
|
||||||
|
document.getElementById("proj-edit-btn").addEventListener("click", async () => {
|
||||||
|
if (!selectedId) return;
|
||||||
|
try {
|
||||||
|
const row = await api("/projekte/" + selectedId);
|
||||||
|
showEdit(row);
|
||||||
|
} catch (error) {
|
||||||
|
showNote("proj-note", error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
document.getElementById("proj-cancel-edit").addEventListener("click", async () => {
|
||||||
|
if (!selectedId) {
|
||||||
|
closePanel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await openProject(selectedId);
|
||||||
|
});
|
||||||
|
|
||||||
document.getElementById("proj-folder").addEventListener("input", () => {
|
document.getElementById("proj-folder").addEventListener("input", () => {
|
||||||
folderTouched = true;
|
folderTouched = true;
|
||||||
});
|
});
|
||||||
@@ -278,7 +531,7 @@ document.getElementById("proj-delete").addEventListener("click", () => {
|
|||||||
try {
|
try {
|
||||||
await api("/projekte/" + id + "?force=1", { method: "DELETE" });
|
await api("/projekte/" + id + "?force=1", { method: "DELETE" });
|
||||||
toast("Projekt gelöscht.");
|
toast("Projekt gelöscht.");
|
||||||
fillBlank();
|
closePanel();
|
||||||
await load();
|
await load();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showNote("proj-note", error);
|
showNote("proj-note", error);
|
||||||
@@ -286,8 +539,36 @@ document.getElementById("proj-delete").addEventListener("click", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.getElementById("proj-enqueue-all").addEventListener("click", () => {
|
||||||
|
const id = selectedId;
|
||||||
|
if (!id) return;
|
||||||
|
armButton(document.getElementById("proj-enqueue-all"), "Alle einreihen?", async () => {
|
||||||
|
try {
|
||||||
|
await enqueueFiles(id, null);
|
||||||
|
} catch (error) {
|
||||||
|
showNote("proj-note", error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById("proj-gcodes").addEventListener("click", (event) => {
|
||||||
|
const btn = event.target.closest("[data-enqueue]");
|
||||||
|
if (!btn) return;
|
||||||
|
event.preventDefault();
|
||||||
|
const id = selectedId;
|
||||||
|
const fileId = Number(btn.dataset.enqueue);
|
||||||
|
if (!id || !fileId) return;
|
||||||
|
armButton(btn, "einreihen?", async () => {
|
||||||
|
try {
|
||||||
|
await enqueueFiles(id, [fileId]);
|
||||||
|
} catch (error) {
|
||||||
|
showNote("proj-note", error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
document.getElementById("proj-asset-file").addEventListener("change", async (event) => {
|
document.getElementById("proj-asset-file").addEventListener("change", async (event) => {
|
||||||
const id = document.getElementById("proj-id").value;
|
const id = selectedId;
|
||||||
const files = [...(event.target.files || [])];
|
const files = [...(event.target.files || [])];
|
||||||
event.target.value = "";
|
event.target.value = "";
|
||||||
if (!id || !files.length) return;
|
if (!id || !files.length) return;
|
||||||
@@ -307,7 +588,7 @@ document.getElementById("proj-asset-file").addEventListener("change", async (eve
|
|||||||
document.getElementById("proj-assets").addEventListener("click", (event) => {
|
document.getElementById("proj-assets").addEventListener("click", (event) => {
|
||||||
const btn = event.target.closest("[data-asset-del]");
|
const btn = event.target.closest("[data-asset-del]");
|
||||||
if (!btn) return;
|
if (!btn) return;
|
||||||
const id = document.getElementById("proj-id").value;
|
const id = selectedId;
|
||||||
const rel = btn.dataset.assetDel;
|
const rel = btn.dataset.assetDel;
|
||||||
if (!id || !rel) return;
|
if (!id || !rel) return;
|
||||||
armButton(btn, "löschen?", async () => {
|
armButton(btn, "löschen?", async () => {
|
||||||
@@ -317,6 +598,14 @@ document.getElementById("proj-assets").addEventListener("click", (event) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
load().catch((error) => showNote("proj-note", error));
|
(async () => {
|
||||||
|
try {
|
||||||
|
await load();
|
||||||
|
const hash = (location.hash || "").replace(/^#/, "");
|
||||||
|
if (hash && /^\d+$/.test(hash)) await openProject(Number(hash));
|
||||||
|
} catch (error) {
|
||||||
|
showNote("proj-note", error);
|
||||||
|
}
|
||||||
|
})();
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -4,6 +4,10 @@
|
|||||||
<div>
|
<div>
|
||||||
<h1>Protokoll</h1>
|
<h1>Protokoll</h1>
|
||||||
<p class="tiny">Abgeschlossene und laufende Drucke mit Dauer, Material und Kosten.</p>
|
<p class="tiny">Abgeschlossene und laufende Drucke mit Dauer, Material und Kosten.</p>
|
||||||
|
<details class="tiny proto-help">
|
||||||
|
<summary>Filament-Pause / doppelte Zeilen</summary>
|
||||||
|
<p>Nach Runout kann der Drucker kurz zwei History-Zeilen erzeugen. „Läufe holen“ legt sie zusammen; sonst „Verbinden“.</p>
|
||||||
|
</details>
|
||||||
</div>
|
</div>
|
||||||
<div class="page-head-side">
|
<div class="page-head-side">
|
||||||
<button type="button" id="sync"><svg class="ico"><use href="#i-refresh"/></svg>Läufe holen</button>
|
<button type="button" id="sync"><svg class="ico"><use href="#i-refresh"/></svg>Läufe holen</button>
|
||||||
@@ -96,7 +100,6 @@ function render() {
|
|||||||
runPage = paged.page;
|
runPage = paged.page;
|
||||||
paged.items.forEach((run) => {
|
paged.items.forEach((run) => {
|
||||||
const tr = document.createElement("tr");
|
const tr = document.createElement("tr");
|
||||||
tr.className = "pick";
|
|
||||||
tr.innerHTML = "<td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>";
|
tr.innerHTML = "<td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>";
|
||||||
tr.children[0].textContent = run.printer_name;
|
tr.children[0].textContent = run.printer_name;
|
||||||
tr.children[0].className = "proto-printer";
|
tr.children[0].className = "proto-printer";
|
||||||
@@ -109,19 +112,54 @@ function render() {
|
|||||||
link.title = fullName;
|
link.title = fullName;
|
||||||
link.textContent = shortRunName(run.filename) || fullName;
|
link.textContent = shortRunName(run.filename) || fullName;
|
||||||
fileCell.appendChild(link);
|
fileCell.appendChild(link);
|
||||||
|
if (run.file_id) {
|
||||||
|
const fileLink = document.createElement("a");
|
||||||
|
fileLink.href = "/dateien?file=" + encodeURIComponent(run.file_id);
|
||||||
|
fileLink.className = "tiny";
|
||||||
|
fileLink.textContent = "Datei";
|
||||||
|
fileLink.style.marginLeft = "0.35rem";
|
||||||
|
fileCell.appendChild(fileLink);
|
||||||
|
}
|
||||||
|
if (run.project_id) {
|
||||||
|
const projLink = document.createElement("a");
|
||||||
|
projLink.href = "/projekte#" + encodeURIComponent(run.project_id);
|
||||||
|
projLink.className = "tiny";
|
||||||
|
projLink.textContent = "Projekt";
|
||||||
|
projLink.style.marginLeft = "0.35rem";
|
||||||
|
fileCell.appendChild(projLink);
|
||||||
|
}
|
||||||
if (run.chargen_nr) {
|
if (run.chargen_nr) {
|
||||||
const code = document.createElement("div");
|
const code = document.createElement("div");
|
||||||
code.className = "mono-badge";
|
code.className = "mono-badge";
|
||||||
code.textContent = run.chargen_nr;
|
code.textContent = run.chargen_nr;
|
||||||
fileCell.appendChild(code);
|
fileCell.appendChild(code);
|
||||||
}
|
}
|
||||||
|
if ((run.spool_names || []).length > 1 || (run.segment_count || 0) > 1) {
|
||||||
|
const swap = document.createElement("div");
|
||||||
|
swap.className = "tiny warn-text";
|
||||||
|
swap.textContent = "Rollenwechsel: " + (run.spool_names || []).join(" → ");
|
||||||
|
fileCell.appendChild(swap);
|
||||||
|
}
|
||||||
|
if (run.merge_with_id) {
|
||||||
|
const hint = document.createElement("div");
|
||||||
|
hint.className = "tiny warn-text";
|
||||||
|
hint.textContent = "Vermutlich Fortsetzung von/zu #" + run.merge_with_id;
|
||||||
|
fileCell.appendChild(hint);
|
||||||
|
}
|
||||||
const stateKey = run.state === "in_progress" || run.state === "printing" ? "printing"
|
const stateKey = run.state === "in_progress" || run.state === "printing" ? "printing"
|
||||||
|
: run.state === "paused" ? "paused"
|
||||||
: run.state === "completed" ? "complete"
|
: run.state === "completed" ? "complete"
|
||||||
: run.state === "error" ? "error"
|
: run.state === "error" ? "error"
|
||||||
: run.state === "cancelled" || run.state === "interrupted" ? "cancelled"
|
: run.state === "cancelled" || run.state === "interrupted" ? "cancelled"
|
||||||
: "idle";
|
: "idle";
|
||||||
tr.children[2].innerHTML = chipHtml(stateKey, states[run.state] || run.state);
|
let stateLabel = states[run.state] || run.state;
|
||||||
tr.children[3].textContent = hours(run.duration_s);
|
if (run.state === "cancelled" && run.merge_with_id) stateLabel = "Teilabbruch (Runout?)";
|
||||||
|
tr.children[2].innerHTML = chipHtml(stateKey, stateLabel);
|
||||||
|
let durationText = hours(run.duration_s);
|
||||||
|
if (run.pause_s && run.pause_s > 60) {
|
||||||
|
durationText += " (Pause " + hours(run.pause_s) + ")";
|
||||||
|
}
|
||||||
|
tr.children[3].textContent = durationText;
|
||||||
tr.children[3].className = "num";
|
tr.children[3].className = "num";
|
||||||
const used = Number(run.weight_used_g) || Number(run.weight_g) || 0;
|
const used = Number(run.weight_used_g) || Number(run.weight_g) || 0;
|
||||||
const planned = Number(run.weight_planned_g) || Number(run.weight_g) || 0;
|
const planned = Number(run.weight_planned_g) || Number(run.weight_g) || 0;
|
||||||
@@ -134,7 +172,11 @@ function render() {
|
|||||||
}
|
}
|
||||||
const cost = Number(run.filament_cost || 0) + Number(run.energy_cost || 0);
|
const cost = Number(run.filament_cost || 0) + Number(run.energy_cost || 0);
|
||||||
tr.children[5].textContent = cost ? euro(cost) : "";
|
tr.children[5].textContent = cost ? euro(cost) : "";
|
||||||
|
const verdictLabel = document.createElement("label");
|
||||||
|
verdictLabel.className = "sr-only";
|
||||||
|
verdictLabel.textContent = "Urteil";
|
||||||
const verdict = document.createElement("select");
|
const verdict = document.createElement("select");
|
||||||
|
verdict.setAttribute("aria-label", "Urteil");
|
||||||
[["", "offen"], ["gut", "gut"], ["ausschuss", "Ausschuss"]].forEach(([value, label]) => {
|
[["", "offen"], ["gut", "gut"], ["ausschuss", "Ausschuss"]].forEach(([value, label]) => {
|
||||||
const option = document.createElement("option");
|
const option = document.createElement("option");
|
||||||
option.value = value;
|
option.value = value;
|
||||||
@@ -145,10 +187,12 @@ function render() {
|
|||||||
verdict.addEventListener("change", async () => {
|
verdict.addEventListener("change", async () => {
|
||||||
try {
|
try {
|
||||||
await api("/laeufe/" + run.id, { method: "PATCH", json: { verdict: verdict.value } });
|
await api("/laeufe/" + run.id, { method: "PATCH", json: { verdict: verdict.value } });
|
||||||
|
toast("Urteil gespeichert.");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showNote("run-note", error);
|
showNote("run-note", error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
tr.children[6].appendChild(verdictLabel);
|
||||||
tr.children[6].appendChild(verdict);
|
tr.children[6].appendChild(verdict);
|
||||||
if (run.needs_spool || !run.deducted) {
|
if (run.needs_spool || !run.deducted) {
|
||||||
const select = document.createElement("select");
|
const select = document.createElement("select");
|
||||||
@@ -183,14 +227,49 @@ function render() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
tr.children[7].appendChild(select);
|
tr.children[7].appendChild(select);
|
||||||
|
} else if ((run.spool_names || []).length > 1) {
|
||||||
|
tr.children[7].className = "proto-spool";
|
||||||
|
tr.children[7].textContent = run.spool_names.join(" → ");
|
||||||
|
tr.children[7].title = run.spool_names.join(" → ");
|
||||||
} else {
|
} else {
|
||||||
const spool = spools.find((item) => item.id === run.spool_id);
|
const spool = spools.find((item) => item.id === run.spool_id);
|
||||||
tr.children[7].textContent = spool ? spool.name : "abgezogen";
|
|
||||||
tr.children[7].title = spool ? spool.name : "";
|
|
||||||
tr.children[7].className = "proto-spool";
|
tr.children[7].className = "proto-spool";
|
||||||
|
if (spool) {
|
||||||
|
tr.children[7].innerHTML = linkTo("spule", spool.id, spool.name);
|
||||||
|
tr.children[7].title = spool.name;
|
||||||
|
} else if ((run.spool_names || []).length) {
|
||||||
|
tr.children[7].textContent = run.spool_names[0];
|
||||||
|
} else {
|
||||||
|
tr.children[7].textContent = "abgezogen";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!tr.children[7].className) tr.children[7].className = "proto-spool";
|
if (!tr.children[7].className) tr.children[7].className = "proto-spool";
|
||||||
if (run.file_id) {
|
const actions = tr.children[8];
|
||||||
|
actions.className = "proto-actions";
|
||||||
|
if (run.merge_with_id) {
|
||||||
|
const mergeBtn = document.createElement("button");
|
||||||
|
mergeBtn.type = "button";
|
||||||
|
mergeBtn.className = "ghost tiny-btn";
|
||||||
|
mergeBtn.textContent = "Verbinden";
|
||||||
|
mergeBtn.title = "Mit Lauf #" + run.merge_with_id + " verbinden";
|
||||||
|
mergeBtn.addEventListener("click", () => {
|
||||||
|
armButton(mergeBtn, "Mit #" + run.merge_with_id + " verbinden?", async () => {
|
||||||
|
try {
|
||||||
|
await api("/laeufe/" + run.id + "/verbinden", {
|
||||||
|
method: "POST",
|
||||||
|
json: { other_id: run.merge_with_id, confirm: true },
|
||||||
|
});
|
||||||
|
toast("Läufe verbunden.");
|
||||||
|
await load();
|
||||||
|
} catch (error) {
|
||||||
|
toast(error.message, "bad");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
actions.appendChild(mergeBtn);
|
||||||
|
}
|
||||||
|
const running = ["in_progress", "printing", "paused"].includes(run.state);
|
||||||
|
if (run.file_id && !running) {
|
||||||
const again = document.createElement("button");
|
const again = document.createElement("button");
|
||||||
again.type = "button";
|
again.type = "button";
|
||||||
again.className = "ghost tiny-btn";
|
again.className = "ghost tiny-btn";
|
||||||
@@ -235,7 +314,7 @@ function render() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
tr.children[8].appendChild(again);
|
actions.appendChild(again);
|
||||||
}
|
}
|
||||||
body.appendChild(tr);
|
body.appendChild(tr);
|
||||||
});
|
});
|
||||||
@@ -250,6 +329,8 @@ async function load() {
|
|||||||
runPage = 1;
|
runPage = 1;
|
||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
|
window.onDruckerLive = () => { load().catch(() => {}); };
|
||||||
|
window.onQueueChanged = () => { load().catch(() => {}); };
|
||||||
|
|
||||||
["run-filter-printer", "run-filter-verdict", "run-filter-spool"].forEach((id) => {
|
["run-filter-printer", "run-filter-verdict", "run-filter-spool"].forEach((id) => {
|
||||||
document.getElementById(id).addEventListener("change", () => { runPage = 1; render(); });
|
document.getElementById(id).addEventListener("change", () => { runPage = 1; render(); });
|
||||||
|
|||||||
@@ -19,14 +19,18 @@
|
|||||||
<button type="button" data-period="last_week" class="fchip">Letzte Woche</button>
|
<button type="button" data-period="last_week" class="fchip">Letzte Woche</button>
|
||||||
<button type="button" data-period="last_month" class="fchip">Letzter Monat</button>
|
<button type="button" data-period="last_month" class="fchip">Letzter Monat</button>
|
||||||
</div>
|
</div>
|
||||||
|
<details class="stat-more">
|
||||||
|
<summary>Weitere Filter</summary>
|
||||||
<div class="stat-filters">
|
<div class="stat-filters">
|
||||||
<input type="date" id="since" title="Von" class="date-field">
|
<input type="date" id="since" title="Von" class="date-field">
|
||||||
<input type="date" id="until" title="Bis" class="date-field">
|
<input type="date" id="until" title="Bis" class="date-field">
|
||||||
<select id="host"><option value="">Alle Drucker</option></select>
|
<select id="host"><option value="">Alle Drucker</option></select>
|
||||||
|
<select id="project"><option value="">Alle Projekte</option></select>
|
||||||
<input type="text" id="material" placeholder="Sorte" size="8" autocomplete="off">
|
<input type="text" id="material" placeholder="Sorte" size="8" autocomplete="off">
|
||||||
<input type="text" id="brand" placeholder="Marke" size="8" autocomplete="off">
|
<input type="text" id="brand" placeholder="Marke" size="8" autocomplete="off">
|
||||||
<input type="text" id="color" placeholder="Farbe" size="8" autocomplete="off">
|
<input type="text" id="color" placeholder="Farbe" size="8" autocomplete="off">
|
||||||
</div>
|
</div>
|
||||||
|
</details>
|
||||||
</div>
|
</div>
|
||||||
<p id="stat-note"></p>
|
<p id="stat-note"></p>
|
||||||
<div id="stat" class="statistik"></div>
|
<div id="stat" class="statistik"></div>
|
||||||
@@ -231,17 +235,37 @@ function render(data) {
|
|||||||
</div>`;
|
</div>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function fillProjects() {
|
||||||
|
const select = document.getElementById("project");
|
||||||
|
if (!select || select.dataset.filled) return;
|
||||||
|
try {
|
||||||
|
const rows = await api("/projekte?status=");
|
||||||
|
const current = select.value;
|
||||||
|
rows.forEach((p) => {
|
||||||
|
const opt = document.createElement("option");
|
||||||
|
opt.value = p.id;
|
||||||
|
opt.textContent = p.name;
|
||||||
|
select.appendChild(opt);
|
||||||
|
});
|
||||||
|
select.dataset.filled = "1";
|
||||||
|
if ([...select.options].some((o) => o.value === current)) select.value = current;
|
||||||
|
} catch (error) { /* optional */ }
|
||||||
|
}
|
||||||
|
|
||||||
async function load() {
|
async function load() {
|
||||||
|
await fillProjects();
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
const since = document.getElementById("since").value;
|
const since = document.getElementById("since").value;
|
||||||
const until = document.getElementById("until").value;
|
const until = document.getElementById("until").value;
|
||||||
const host = document.getElementById("host").value;
|
const host = document.getElementById("host").value;
|
||||||
|
const project = document.getElementById("project").value;
|
||||||
const material = document.getElementById("material").value.trim();
|
const material = document.getElementById("material").value.trim();
|
||||||
const brand = document.getElementById("brand").value.trim();
|
const brand = document.getElementById("brand").value.trim();
|
||||||
const color = document.getElementById("color").value.trim();
|
const color = document.getElementById("color").value.trim();
|
||||||
if (since) params.set("since", since);
|
if (since) params.set("since", since);
|
||||||
if (until) params.set("until", until);
|
if (until) params.set("until", until);
|
||||||
if (host) params.set("host", host);
|
if (host) params.set("host", host);
|
||||||
|
if (project) params.set("project_id", project);
|
||||||
if (material) params.set("material", material);
|
if (material) params.set("material", material);
|
||||||
if (brand) params.set("brand", brand);
|
if (brand) params.set("brand", brand);
|
||||||
if (color) params.set("color", color);
|
if (color) params.set("color", color);
|
||||||
@@ -278,6 +302,7 @@ document.getElementById("period").addEventListener("click", (event) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
document.getElementById("host").addEventListener("change", scheduleLoad);
|
document.getElementById("host").addEventListener("change", scheduleLoad);
|
||||||
|
document.getElementById("project").addEventListener("change", scheduleLoad);
|
||||||
["material", "brand", "color"].forEach((id) => {
|
["material", "brand", "color"].forEach((id) => {
|
||||||
const node = document.getElementById(id);
|
const node = document.getElementById(id);
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
|
|||||||
+194
-3
@@ -49,6 +49,10 @@
|
|||||||
<div class="desk-facts" data-role="facts"></div>
|
<div class="desk-facts" data-role="facts"></div>
|
||||||
<div data-role="flow"></div>
|
<div data-role="flow"></div>
|
||||||
<div data-role="strips"></div>
|
<div data-role="strips"></div>
|
||||||
|
<div class="desk-next" data-role="next" hidden>
|
||||||
|
<div class="desk-next-head"><svg class="ico"><use href="#i-play"/></svg><span class="grow">Als Nächstes</span></div>
|
||||||
|
<div data-role="next-body"></div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="desk-foot">
|
<div class="desk-foot">
|
||||||
<div class="card-actions" data-role="controls"></div>
|
<div class="card-actions" data-role="controls"></div>
|
||||||
@@ -367,10 +371,15 @@ function stripsHtml(printer, state) {
|
|||||||
}
|
}
|
||||||
const filamentHint = state === "paused" ? filamentPauseHint(printer) : "";
|
const filamentHint = state === "paused" ? filamentPauseHint(printer) : "";
|
||||||
if (filamentHint) {
|
if (filamentHint) {
|
||||||
|
const slot = (printer.slots || []).find((s) => s && (s.empty || s.runout)) || (printer.slots || [])[0];
|
||||||
|
const slotN = slot && (slot.index != null ? Number(slot.index) + 1 : slot.slot);
|
||||||
|
const matHref = "/material?host=" + encodeURIComponent(printer.host || "")
|
||||||
|
+ (slotN ? "&slot=" + encodeURIComponent(slotN) : "");
|
||||||
|
const slotTxt = slotN ? "ACE Platz " + slotN + ": " : "";
|
||||||
bits.push(`<div class="strip warn filament-swap">
|
bits.push(`<div class="strip warn filament-swap">
|
||||||
<div class="strip-head">${icon("alert")}<span class="grow"><b>Neue Rolle in Material dem Drucker zuweisen</b></span></div>
|
<div class="strip-head">${icon("alert")}<span class="grow"><b>${slotTxt}Neue Rolle in Material zuweisen</b></span></div>
|
||||||
<span class="strip-msg">${escapeHtml(filamentHint)} — sonst zählt der Verbrauch weiter zur alten Spule. Ort = dieser Drucker, speichern, dann Weiter.</span>
|
<span class="strip-msg">${escapeHtml(filamentHint)} — 1) Rolle dem Drucker zuweisen, 2) speichern, 3) Weiter. Verbrauch bleibt dieselbe Charge.</span>
|
||||||
<div class="strip-actions"><a class="ghost" href="/material">Zu Material</a></div>
|
<div class="strip-actions"><a class="ghost" href="${matHref}">Zu Material</a></div>
|
||||||
</div>`);
|
</div>`);
|
||||||
}
|
}
|
||||||
const failed = !queueBusy && printer.queue_failed;
|
const failed = !queueBusy && printer.queue_failed;
|
||||||
@@ -1065,6 +1074,156 @@ function patchDesk(printer) {
|
|||||||
// Kamera nur über Timer aktualisieren — sonst doppelter Reload + Layout-Ruckler
|
// Kamera nur über Timer aktualisieren — sonst doppelter Reload + Layout-Ruckler
|
||||||
syncDeskViewer(printer).catch(() => {});
|
syncDeskViewer(printer).catch(() => {});
|
||||||
refreshDeskVerlauf(false);
|
refreshDeskVerlauf(false);
|
||||||
|
refreshDeskNext(printer, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
let deskNextAt = 0;
|
||||||
|
let deskNextHost = "";
|
||||||
|
let deskNextKey = "";
|
||||||
|
|
||||||
|
function deskCanOfferStart(printer, state) {
|
||||||
|
if (!printer) return false;
|
||||||
|
if (["printing", "paused", "heating", "offline", "error"].includes(state)) return false;
|
||||||
|
if (printer.queue_running || startingJob(printer)) return false;
|
||||||
|
if (needsClear(printer)) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function deskMaterialTypes(printer) {
|
||||||
|
const types = new Set();
|
||||||
|
(printer.spools || []).forEach((s) => {
|
||||||
|
if (s && s.material_type) types.add(String(s.material_type).toLowerCase());
|
||||||
|
});
|
||||||
|
(printer.ace_slots || printer.slots || []).forEach((s) => {
|
||||||
|
const t = (s && (s.type || s.material_type)) || "";
|
||||||
|
if (t) types.add(String(t).toLowerCase());
|
||||||
|
});
|
||||||
|
return types;
|
||||||
|
}
|
||||||
|
|
||||||
|
function fileMatchesPrinter(file, printer) {
|
||||||
|
if (!file) return false;
|
||||||
|
const family = printer.family || "";
|
||||||
|
if (file.printer_family && family && file.printer_family !== family) return false;
|
||||||
|
const types = deskMaterialTypes(printer);
|
||||||
|
if (!types.size) return true;
|
||||||
|
const mats = (file.filaments || []).map((f) => String(f.type || f.material_type || "").toLowerCase()).filter(Boolean);
|
||||||
|
if (!mats.length) return true;
|
||||||
|
return mats.some((m) => [...types].some((t) => t.includes(m) || m.includes(t)));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function refreshDeskNext(printer, state, force) {
|
||||||
|
const box = deskEl.querySelector('[data-role="next"]');
|
||||||
|
const body = deskEl.querySelector('[data-role="next-body"]');
|
||||||
|
if (!box || !body) return;
|
||||||
|
if (!deskCanOfferStart(printer, state)) {
|
||||||
|
box.hidden = true;
|
||||||
|
body.innerHTML = "";
|
||||||
|
deskNextKey = "";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const host = printer.host;
|
||||||
|
const key = host + "|" + (printer.queue_waiting || 0) + "|" + (printer.filename || "");
|
||||||
|
const now = Date.now();
|
||||||
|
if (!force && deskNextHost === host && deskNextKey === key && now - deskNextAt < 25000) {
|
||||||
|
box.hidden = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
deskNextAt = now;
|
||||||
|
deskNextHost = host;
|
||||||
|
deskNextKey = key;
|
||||||
|
box.hidden = false;
|
||||||
|
body.innerHTML = '<p class="tiny">Lade Vorschläge …</p>';
|
||||||
|
try {
|
||||||
|
const [last, queue, files] = await Promise.all([
|
||||||
|
api("/senden-zuletzt?host=" + encodeURIComponent(host)).catch(() => null),
|
||||||
|
api("/druck-queue?host=" + encodeURIComponent(host) + "&status=waiting&limit=5").catch(() => []),
|
||||||
|
api("/dateien?family=" + encodeURIComponent(printer.family || "") + "&limit=40").catch(() => []),
|
||||||
|
]);
|
||||||
|
if (deskHost !== host) return;
|
||||||
|
const bits = [];
|
||||||
|
if (last && last.file_id) {
|
||||||
|
const name = jobLabel(last.filename) || ("#" + last.file_id);
|
||||||
|
bits.push(`<div class="desk-next-row">
|
||||||
|
<div class="grow"><b>Nochmal</b><span class="tiny">${escapeHtml(name)}</span></div>
|
||||||
|
<button type="button" class="btn-primary tiny-btn" data-next-again="${last.file_id}">Start</button>
|
||||||
|
<a class="ghost tiny-btn" href="/dateien?host=${encodeURIComponent(host)}&file=${encodeURIComponent(last.file_id)}">Anpassen</a>
|
||||||
|
</div>`);
|
||||||
|
}
|
||||||
|
const waiting = (Array.isArray(queue) ? queue : []).filter((j) => j.status === "waiting");
|
||||||
|
if (waiting.length) {
|
||||||
|
const job = waiting[0];
|
||||||
|
bits.push(`<div class="desk-next-row">
|
||||||
|
<div class="grow"><b>Warteschlange</b><span class="tiny">${escapeHtml(jobLabel(job.filename) || "Job")}</span></div>
|
||||||
|
<a class="ghost tiny-btn" href="/warteschlange">Zur Queue</a>
|
||||||
|
</div>`);
|
||||||
|
}
|
||||||
|
const matched = (Array.isArray(files) ? files : [])
|
||||||
|
.filter((f) => fileMatchesPrinter(f, printer))
|
||||||
|
.slice(0, 5);
|
||||||
|
if (matched.length) {
|
||||||
|
bits.push('<div class="desk-next-files"><span class="tiny">Passende Dateien</span>' + matched.map((f) => {
|
||||||
|
const mats = [...new Set((f.filaments || []).map((x) => x.type || x.material_type).filter(Boolean))].join(" / ");
|
||||||
|
return `<div class="desk-next-row">
|
||||||
|
<div class="grow"><span>${escapeHtml(jobLabel(f.name) || f.name)}</span><span class="tiny">${escapeHtml(mats || "")}</span></div>
|
||||||
|
<button type="button" class="ghost tiny-btn" data-next-start="${f.id}">Start</button>
|
||||||
|
<a class="ghost tiny-btn" href="/dateien?host=${encodeURIComponent(host)}&file=${encodeURIComponent(f.id)}">Anpassen</a>
|
||||||
|
</div>`;
|
||||||
|
}).join("") + "</div>");
|
||||||
|
}
|
||||||
|
if (!bits.length) {
|
||||||
|
body.innerHTML = `<p class="tiny">Keine Vorschläge. <a href="/dateien?host=${encodeURIComponent(host)}">Datei wählen →</a></p>`;
|
||||||
|
} else {
|
||||||
|
body.innerHTML = bits.join("");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (deskHost !== host) return;
|
||||||
|
body.innerHTML = '<p class="tiny msg">' + escapeHtml(error.message || "Vorschläge fehlen") + "</p>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deskStartFile(fileId, fromLast) {
|
||||||
|
if (!deskHost || !fileId) return;
|
||||||
|
const host = deskHost;
|
||||||
|
let aceMap = [];
|
||||||
|
let bedLevel = false;
|
||||||
|
let spoolId = null;
|
||||||
|
try {
|
||||||
|
const last = await api(
|
||||||
|
"/senden-zuletzt?host=" + encodeURIComponent(host)
|
||||||
|
+ "&file_id=" + encodeURIComponent(fileId)
|
||||||
|
);
|
||||||
|
if (last) {
|
||||||
|
aceMap = last.ace_map || [];
|
||||||
|
bedLevel = !!last.bed_leveling;
|
||||||
|
spoolId = last.spool_id || null;
|
||||||
|
}
|
||||||
|
} catch (error) { /* Defaults */ }
|
||||||
|
if (fromLast && !aceMap.length) {
|
||||||
|
try {
|
||||||
|
const lastHost = await api("/senden-zuletzt?host=" + encodeURIComponent(host));
|
||||||
|
if (lastHost && String(lastHost.file_id) === String(fileId)) {
|
||||||
|
aceMap = lastHost.ace_map || [];
|
||||||
|
bedLevel = !!lastHost.bed_leveling;
|
||||||
|
spoolId = lastHost.spool_id || null;
|
||||||
|
}
|
||||||
|
} catch (error) { /* ignore */ }
|
||||||
|
}
|
||||||
|
const printer = printerCache.get(host);
|
||||||
|
const canNow = printer && deskCanOfferStart(printer, shownState(printer));
|
||||||
|
const payload = {
|
||||||
|
file_id: Number(fileId),
|
||||||
|
hosts: [host],
|
||||||
|
confirm: true,
|
||||||
|
when_free: !canNow,
|
||||||
|
bed_leveling: bedLevel,
|
||||||
|
};
|
||||||
|
if (spoolId) payload.spool_id = spoolId;
|
||||||
|
if (aceMap.length) payload.ace_maps = { [host]: aceMap };
|
||||||
|
await api("/senden", { method: "POST", json: payload });
|
||||||
|
toast(canNow ? "Druck startet…" : "In die Warteschlange.", "good");
|
||||||
|
deskNextAt = 0;
|
||||||
|
if (printer) refreshDeskNext(printer, shownState(printer), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function refreshDeskVerlauf(force) {
|
async function refreshDeskVerlauf(force) {
|
||||||
@@ -1102,8 +1261,12 @@ async function refreshDeskVerlauf(force) {
|
|||||||
kwh,
|
kwh,
|
||||||
].filter(Boolean);
|
].filter(Boolean);
|
||||||
if (caption) caption.textContent = bits.join(" · ");
|
if (caption) caption.textContent = bits.join(" · ");
|
||||||
|
const fileBit = run.file_id
|
||||||
|
? `<a class="ghost tiny-btn" href="/dateien?file=${encodeURIComponent(run.file_id)}">Datei</a>`
|
||||||
|
: "";
|
||||||
const head = `<div class="desk-verlauf-head">
|
const head = `<div class="desk-verlauf-head">
|
||||||
<span class="tiny grow">${escapeHtml(jobLabel(run.filename) || "Druck")}${run.chargen_nr ? " · " + escapeHtml(run.chargen_nr) : ""}</span>
|
<span class="tiny grow">${escapeHtml(jobLabel(run.filename) || "Druck")}${run.chargen_nr ? " · " + escapeHtml(run.chargen_nr) : ""}</span>
|
||||||
|
${fileBit}
|
||||||
<a class="ghost tiny-btn" href="/protokoll/${run.id}">Bericht →</a>
|
<a class="ghost tiny-btn" href="/protokoll/${run.id}">Bericht →</a>
|
||||||
</div>`;
|
</div>`;
|
||||||
const html = head + tempChartHtml(data.samples || []);
|
const html = head + tempChartHtml(data.samples || []);
|
||||||
@@ -1515,6 +1678,34 @@ window.addEventListener("keydown", (event) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
async function handleWallClick(event) {
|
async function handleWallClick(event) {
|
||||||
|
const nextAgain = event.target.closest("[data-next-again]");
|
||||||
|
if (nextAgain) {
|
||||||
|
armButton(nextAgain, "Nochmal starten?", async () => {
|
||||||
|
nextAgain.disabled = true;
|
||||||
|
try {
|
||||||
|
await deskStartFile(nextAgain.dataset.nextAgain, true);
|
||||||
|
} catch (error) {
|
||||||
|
toast(error.message || String(error), "bad");
|
||||||
|
} finally {
|
||||||
|
nextAgain.disabled = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const nextStart = event.target.closest("[data-next-start]");
|
||||||
|
if (nextStart) {
|
||||||
|
armButton(nextStart, "Starten?", async () => {
|
||||||
|
nextStart.disabled = true;
|
||||||
|
try {
|
||||||
|
await deskStartFile(nextStart.dataset.nextStart, false);
|
||||||
|
} catch (error) {
|
||||||
|
toast(error.message || String(error), "bad");
|
||||||
|
} finally {
|
||||||
|
nextStart.disabled = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
const pill = event.target.closest("[data-desk-host]");
|
const pill = event.target.closest("[data-desk-host]");
|
||||||
if (pill) {
|
if (pill) {
|
||||||
openDesk(pill.dataset.deskHost);
|
openDesk(pill.dataset.deskHost);
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ function render() {
|
|||||||
if (job.direct) {
|
if (job.direct) {
|
||||||
return `<tr data-direct="${escapeHtml(job.host)}">
|
return `<tr data-direct="${escapeHtml(job.host)}">
|
||||||
<td>${chipHtml("printing", "läuft")}</td>
|
<td>${chipHtml("printing", "läuft")}</td>
|
||||||
<td><span class="cell-file" title="${escapeHtml(job.filename || "")}">${escapeHtml(jobLabel(job.filename))}</span></td>
|
<td>${job.file_id ? `<a class="cell-file" href="/dateien?file=${encodeURIComponent(job.file_id)}" title="${escapeHtml(job.filename || "")}">${escapeHtml(jobLabel(job.filename))}</a>` : `<span class="cell-file" title="${escapeHtml(job.filename || "")}">${escapeHtml(jobLabel(job.filename))}</span>`}</td>
|
||||||
<td><a href="/#${encodeURIComponent(job.host)}">${escapeHtml(targetOf(job))}</a></td>
|
<td><a href="/#${encodeURIComponent(job.host)}">${escapeHtml(targetOf(job))}</a></td>
|
||||||
<td>—</td>
|
<td>—</td>
|
||||||
<td class="tiny">${escapeHtml(job.message || "")}</td>
|
<td class="tiny">${escapeHtml(job.message || "")}</td>
|
||||||
@@ -125,16 +125,24 @@ function render() {
|
|||||||
const rep = repeatText(job);
|
const rep = repeatText(job);
|
||||||
const tools = [];
|
const tools = [];
|
||||||
if (st === "waiting" && waitIdx > 0) {
|
if (st === "waiting" && waitIdx > 0) {
|
||||||
tools.push(`<button type="button" class="icon-btn" data-prio="${job.id}" data-dir="-1" title="Höher">${icon("up")}</button>`);
|
tools.push(`<button type="button" class="icon-btn" data-prio="${job.id}" data-dir="-1" title="Höher" aria-label="Höher">${icon("up")}</button>`);
|
||||||
}
|
}
|
||||||
if (st === "waiting" && waitIdx >= 0 && waitIdx < waiting.length - 1) {
|
if (st === "waiting" && waitIdx >= 0 && waitIdx < waiting.length - 1) {
|
||||||
tools.push(`<button type="button" class="icon-btn" data-prio="${job.id}" data-dir="1" title="Tiefer">${icon("down")}</button>`);
|
tools.push(`<button type="button" class="icon-btn" data-prio="${job.id}" data-dir="1" title="Tiefer" aria-label="Tiefer">${icon("down")}</button>`);
|
||||||
}
|
}
|
||||||
if (st === "error" && job.is_ablauf) {
|
if (st === "error" && job.is_ablauf) {
|
||||||
tools.push(`<button type="button" class="icon-btn" data-resume="${job.id}" title="Fortsetzen">${icon("play")}</button>`);
|
tools.push(`<button type="button" class="ghost tiny-btn with-label" data-resume="${job.id}" title="Fortsetzen" aria-label="Fortsetzen">${icon("play")}<span class="act-label">Fortsetzen</span></button>`);
|
||||||
tools.push(`<button type="button" class="icon-btn danger" data-dismiss="${job.id}" title="Verwerfen">${icon("x")}</button>`);
|
tools.push(`<button type="button" class="ghost tiny-btn with-label danger" data-dismiss="${job.id}" title="Verwerfen" aria-label="Verwerfen">${icon("x")}<span class="act-label">Verwerfen</span></button>`);
|
||||||
|
} else if (st === "error") {
|
||||||
|
if (job.host) {
|
||||||
|
tools.push(`<a class="ghost tiny-btn with-label" href="/#${encodeURIComponent(job.host)}" title="Zur Wand" aria-label="Zur Wand">${icon("printer")}<span class="act-label">Wand</span></a>`);
|
||||||
|
}
|
||||||
|
if (job.file_id) {
|
||||||
|
tools.push(`<button type="button" class="ghost tiny-btn with-label" data-requeue="${job.id}" title="Erneut einreihen" aria-label="Erneut einreihen">${icon("refresh")}<span class="act-label">Nochmal</span></button>`);
|
||||||
|
}
|
||||||
|
tools.push(`<button type="button" class="ghost tiny-btn with-label danger" data-dismiss="${job.id}" title="Verwerfen" aria-label="Verwerfen">${icon("x")}<span class="act-label">Verwerfen</span></button>`);
|
||||||
} else if (st === "waiting" || st === "running") {
|
} else if (st === "waiting" || st === "running") {
|
||||||
tools.push(`<button type="button" class="icon-btn danger" data-cancel="${job.id}" title="Abbrechen">${icon("x")}</button>`);
|
tools.push(`<button type="button" class="ghost tiny-btn with-label danger" data-cancel="${job.id}" title="Abbrechen" aria-label="Abbrechen">${icon("x")}<span class="act-label">Abbrechen</span></button>`);
|
||||||
}
|
}
|
||||||
const phase = String(job.phase || "").toLowerCase();
|
const phase = String(job.phase || "").toLowerCase();
|
||||||
const starting = st === "running" && (phase === "starting" || phase === "await_print");
|
const starting = st === "running" && (phase === "starting" || phase === "await_print");
|
||||||
@@ -142,7 +150,7 @@ function render() {
|
|||||||
const chipLabel = starting ? "startet" : (STATUS_LABEL[st] || st);
|
const chipLabel = starting ? "startet" : (STATUS_LABEL[st] || st);
|
||||||
return `<tr data-id="${job.id}">
|
return `<tr data-id="${job.id}">
|
||||||
<td>${chipHtml(chipState, chipLabel)}</td>
|
<td>${chipHtml(chipState, chipLabel)}</td>
|
||||||
<td><span class="cell-file" title="${escapeHtml(job.filename || "")}">${escapeHtml(jobLabel(job.filename))}</span>${rep ? " · " + escapeHtml(rep) : ""}</td>
|
<td>${job.file_id ? `<a class="cell-file" href="/dateien?file=${encodeURIComponent(job.file_id)}" title="${escapeHtml(job.filename || "")}">${escapeHtml(jobLabel(job.filename))}</a>` : `<span class="cell-file" title="${escapeHtml(job.filename || "")}">${escapeHtml(jobLabel(job.filename))}</span>`}${rep ? " · " + escapeHtml(rep) : ""}</td>
|
||||||
<td>${job.host ? `<a href="/#${encodeURIComponent(job.host)}">${escapeHtml(targetOf(job))}</a>` : escapeHtml(targetOf(job))}</td>
|
<td>${job.host ? `<a href="/#${encodeURIComponent(job.host)}">${escapeHtml(targetOf(job))}</a>` : escapeHtml(targetOf(job))}</td>
|
||||||
<td>${steps || "—"}</td>
|
<td>${steps || "—"}</td>
|
||||||
<td class="tiny">${escapeHtml(job.message || "")}</td>
|
<td class="tiny">${escapeHtml(job.message || "")}</td>
|
||||||
@@ -217,6 +225,38 @@ document.getElementById("q-rows").addEventListener("click", async (event) => {
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const requeue = event.target.closest("[data-requeue]");
|
||||||
|
if (requeue) {
|
||||||
|
const job = jobs.find((j) => j.id === Number(requeue.dataset.requeue));
|
||||||
|
if (!job || !job.file_id) return;
|
||||||
|
armButton(requeue, "Erneut einreihen?", async () => {
|
||||||
|
try {
|
||||||
|
await api("/druck-queue/" + job.id, {
|
||||||
|
method: "PATCH", json: { status: "waiting", undo: true },
|
||||||
|
});
|
||||||
|
toast("Wieder in der Warteschlange.");
|
||||||
|
load();
|
||||||
|
if (typeof refreshPrintQueue === "function") refreshPrintQueue();
|
||||||
|
} catch (error) {
|
||||||
|
try {
|
||||||
|
await api("/senden", {
|
||||||
|
method: "POST",
|
||||||
|
json: {
|
||||||
|
file_id: job.file_id,
|
||||||
|
hosts: job.host ? [job.host] : [],
|
||||||
|
confirm: true,
|
||||||
|
when_free: true,
|
||||||
|
ace_maps: job.host && (job.ace_map || []).length ? { [job.host]: job.ace_map } : {},
|
||||||
|
bed_leveling: !!job.bed_leveling,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
toast("Erneut eingereiht.");
|
||||||
|
load();
|
||||||
|
} catch (err2) { toast(err2.message, "bad"); }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
const prio = event.target.closest("[data-prio]");
|
const prio = event.target.closest("[data-prio]");
|
||||||
if (prio) {
|
if (prio) {
|
||||||
const id = Number(prio.dataset.prio);
|
const id = Number(prio.dataset.prio);
|
||||||
|
|||||||
Reference in new issue
Block a user