From b2d8f48c962cbb20099e4303b14229100873b51b Mon Sep 17 00:00:00 2001 From: Rein Appeldoorn Date: Mon, 12 Apr 2021 20:43:37 +0200 Subject: [PATCH] feat(options): autoFetch, csvExport processed data --- src/components/DataSelection.vue | 24 +++++++++--- src/components/DataTable.vue | 14 ++++++- src/components/GlobalOptionsModal.vue | 54 +++++++++++++++++++++------ src/services/global_options.js | 5 +++ src/util/filters.js | 20 ++++++++-- 5 files changed, 95 insertions(+), 22 deletions(-) diff --git a/src/components/DataSelection.vue b/src/components/DataSelection.vue index af5fb65..f9948f5 100644 --- a/src/components/DataSelection.vue +++ b/src/components/DataSelection.vue @@ -15,7 +15,7 @@ - - - + + + + + + @@ -90,10 +93,19 @@ export default { } }, created() { - this.fetchData() + if (globalOptions.autoFetch) { + this.fetchData() + } }, methods: { + dateChanged() { + if (globalOptions.autoFetch) { + this.fetchData() + } + }, fetchData() { + this.$emit('data-updated', { name: '', items: [] }) + this.fetching = true this.error429 = false chrome.runtime.sendMessage({ from: this.fromDate, to: this.toDate }, response => { diff --git a/src/components/DataTable.vue b/src/components/DataTable.vue index e69eba1..a6680f1 100644 --- a/src/components/DataTable.vue +++ b/src/components/DataTable.vue @@ -6,7 +6,7 @@ - CSV + CSV PDF @@ -103,6 +103,18 @@ export default { } return undefined }, undefined) + }, + csvItems() { + return this.data.items.map(item => { + let csvItem = Object.assign({}, item) + if (globalOptions.csvExportProcessedDistance) { + csvItem.distance = this.$options.filters.distance(item.distance, 2, true) + } + if (globalOptions.csvExportProcessedDuration) { + csvItem.duration = this.$options.filters.hhmmss(item.duration) + } + return csvItem + }) } } } diff --git a/src/components/GlobalOptionsModal.vue b/src/components/GlobalOptionsModal.vue index 325a923..8811ece 100644 --- a/src/components/GlobalOptionsModal.vue +++ b/src/components/GlobalOptionsModal.vue @@ -3,18 +3,48 @@ - - - - + + + + + + + + + On page load & date input change + + + + + + meters vs kilometers / miles + + + + seconds vs hh:mm:ss + + + diff --git a/src/services/global_options.js b/src/services/global_options.js index 0800fb7..6351482 100644 --- a/src/services/global_options.js +++ b/src/services/global_options.js @@ -6,6 +6,11 @@ class Globaloptions { this.distanceMode = 'Kilometers' this.distanceModeOptions = ['Kilometers', 'Miles'] + this.autoFetch = true + + this.csvExportProcessedDistance = false + this.csvExportProcessedDuration = false + this.load() } diff --git a/src/util/filters.js b/src/util/filters.js index a88d41c..17eca04 100644 --- a/src/util/filters.js +++ b/src/util/filters.js @@ -1,3 +1,5 @@ +import moment from 'moment' + import globalOptions from '../services/global_options' export default { @@ -7,16 +9,28 @@ export default { var fixed = value.toFixed(accuracy) return keep ? fixed : +fixed }) - Vue.filter('distance', (meters, decimals) => { + Vue.filter('distance', (meters, decimals, asFloat) => { if (meters === 0) { return '' } decimals = decimals || 2 + asFloat = asFloat || false const f = Math.pow(10, decimals) if (globalOptions.distanceMode === 'Miles') { - return `${Math.round((meters / 1609.344) * f) / f} miles` + let v = Math.round((meters / 1609.344) * f) / f + if (asFloat) { + return v + } + return `${v} miles` + } + let v = Math.round((meters / 1000) * f) / f + if (asFloat) { + return v } - return `${Math.round((meters / 1000) * f) / f} km` + return `${v} km` + }) + Vue.filter('hhmmss', seconds => { + return moment.utc(seconds * 1000).format('HH:mm:ss') }) } }