"feat: Update WARTESCHLANGEN System Documentation and related files"
This commit is contained in:
@@ -187,13 +187,13 @@
|
||||
// Load available printers
|
||||
async function loadPrinters() {
|
||||
try {
|
||||
// Versuche zuerst Status-Check API für bessere Verfügbarkeitsprüfung
|
||||
// Lade ALLE Drucker mit Live-Status-Check (nicht nur verfügbare)
|
||||
let response;
|
||||
try {
|
||||
response = await apiCall('/api/printers/status');
|
||||
response = await apiCall('/api/printers/status/live');
|
||||
printers = Array.isArray(response) ? response : (response.printers || []);
|
||||
} catch (statusError) {
|
||||
console.log('Status-API fehlgeschlagen, verwende normale API:', statusError);
|
||||
console.log('Live-Status-API fehlgeschlagen, verwende normale API:', statusError);
|
||||
response = await apiCall('/api/printers');
|
||||
printers = response.printers || [];
|
||||
}
|
||||
@@ -203,43 +203,85 @@
|
||||
|
||||
console.log('Geladene Drucker:', printers);
|
||||
|
||||
// Filtere verfügbare Drucker (status: 'available' oder active: true)
|
||||
const availablePrinters = printers.filter(p => {
|
||||
return p.status === 'available' || p.active === true;
|
||||
});
|
||||
|
||||
console.log('Verfügbare Drucker:', availablePrinters);
|
||||
|
||||
if (availablePrinters.length === 0) {
|
||||
// Zeige alle Drucker an, falls keine als verfügbar markiert sind
|
||||
if (printers.length > 0) {
|
||||
printers.forEach(printer => {
|
||||
const option = document.createElement('option');
|
||||
option.value = printer.id;
|
||||
option.textContent = `${printer.name} (${printer.location || printer.model || 'Unbekanntes Modell'}) - Status unbekannt`;
|
||||
select.appendChild(option);
|
||||
});
|
||||
showFlashMessage(`${printers.length} Drucker geladen (Status unbekannt)`, 'warning');
|
||||
} else {
|
||||
select.innerHTML = '<option value="">Keine Drucker verfügbar</option>';
|
||||
select.disabled = true;
|
||||
showFlashMessage('Keine Drucker in der Datenbank gefunden', 'error');
|
||||
}
|
||||
if (printers.length === 0) {
|
||||
select.innerHTML = '<option value="">Keine Drucker in der Datenbank</option>';
|
||||
select.disabled = true;
|
||||
showFlashMessage('Keine Drucker in der Datenbank gefunden', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
availablePrinters.forEach(printer => {
|
||||
// Sortiere Drucker: Online zuerst, dann nach Name
|
||||
const sortedPrinters = printers.sort((a, b) => {
|
||||
const aOnline = a.status === 'available' || a.is_online || a.active;
|
||||
const bOnline = b.status === 'available' || b.is_online || b.active;
|
||||
|
||||
if (aOnline && !bOnline) return -1;
|
||||
if (!aOnline && bOnline) return 1;
|
||||
|
||||
return a.name.localeCompare(b.name);
|
||||
});
|
||||
|
||||
// Zähler für Online- und Offline-Drucker
|
||||
let onlineCount = 0;
|
||||
let offlineCount = 0;
|
||||
|
||||
// Alle Drucker anzeigen (online und offline)
|
||||
sortedPrinters.forEach(printer => {
|
||||
const option = document.createElement('option');
|
||||
option.value = printer.id;
|
||||
|
||||
// Status-Indikator hinzufügen
|
||||
const statusText = printer.status === 'available' ? '✅ Verfügbar' : '⚠️ Status unbekannt';
|
||||
// Status-Indikator bestimmen
|
||||
const isOnline = printer.status === 'available' || printer.is_online || printer.active;
|
||||
let statusIcon, statusText;
|
||||
|
||||
if (isOnline) {
|
||||
statusIcon = '✅';
|
||||
statusText = 'ONLINE - Sofortiger Start';
|
||||
option.style.backgroundColor = 'rgba(4, 120, 87, 0.1)';
|
||||
option.style.color = '#047857';
|
||||
option.style.fontWeight = '500';
|
||||
onlineCount++;
|
||||
} else {
|
||||
statusIcon = '🔄';
|
||||
statusText = 'OFFLINE - Warteschlange';
|
||||
option.style.backgroundColor = 'rgba(245, 158, 11, 0.1)';
|
||||
option.style.color = '#d97706';
|
||||
option.style.fontWeight = '400';
|
||||
option.setAttribute('data-offline', 'true');
|
||||
offlineCount++;
|
||||
}
|
||||
|
||||
// Letzter Check-Zeitstempel
|
||||
let lastChecked = '';
|
||||
if (printer.last_checked) {
|
||||
const checkTime = new Date(printer.last_checked);
|
||||
const now = new Date();
|
||||
const diffMinutes = Math.floor((now - checkTime) / 60000);
|
||||
|
||||
if (diffMinutes < 1) {
|
||||
lastChecked = ' (gerade geprüft)';
|
||||
} else if (diffMinutes < 60) {
|
||||
lastChecked = ` (vor ${diffMinutes} Min)`;
|
||||
} else {
|
||||
lastChecked = ` (vor ${Math.floor(diffMinutes / 60)} Std)`;
|
||||
}
|
||||
}
|
||||
|
||||
const location = printer.location || printer.model || 'Unbekanntes Modell';
|
||||
option.textContent = `${printer.name} (${location}) - ${statusText}`;
|
||||
option.textContent = `${statusIcon} ${printer.name} (${location}) - ${statusText}${lastChecked}`;
|
||||
select.appendChild(option);
|
||||
});
|
||||
|
||||
showFlashMessage(`${availablePrinters.length} verfügbare Drucker geladen`, 'success');
|
||||
// Status-Nachricht anzeigen
|
||||
if (onlineCount > 0) {
|
||||
if (onlineCount === sortedPrinters.length) {
|
||||
showFlashMessage(`✅ OPTIMAL: Alle ${sortedPrinters.length} Drucker sind ONLINE und bereit`, 'success');
|
||||
} else {
|
||||
showFlashMessage(`🔄 ${onlineCount} von ${sortedPrinters.length} Drucker ONLINE | ${offlineCount} Drucker in Warteschlange verfügbar`, 'success');
|
||||
}
|
||||
} else {
|
||||
showFlashMessage(`🔄 WARTESCHLANGEN-MODUS: Alle ${sortedPrinters.length} Drucker sind OFFLINE - Jobs werden automatisch gestartet, wenn Drucker verfügbar werden`, 'warning');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error loading printers:', error);
|
||||
|
Reference in New Issue
Block a user