mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-06 06:02:05 +02:00
* Added "Force Color Match" feature to filament override * Update settings.py * Update settings.py * Label updates for warnings and checkbox case * Initial plan * Add noMatchingMaterial i18n translations to all 7 locale files Co-authored-by: cadtoolbox <12723486+cadtoolbox@users.noreply.github.com> * Use {{material}} interpolation in noMatchingMaterial; populate from filament_overrides with getColorName Co-authored-by: cadtoolbox <12723486+cadtoolbox@users.noreply.github.com> * Updates for PR#625 comments * Added "Force Color Match" feature to filament override * Update settings.py * Update settings.py * Label updates for warnings and checkbox case * Initial plan * Add noMatchingMaterial i18n translations to all 7 locale files Co-authored-by: cadtoolbox <12723486+cadtoolbox@users.noreply.github.com> * Use {{material}} interpolation in noMatchingMaterial; populate from filament_overrides with getColorName Co-authored-by: cadtoolbox <12723486+cadtoolbox@users.noreply.github.com> * Updates to PrintersPage and QueuePage * Update QueuePage.tsx * Rebase to 0.2.2b3 * Fix compile errors with FilamentOverride * Updates for PR#625 comments https://github.com/maziggy/bambuddy/pull/625#pullrequestreview-3908738261 * Fix force color match default, loadedFilamentTypes bug, remove dead translations --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: cadtoolbox <12723486+cadtoolbox@users.noreply.github.com> Co-authored-by: MartinNYHC <mz@v8w.de>
81 lines
3.9 KiB
TypeScript
81 lines
3.9 KiB
TypeScript
export function getPrinterImage(model: string | null | undefined): string {
|
|
if (!model) return '/img/printers/default.png';
|
|
const m = model.toLowerCase().replace(/\s+/g, '');
|
|
if (m.includes('x1e')) return '/img/printers/x1e.png';
|
|
if (m.includes('x1c') || m.includes('x1carbon')) return '/img/printers/x1c.png';
|
|
if (m.includes('x1')) return '/img/printers/x1c.png';
|
|
if (m.includes('h2dpro') || m.includes('h2d-pro')) return '/img/printers/h2dpro.png';
|
|
if (m.includes('h2d')) return '/img/printers/h2d.png';
|
|
if (m.includes('h2c')) return '/img/printers/h2c.png';
|
|
if (m.includes('h2s')) return '/img/printers/h2d.png';
|
|
if (m.includes('p2s')) return '/img/printers/p1s.png';
|
|
if (m.includes('p1s')) return '/img/printers/p1s.png';
|
|
if (m.includes('p1p')) return '/img/printers/p1p.png';
|
|
if (m.includes('a1mini')) return '/img/printers/a1mini.png';
|
|
if (m.includes('a1')) return '/img/printers/a1.png';
|
|
return '/img/printers/default.png';
|
|
}
|
|
|
|
export function getWifiStrength(rssi: number): { labelKey: string; color: string; bars: number } {
|
|
if (rssi >= -50) return { labelKey: 'printers.wifiSignal.excellent', color: 'text-bambu-green', bars: 4 };
|
|
if (rssi >= -60) return { labelKey: 'printers.wifiSignal.good', color: 'text-bambu-green', bars: 3 };
|
|
if (rssi >= -70) return { labelKey: 'printers.wifiSignal.fair', color: 'text-yellow-400', bars: 2 };
|
|
if (rssi >= -80) return { labelKey: 'printers.wifiSignal.weak', color: 'text-orange-400', bars: 1 };
|
|
return { labelKey: 'printers.wifiSignal.veryWeak', color: 'text-red-400', bars: 1 };
|
|
}
|
|
|
|
import type { PrintQueueItem } from '../api/client';
|
|
|
|
/**
|
|
* Filters queue items based on printer compatibility (filament types and colors).
|
|
* Mirrors backend _find_idle_printer_for_model() logic.
|
|
* @param items - Array of queue items to filter
|
|
* @param loadedFilamentTypes - Set of loaded filament types (e.g., "PLA", "PETG")
|
|
* @param loadedFilaments - Set of loaded filament type+color pairs (e.g., "PLA:ffffff", "PETG:ff0000")
|
|
* @returns Array of compatible queue items
|
|
*/
|
|
export function filterCompatibleQueueItems(
|
|
items: PrintQueueItem[],
|
|
loadedFilamentTypes?: Set<string>,
|
|
loadedFilaments?: Set<string>
|
|
): PrintQueueItem[] {
|
|
return items.filter(item => {
|
|
// Type check: all required filament types must be loaded
|
|
if (item.required_filament_types && item.required_filament_types.length > 0 && loadedFilamentTypes !== undefined) {
|
|
if (!item.required_filament_types.every((t: string) => loadedFilamentTypes.has(t.toUpperCase()))) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Color check: evaluate force_color_match per slot
|
|
// Only apply when loadedFilaments is provided (not undefined).
|
|
// An empty Set means no filaments are loaded — force-matched slots cannot match.
|
|
if (item.filament_overrides && item.filament_overrides.length > 0 && loadedFilaments !== undefined) {
|
|
const forceOverrides = item.filament_overrides.filter(o => o.force_color_match === true);
|
|
const prefOverrides = item.filament_overrides.filter(o => o.force_color_match !== true);
|
|
|
|
// All force-matched slots must have exact type+color on this printer
|
|
if (forceOverrides.length > 0) {
|
|
const allForceMatch = forceOverrides.every(o => {
|
|
const oType = (o.type || '').toUpperCase();
|
|
const oColor = (o.color || '').replace('#', '').toLowerCase().slice(0, 6);
|
|
return loadedFilaments.has(`${oType}:${oColor}`);
|
|
});
|
|
if (!allForceMatch) return false;
|
|
}
|
|
|
|
// Preference-only overrides: at least one color must match (existing behaviour)
|
|
if (prefOverrides.length > 0 && forceOverrides.length === 0) {
|
|
const hasColorMatch = prefOverrides.some(o => {
|
|
const oType = (o.type || '').toUpperCase();
|
|
const oColor = (o.color || '').replace('#', '').toLowerCase().slice(0, 6);
|
|
return loadedFilaments.has(`${oType}:${oColor}`);
|
|
});
|
|
if (!hasColorMatch) return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
});
|
|
}
|