root 097934ac18 Verbesserte Druckeransicht mit Warteschlange und verbleibender Zeit
- Anzeige der verbleibenden Zeit für aktuelle Druckaufträge in der Druckeransicht
- Neue Spalte für wartende Jobs in der Druckerliste
- Übersichtliche Anzeige der Warteschlange mit Job-Informationen

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-03-12 13:28:37 +01:00

280 lines
14 KiB
HTML

{% extends "base.html" %}
{% block title %}Drucker - MYP API Tester{% endblock %}
{% block content %}
<div class="row">
<div class="col-md-12 mb-4">
<div class="card">
<div class="card-header d-flex justify-content-between align-items-center">
<h4 class="mb-0">Drucker verwalten</h4>
<button class="btn btn-primary" type="button" data-bs-toggle="collapse" data-bs-target="#newPrinterForm">
Neuen Drucker hinzufügen
</button>
</div>
<div class="collapse" id="newPrinterForm">
<div class="card-body border-bottom">
<form class="api-form" data-url="/api/printers" data-method="POST" data-response="createPrinterResponse" data-reload="true">
<div class="mb-3">
<label for="printerName" class="form-label">Name</label>
<input type="text" class="form-control" id="printerName" name="name" required>
</div>
<div class="mb-3">
<label for="printerDescription" class="form-label">Beschreibung</label>
<textarea class="form-control" id="printerDescription" name="description" rows="3" required></textarea>
</div>
<div class="mb-3">
<label for="printerStatus" class="form-label">Status</label>
<select class="form-control" id="printerStatus" name="status">
<option value="0">Verfügbar (0)</option>
<option value="1">Besetzt (1)</option>
<option value="2">Wartung (2)</option>
</select>
</div>
<div class="mb-3">
<label for="printerIpAddress" class="form-label">IP-Adresse (Tapo Steckdose)</label>
<input type="text" class="form-control" id="printerIpAddress" name="ipAddress" placeholder="z.B. 192.168.1.100">
</div>
<button type="submit" class="btn btn-success">Drucker erstellen</button>
</form>
<div class="mt-3">
<h6>Antwort:</h6>
<pre class="api-response" id="createPrinterResponse"></pre>
</div>
</div>
</div>
<div class="card-body">
<form class="api-form mb-3" data-url="/api/printers" data-method="GET" data-response="printersResponse">
<button type="submit" class="btn btn-primary">Drucker aktualisieren</button>
</form>
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Beschreibung</th>
<th>Status</th>
<th>IP-Adresse</th>
<th>Aktueller Job</th>
<th>Wartende Jobs</th>
<th>Aktionen</th>
</tr>
</thead>
<tbody id="printersTableBody">
<!-- Wird dynamisch gefüllt -->
</tbody>
</table>
</div>
<div>
<h6>API-Antwort:</h6>
<pre class="api-response" id="printersResponse"></pre>
</div>
</div>
</div>
</div>
</div>
<!-- Drucker bearbeiten Modal -->
<div class="modal fade" id="editPrinterModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Drucker bearbeiten</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form id="editPrinterForm" class="api-form" data-method="PUT" data-response="editPrinterResponse" data-reload="true">
<input type="hidden" id="editPrinterId" name="printerId">
<div class="mb-3">
<label for="editPrinterName" class="form-label">Name</label>
<input type="text" class="form-control" id="editPrinterName" name="name" required>
</div>
<div class="mb-3">
<label for="editPrinterDescription" class="form-label">Beschreibung</label>
<textarea class="form-control" id="editPrinterDescription" name="description" rows="3" required></textarea>
</div>
<div class="mb-3">
<label for="editPrinterStatus" class="form-label">Status</label>
<select class="form-control" id="editPrinterStatus" name="status">
<option value="0">Verfügbar (0)</option>
<option value="1">Besetzt (1)</option>
<option value="2">Wartung (2)</option>
</select>
</div>
<div class="mb-3">
<label for="editPrinterIpAddress" class="form-label">IP-Adresse (Tapo Steckdose)</label>
<input type="text" class="form-control" id="editPrinterIpAddress" name="ipAddress" placeholder="z.B. 192.168.1.100">
</div>
</form>
<div class="mt-3">
<h6>Antwort:</h6>
<pre class="api-response" id="editPrinterResponse"></pre>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Abbrechen</button>
<button type="submit" form="editPrinterForm" class="btn btn-primary">Änderungen speichern</button>
</div>
</div>
</div>
</div>
<!-- Drucker löschen Modal -->
<div class="modal fade" id="deletePrinterModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Drucker löschen</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p>Möchten Sie den Drucker <span id="deletePrinterName"></span> wirklich löschen?</p>
<form id="deletePrinterForm" class="api-form" data-method="DELETE" data-response="deletePrinterResponse" data-reload="true">
<input type="hidden" id="deletePrinterId" name="printerId">
</form>
<div class="mt-3">
<h6>Antwort:</h6>
<pre class="api-response" id="deletePrinterResponse"></pre>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Abbrechen</button>
<button type="submit" form="deletePrinterForm" class="btn btn-danger">Löschen</button>
</div>
</div>
</div>
</div>
{% endblock %}
{% block scripts %}
<script>
document.addEventListener('DOMContentLoaded', function() {
// Drucker laden
document.querySelector('form[data-url="/api/printers"]').dispatchEvent(new Event('submit'));
// Tabelle aktualisieren, wenn Drucker geladen werden
const printersResponse = document.getElementById('printersResponse');
const observer = new MutationObserver(function(mutations) {
try {
const printers = JSON.parse(printersResponse.textContent);
updatePrintersTable(printers);
} catch (e) {
console.error('Fehler beim Parsen der Drucker-Daten:', e);
}
});
observer.observe(printersResponse, { childList: true, characterData: true, subtree: true });
// Edit-Modal vorbereiten
document.getElementById('editPrinterModal').addEventListener('show.bs.modal', function(event) {
const button = event.relatedTarget;
const printerId = button.getAttribute('data-printer-id');
const printerName = button.getAttribute('data-printer-name');
const printerDescription = button.getAttribute('data-printer-description');
const printerStatus = button.getAttribute('data-printer-status');
const printerIpAddress = button.getAttribute('data-printer-ip');
document.getElementById('editPrinterId').value = printerId;
document.getElementById('editPrinterForm').setAttribute('data-url', `/api/printers/${printerId}`);
document.getElementById('editPrinterName').value = printerName;
document.getElementById('editPrinterDescription').value = printerDescription;
document.getElementById('editPrinterStatus').value = printerStatus;
document.getElementById('editPrinterIpAddress').value = printerIpAddress || '';
});
// Delete-Modal vorbereiten
document.getElementById('deletePrinterModal').addEventListener('show.bs.modal', function(event) {
const button = event.relatedTarget;
const printerId = button.getAttribute('data-printer-id');
const printerName = button.getAttribute('data-printer-name');
document.getElementById('deletePrinterId').value = printerId;
document.getElementById('deletePrinterForm').setAttribute('data-url', `/api/printers/${printerId}`);
document.getElementById('deletePrinterName').textContent = printerName;
});
});
function updatePrintersTable(printers) {
const tableBody = document.getElementById('printersTableBody');
tableBody.innerHTML = '';
printers.forEach(printer => {
const row = document.createElement('tr');
const statusText = {
0: 'Verfügbar',
1: 'Besetzt',
2: 'Wartung'
}[printer.status] || 'Unbekannt';
const statusClass = {
0: 'text-success',
1: 'text-warning',
2: 'text-danger'
}[printer.status] || '';
// Informationen zum aktuellen Job
let currentJobInfo = '-';
if (printer.latestJob && printer.status === 1) {
// Verbleibende Zeit berechnen
const remainingTime = printer.latestJob.remainingMinutes || 0;
currentJobInfo = `
<div class="small">
<strong>ID:</strong> ${printer.latestJob.id.substring(0, 8)}...<br>
<strong>Dauer:</strong> ${printer.latestJob.durationInMinutes} Min<br>
<strong>Verbleibend:</strong> ${remainingTime} Min
</div>
`;
}
// Wartende Jobs anzeigen
let waitingJobsInfo = '-';
if (printer.waitingJobs && printer.waitingJobs.length > 0) {
const waitingJobsCount = printer.waitingJobs.length;
waitingJobsInfo = `
<div class="small">
<strong>${waitingJobsCount} Job${waitingJobsCount !== 1 ? 's' : ''} in Warteschlange</strong><br>
${printer.waitingJobs.map((job, index) =>
`<span>${index + 1}. Job ${job.id.substring(0, 8)}... (${job.durationInMinutes} Min)</span>`
).join('<br>')}
</div>
`;
}
row.innerHTML = `
<td>${printer.id}</td>
<td>${printer.name}</td>
<td>${printer.description}</td>
<td><span class="${statusClass}">${statusText} (${printer.status})</span></td>
<td>${printer.ipAddress || '-'}</td>
<td>${currentJobInfo}</td>
<td>${waitingJobsInfo}</td>
<td>
<button type="button" class="btn btn-sm btn-primary"
data-bs-toggle="modal"
data-bs-target="#editPrinterModal"
data-printer-id="${printer.id}"
data-printer-name="${printer.name}"
data-printer-description="${printer.description}"
data-printer-status="${printer.status}"
data-printer-ip="${printer.ipAddress || ''}">
Bearbeiten
</button>
<button type="button" class="btn btn-sm btn-danger"
data-bs-toggle="modal"
data-bs-target="#deletePrinterModal"
data-printer-id="${printer.id}"
data-printer-name="${printer.name}">
Löschen
</button>
</td>
`;
tableBody.appendChild(row);
});
}
</script>
{% endblock %}