249 lines
13 KiB
HTML
249 lines
13 KiB
HTML
{% extends "base.html" %}
|
|
|
|
{% block title %}Drucker hinzufügen - Mercedes-Benz MYP Platform{% endblock %}
|
|
|
|
{% block head %}
|
|
{{ super() }}
|
|
<meta name="csrf-token" content="{{ csrf_token() }}">
|
|
{% endblock %}
|
|
|
|
{% block content %}
|
|
<div class="min-h-screen bg-gradient-to-br from-slate-50 via-blue-50 to-indigo-50 dark:from-slate-900 dark:via-slate-800 dark:to-slate-900">
|
|
<div class="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
|
|
|
|
<!-- Header -->
|
|
<div class="mb-8">
|
|
<div class="flex items-center justify-between">
|
|
<div>
|
|
<h1 class="text-3xl font-bold text-slate-900 dark:text-white">Neuen Drucker hinzufügen</h1>
|
|
<p class="text-slate-600 dark:text-slate-400 mt-2">Fügen Sie einen neuen 3D-Drucker zum MYP-System hinzu</p>
|
|
</div>
|
|
<a href="{{ url_for('admin_page', tab='printers') }}" class="inline-flex items-center px-4 py-2 bg-slate-200 dark:bg-slate-700 text-slate-700 dark:text-slate-300 rounded-xl hover:bg-slate-300 dark:hover:bg-slate-600 transition-all duration-300">
|
|
<svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"/>
|
|
</svg>
|
|
Zurück
|
|
</a>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Formular -->
|
|
<div class="bg-white/80 dark:bg-slate-800/80 backdrop-blur-xl rounded-3xl border border-white/20 dark:border-slate-700/50 shadow-xl p-8">
|
|
<form id="add-printer-form" class="space-y-6">
|
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
|
|
<!-- Druckername -->
|
|
<div>
|
|
<label for="name" class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-2">
|
|
Druckername *
|
|
</label>
|
|
<input type="text" id="name" name="name" required
|
|
class="w-full px-4 py-3 bg-white dark:bg-slate-700 border border-slate-300 dark:border-slate-600 rounded-xl text-slate-900 dark:text-white focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all duration-300"
|
|
placeholder="z.B. Prusa i3 MK3S+">
|
|
</div>
|
|
|
|
<!-- Modell -->
|
|
<div>
|
|
<label for="model" class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-2">
|
|
Modell *
|
|
</label>
|
|
<input type="text" id="model" name="model" required
|
|
class="w-full px-4 py-3 bg-white dark:bg-slate-700 border border-slate-300 dark:border-slate-600 rounded-xl text-slate-900 dark:text-white focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all duration-300"
|
|
placeholder="z.B. Prusa i3 MK3S+">
|
|
</div>
|
|
|
|
<!-- Standort -->
|
|
<div>
|
|
<label for="location" class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-2">
|
|
Standort *
|
|
</label>
|
|
<input type="text" id="location" name="location" required
|
|
class="w-full px-4 py-3 bg-white dark:bg-slate-700 border border-slate-300 dark:border-slate-600 rounded-xl text-slate-900 dark:text-white focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all duration-300"
|
|
placeholder="z.B. Labor A, Raum 101">
|
|
</div>
|
|
|
|
<!-- MAC-Adresse -->
|
|
<div>
|
|
<label for="mac_address" class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-2">
|
|
MAC-Adresse *
|
|
</label>
|
|
<input type="text" id="mac_address" name="mac_address" required
|
|
class="w-full px-4 py-3 bg-white dark:bg-slate-700 border border-slate-300 dark:border-slate-600 rounded-xl text-slate-900 dark:text-white focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all duration-300"
|
|
placeholder="z.B. 00:11:22:33:44:55"
|
|
pattern="^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$">
|
|
</div>
|
|
|
|
<!-- Plug IP-Adresse -->
|
|
<div>
|
|
<label for="plug_ip" class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-2">
|
|
Smart Plug IP-Adresse *
|
|
</label>
|
|
<input type="text" id="plug_ip" name="plug_ip" required
|
|
class="w-full px-4 py-3 bg-white dark:bg-slate-700 border border-slate-300 dark:border-slate-600 rounded-xl text-slate-900 dark:text-white focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all duration-300"
|
|
placeholder="z.B. 192.168.1.100"
|
|
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]?)$">
|
|
</div>
|
|
|
|
<!-- Drucker IP-Adresse -->
|
|
<div>
|
|
<label for="printer_ip" class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-2">
|
|
Drucker IP-Adresse
|
|
</label>
|
|
<input type="text" id="printer_ip" name="printer_ip"
|
|
class="w-full px-4 py-3 bg-white dark:bg-slate-700 border border-slate-300 dark:border-slate-600 rounded-xl text-slate-900 dark:text-white focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all duration-300"
|
|
placeholder="z.B. 192.168.1.101"
|
|
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]?)$">
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Erweiterte Einstellungen -->
|
|
<div class="border-t border-slate-200 dark:border-slate-700 pt-6">
|
|
<h3 class="text-lg font-medium text-slate-900 dark:text-white mb-4">Erweiterte Einstellungen</h3>
|
|
|
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
|
|
<!-- Plug Benutzername -->
|
|
<div>
|
|
<label for="plug_username" class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-2">
|
|
Smart Plug Benutzername
|
|
</label>
|
|
<input type="text" id="plug_username" name="plug_username" value="admin"
|
|
class="w-full px-4 py-3 bg-white dark:bg-slate-700 border border-slate-300 dark:border-slate-600 rounded-xl text-slate-900 dark:text-white focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all duration-300">
|
|
</div>
|
|
|
|
<!-- Plug Passwort -->
|
|
<div>
|
|
<label for="plug_password" class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-2">
|
|
Smart Plug Passwort
|
|
</label>
|
|
<input type="password" id="plug_password" name="plug_password" value="vT6Vsd^p"
|
|
class="w-full px-4 py-3 bg-white dark:bg-slate-700 border border-slate-300 dark:border-slate-600 rounded-xl text-slate-900 dark:text-white focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all duration-300">
|
|
</div>
|
|
|
|
<!-- Status -->
|
|
<div>
|
|
<label for="status" class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-2">
|
|
Anfangsstatus
|
|
</label>
|
|
<select id="status" name="status"
|
|
class="w-full px-4 py-3 bg-white dark:bg-slate-700 border border-slate-300 dark:border-slate-600 rounded-xl text-slate-900 dark:text-white focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all duration-300">
|
|
<option value="available">Verfügbar</option>
|
|
<option value="offline">Offline</option>
|
|
<option value="maintenance">Wartung</option>
|
|
</select>
|
|
</div>
|
|
|
|
<!-- Beschreibung -->
|
|
<div>
|
|
<label for="description" class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-2">
|
|
Beschreibung
|
|
</label>
|
|
<textarea id="description" name="description" rows="3"
|
|
class="w-full px-4 py-3 bg-white dark:bg-slate-700 border border-slate-300 dark:border-slate-600 rounded-xl text-slate-900 dark:text-white focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all duration-300"
|
|
placeholder="Zusätzliche Informationen zum Drucker..."></textarea>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Buttons -->
|
|
<div class="flex justify-end space-x-4 pt-6">
|
|
<button type="button" onclick="window.history.back()"
|
|
class="px-6 py-3 bg-slate-200 dark:bg-slate-700 text-slate-700 dark:text-slate-300 rounded-xl hover:bg-slate-300 dark:hover:bg-slate-600 transition-all duration-300">
|
|
Abbrechen
|
|
</button>
|
|
<button type="submit"
|
|
class="px-6 py-3 bg-gradient-to-r from-green-500 to-green-600 text-white rounded-xl hover:from-green-600 hover:to-green-700 transition-all duration-300 shadow-lg hover:shadow-xl">
|
|
Drucker hinzufügen
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Notification -->
|
|
<div id="notification" class="fixed top-4 right-4 z-50 p-4 rounded-lg shadow-lg max-w-sm transition-all duration-300 transform translate-x-full hidden">
|
|
<span id="notification-message"></span>
|
|
</div>
|
|
|
|
<script>
|
|
// CSRF Token
|
|
function getCsrfToken() {
|
|
const token = document.querySelector('meta[name="csrf-token"]');
|
|
return token ? token.getAttribute('content') : '';
|
|
}
|
|
|
|
// Notification anzeigen
|
|
function showNotification(message, type = 'info') {
|
|
const notification = document.getElementById('notification');
|
|
const messageEl = document.getElementById('notification-message');
|
|
|
|
const colors = {
|
|
success: 'bg-green-500 text-white',
|
|
error: 'bg-red-500 text-white',
|
|
warning: 'bg-yellow-500 text-white',
|
|
info: 'bg-blue-500 text-white'
|
|
};
|
|
|
|
notification.className = `fixed top-4 right-4 z-50 p-4 rounded-lg shadow-lg max-w-sm transition-all duration-300 ${colors[type] || colors.info}`;
|
|
messageEl.textContent = message;
|
|
notification.classList.remove('hidden');
|
|
notification.style.transform = 'translateX(0)';
|
|
|
|
setTimeout(() => {
|
|
notification.style.transform = 'translateX(100%)';
|
|
setTimeout(() => notification.classList.add('hidden'), 300);
|
|
}, 5000);
|
|
}
|
|
|
|
// Formular absenden
|
|
document.getElementById('add-printer-form').addEventListener('submit', async function(e) {
|
|
e.preventDefault();
|
|
|
|
const formData = new FormData(this);
|
|
const data = Object.fromEntries(formData);
|
|
|
|
// API-Aufruf
|
|
try {
|
|
const response = await fetch('/api/printers', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-CSRFToken': getCsrfToken()
|
|
},
|
|
body: JSON.stringify({
|
|
name: data.name,
|
|
model: data.model,
|
|
location: data.location,
|
|
mac_address: data.mac_address,
|
|
plug_ip: data.plug_ip,
|
|
printer_ip: data.printer_ip,
|
|
plug_username: data.plug_username || 'admin',
|
|
plug_password: data.plug_password || 'vT6Vsd^p',
|
|
status: data.status || 'available',
|
|
description: data.description
|
|
})
|
|
});
|
|
|
|
const result = await response.json();
|
|
|
|
if (response.ok) {
|
|
showNotification('Drucker erfolgreich hinzugefügt', 'success');
|
|
setTimeout(() => {
|
|
window.location.href = '/admin-dashboard?tab=printers';
|
|
}, 2000);
|
|
} else {
|
|
showNotification(result.error || 'Fehler beim Hinzufügen des Druckers', 'error');
|
|
}
|
|
} catch (error) {
|
|
showNotification('Netzwerkfehler: ' + error.message, 'error');
|
|
}
|
|
});
|
|
|
|
// MAC-Adresse formatieren
|
|
document.getElementById('mac_address').addEventListener('input', function(e) {
|
|
let value = e.target.value.replace(/[^0-9A-Fa-f]/g, '');
|
|
let formatted = value.match(/.{1,2}/g)?.join(':') || value;
|
|
if (formatted.length > 17) formatted = formatted.substring(0, 17);
|
|
e.target.value = formatted;
|
|
});
|
|
</script>
|
|
{% endblock %} |