Skip to content

Commit

Permalink
refact: move digit calculation to SpoolmanChangeSpoolDialog
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Stainbrook <[email protected]>
  • Loading branch information
rackrick committed Oct 15, 2023
1 parent 8ea6d5d commit 2130a1c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/components/dialogs/SpoolmanChangeSpoolDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<SpoolmanChangeSpoolDialogRow
:key="item.id"
:spool="item"
:max_id="max_spool_id"
:max_id_digits="max_spool_id_digits"
@set-spool="setSpool" />
</template>
</v-data-table>
Expand Down Expand Up @@ -91,11 +91,13 @@ export default class SpoolmanChangeSpoolDialog extends Mixins(BaseMixin) {
return this.$store.state.server.spoolman.spools ?? []
}
get max_spool_id(): number {
return this.$store.state.server.spoolman.spools.reduce(
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() {
Expand Down
5 changes: 2 additions & 3 deletions src/components/dialogs/SpoolmanChangeSpoolDialogRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ 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: number
@Prop({ required: false }) declare readonly max_id_digits: number
get color() {
const color = this.spool.filament?.color_hex ?? '000'
Expand All @@ -49,10 +49,9 @@ export default class SpoolmanChangeSpoolDialogRow extends Mixins(BaseMixin) {
get id() {
// add leading zeros depending on max_id digit count
const digits: number = this.max_id.toString().length ?? 1
let id: string = this.spool.id.toString()
while (id.length < digits) {
while (id.length < this.max_id_digits) {
id = '0' + id
}
Expand Down

0 comments on commit 2130a1c

Please sign in to comment.