|
@@ -1095,7 +1095,7 @@ function StatusSummaryBar({ printers }: { printers: Printer[] | undefined }) {
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-type SortOption = 'name' | 'status' | 'model' | 'location';
|
|
|
|
|
|
|
+type SortOption = 'name' | 'status' | 'model' | 'location' | 'eta';
|
|
|
type ViewMode = 'expanded' | 'compact';
|
|
type ViewMode = 'expanded' | 'compact';
|
|
|
|
|
|
|
|
type ToolbarDropdownOption<T extends string> = {
|
|
type ToolbarDropdownOption<T extends string> = {
|
|
@@ -8014,6 +8014,28 @@ export function PrintersPage() {
|
|
|
return getPriority(statusA) - getPriority(statusB);
|
|
return getPriority(statusA) - getPriority(statusB);
|
|
|
});
|
|
});
|
|
|
break;
|
|
break;
|
|
|
|
|
+ case 'eta':
|
|
|
|
|
+ sorted.sort((a, b) => {
|
|
|
|
|
+ const statusA = queryClient.getQueryData<{ connected: boolean; state: string | null; remaining_time: number | null }>(['printerStatus', a.id]);
|
|
|
|
|
+ const statusB = queryClient.getQueryData<{ connected: boolean; state: string | null; remaining_time: number | null }>(['printerStatus', b.id]);
|
|
|
|
|
+
|
|
|
|
|
+ const tier = (s: typeof statusA) => {
|
|
|
|
|
+ if (!s?.connected) return 3; // offline last
|
|
|
|
|
+ if (s.state === 'RUNNING' && s.remaining_time != null && s.remaining_time > 0) return 0; // printing with ETA
|
|
|
|
|
+ if (s.state === 'RUNNING') return 1; // printing without ETA
|
|
|
|
|
+ return 2; // idle
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const ta = tier(statusA);
|
|
|
|
|
+ const tb = tier(statusB);
|
|
|
|
|
+ if (ta !== tb) return ta - tb;
|
|
|
|
|
+ if (ta === 0) {
|
|
|
|
|
+ const diff = (statusA!.remaining_time ?? 0) - (statusB!.remaining_time ?? 0);
|
|
|
|
|
+ if (diff !== 0) return diff;
|
|
|
|
|
+ }
|
|
|
|
|
+ return a.name.localeCompare(b.name);
|
|
|
|
|
+ });
|
|
|
|
|
+ break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Apply ascending/descending
|
|
// Apply ascending/descending
|
|
@@ -8069,7 +8091,7 @@ export function PrintersPage() {
|
|
|
|
|
|
|
|
// Group printers when sorted by location, status, or model
|
|
// Group printers when sorted by location, status, or model
|
|
|
const groupedPrinters = useMemo(() => {
|
|
const groupedPrinters = useMemo(() => {
|
|
|
- if (sortBy === 'name') return null;
|
|
|
|
|
|
|
+ if (sortBy === 'name' || sortBy === 'eta') return null;
|
|
|
|
|
|
|
|
const groups: Record<string, typeof sortedPrinters> = {};
|
|
const groups: Record<string, typeof sortedPrinters> = {};
|
|
|
|
|
|
|
@@ -8207,6 +8229,7 @@ export function PrintersPage() {
|
|
|
{ value: 'status', label: t('printers.sort.status') },
|
|
{ value: 'status', label: t('printers.sort.status') },
|
|
|
{ value: 'model', label: t('printers.sort.model') },
|
|
{ value: 'model', label: t('printers.sort.model') },
|
|
|
{ value: 'location', label: t('printers.sort.location') },
|
|
{ value: 'location', label: t('printers.sort.location') },
|
|
|
|
|
+ { value: 'eta', label: t('printers.sort.eta') },
|
|
|
]}
|
|
]}
|
|
|
/>
|
|
/>
|
|
|
<button
|
|
<button
|