2021-08-21 18:47:35 +02:00
|
|
|
<template>
|
2021-09-05 09:41:39 +02:00
|
|
|
<div class="user-month-stats">
|
2021-09-04 19:40:27 +02:00
|
|
|
<Card :without-title="false">
|
|
|
|
<template #title>{{ $t('dashboard.THIS_MONTH') }}</template>
|
|
|
|
<template #content>
|
2021-09-21 08:51:07 +02:00
|
|
|
<div v-if="Object.keys(statistics).length === 0">
|
|
|
|
{{ t('workouts.NO_WORKOUTS') }}
|
2021-09-04 19:40:27 +02:00
|
|
|
</div>
|
2021-09-21 08:51:07 +02:00
|
|
|
<div v-else>
|
|
|
|
<div class="chart-radio">
|
|
|
|
<label class="">
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
name="total_distance"
|
|
|
|
:checked="displayedData === 'total_distance'"
|
|
|
|
@click="updateDisplayData"
|
|
|
|
/>
|
|
|
|
{{ t('workouts.DISTANCE') }}
|
|
|
|
</label>
|
|
|
|
<label class="">
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
name="total_duration"
|
|
|
|
:checked="displayedData === 'total_duration'"
|
|
|
|
@click="updateDisplayData"
|
|
|
|
/>
|
|
|
|
{{ t('workouts.DURATION') }}
|
|
|
|
</label>
|
|
|
|
<label class="">
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
name="nb_workouts"
|
|
|
|
:checked="displayedData === 'nb_workouts'"
|
|
|
|
@click="updateDisplayData"
|
|
|
|
/>
|
|
|
|
{{ t('workouts.WORKOUT', 2) }}
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
<Chart
|
|
|
|
:displayedData="displayedData"
|
|
|
|
:params="chartParams"
|
|
|
|
:statistics="statistics"
|
|
|
|
:sports="sports"
|
|
|
|
:week-starting-monday="weekStartingMonday"
|
|
|
|
v-if="statistics && weekStartingMonday !== undefined"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</template>
|
2021-09-04 19:40:27 +02:00
|
|
|
</Card>
|
|
|
|
</div>
|
2021-08-21 18:47:35 +02:00
|
|
|
</template>
|
2021-09-04 19:40:27 +02:00
|
|
|
|
|
|
|
<script lang="ts">
|
2021-09-27 13:06:17 +02:00
|
|
|
import { endOfMonth, format, startOfMonth } from 'date-fns'
|
2021-09-04 19:40:27 +02:00
|
|
|
import {
|
|
|
|
ComputedRef,
|
|
|
|
PropType,
|
|
|
|
computed,
|
|
|
|
defineComponent,
|
|
|
|
ref,
|
2021-09-05 17:43:14 +02:00
|
|
|
onBeforeMount,
|
2021-09-04 19:40:27 +02:00
|
|
|
} from 'vue'
|
|
|
|
import { useI18n } from 'vue-i18n'
|
|
|
|
|
|
|
|
import Card from '@/components/Common/Card.vue'
|
|
|
|
import Chart from '@/components/Common/StatsChart/index.vue'
|
2021-09-27 13:06:17 +02:00
|
|
|
import { STATS_STORE } from '@/store/constants'
|
2021-09-04 19:40:27 +02:00
|
|
|
import { ISport } from '@/types/sports'
|
|
|
|
import { IStatisticsDateParams, TStatisticsFromApi } from '@/types/statistics'
|
|
|
|
import { IAuthUserProfile } from '@/types/user'
|
|
|
|
import { useStore } from '@/use/useStore'
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
name: 'UserMonthStats',
|
|
|
|
components: {
|
|
|
|
Card,
|
|
|
|
Chart,
|
|
|
|
},
|
|
|
|
props: {
|
2021-09-27 13:06:17 +02:00
|
|
|
sports: {
|
|
|
|
type: Object as PropType<ISport[]>,
|
|
|
|
required: true,
|
|
|
|
},
|
2021-09-04 19:40:27 +02:00
|
|
|
user: {
|
|
|
|
type: Object as PropType<IAuthUserProfile>,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
setup(props) {
|
|
|
|
const store = useStore()
|
|
|
|
const { t } = useI18n()
|
2021-09-27 13:06:17 +02:00
|
|
|
|
|
|
|
onBeforeMount(() => getStatistics())
|
|
|
|
|
|
|
|
const date = new Date()
|
2021-09-04 19:40:27 +02:00
|
|
|
const dateFormat = 'yyyy-MM-dd'
|
2021-09-27 13:06:17 +02:00
|
|
|
let displayedData = ref('total_distance')
|
2021-09-04 19:40:27 +02:00
|
|
|
const chartParams: IStatisticsDateParams = {
|
|
|
|
duration: 'week',
|
|
|
|
start: startOfMonth(date),
|
|
|
|
end: endOfMonth(date),
|
|
|
|
}
|
|
|
|
const apiParams = {
|
|
|
|
from: format(chartParams.start, dateFormat),
|
|
|
|
to: format(chartParams.end, dateFormat),
|
|
|
|
time: `week${props.user.weekm ? 'm' : ''}`,
|
|
|
|
}
|
|
|
|
const statistics: ComputedRef<TStatisticsFromApi> = computed(
|
|
|
|
() => store.getters[STATS_STORE.GETTERS.USER_STATS]
|
|
|
|
)
|
|
|
|
|
|
|
|
function updateDisplayData(event: Event & { target: HTMLInputElement }) {
|
|
|
|
displayedData.value = event.target.name
|
|
|
|
}
|
2021-09-05 17:43:14 +02:00
|
|
|
function getStatistics() {
|
|
|
|
store.dispatch(STATS_STORE.ACTIONS.GET_USER_STATS, {
|
|
|
|
username: props.user.username,
|
|
|
|
filterType: 'by_time',
|
|
|
|
params: apiParams,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-09-04 19:40:27 +02:00
|
|
|
return {
|
2021-09-27 13:06:17 +02:00
|
|
|
weekStartingMonday: computed<boolean>(() => props.user.weekm),
|
2021-09-04 19:40:27 +02:00
|
|
|
chartParams,
|
|
|
|
displayedData,
|
|
|
|
statistics,
|
|
|
|
t,
|
|
|
|
updateDisplayData,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
2021-09-20 18:23:05 +02:00
|
|
|
<style lang="scss" scoped>
|
2021-09-04 19:40:27 +02:00
|
|
|
@import '~@/scss/base';
|
|
|
|
|
2021-09-20 18:23:05 +02:00
|
|
|
.user-month-stats {
|
2021-09-22 11:49:56 +02:00
|
|
|
::v-deep(.card-content) {
|
|
|
|
padding: $default-padding;
|
|
|
|
.stat-chart {
|
|
|
|
.chart {
|
2021-09-20 18:23:05 +02:00
|
|
|
.bar-chart {
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-09-22 11:49:56 +02:00
|
|
|
.chart-radio {
|
|
|
|
display: flex;
|
|
|
|
justify-content: space-between;
|
|
|
|
padding: $default-padding;
|
2021-09-04 19:40:27 +02:00
|
|
|
|
2021-09-22 11:49:56 +02:00
|
|
|
label {
|
|
|
|
font-size: 0.85em;
|
|
|
|
font-weight: normal;
|
|
|
|
}
|
2021-09-20 18:23:05 +02:00
|
|
|
}
|
2021-09-04 19:40:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|