Skip to content

Commit 30a2491

Browse files
committed
Improve Spoolman integration in AFC lane components
Align AFC lane body with Spoolman data: use information from Spoolman or directly from the AFC component instead of deducing values or hardcoding defaults such as `initial_weight` of 1000. Expand the spool reel tooltip to show ID, vendor, filament name, material with extruder/bed temps, and remaining/used weight from Spoolman when available. Make the filament name row a clickable link to `/spool/show/{id}` on the Spoolman UI when configured; falls back to plain text otherwise. Add `initial_weight` and `filament_name` to `AfcLaneState` typings. Signed-off-by: paxx12 <245230251+paxx12@users.noreply.github.com>
1 parent a9f525f commit 30a2491

3 files changed

Lines changed: 67 additions & 25 deletions

File tree

src/components/widgets/afc/AfcCardUnitLaneBody.vue

Lines changed: 65 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,26 @@
2121
</span>
2222
</template>
2323
<span>
24-
#{{ spoolId }} | {{ spoolVendor }}
24+
<strong>ID #{{ spoolId }}</strong>
2525
<br>
26-
{{ spoolFilamentName }}
26+
<template v-if="spoolFilamentVendor">{{ spoolFilamentVendor }} — </template>{{ spoolFilamentName }}
27+
<template v-if="spoolMaterial">
28+
<br>
29+
{{ spoolMaterial }}
30+
<template v-if="spoolExtruderTemp">
31+
| {{ spoolExtruderTemp }}°C
32+
</template>
33+
<template v-if="spoolBedTemp">
34+
| {{ spoolBedTemp }}°C
35+
</template>
36+
</template>
37+
<template v-if="spoolRemainingWeight != null">
38+
<br>
39+
{{ Math.round(spoolRemainingWeight) }} g remaining
40+
<template v-if="spoolUsedWeight">
41+
({{ Math.round(spoolUsedWeight) }} g used)
42+
</template>
43+
</template>
2744
</span>
2845
</v-tooltip>
2946
<afc-unit-lane-filament-dialog
@@ -56,7 +73,8 @@
5673
{{ spoolMaterial }}
5774
</span>
5875
<span class="text--disabled">
59-
{{ spoolRemainingWeightOutput }}
76+
<template v-if="spoolRemainingWeight != null">{{ Math.round(spoolRemainingWeight) }} g</template>
77+
<template v-else>--</template>
6078
</span>
6179
<v-tooltip
6280
v-if="tdPresent"
@@ -84,9 +102,16 @@
84102
>
85103
<v-col class="px-6 pt-1">
86104
<div class="position-relative pb-4">
87-
<span class="position-absolute text-truncate text-truncate-element text-center">
88-
{{ spoolFilamentName }}
89-
</span>
105+
<a
106+
v-if="spoolUrl"
107+
:href="spoolUrl"
108+
target="_blank"
109+
class="position-absolute text-truncate text-truncate-element text-center text-decoration-none filament-link"
110+
>{{ spoolFilamentName }}</a>
111+
<span
112+
v-else
113+
class="position-absolute text-truncate text-truncate-element text-center"
114+
>{{ spoolFilamentName }}</span>
90115
</div>
91116
</v-col>
92117
</v-row>
@@ -147,39 +172,51 @@ export default class AfcCardUnitLaneBody extends Mixins(StateMixin, AfcMixin) {
147172
return this.lane?.color || '#000000'
148173
}
149174
150-
get spoolRemainingWeight (): number {
151-
if (this.afcExistsSpoolman && this.spool?.remaining_weight != null) {
152-
return Math.round(this.spool.remaining_weight)
153-
}
154-
return Math.round(this.lane?.weight ?? 0)
155-
}
156-
157-
get spoolRemainingWeightOutput (): string {
158-
return `${this.spoolRemainingWeight} g`
175+
get spoolRemainingWeight (): number | undefined {
176+
return this.spool?.remaining_weight ?? this.lane?.weight
159177
}
160178
161-
get spoolFullWeight (): number {
162-
return this.spool?.initial_weight ?? 1000
179+
get spoolFullWeight (): number | null {
180+
return this.spool?.initial_weight ?? this.lane?.initial_weight ?? null
163181
}
164182
165183
get spoolPercent (): number {
184+
if (this.spoolRemainingWeight == null || this.spoolFullWeight == null) return 100
166185
if (this.spoolFullWeight === 0) return 100
167186
168187
return Math.round((this.spoolRemainingWeight / this.spoolFullWeight) * 100)
169188
}
170189
171190
get spoolMaterial (): string {
172-
return this.lane?.material || '--'
191+
return this.spool?.filament?.material ?? this.lane?.material ?? ''
192+
}
193+
194+
get spoolFilamentVendor (): string | undefined {
195+
return this.spool?.filament?.vendor?.name
196+
}
197+
198+
get spoolFilamentName (): string | undefined {
199+
return this.spool?.filament?.name ||
200+
this.lane?.filament_name ||
201+
undefined
202+
}
203+
204+
get spoolUrl (): string | undefined {
205+
const base: string | undefined = this.$typedGetters['spoolman/getSpoolmanUrl']
206+
if (!base || !this.spoolId) return undefined
207+
return `${base.replace(/\/$/, '')}/spool/show/${this.spoolId}`
173208
}
174209
175-
get spoolVendor (): string {
176-
return this.spool?.filament?.vendor?.name ?? this.$t('app.afc.Unknown').toString()
210+
get spoolExtruderTemp (): number | undefined {
211+
return this.spool?.filament?.settings_extruder_temp
177212
}
178213
179-
get spoolFilamentName (): string {
180-
return this.afcExistsSpoolman
181-
? this.spool?.filament?.name ?? this.$t('app.afc.Unknown').toString()
182-
: ''
214+
get spoolBedTemp (): number | undefined {
215+
return this.spool?.filament?.settings_bed_temp
216+
}
217+
218+
get spoolUsedWeight (): number | undefined {
219+
return this.spool?.used_weight
183220
}
184221
185222
get tdPresent (): boolean {
@@ -246,4 +283,8 @@ export default class AfcCardUnitLaneBody extends Mixins(StateMixin, AfcMixin) {
246283
.position-relative {
247284
position: relative !important;
248285
}
286+
287+
.filament-link {
288+
color: inherit !important;
289+
}
249290
</style>

src/locales/en.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ app:
8686
ShowTd1Color: "Show TD-1 Color"
8787
Unloading: "Unloading"
8888
UnloadLane: "Unload Lane"
89-
Unknown: "Unknown"
9089
Weight: "Weight"
9190
WeightSubtitle: "The weight of the filament in grams (without spool)."
9291
bedmesh:

src/typings/klipper.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,9 +815,11 @@ declare namespace Klipper {
815815
density?: number;
816816
diameter?: number;
817817
empty_spool_weight?: number;
818+
initial_weight?: number;
818819
spool_id: number | null;
819820
color: string | null;
820821
weight: number;
822+
filament_name?: string;
821823
extruder_temp: number | null;
822824
runout_lane: string | null;
823825
filament_status: 'In Tool' | 'Ready' | 'Prep' | 'Not Ready';

0 commit comments

Comments
 (0)