Skip to content

Commit

Permalink
feat: formats weight as human readable (fluidd-core#628)
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Lamas <[email protected]>
  • Loading branch information
pedrolamas authored and matmen committed Jun 27, 2022
1 parent eaaeb2d commit 4959206
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/widgets/filesystem/FileSystemBrowser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
item-value="filament_weight_total"
>
<span v-if="item.filament_weight_total !== undefined">
{{ item.filament_weight_total }} g
{{ $filters.getReadableWeightString(item.filament_weight_total) }}
</span>
</file-row-item>

Expand Down
8 changes: 8 additions & 0 deletions src/plugins/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ export const Filters = {
return lengthInMm.toFixed(1) + ' mm'
},

/**
* Formats a number representing g to human readable weight.
*/
getReadableWeightString (weightInG: number) {
if (weightInG >= 1000) return (weightInG / 1000).toFixed(2) + ' kg'
return weightInG.toFixed(2) + ' g'
},

/**
* The filesystem sorter. This is copied from vuetify, and modified to ensure our directories
* are always sorted to the top.
Expand Down

0 comments on commit 4959206

Please sign in to comment.