Skip to content

Commit

Permalink
feat: miles
Browse files Browse the repository at this point in the history
  • Loading branch information
reinzor committed Mar 22, 2021
1 parent e75bedc commit c27ac3d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/components/DataTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@
<span v-b-tooltip.hover :title="`${data.value}`">{{ data.value | duration('humanize') }}</span>
</template>
<template #cell(distance)="data">
<span v-b-tooltip.hover :title="`${data.value}`">{{ data.value | kilometers }}</span>
<span v-b-tooltip.hover :title="`${data.value}`">{{ data.value | distance }}</span>
</template>
</b-table>
<small class="text-muted">
<i>Duration: {{ data.durationSum | duration('asHours') | round(2) }} hours</i>
<i v-if="data.distanceSum">, Distance: {{ data.distanceSum | kilometers }}</i>
<i v-if="data.distanceSum">, Distance: {{ data.distanceSum | distance }}</i>
</small>
</div>
<hr />
<p class="text-muted">
<i>Duration: {{ durationSum | duration('asHours') | round(2) }} hours</i>
<i v-if="distanceSum">, Distance: {{ distanceSum | kilometers }}</i>
<i v-if="distanceSum">, Distance: {{ distanceSum | distance }}</i>
</p>
</b-card-body>
</template>
Expand Down
6 changes: 6 additions & 0 deletions src/components/GlobalOptionsModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
v-model="globalOptions.groupMode"
:options="globalOptions.groupModeOptions"
></b-form-select>
<label for="distance-mode" class="mt-2">Distance mode:</label>
<b-form-select
id="distance-mode"
v-model="globalOptions.distanceMode"
:options="globalOptions.distanceModeOptions"
></b-form-select>
</b-modal>
</template>

Expand Down
3 changes: 3 additions & 0 deletions src/services/global_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ class Globaloptions {
this.groupMode = 'None'
this.groupModeOptions = ['None', 'Week', 'Month']

this.distanceMode = 'Kilometers'
this.distanceModeOptions = ['Kilometers', 'Miles']

this.load()
}

Expand Down
7 changes: 6 additions & 1 deletion src/util/filters.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import globalOptions from '../services/global_options'

export default {
install(Vue) {
Vue.filter('round', (value, accuracy, keep) => {
if (typeof value !== 'number') return value
var fixed = value.toFixed(accuracy)
return keep ? fixed : +fixed
})
Vue.filter('kilometers', (meters, decimals) => {
Vue.filter('distance', (meters, decimals) => {
if (meters === 0) {
return ''
}
decimals = decimals || 2
const f = Math.pow(10, decimals)
if (globalOptions.distanceMode === 'Miles') {
return `${Math.round((meters / 1609.344) * f) / f} miles`
}
return `${Math.round((meters / 1000) * f) / f} km`
})
}
Expand Down

0 comments on commit c27ac3d

Please sign in to comment.