🔧 Update: Enhanced error handling and logging across various modules
**Ä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>
This commit is contained in:
@ -4,6 +4,135 @@
|
||||
|
||||
{% 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 %}
|
||||
@ -219,6 +348,50 @@
|
||||
<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 -->
|
||||
@ -233,8 +406,8 @@
|
||||
|
||||
{% 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">
|
||||
Startbereit
|
||||
<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 %}
|
||||
@ -253,7 +426,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
function updateTabTitle() {
|
||||
const now = new Date();
|
||||
const timeString = now.toLocaleTimeString('de-DE');
|
||||
document.title = `Druckanträge (${timeString}) - Mercedes-Benz MYP Platform`;
|
||||
document.title = 'Druckanträge (' + timeString + ') - Mercedes-Benz MYP Platform';
|
||||
}
|
||||
|
||||
updateTabTitle();
|
||||
@ -265,6 +438,153 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
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 %}
|
Reference in New Issue
Block a user