mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-22 03:49:18 +02:00
Feature: Force Color Match (#625)
* 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>
This commit is contained in:
co-authored by
cadtoolbox
copilot-swe-agent[bot]
MartinNYHC
parent
7b74605ae4
commit
d7401a80df
@@ -23,3 +23,58 @@ export function getWifiStrength(rssi: number): { labelKey: string; color: string
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user