Skip to content

Commit d8a9555

Browse files
authored
feat: new Moonraker metadata support (#1617)
Signed-off-by: Pedro Lamas <[email protected]>
1 parent 8a3cf5f commit d8a9555

17 files changed

+503
-366
lines changed

components.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ declare module 'vue' {
1919
AppBtnToggle: typeof import('./src/components/ui/AppBtnToggle.vue')['default']
2020
AppBtnToolheadMove: typeof import('./src/components/ui/AppBtnToolheadMove.vue')['default']
2121
AppChart: typeof import('./src/components/ui/AppChart.vue')['default']
22+
AppChipColor: typeof import('./src/components/ui/AppChipColor.vue')['default']
2223
AppColorPicker: typeof import('./src/components/ui/AppColorPicker.vue')['default']
2324
AppColumnPicker: typeof import('./src/components/ui/AppColumnPicker.vue')['default']
2425
AppDataTableRow: typeof import('./src/components/ui/AppDataTableRow.vue')['default']

src/components/ui/AppChipColor.vue

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<template>
2+
<v-chip
3+
:style="{
4+
background: color
5+
}"
6+
small
7+
>
8+
<slot />
9+
</v-chip>
10+
</template>
11+
12+
<script lang="ts">
13+
import { Component, Prop, Vue } from 'vue-property-decorator'
14+
15+
@Component({
16+
inheritAttrs: false
17+
})
18+
export default class AppChipColor extends Vue {
19+
@Prop({ type: String, required: true })
20+
color!: string
21+
}
22+
</script>
23+
24+
<style lang="scss" scoped>
25+
@import 'vuetify/src/styles/styles.sass';
26+
27+
@include theme(v-chip) using ($material) {
28+
border-color: map-deep-get($material, 'text', 'primary');
29+
}
30+
31+
.v-chip {
32+
border-style: solid;
33+
padding: 0;
34+
width: 24px;
35+
}
36+
</style>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<template>
2+
<div>
3+
<v-tooltip
4+
v-for="(color, index) in colors"
5+
:key="index"
6+
top
7+
>
8+
<template #activator="{ on, attrs }">
9+
<app-chip-color
10+
v-bind="{...$attrs, ...attrs}"
11+
:color="color"
12+
:class="{
13+
'ms-1': index > 0
14+
}"
15+
v-on="{...$listeners, ...on }"
16+
/>
17+
</template>
18+
<span>{{ color }}</span>
19+
</v-tooltip>
20+
</div>
21+
</template>
22+
23+
<script lang="ts">
24+
import { Component, Prop, Vue } from 'vue-property-decorator'
25+
26+
@Component({
27+
inheritAttrs: false
28+
})
29+
export default class AppDataTableCellColors extends Vue {
30+
@Prop({ type: Array, required: true })
31+
readonly colors!: string[]
32+
}
33+
</script>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<template>
2+
<div>
3+
<v-chip
4+
v-for="(temp, index) in temps"
5+
:key="index"
6+
:class="{
7+
'ms-1': index > 0
8+
}"
9+
small
10+
>
11+
{{ temp }}<small>°C</small>
12+
</v-chip>
13+
</div>
14+
</template>
15+
16+
<script lang="ts">
17+
import { Component, Prop, Vue } from 'vue-property-decorator'
18+
19+
@Component({
20+
inheritAttrs: false
21+
})
22+
export default class AppDataTableCellColors extends Vue {
23+
@Prop({ type: Array, required: true })
24+
readonly temps!: string[]
25+
}
26+
</script>

src/components/ui/AppDataTableRow.vue

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
}"
77
v-on="$listeners"
88
>
9-
<template v-for="header in headers">
9+
<template v-for="{ header, value } in items">
1010
<td
1111
:key="header.value"
1212
:class="[
@@ -20,15 +20,38 @@
2020
<slot
2121
:name="`item.${header.value}`"
2222
:header="header"
23-
:value="getValue(header)"
23+
:value="value"
2424
>
25-
<slot
26-
name="item.data-table-default"
27-
:header="header"
28-
:value="getValue(header)"
29-
>
30-
{{ formatValue(getValue(header)) }}
31-
</slot>
25+
<template v-if="isEmpty(value)">
26+
--
27+
</template>
28+
<template v-else-if="Array.isArray(value) && value.length > 0">
29+
<slot
30+
:name="`item-value.${header.value}`"
31+
:header="header"
32+
:value="value"
33+
>
34+
<v-chip
35+
v-for="(arrayItem, index) in value"
36+
:key="index"
37+
:class="{
38+
'ms-1': index > 0
39+
}"
40+
small
41+
>
42+
{{ isEmpty(arrayItem) ? '--' : arrayItem }}
43+
</v-chip>
44+
</slot>
45+
</template>
46+
<template v-else>
47+
<slot
48+
:name="`item-value.${header.value}`"
49+
:header="header"
50+
:value="value"
51+
>
52+
{{ value }}
53+
</slot>
54+
</template>
3255
</slot>
3356
</td>
3457
</template>
@@ -40,6 +63,12 @@ import { Component, Prop, Vue } from 'vue-property-decorator'
4063
import { get } from 'lodash-es'
4164
import type { DataTableHeader } from 'vuetify'
4265
66+
export type GetterFunction = (item: unknown, header: DataTableHeader, defaultGetter: DefaultGetterFunction) => unknown
67+
68+
const defaultGetter = (item: unknown, header: DataTableHeader): unknown => get(item, header.value)
69+
70+
export type DefaultGetterFunction = typeof defaultGetter
71+
4372
@Component({
4473
inheritAttrs: false
4574
})
@@ -53,14 +82,27 @@ export default class AppDataTableRow extends Vue {
5382
@Prop({ type: Boolean })
5483
readonly isSelected!: boolean
5584
56-
getValue (header: DataTableHeader) {
57-
return get(this.item, header.value)
85+
@Prop({ type: Function })
86+
readonly customGetter?: GetterFunction
87+
88+
isEmpty (value: unknown) {
89+
return (
90+
value == null ||
91+
value === '' ||
92+
(
93+
Array.isArray(value) &&
94+
value.length === 0
95+
)
96+
)
5897
}
5998
60-
formatValue (value: unknown) {
61-
return value == null || value === ''
62-
? '--'
63-
: value
99+
get items () {
100+
const getter = this.customGetter ?? defaultGetter
101+
102+
return this.headers.map(header => ({
103+
header,
104+
value: getter(this.item, header, defaultGetter)
105+
}))
64106
}
65107
}
66108
</script>

src/components/widgets/filesystem/FileSystem.vue

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,24 @@ export default class FileSystem extends Mixins(StateMixin, FilesMixin, ServicesM
324324
visible: isNotDashboard,
325325
cellClass: 'text-no-wrap'
326326
},
327+
{
328+
text: this.$tc('app.general.table.header.filament_colors'),
329+
value: 'filament_colors',
330+
visible: isNotDashboard,
331+
cellClass: 'text-no-wrap'
332+
},
333+
{
334+
text: this.$tc('app.general.table.header.extruder_colors'),
335+
value: 'extruder_colors',
336+
visible: isNotDashboard,
337+
cellClass: 'text-no-wrap'
338+
},
339+
{
340+
text: this.$tc('app.general.table.header.filament_temps'),
341+
value: 'filament_temps',
342+
visible: isNotDashboard,
343+
cellClass: 'text-no-wrap'
344+
},
327345
{
328346
text: this.$tc('app.general.table.header.filament_type'),
329347
value: 'filament_type',
@@ -336,12 +354,36 @@ export default class FileSystem extends Mixins(StateMixin, FilesMixin, ServicesM
336354
visible: isNotDashboard,
337355
cellClass: 'text-no-wrap'
338356
},
357+
{
358+
text: this.$tc('app.general.table.header.filament_change_count'),
359+
value: 'filament_change_count',
360+
visible: isNotDashboard,
361+
cellClass: 'text-no-wrap'
362+
},
339363
{
340364
text: this.$tc('app.general.table.header.filament_weight_total'),
341365
value: 'filament_weight_total',
342366
visible: isNotDashboard,
343367
cellClass: 'text-no-wrap'
344368
},
369+
{
370+
text: this.$tc('app.general.table.header.filament_weights'),
371+
value: 'filament_weights',
372+
visible: isNotDashboard,
373+
cellClass: 'text-no-wrap'
374+
},
375+
{
376+
text: this.$tc('app.general.table.header.mmu_print'),
377+
value: 'mmu_print',
378+
visible: isNotDashboard,
379+
cellClass: 'text-no-wrap'
380+
},
381+
{
382+
text: this.$tc('app.general.table.header.referenced_tools'),
383+
value: 'referenced_tools',
384+
visible: isNotDashboard,
385+
cellClass: 'text-no-wrap'
386+
},
345387
{
346388
text: this.$tc('app.general.table.header.filament_used'),
347389
value: 'history.filament_used',

0 commit comments

Comments
 (0)