📝 🎉 Improved session management system with new backup database and enhanced logs 🌐
This commit is contained in:
@ -38,7 +38,7 @@
|
||||
|
||||
<!-- Formular -->
|
||||
<div class="form-container rounded-lg p-6">
|
||||
<form action="{{ url_for('admin.create_printer_api') }}" method="POST" class="space-y-6">
|
||||
<form id="printerForm" class="space-y-6">
|
||||
<!-- CSRF Token -->
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
|
||||
|
||||
@ -52,34 +52,20 @@
|
||||
name="name"
|
||||
required
|
||||
class="w-full px-3 py-2 border border-slate-300 dark:border-slate-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent bg-white dark:bg-slate-800 text-slate-900 dark:text-white"
|
||||
placeholder="3D-Drucker Raum A001">
|
||||
</div>
|
||||
|
||||
<!-- IP-Adresse -->
|
||||
<div>
|
||||
<label for="ip_address" class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-2">
|
||||
<i class="fas fa-network-wired mr-2"></i>IP-Adresse *
|
||||
</label>
|
||||
<input type="text"
|
||||
id="ip_address"
|
||||
name="ip_address"
|
||||
required
|
||||
pattern="^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
|
||||
class="w-full px-3 py-2 border border-slate-300 dark:border-slate-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent bg-white dark:bg-slate-800 text-slate-900 dark:text-white"
|
||||
placeholder="192.168.1.100">
|
||||
<p class="text-sm text-slate-500 dark:text-slate-400 mt-1">IP-Adresse der Tapo-Steckdose</p>
|
||||
placeholder="z.B. Prusa MK3S+ Raum 101">
|
||||
</div>
|
||||
|
||||
<!-- Modell -->
|
||||
<div>
|
||||
<label for="model" class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-2">
|
||||
<i class="fas fa-cogs mr-2"></i>Drucker-Modell
|
||||
<i class="fas fa-cogs mr-2"></i>Drucker-Modell *
|
||||
</label>
|
||||
<input type="text"
|
||||
id="model"
|
||||
name="model"
|
||||
required
|
||||
class="w-full px-3 py-2 border border-slate-300 dark:border-slate-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent bg-white dark:bg-slate-800 text-slate-900 dark:text-white"
|
||||
placeholder="Ender 3 V2">
|
||||
placeholder="z.B. Prusa i3 MK3S+">
|
||||
</div>
|
||||
|
||||
<!-- Standort -->
|
||||
@ -91,33 +77,77 @@
|
||||
id="location"
|
||||
name="location"
|
||||
class="w-full px-3 py-2 border border-slate-300 dark:border-slate-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent bg-white dark:bg-slate-800 text-slate-900 dark:text-white"
|
||||
placeholder="Raum A001, Erdgeschoss">
|
||||
placeholder="z.B. Werkstatt Erdgeschoss">
|
||||
</div>
|
||||
|
||||
<!-- Beschreibung -->
|
||||
<!-- Steckdosen-Konfiguration -->
|
||||
<div class="bg-slate-50 dark:bg-slate-900/50 rounded-lg p-4 space-y-4">
|
||||
<h3 class="text-lg font-semibold text-slate-800 dark:text-white">
|
||||
<i class="fas fa-plug mr-2"></i>Tapo Smart-Plug Konfiguration (optional)
|
||||
</h3>
|
||||
|
||||
<!-- Plug IP -->
|
||||
<div>
|
||||
<label for="plug_ip" class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-2">
|
||||
IP-Adresse der Steckdose
|
||||
</label>
|
||||
<input type="text"
|
||||
id="plug_ip"
|
||||
name="plug_ip"
|
||||
pattern="^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
|
||||
class="w-full px-3 py-2 border border-slate-300 dark:border-slate-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent bg-white dark:bg-slate-800 text-slate-900 dark:text-white"
|
||||
placeholder="192.168.1.100">
|
||||
</div>
|
||||
|
||||
<!-- Plug Username -->
|
||||
<div>
|
||||
<label for="plug_username" class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-2">
|
||||
Tapo Benutzername
|
||||
</label>
|
||||
<input type="text"
|
||||
id="plug_username"
|
||||
name="plug_username"
|
||||
class="w-full px-3 py-2 border border-slate-300 dark:border-slate-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent bg-white dark:bg-slate-800 text-slate-900 dark:text-white"
|
||||
placeholder="TP-Link Konto E-Mail">
|
||||
</div>
|
||||
|
||||
<!-- Plug Password -->
|
||||
<div>
|
||||
<label for="plug_password" class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-2">
|
||||
Tapo Passwort
|
||||
</label>
|
||||
<input type="password"
|
||||
id="plug_password"
|
||||
name="plug_password"
|
||||
class="w-full px-3 py-2 border border-slate-300 dark:border-slate-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent bg-white dark:bg-slate-800 text-slate-900 dark:text-white"
|
||||
placeholder="TP-Link Konto Passwort">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Drucker IP (optional) -->
|
||||
<div>
|
||||
<label for="description" class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-2">
|
||||
<i class="fas fa-comment mr-2"></i>Beschreibung
|
||||
<label for="ip_address" class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-2">
|
||||
<i class="fas fa-network-wired mr-2"></i>Drucker IP-Adresse (optional)
|
||||
</label>
|
||||
<textarea id="description"
|
||||
name="description"
|
||||
rows="3"
|
||||
class="w-full px-3 py-2 border border-slate-300 dark:border-slate-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent bg-white dark:bg-slate-800 text-slate-900 dark:text-white"
|
||||
placeholder="Zusätzliche Informationen zum Drucker..."></textarea>
|
||||
<input type="text"
|
||||
id="ip_address"
|
||||
name="ip_address"
|
||||
pattern="^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
|
||||
class="w-full px-3 py-2 border border-slate-300 dark:border-slate-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent bg-white dark:bg-slate-800 text-slate-900 dark:text-white"
|
||||
placeholder="192.168.1.101">
|
||||
<p class="text-sm text-slate-500 dark:text-slate-400 mt-1">IP-Adresse des Druckers selbst (falls verfügbar)</p>
|
||||
</div>
|
||||
|
||||
<!-- Status -->
|
||||
<div>
|
||||
<label for="status" class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-2">
|
||||
<i class="fas fa-circle mr-2"></i>Anfangsstatus
|
||||
<label for="active" class="flex items-center space-x-2 text-sm font-medium text-slate-700 dark:text-slate-300 cursor-pointer">
|
||||
<input type="checkbox"
|
||||
id="active"
|
||||
name="active"
|
||||
checked
|
||||
class="rounded text-blue-600 focus:ring-2 focus:ring-blue-500">
|
||||
<span>Drucker aktiv</span>
|
||||
</label>
|
||||
<select id="status"
|
||||
name="status"
|
||||
class="w-full px-3 py-2 border border-slate-300 dark:border-slate-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent bg-white dark:bg-slate-800 text-slate-900 dark:text-white">
|
||||
<option value="available">Verfügbar</option>
|
||||
<option value="offline">Offline</option>
|
||||
<option value="maintenance">Wartung</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- Hinweise -->
|
||||
@ -128,9 +158,9 @@
|
||||
<p class="font-semibold mb-1">Hinweise:</p>
|
||||
<ul class="list-disc list-inside space-y-1">
|
||||
<li>Felder mit * sind Pflichtfelder</li>
|
||||
<li>Die IP-Adresse sollte die Adresse der Tapo-Steckdose sein</li>
|
||||
<li>Der Drucker wird automatisch mit Standard-Tapo-Einstellungen konfiguriert</li>
|
||||
<li>Status "Verfügbar" bedeutet bereit für Druckaufträge</li>
|
||||
<li>Die Tapo-Konfiguration ist optional, ermöglicht aber die Stromsteuerung</li>
|
||||
<li>Bei fehlenden Tapo-Zugangsdaten werden die globalen Einstellungen verwendet</li>
|
||||
<li>Eine MAC-Adresse wird automatisch generiert wenn nicht vorhanden</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -139,6 +169,7 @@
|
||||
<!-- Aktionen -->
|
||||
<div class="flex space-x-3 pt-4">
|
||||
<button type="submit"
|
||||
id="submitBtn"
|
||||
class="flex-1 bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg transition-colors">
|
||||
<i class="fas fa-save mr-2"></i>Drucker erstellen
|
||||
</button>
|
||||
@ -154,55 +185,96 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_js %}
|
||||
<!-- JavaScript für Form-Validierung -->
|
||||
<!-- JavaScript für Form-Validierung und AJAX-Submit -->
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const form = document.querySelector('form');
|
||||
const nameInput = document.getElementById('name');
|
||||
const ipInput = document.getElementById('ip_address');
|
||||
const form = document.getElementById('printerForm');
|
||||
const submitBtn = document.getElementById('submitBtn');
|
||||
|
||||
// IP-Adresse-Validierung
|
||||
ipInput.addEventListener('blur', function() {
|
||||
const ip = this.value;
|
||||
function validateIP(ip) {
|
||||
const ipRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
||||
return !ip || ipRegex.test(ip);
|
||||
}
|
||||
|
||||
// Form-Submit mit AJAX
|
||||
form.addEventListener('submit', async function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
if (ip && !ipRegex.test(ip)) {
|
||||
this.classList.add('border-red-500');
|
||||
this.classList.remove('border-slate-300', 'dark:border-slate-600');
|
||||
} else {
|
||||
this.classList.remove('border-red-500');
|
||||
this.classList.add('border-slate-300', 'dark:border-slate-600');
|
||||
}
|
||||
});
|
||||
|
||||
// Form-Submit-Validierung
|
||||
form.addEventListener('submit', function(e) {
|
||||
const name = nameInput.value.trim();
|
||||
const ip = ipInput.value.trim();
|
||||
const ipRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
||||
|
||||
if (!name) {
|
||||
e.preventDefault();
|
||||
if (typeof showFlashMessage === 'function') {
|
||||
showFlashMessage('Bitte geben Sie einen Drucker-Namen ein.', 'error');
|
||||
} else {
|
||||
alert('Bitte geben Sie einen Drucker-Namen ein.');
|
||||
}
|
||||
nameInput.focus();
|
||||
// Validierung
|
||||
const plugIp = document.getElementById('plug_ip').value;
|
||||
const printerIp = document.getElementById('ip_address').value;
|
||||
|
||||
if (!validateIP(plugIp)) {
|
||||
showNotification('Ungültige Steckdosen-IP-Adresse', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ip || !ipRegex.test(ip)) {
|
||||
e.preventDefault();
|
||||
if (typeof showFlashMessage === 'function') {
|
||||
showFlashMessage('Bitte geben Sie eine gültige IP-Adresse ein.', 'error');
|
||||
} else {
|
||||
alert('Bitte geben Sie eine gültige IP-Adresse ein.');
|
||||
}
|
||||
ipInput.focus();
|
||||
|
||||
if (!validateIP(printerIp)) {
|
||||
showNotification('Ungültige Drucker-IP-Adresse', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
// Button deaktivieren
|
||||
submitBtn.disabled = true;
|
||||
submitBtn.innerHTML = '<i class="fas fa-spinner fa-spin mr-2"></i>Wird erstellt...';
|
||||
|
||||
// Daten sammeln
|
||||
const formData = {
|
||||
name: document.getElementById('name').value,
|
||||
model: document.getElementById('model').value,
|
||||
location: document.getElementById('location').value || '',
|
||||
ip_address: printerIp || null,
|
||||
plug_ip: plugIp || null,
|
||||
plug_username: document.getElementById('plug_username').value || null,
|
||||
plug_password: document.getElementById('plug_password').value || null,
|
||||
active: document.getElementById('active').checked
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/admin/printers', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRFToken': document.querySelector('[name=csrf_token]').value
|
||||
},
|
||||
body: JSON.stringify(formData)
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (response.ok && result.success) {
|
||||
showNotification(result.message || 'Drucker erfolgreich erstellt', 'success');
|
||||
// Nach kurzer Verzögerung zur Drucker-Liste
|
||||
setTimeout(() => {
|
||||
window.location.href = "{{ url_for('admin.admin_dashboard', tab='printers') }}";
|
||||
}, 1500);
|
||||
} else {
|
||||
showNotification(result.error || 'Fehler beim Erstellen des Druckers', 'error');
|
||||
submitBtn.disabled = false;
|
||||
submitBtn.innerHTML = '<i class="fas fa-save mr-2"></i>Drucker erstellen';
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Fehler:', error);
|
||||
showNotification('Netzwerkfehler beim Erstellen des Druckers', 'error');
|
||||
submitBtn.disabled = false;
|
||||
submitBtn.innerHTML = '<i class="fas fa-save mr-2"></i>Drucker erstellen';
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Notification-Funktion
|
||||
function showNotification(message, type = 'info') {
|
||||
// Verwende die globale Notification-Funktion falls vorhanden
|
||||
if (typeof window.showNotification === 'function') {
|
||||
window.showNotification(message, type);
|
||||
} else if (typeof showFlashMessage === 'function') {
|
||||
showFlashMessage(message, type);
|
||||
} else {
|
||||
// Fallback
|
||||
alert(message);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
Reference in New Issue
Block a user