delete quick entry and some stats

This commit is contained in:
Akhil Gupta
2021-08-13 13:04:00 +05:30
parent 4ee44fb1f1
commit 0e7d105e52
16 changed files with 350 additions and 22 deletions

View File

@@ -0,0 +1,54 @@
<script>
import { Line } from 'vue-chartjs'
import axios from 'axios'
import { mapState } from 'vuex'
export default {
extends: Line,
props: { vehicle: { type: Object, required: true }, since: { type: Date, default: '' }, user: { type: Object, required: true } },
computed: {
...mapState('utils', ['isMobile']),
},
watch: {
since(newOne, old) {
if (newOne === old) {
return
}
this.fetchMileage()
},
},
data: function() {
return {
chartData: [],
}
},
mounted() {
this.fetchMileage()
},
methods: {
showChart() {
var labels = this.chartData.map((x) => x.date.substr(0, 10))
var dataset = {
steppedLine: true,
label: `Mileage (${this.user.distanceUnitDetail.short}/${this.vehicle.fuelUnitDetail.short})`,
fill: true,
data: this.chartData.map((x) => x.mileage),
}
this.renderChart({ labels, datasets: [dataset] }, { maintainAspectRatio: false })
},
fetchMileage() {
axios
.get(`/api/vehicles/${this.vehicle.id}/mileage`, {
params: {
since: this.since,
},
})
.then((response) => {
this.chartData = response.data
this.showChart()
})
.catch((err) => console.log(err))
},
},
}
</script>