Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rework spoolman change dialog to display spool ids #1605

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/components/dialogs/SpoolmanChangeSpoolDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@
</template>

<template #item="{ item }">
<SpoolmanChangeSpoolDialogRow :key="item.id" :spool="item" @set-spool="setSpool" />
<SpoolmanChangeSpoolDialogRow
:key="item.id"
:spool="item"
:max_id_digits="max_spool_id_digits"
@set-spool="setSpool" />
</template>
</v-data-table>
</v-card-text>
Expand Down Expand Up @@ -87,6 +91,15 @@ export default class SpoolmanChangeSpoolDialog extends Mixins(BaseMixin) {
return this.$store.state.server.spoolman.spools ?? []
}

get max_spool_id_digits(): number {
const max_id = this.$store.state.server.spoolman.spools.reduce(
(x: number, s: ServerSpoolmanStateSpool) => Math.max(x, s.id),
0
)

return max_id.toString().length
}

get headers() {
return [
{
Expand Down
32 changes: 31 additions & 1 deletion src/components/dialogs/SpoolmanChangeSpoolDialogRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@
<td style="width: 50px" class="pr-0 py-2">
<spool-icon :color="color" style="width: 50px; float: left" class="mr-3" />
</td>

<td class="py-2" style="min-width: 300px">
<strong class="text-no-wrap">{{ vendor }} - {{ name }}</strong>
<v-list-item two-line>
<v-list-item-content class="no--padding">
<div class="text--disabled mb-1">#{{ id }} | {{ vendor }}</div>
<v-list-item-title class="mb-1">
<span class="text--filament">{{ name }}</span>
</v-list-item-title>
</v-list-item-content>
</v-list-item>
<template v-if="location">
<br />
{{ $t('Panels.SpoolmanPanel.Location') }}: {{ location }}
Expand All @@ -31,12 +39,25 @@ import { ServerSpoolmanStateSpool } from '@/store/server/spoolman/types'
@Component({})
export default class SpoolmanChangeSpoolDialogRow extends Mixins(BaseMixin) {
@Prop({ required: true }) declare readonly spool: ServerSpoolmanStateSpool
@Prop({ required: false }) declare readonly max_id_digits: number

get color() {
const color = this.spool.filament?.color_hex ?? '000'

return `#${color}`
}

get id() {
// add leading zeros depending on max_id digit count
let id: string = this.spool.id.toString()

while (id.length < this.max_id_digits) {
id = '0' + id
}

return id
}

get vendor() {
return this.spool.filament?.vendor?.name ?? 'Unknown'
}
Expand Down Expand Up @@ -102,3 +123,12 @@ export default class SpoolmanChangeSpoolDialogRow extends Mixins(BaseMixin) {
}
}
</script>
<style scoped>
.text--filament {
font-size: 1.1rem;
}

.no--padding {
padding: 0;
}
</style>
Loading