**Änderungen:** - ✅ app.py: Hinzugefügt, um CSRF-Fehler zu behandeln - ✅ models.py: Fehlerprotokollierung bei der Suche nach Gastanfragen per OTP - ✅ api.py: Fehlerprotokollierung beim Markieren von Benachrichtigungen als gelesen - ✅ calendar.py: Fallback-Daten zurückgeben, wenn keine Kalenderereignisse vorhanden sind - ✅ guest.py: Status-Check-Seite für Gäste aktualisiert - ✅ hardware_integration.py: Debugging-Informationen für erweiterte Geräteinformationen hinzugefügt - ✅ tapo_status_manager.py: Rückgabewert für Statusabfrage hinzugefügt **Ergebnis:** - Verbesserte Fehlerbehandlung und Protokollierung für eine robustere Anwendung - Bessere Nachverfolgbarkeit von Fehlern und Systemverhalten 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
590 lines
26 KiB
HTML
590 lines
26 KiB
HTML
{% extends "base.html" %}
|
|
|
|
{% block title %}Druckanträge Übersicht - Mercedes-Benz MYP Platform{% endblock %}
|
|
|
|
{% block head %}
|
|
{{ super() }}
|
|
<style>
|
|
/* Code-Eingabe Styling */
|
|
.code-input-container {
|
|
background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
|
|
border: 2px solid #10b981;
|
|
border-radius: 12px;
|
|
padding: 20px;
|
|
margin-top: 16px;
|
|
box-shadow: 0 4px 6px -1px rgba(16, 185, 129, 0.1);
|
|
}
|
|
|
|
.dark .code-input-container {
|
|
background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
|
|
border-color: #10b981;
|
|
}
|
|
|
|
.code-input {
|
|
font-family: 'Courier New', monospace;
|
|
font-size: 24px;
|
|
font-weight: bold;
|
|
text-align: center;
|
|
letter-spacing: 8px;
|
|
padding: 16px;
|
|
border: 2px solid #d1d5db;
|
|
border-radius: 8px;
|
|
background: white;
|
|
color: #1f2937;
|
|
transition: all 0.3s ease;
|
|
text-transform: uppercase;
|
|
}
|
|
|
|
.dark .code-input {
|
|
background: #374151;
|
|
color: #f9fafb;
|
|
border-color: #4b5563;
|
|
}
|
|
|
|
.code-input:focus {
|
|
outline: none;
|
|
border-color: #10b981;
|
|
box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
|
|
transform: scale(1.02);
|
|
}
|
|
|
|
.start-job-btn {
|
|
background: linear-gradient(135deg, #10b981 0%, #059669 100%);
|
|
color: white;
|
|
border: none;
|
|
padding: 12px 24px;
|
|
border-radius: 8px;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
transition: all 0.3s ease;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
justify-content: center;
|
|
min-width: 140px;
|
|
}
|
|
|
|
.start-job-btn:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 8px 25px rgba(16, 185, 129, 0.3);
|
|
}
|
|
|
|
.start-job-btn:disabled {
|
|
background: #9ca3af;
|
|
cursor: not-allowed;
|
|
transform: none;
|
|
box-shadow: none;
|
|
}
|
|
|
|
.start-job-btn .spinner {
|
|
width: 16px;
|
|
height: 16px;
|
|
border: 2px solid #ffffff;
|
|
border-top: 2px solid transparent;
|
|
border-radius: 50%;
|
|
animation: spin 1s linear infinite;
|
|
}
|
|
|
|
@keyframes spin {
|
|
0% { transform: rotate(0deg); }
|
|
100% { transform: rotate(360deg); }
|
|
}
|
|
|
|
.success-message {
|
|
background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
|
|
border: 2px solid #10b981;
|
|
color: #065f46;
|
|
padding: 16px;
|
|
border-radius: 8px;
|
|
margin-top: 12px;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 12px;
|
|
}
|
|
|
|
.dark .success-message {
|
|
background: linear-gradient(135deg, #064e3b 0%, #065f46 100%);
|
|
color: #a7f3d0;
|
|
}
|
|
|
|
.error-message {
|
|
background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
|
|
border: 2px solid #ef4444;
|
|
color: #991b1b;
|
|
padding: 16px;
|
|
border-radius: 8px;
|
|
margin-top: 12px;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 12px;
|
|
}
|
|
|
|
.dark .error-message {
|
|
background: linear-gradient(135deg, #7f1d1d 0%, #991b1b 100%);
|
|
color: #fecaca;
|
|
}
|
|
|
|
.pulse-animation {
|
|
animation: pulse 2s infinite;
|
|
}
|
|
|
|
@keyframes pulse {
|
|
0%, 100% { opacity: 1; }
|
|
50% { opacity: 0.7; }
|
|
}
|
|
</style>
|
|
{% endblock %}
|
|
|
|
{% block content %}
|
|
<div class="space-y-8">
|
|
<!-- Page Header -->
|
|
<div class="dashboard-card p-6">
|
|
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-6">
|
|
<div class="flex items-center gap-4">
|
|
<div class="w-12 h-12 flex-shrink-0">
|
|
<svg class="w-full h-full text-slate-900 dark:text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
|
|
</svg>
|
|
</div>
|
|
<div>
|
|
<h1 class="text-3xl font-bold text-slate-900 dark:text-white tracking-tight">Anträge Übersicht</h1>
|
|
<p class="text-slate-500 dark:text-slate-400 mt-1">Transparente Übersicht aller eingereichten Druckanträge</p>
|
|
</div>
|
|
</div>
|
|
<div class="flex flex-wrap gap-3">
|
|
<a href="{{ url_for('guest.guest_request_form') }}"
|
|
class="btn-primary flex items-center gap-2">
|
|
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6"/>
|
|
</svg>
|
|
<span>Neuen Antrag stellen</span>
|
|
</a>
|
|
<button onclick="location.reload()"
|
|
class="btn-secondary flex items-center gap-2">
|
|
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/>
|
|
</svg>
|
|
<span>Aktualisieren</span>
|
|
</button>
|
|
<a href="{{ url_for('index') }}"
|
|
class="btn-secondary flex items-center gap-2">
|
|
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"/>
|
|
</svg>
|
|
<span>Startseite</span>
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Info Banner -->
|
|
<div class="dashboard-card p-6">
|
|
<div class="flex items-start gap-4">
|
|
<div class="w-12 h-12 bg-blue-100 dark:bg-blue-900/30 rounded-xl flex items-center justify-center flex-shrink-0">
|
|
<svg class="h-6 w-6 text-blue-600 dark:text-blue-400" fill="currentColor" viewBox="0 0 20 20">
|
|
<path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd"></path>
|
|
</svg>
|
|
</div>
|
|
<div class="flex-1">
|
|
<h3 class="text-lg font-semibold text-slate-900 dark:text-white mb-2">
|
|
Datenschutz & Transparenz
|
|
</h3>
|
|
<p class="text-slate-600 dark:text-slate-400 mb-4">
|
|
Diese Übersicht zeigt alle eingereichten Druckanträge in anonymisierter Form. Persönliche Daten sind durch "***" zensiert, um die Privatsphäre zu schützen und gleichzeitig Transparenz über den Bearbeitungsstand zu gewährleisten.
|
|
</p>
|
|
<div class="flex flex-wrap gap-2">
|
|
<span class="inline-flex items-center px-3 py-1 rounded-full text-xs font-medium bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-400">
|
|
Datenkonform
|
|
</span>
|
|
<span class="inline-flex items-center px-3 py-1 rounded-full text-xs font-medium bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400">
|
|
Anonymisiert
|
|
</span>
|
|
<span class="inline-flex items-center px-3 py-1 rounded-full text-xs font-medium bg-purple-100 text-purple-800 dark:bg-purple-900/30 dark:text-purple-400">
|
|
Transparent
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Statistics Cards -->
|
|
<div class="grid grid-cols-1 md:grid-cols-4 gap-6">
|
|
{% set total_requests = requests|length %}
|
|
{% set pending_requests = requests|selectattr("status", "equalto", "pending")|list|length %}
|
|
{% set approved_requests = requests|selectattr("status", "equalto", "approved")|list|length %}
|
|
{% set denied_requests = requests|selectattr("status", "equalto", "denied")|list|length %}
|
|
|
|
<div class="dashboard-card p-6">
|
|
<div class="flex justify-between">
|
|
<div>
|
|
<h3 class="stat-label">Gesamt</h3>
|
|
<div class="stat-value">{{ total_requests }}</div>
|
|
</div>
|
|
<div class="mb-stat-icon text-slate-600 dark:text-slate-400">
|
|
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
|
|
</svg>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="dashboard-card p-6">
|
|
<div class="flex justify-between">
|
|
<div>
|
|
<h3 class="stat-label">Prüfung</h3>
|
|
<div class="stat-value text-yellow-600 dark:text-yellow-400">{{ pending_requests }}</div>
|
|
</div>
|
|
<div class="mb-stat-icon text-yellow-600 dark:text-yellow-400">
|
|
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"/>
|
|
</svg>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="dashboard-card p-6">
|
|
<div class="flex justify-between">
|
|
<div>
|
|
<h3 class="stat-label">Genehmigt</h3>
|
|
<div class="stat-value text-green-600 dark:text-green-400">{{ approved_requests }}</div>
|
|
</div>
|
|
<div class="mb-stat-icon text-green-600 dark:text-green-400">
|
|
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/>
|
|
</svg>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="dashboard-card p-6">
|
|
<div class="flex justify-between">
|
|
<div>
|
|
<h3 class="stat-label">Abgelehnt</h3>
|
|
<div class="stat-value text-red-600 dark:text-red-400">{{ denied_requests }}</div>
|
|
</div>
|
|
<div class="mb-stat-icon text-red-600 dark:text-red-400">
|
|
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
|
|
</svg>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Requests List -->
|
|
{% if error %}
|
|
<div class="dashboard-card p-8 text-center">
|
|
<div class="text-red-500 dark:text-red-400 mb-4">
|
|
<svg class="w-12 h-12 mx-auto mb-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
|
|
</svg>
|
|
</div>
|
|
<h3 class="text-lg font-semibold text-slate-900 dark:text-white mb-2">Fehler beim Laden</h3>
|
|
<p class="text-slate-500 dark:text-slate-400">{{ error }}</p>
|
|
</div>
|
|
{% elif requests|length == 0 %}
|
|
<div class="dashboard-card p-8 text-center">
|
|
<div class="text-slate-400 dark:text-slate-500 mb-4">
|
|
<svg class="w-12 h-12 mx-auto mb-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
|
|
</svg>
|
|
</div>
|
|
<h3 class="text-lg font-semibold text-slate-900 dark:text-white mb-2">Keine Druckanträge</h3>
|
|
<p class="text-slate-500 dark:text-slate-400 mb-4">
|
|
Derzeit sind keine Druckanträge vorhanden.
|
|
</p>
|
|
<a href="{{ url_for('guest.guest_request_form') }}"
|
|
class="btn-primary">
|
|
Ersten Antrag stellen
|
|
</a>
|
|
</div>
|
|
{% else %}
|
|
<div class="space-y-4">
|
|
{% for request in requests %}
|
|
<div class="dashboard-card p-6 border-l-4 {% if request.status == 'pending' %}border-yellow-400{% elif request.status == 'approved' %}border-green-400{% elif request.status == 'denied' %}border-red-400{% endif %}">
|
|
<div class="flex flex-col lg:flex-row lg:items-center lg:justify-between gap-4">
|
|
|
|
<!-- Left Section: Request Info -->
|
|
<div class="flex-1">
|
|
<div class="flex items-center gap-4 mb-4">
|
|
<span class="text-lg font-bold text-slate-900 dark:text-white">
|
|
#{{ request.id }}
|
|
</span>
|
|
<span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium {% if request.status == 'pending' %}bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-400{% elif request.status == 'approved' %}bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400{% elif request.status == 'denied' %}bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400{% endif %}">
|
|
{% if request.status == 'pending' %}
|
|
Wird geprüft
|
|
{% elif request.status == 'approved' %}
|
|
Genehmigt
|
|
{% elif request.status == 'denied' %}
|
|
Abgelehnt
|
|
{% endif %}
|
|
</span>
|
|
{% if request.job_status %}
|
|
<span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-purple-100 text-purple-800 dark:bg-purple-900/30 dark:text-purple-400">
|
|
Druckstatus: {{ request.job_status|title }}
|
|
</span>
|
|
{% endif %}
|
|
</div>
|
|
|
|
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 text-sm">
|
|
<div class="bg-gray-50 dark:bg-slate-700/30 p-3 rounded-lg">
|
|
<div class="text-slate-500 dark:text-slate-400 font-medium mb-1">Antragsteller</div>
|
|
<div class="font-mono text-slate-600 dark:text-slate-300">{{ request.name }}</div>
|
|
</div>
|
|
<div class="bg-gray-50 dark:bg-slate-700/30 p-3 rounded-lg">
|
|
<div class="text-slate-500 dark:text-slate-400 font-medium mb-1">E-Mail</div>
|
|
<div class="font-mono text-slate-600 dark:text-slate-300">{{ request.email }}</div>
|
|
</div>
|
|
<div class="bg-gray-50 dark:bg-slate-700/30 p-3 rounded-lg">
|
|
<div class="text-slate-500 dark:text-slate-400 font-medium mb-1">Drucker</div>
|
|
<div class="text-slate-600 dark:text-slate-300">{{ request.printer_name if request.printer_name else 'Automatisch' }}</div>
|
|
</div>
|
|
<div class="bg-gray-50 dark:bg-slate-700/30 p-3 rounded-lg">
|
|
<div class="text-slate-500 dark:text-slate-400 font-medium mb-1">Dauer</div>
|
|
<div class="text-slate-600 dark:text-slate-300">{{ request.duration_min }} Min</div>
|
|
</div>
|
|
</div>
|
|
|
|
{% if request.reason %}
|
|
<div class="mt-4 bg-gray-50 dark:bg-slate-700/30 p-3 rounded-lg">
|
|
<div class="text-slate-500 dark:text-slate-400 font-medium mb-2">Projektbeschreibung</div>
|
|
<div class="font-mono text-sm text-slate-600 dark:text-slate-300">{{ request.reason }}</div>
|
|
</div>
|
|
{% endif %}
|
|
|
|
<!-- Code-Eingabe für genehmigte Aufträge -->
|
|
{% if request.status == 'approved' %}
|
|
<div class="code-input-container" id="code-container-{{ request.id }}">
|
|
<div class="flex items-center gap-3 mb-4">
|
|
<div class="w-8 h-8 bg-green-100 dark:bg-green-900/30 rounded-full flex items-center justify-center">
|
|
<svg class="w-5 h-5 text-green-600 dark:text-green-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 7a2 2 0 012 2m0 0a2 2 0 012 2m-2-2a2 2 0 00-2 2m0 0a2 2 0 01-2 2m2-2V9a2 2 0 00-2-2m0 0V7a2 2 0 00-2-2"/>
|
|
</svg>
|
|
</div>
|
|
<div>
|
|
<h4 class="font-semibold text-slate-900 dark:text-white">Auftrag starten</h4>
|
|
<p class="text-sm text-slate-600 dark:text-slate-400">Geben Sie Ihren 6-stelligen Startcode ein</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="flex flex-col sm:flex-row gap-4 items-end">
|
|
<div class="flex-1">
|
|
<label for="code-input-{{ request.id }}" class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-2">
|
|
Startcode (6 Zeichen)
|
|
</label>
|
|
<input type="text"
|
|
id="code-input-{{ request.id }}"
|
|
class="code-input w-full"
|
|
placeholder="ABC123"
|
|
maxlength="6"
|
|
autocomplete="off"
|
|
data-request-id="{{ request.id }}">
|
|
</div>
|
|
<button type="button"
|
|
class="start-job-btn"
|
|
onclick="startJobWithCode({{ request.id }})"
|
|
id="start-btn-{{ request.id }}">
|
|
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14.828 14.828a4 4 0 01-5.656 0M9 10h1m4 0h1m-6 4h8m-9-4V8a3 3 0 016 0v2M7 16a3 3 0 003 3h4a3 3 0 003-3v-8a3 3 0 00-3-3H10a3 3 0 00-3 3v8z"/>
|
|
</svg>
|
|
<span>Starten</span>
|
|
</button>
|
|
</div>
|
|
|
|
<!-- Nachrichten-Container -->
|
|
<div id="message-container-{{ request.id }}" class="mt-4" style="display: none;"></div>
|
|
</div>
|
|
{% endif %}
|
|
</div>
|
|
|
|
<!-- Right Section: Timestamp and Actions -->
|
|
<div class="lg:text-right">
|
|
<div class="bg-gray-50 dark:bg-slate-700/30 p-4 rounded-lg text-center lg:text-right">
|
|
<div class="text-sm font-medium text-slate-900 dark:text-white mb-1">
|
|
{{ request.created_at.strftime('%d.%m.%Y') }}
|
|
</div>
|
|
<div class="text-xs text-slate-500 dark:text-slate-400">
|
|
{{ request.created_at.strftime('%H:%M') }} Uhr
|
|
</div>
|
|
|
|
{% if request.status == 'approved' %}
|
|
<div class="mt-3">
|
|
<span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400 pulse-animation">
|
|
✨ Startbereit
|
|
</span>
|
|
</div>
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endfor %}
|
|
</div>
|
|
{% endif %}
|
|
</div>
|
|
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
// Live-Zeitanzeige im Browser-Tab
|
|
function updateTabTitle() {
|
|
const now = new Date();
|
|
const timeString = now.toLocaleTimeString('de-DE');
|
|
document.title = 'Druckanträge (' + timeString + ') - Mercedes-Benz MYP Platform';
|
|
}
|
|
|
|
updateTabTitle();
|
|
setInterval(updateTabTitle, 1000);
|
|
|
|
// Auto-Refresh alle 30 Sekunden
|
|
setInterval(function() {
|
|
if (!document.hidden) {
|
|
window.location.reload();
|
|
}
|
|
}, 30000);
|
|
|
|
// Code-Eingabe Event-Listener
|
|
document.querySelectorAll('.code-input').forEach(input => {
|
|
input.addEventListener('input', function(e) {
|
|
// Nur Buchstaben und Zahlen erlauben, automatisch in Großbuchstaben umwandeln
|
|
this.value = this.value.replace(/[^A-Za-z0-9]/g, '').toUpperCase();
|
|
|
|
// Automatisch starten wenn 6 Zeichen erreicht
|
|
if (this.value.length === 6) {
|
|
const requestId = this.getAttribute('data-request-id');
|
|
setTimeout(() => startJobWithCode(parseInt(requestId)), 100);
|
|
}
|
|
});
|
|
|
|
input.addEventListener('keypress', function(e) {
|
|
if (e.key === 'Enter' && this.value.length === 6) {
|
|
const requestId = this.getAttribute('data-request-id');
|
|
startJobWithCode(parseInt(requestId));
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
/**
|
|
* Startet einen Job mit dem eingegebenen 6-stelligen Code
|
|
*/
|
|
async function startJobWithCode(requestId) {
|
|
const codeInput = document.getElementById(`code-input-${requestId}`);
|
|
const startBtn = document.getElementById(`start-btn-${requestId}`);
|
|
const messageContainer = document.getElementById(`message-container-${requestId}`);
|
|
|
|
const code = codeInput.value.trim().toUpperCase();
|
|
|
|
// Validierung
|
|
if (!code || code.length !== 6) {
|
|
showMessage(messageContainer, 'error', 'Bitte geben Sie einen 6-stelligen Code ein.');
|
|
codeInput.focus();
|
|
return;
|
|
}
|
|
|
|
// Button deaktivieren und Loading-Zustand anzeigen
|
|
startBtn.disabled = true;
|
|
startBtn.innerHTML = `
|
|
<div class="spinner"></div>
|
|
<span>Wird gestartet...</span>
|
|
`;
|
|
|
|
try {
|
|
const response = await fetch('/api/guest/start-job', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({ code: code })
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (data.success) {
|
|
// Erfolg anzeigen
|
|
showMessage(messageContainer, 'success', `
|
|
<div>
|
|
<div class="font-semibold">Job erfolgreich gestartet! 🎉</div>
|
|
<div class="text-sm mt-1">
|
|
<strong>${data.job_name}</strong> läuft auf <strong>${data.printer_name}</strong><br>
|
|
Startzeit: ${data.start_time} Uhr | Endzeit: ${data.end_time} Uhr<br>
|
|
Dauer: ${data.duration_minutes} Minuten
|
|
</div>
|
|
</div>
|
|
`);
|
|
|
|
// Code-Eingabe ausblenden und Button permanent deaktivieren
|
|
codeInput.disabled = true;
|
|
codeInput.style.opacity = '0.5';
|
|
startBtn.innerHTML = `
|
|
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/>
|
|
</svg>
|
|
<span>Gestartet</span>
|
|
`;
|
|
startBtn.style.background = '#6b7280';
|
|
|
|
// Nach 3 Sekunden Seite neu laden
|
|
setTimeout(() => {
|
|
window.location.reload();
|
|
}, 3000);
|
|
|
|
} else {
|
|
// Fehler anzeigen
|
|
showMessage(messageContainer, 'error', data.error || 'Unbekannter Fehler beim Starten des Jobs.');
|
|
|
|
// Button wieder aktivieren
|
|
startBtn.disabled = false;
|
|
startBtn.innerHTML = `
|
|
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14.828 14.828a4 4 0 01-5.656 0M9 10h1m4 0h1m-6 4h8m-9-4V8a3 3 0 616 0v2M7 16a3 3 0 003 3h4a3 3 0 003-3v-8a3 3 0 00-3-3H10a3 3 0 00-3 3v8z"/>
|
|
</svg>
|
|
<span>Starten</span>
|
|
`;
|
|
|
|
// Code-Eingabe fokussieren
|
|
codeInput.focus();
|
|
codeInput.select();
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error('Fehler beim Starten des Jobs:', error);
|
|
showMessage(messageContainer, 'error', 'Netzwerkfehler. Bitte versuchen Sie es erneut.');
|
|
|
|
// Button wieder aktivieren
|
|
startBtn.disabled = false;
|
|
startBtn.innerHTML = `
|
|
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14.828 14.828a4 4 0 01-5.656 0M9 10h1m4 0h1m-6 4h8m-9-4V8a3 3 0 616 0v2M7 16a3 3 0 003 3h4a3 3 0 003-3v-8a3 3 0 00-3-3H10a3 3 0 00-3 3v8z"/>
|
|
</svg>
|
|
<span>Starten</span>
|
|
`;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Zeigt eine Nachricht im angegebenen Container an
|
|
*/
|
|
function showMessage(container, type, message) {
|
|
const className = type === 'success' ? 'success-message' : 'error-message';
|
|
const icon = type === 'success' ?
|
|
`<svg class="w-6 h-6 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
|
|
</svg>` :
|
|
`<svg class="w-6 h-6 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
|
|
</svg>`;
|
|
|
|
container.innerHTML = `
|
|
<div class="${className}">
|
|
${icon}
|
|
<div class="flex-1">${message}</div>
|
|
</div>
|
|
`;
|
|
container.style.display = 'block';
|
|
|
|
// Bei Fehlern nach 10 Sekunden ausblenden
|
|
if (type === 'error') {
|
|
setTimeout(() => {
|
|
container.style.display = 'none';
|
|
}, 10000);
|
|
}
|
|
}
|
|
</script>
|
|
{% endblock %} |