347 lines
18 KiB
HTML
347 lines
18 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="de">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Drucker bearbeiten - MYP Admin</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
|
</head>
|
|
<body class="bg-gray-100">
|
|
<div class="min-h-screen py-8">
|
|
<div class="max-w-2xl mx-auto">
|
|
<!-- Header -->
|
|
<div class="bg-white rounded-lg shadow-md p-6 mb-6">
|
|
<div class="flex items-center justify-between">
|
|
<div class="flex items-center space-x-3">
|
|
<i class="fas fa-edit text-blue-600 text-2xl"></i>
|
|
<h1 class="text-2xl font-bold text-gray-800">Drucker bearbeiten</h1>
|
|
</div>
|
|
<a href="{{ url_for('admin_page', tab='printers') }}"
|
|
class="bg-gray-500 hover:bg-gray-600 text-white px-4 py-2 rounded-lg transition-colors">
|
|
<i class="fas fa-arrow-left mr-2"></i>Zurück
|
|
</a>
|
|
</div>
|
|
<div class="mt-4 p-3 bg-blue-50 rounded-lg">
|
|
<p class="text-sm text-blue-700">
|
|
<i class="fas fa-info-circle mr-2"></i>
|
|
<strong>Drucker-ID:</strong> {{ printer.id }} |
|
|
<strong>Erstellt am:</strong> {{ printer.created_at[:10] if printer.created_at else 'Unbekannt' }}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Formular -->
|
|
<div class="bg-white rounded-lg shadow-md p-6">
|
|
<form action="{{ url_for('admin_update_printer_form', printer_id=printer.id) }}" method="POST" class="space-y-6">
|
|
<!-- CSRF Token -->
|
|
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
|
|
|
|
<!-- Name -->
|
|
<div>
|
|
<label for="name" class="block text-sm font-medium text-gray-700 mb-2">
|
|
<i class="fas fa-tag mr-2"></i>Drucker-Name *
|
|
</label>
|
|
<input type="text"
|
|
id="name"
|
|
name="name"
|
|
required
|
|
value="{{ printer.name }}"
|
|
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
|
placeholder="3D-Drucker Raum A001">
|
|
</div>
|
|
|
|
<!-- IP-Adresse -->
|
|
<div>
|
|
<label for="ip_address" class="block text-sm font-medium text-gray-700 mb-2">
|
|
<i class="fas fa-network-wired mr-2"></i>IP-Adresse *
|
|
</label>
|
|
<input type="text"
|
|
id="ip_address"
|
|
name="ip_address"
|
|
required
|
|
value="{{ printer.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-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
|
placeholder="192.168.1.100">
|
|
<p class="text-sm text-gray-500 mt-1">IP-Adresse der Tapo-Steckdose</p>
|
|
</div>
|
|
|
|
<!-- Modell -->
|
|
<div>
|
|
<label for="model" class="block text-sm font-medium text-gray-700 mb-2">
|
|
<i class="fas fa-cogs mr-2"></i>Drucker-Modell
|
|
</label>
|
|
<input type="text"
|
|
id="model"
|
|
name="model"
|
|
value="{{ printer.model }}"
|
|
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
|
placeholder="Ender 3 V2">
|
|
</div>
|
|
|
|
<!-- Standort -->
|
|
<div>
|
|
<label for="location" class="block text-sm font-medium text-gray-700 mb-2">
|
|
<i class="fas fa-map-marker-alt mr-2"></i>Standort
|
|
</label>
|
|
<input type="text"
|
|
id="location"
|
|
name="location"
|
|
value="{{ printer.location }}"
|
|
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
|
placeholder="Raum A001, Erdgeschoss">
|
|
</div>
|
|
|
|
<!-- Beschreibung -->
|
|
<div>
|
|
<label for="description" class="block text-sm font-medium text-gray-700 mb-2">
|
|
<i class="fas fa-comment mr-2"></i>Beschreibung
|
|
</label>
|
|
<textarea id="description"
|
|
name="description"
|
|
rows="3"
|
|
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
|
placeholder="Zusätzliche Informationen zum Drucker...">{{ printer.description or '' }}</textarea>
|
|
</div>
|
|
|
|
<!-- Status -->
|
|
<div>
|
|
<label for="status" class="block text-sm font-medium text-gray-700 mb-2">
|
|
<i class="fas fa-circle mr-2"></i>Aktueller Status
|
|
</label>
|
|
<select id="status"
|
|
name="status"
|
|
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent">
|
|
<option value="available" {{ 'selected' if printer.status == 'available' else '' }}>Verfügbar</option>
|
|
<option value="offline" {{ 'selected' if printer.status == 'offline' else '' }}>Offline</option>
|
|
<option value="maintenance" {{ 'selected' if printer.status == 'maintenance' else '' }}>Wartung</option>
|
|
<option value="online" {{ 'selected' if printer.status == 'online' else '' }}>Online</option>
|
|
<option value="printing" {{ 'selected' if printer.status == 'printing' else '' }}>Druckt</option>
|
|
</select>
|
|
</div>
|
|
|
|
<!-- Aktiv-Status -->
|
|
<div>
|
|
<label class="flex items-center space-x-3">
|
|
<input type="checkbox"
|
|
name="is_active"
|
|
{{ 'checked' if printer.active else '' }}
|
|
class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 focus:ring-2">
|
|
<span class="text-sm font-medium text-gray-700">
|
|
<i class="fas fa-power-off mr-2"></i>Drucker aktiv
|
|
</span>
|
|
</label>
|
|
<p class="text-sm text-gray-500 mt-1">Inaktive Drucker werden nicht für neue Aufträge verwendet</p>
|
|
</div>
|
|
|
|
<!-- Erweiterte Informationen -->
|
|
<div class="bg-gray-50 border border-gray-200 rounded-lg p-4">
|
|
<h3 class="text-sm font-semibold text-gray-700 mb-3">
|
|
<i class="fas fa-info-circle mr-2"></i>Drucker-Informationen
|
|
</h3>
|
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-3 text-sm">
|
|
<div>
|
|
<span class="font-medium text-gray-600">MAC-Adresse:</span>
|
|
<span class="text-gray-800">{{ printer.mac_address or 'Nicht verfügbar' }}</span>
|
|
</div>
|
|
<div>
|
|
<span class="font-medium text-gray-600">Letzter Check:</span>
|
|
<span class="text-gray-800">{{ printer.last_checked or 'Nie' }}</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Warnung -->
|
|
<div class="bg-yellow-50 border border-yellow-200 rounded-lg p-4">
|
|
<div class="flex">
|
|
<i class="fas fa-exclamation-triangle text-yellow-500 mt-0.5 mr-3"></i>
|
|
<div class="text-sm text-yellow-700">
|
|
<p class="font-semibold mb-1">Wichtige Hinweise:</p>
|
|
<ul class="list-disc list-inside space-y-1">
|
|
<li>Änderungen an der IP-Adresse können die Verbindung unterbrechen</li>
|
|
<li>Stellen Sie sicher, dass die Tapo-Steckdose unter der neuen IP erreichbar ist</li>
|
|
<li>Bei Status-Änderungen werden laufende Jobs möglicherweise beeinflusst</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Aktionen -->
|
|
<div class="flex space-x-3 pt-4">
|
|
<button type="submit"
|
|
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>Änderungen speichern
|
|
</button>
|
|
<a href="{{ url_for('admin_page', tab='printers') }}"
|
|
class="flex-1 bg-gray-500 hover:bg-gray-600 text-white px-4 py-2 rounded-lg text-center transition-colors">
|
|
<i class="fas fa-times mr-2"></i>Abbrechen
|
|
</a>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
|
|
<!-- Zusätzliche Aktionen -->
|
|
<div class="bg-white rounded-lg shadow-md p-6 mt-6">
|
|
<h3 class="text-lg font-semibold text-gray-800 mb-4">
|
|
<i class="fas fa-tools mr-2"></i>Drucker-Aktionen
|
|
</h3>
|
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
<button data-printer-id="{{ printer.id }}"
|
|
data-action="test"
|
|
class="printer-action-btn bg-green-600 hover:bg-green-700 text-white px-4 py-3 rounded-lg transition-colors">
|
|
<i class="fas fa-plug mr-2"></i>Verbindung testen
|
|
</button>
|
|
<button data-printer-id="{{ printer.id }}"
|
|
data-action="toggle"
|
|
class="printer-action-btn bg-orange-600 hover:bg-orange-700 text-white px-4 py-3 rounded-lg transition-colors">
|
|
<i class="fas fa-power-off mr-2"></i>Ein/Ausschalten
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Flash Messages -->
|
|
{% with messages = get_flashed_messages(with_categories=true) %}
|
|
{% if messages %}
|
|
<div class="fixed top-4 right-4 z-50 space-y-2">
|
|
{% for category, message in messages %}
|
|
<div class="alert alert-{{ 'danger' if category == 'error' else category }} bg-{{ 'red' if category == 'error' else 'green' }}-100 border border-{{ 'red' if category == 'error' else 'green' }}-400 text-{{ 'red' if category == 'error' else 'green' }}-700 px-4 py-3 rounded-lg shadow-md">
|
|
<div class="flex items-center">
|
|
<i class="fas fa-{{ 'exclamation-triangle' if category == 'error' else 'check-circle' }} mr-2"></i>
|
|
{{ message }}
|
|
</div>
|
|
</div>
|
|
{% endfor %}
|
|
</div>
|
|
{% endif %}
|
|
{% endwith %}
|
|
|
|
<!-- JavaScript -->
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const form = document.querySelector('form');
|
|
const nameInput = document.getElementById('name');
|
|
const ipInput = document.getElementById('ip_address');
|
|
|
|
// IP-Adresse-Validierung
|
|
ipInput.addEventListener('blur', function() {
|
|
const ip = this.value;
|
|
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 (ip && !ipRegex.test(ip)) {
|
|
this.classList.add('border-red-500');
|
|
this.classList.remove('border-gray-300');
|
|
} else {
|
|
this.classList.remove('border-red-500');
|
|
this.classList.add('border-gray-300');
|
|
}
|
|
});
|
|
|
|
// 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();
|
|
alert('Bitte geben Sie einen Drucker-Namen ein.');
|
|
nameInput.focus();
|
|
return;
|
|
}
|
|
|
|
if (!ip || !ipRegex.test(ip)) {
|
|
e.preventDefault();
|
|
alert('Bitte geben Sie eine gültige IP-Adresse ein.');
|
|
ipInput.focus();
|
|
return;
|
|
}
|
|
});
|
|
|
|
// Event-Listener für Drucker-Aktions-Buttons
|
|
document.querySelectorAll('.printer-action-btn').forEach(button => {
|
|
button.addEventListener('click', function() {
|
|
const printerId = this.getAttribute('data-printer-id');
|
|
const action = this.getAttribute('data-action');
|
|
|
|
if (action === 'test') {
|
|
testPrinterConnection(printerId, this);
|
|
} else if (action === 'toggle') {
|
|
togglePrinterPower(printerId, this);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
// Verbindungstest
|
|
function testPrinterConnection(printerId, button) {
|
|
const originalText = button.innerHTML;
|
|
|
|
button.innerHTML = '<i class="fas fa-spinner fa-spin mr-2"></i>Teste...';
|
|
button.disabled = true;
|
|
|
|
fetch(`/api/admin/printers/${printerId}/test-tapo`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-CSRFToken': '{{ csrf_token() }}'
|
|
}
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.tapo_test && data.tapo_test.success) {
|
|
alert('✅ Verbindung erfolgreich!\n\nStatus: ' + (data.tapo_test.device_info ? data.tapo_test.device_info.device_on ? 'EIN' : 'AUS' : 'Unbekannt'));
|
|
} else {
|
|
alert('❌ Verbindung fehlgeschlagen!\n\nFehler: ' + (data.tapo_test ? data.tapo_test.error : 'Unbekannter Fehler'));
|
|
}
|
|
})
|
|
.catch(error => {
|
|
alert('❌ Verbindungstest fehlgeschlagen!\n\nFehler: ' + error.message);
|
|
})
|
|
.finally(() => {
|
|
button.innerHTML = originalText;
|
|
button.disabled = false;
|
|
});
|
|
}
|
|
|
|
// Drucker ein/ausschalten
|
|
function togglePrinterPower(printerId, button) {
|
|
const originalText = button.innerHTML;
|
|
|
|
if (!confirm('Möchten Sie den Drucker ein-/ausschalten?')) {
|
|
return;
|
|
}
|
|
|
|
button.innerHTML = '<i class="fas fa-spinner fa-spin mr-2"></i>Schaltet...';
|
|
button.disabled = true;
|
|
|
|
fetch(`/api/admin/printers/${printerId}/toggle`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-CSRFToken': '{{ csrf_token() }}'
|
|
}
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
alert('✅ Drucker erfolgreich ' + data.action + '!');
|
|
// Seite neu laden um aktuellen Status zu zeigen
|
|
location.reload();
|
|
} else {
|
|
alert('❌ Fehler beim Schalten!\n\nFehler: ' + (data.error || 'Unbekannter Fehler'));
|
|
}
|
|
})
|
|
.catch(error => {
|
|
alert('❌ Schaltvorgang fehlgeschlagen!\n\nFehler: ' + error.message);
|
|
})
|
|
.finally(() => {
|
|
button.innerHTML = originalText;
|
|
button.disabled = false;
|
|
});
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |