2021-09-24 12:11:38 +02:00
|
|
|
<template>
|
|
|
|
<div class="workout-detail">
|
2021-09-28 09:10:01 +02:00
|
|
|
<Modal
|
|
|
|
v-if="displayModal"
|
2021-10-20 17:38:25 +02:00
|
|
|
:title="$t('common.CONFIRMATION')"
|
|
|
|
:message="$t('workouts.WORKOUT_DELETION_CONFIRMATION')"
|
2021-09-28 09:10:01 +02:00
|
|
|
@confirmAction="deleteWorkout(workoutObject.workoutId)"
|
|
|
|
@cancelAction="updateDisplayModal(false)"
|
|
|
|
/>
|
2021-10-02 16:16:58 +02:00
|
|
|
<Card>
|
2021-09-24 12:11:38 +02:00
|
|
|
<template #title>
|
2021-09-28 09:10:01 +02:00
|
|
|
<WorkoutCardTitle
|
|
|
|
:sport="sport"
|
|
|
|
:workoutObject="workoutObject"
|
|
|
|
@displayModal="updateDisplayModal(true)"
|
|
|
|
/>
|
2021-09-24 12:11:38 +02:00
|
|
|
</template>
|
|
|
|
<template #content>
|
2021-09-26 13:40:12 +02:00
|
|
|
<WorkoutMap
|
|
|
|
:workoutData="workoutData"
|
|
|
|
:markerCoordinates="markerCoordinates"
|
|
|
|
/>
|
2021-11-14 12:12:21 +01:00
|
|
|
<WorkoutData
|
|
|
|
:workoutObject="workoutObject"
|
|
|
|
:useImperialUnits="authUser.imperial_units"
|
2022-07-27 09:04:01 +02:00
|
|
|
:displayHARecord="authUser.display_ascent"
|
2021-11-14 12:12:21 +01:00
|
|
|
/>
|
2021-09-24 12:11:38 +02:00
|
|
|
</template>
|
|
|
|
</Card>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2021-11-10 21:19:27 +01:00
|
|
|
<script setup lang="ts">
|
2021-09-27 10:01:17 +02:00
|
|
|
import {
|
|
|
|
ComputedRef,
|
|
|
|
Ref,
|
|
|
|
computed,
|
|
|
|
ref,
|
2021-11-10 21:19:27 +01:00
|
|
|
toRefs,
|
2021-09-27 10:01:17 +02:00
|
|
|
watch,
|
2021-11-10 21:19:27 +01:00
|
|
|
withDefaults,
|
2021-09-27 10:01:17 +02:00
|
|
|
} from 'vue'
|
2021-09-24 15:03:40 +02:00
|
|
|
import { useRoute } from 'vue-router'
|
2021-09-24 12:11:38 +02:00
|
|
|
|
2021-09-27 11:49:17 +02:00
|
|
|
import WorkoutCardTitle from '@/components/Workout/WorkoutDetail/WorkoutCardTitle.vue'
|
2021-09-24 19:51:04 +02:00
|
|
|
import WorkoutData from '@/components/Workout/WorkoutDetail/WorkoutData.vue'
|
2022-01-15 15:42:11 +01:00
|
|
|
import WorkoutMap from '@/components/Workout/WorkoutDetail/WorkoutMap/index.vue'
|
2021-09-28 09:10:01 +02:00
|
|
|
import { WORKOUTS_STORE } from '@/store/constants'
|
2021-09-24 12:11:38 +02:00
|
|
|
import { ISport } from '@/types/sports'
|
2022-05-28 20:03:58 +02:00
|
|
|
import { IAuthUserProfile } from '@/types/user'
|
2021-09-27 10:01:17 +02:00
|
|
|
import {
|
|
|
|
IWorkout,
|
|
|
|
IWorkoutData,
|
|
|
|
IWorkoutObject,
|
|
|
|
IWorkoutSegment,
|
|
|
|
TCoordinates,
|
|
|
|
} from '@/types/workouts'
|
2021-09-28 09:10:01 +02:00
|
|
|
import { useStore } from '@/use/useStore'
|
2021-09-24 12:11:38 +02:00
|
|
|
import { formatWorkoutDate, getDateWithTZ } from '@/utils/dates'
|
|
|
|
|
2021-11-10 21:19:27 +01:00
|
|
|
interface Props {
|
2022-05-28 20:03:58 +02:00
|
|
|
authUser: IAuthUserProfile
|
2021-11-10 21:19:27 +01:00
|
|
|
displaySegment: boolean
|
|
|
|
sports: ISport[]
|
|
|
|
workoutData: IWorkoutData
|
|
|
|
markerCoordinates?: TCoordinates
|
|
|
|
}
|
|
|
|
const props = withDefaults(defineProps<Props>(), {
|
|
|
|
markerCoordinates: () => ({} as TCoordinates),
|
|
|
|
})
|
2021-09-27 10:01:17 +02:00
|
|
|
|
2021-11-10 21:19:27 +01:00
|
|
|
const route = useRoute()
|
|
|
|
const store = useStore()
|
2021-09-27 10:01:17 +02:00
|
|
|
|
2021-11-14 12:12:21 +01:00
|
|
|
const { authUser, markerCoordinates, workoutData } = toRefs(props)
|
2021-11-10 21:19:27 +01:00
|
|
|
const workout: ComputedRef<IWorkout> = computed(
|
|
|
|
() => props.workoutData.workout
|
|
|
|
)
|
2022-06-22 17:53:59 +02:00
|
|
|
const segmentId: Ref<number | null> = ref(
|
2021-11-10 21:19:27 +01:00
|
|
|
route.params.workoutId ? +route.params.segmentId : null
|
|
|
|
)
|
|
|
|
const segment: ComputedRef<IWorkoutSegment | null> = computed(() =>
|
|
|
|
workout.value.segments.length > 0 && segmentId.value
|
|
|
|
? workout.value.segments[+segmentId.value - 1]
|
|
|
|
: null
|
|
|
|
)
|
2022-06-22 17:53:59 +02:00
|
|
|
const displayModal: Ref<boolean> = ref(false)
|
2021-11-10 21:19:27 +01:00
|
|
|
const sport = computed(() =>
|
|
|
|
props.sports
|
|
|
|
? props.sports.find(
|
|
|
|
(sport) => sport.id === props.workoutData.workout.sport_id
|
|
|
|
)
|
|
|
|
: {}
|
|
|
|
)
|
|
|
|
const workoutObject = computed(() =>
|
|
|
|
getWorkoutObject(workout.value, segment.value)
|
|
|
|
)
|
2021-09-27 10:01:17 +02:00
|
|
|
|
2021-11-10 21:19:27 +01:00
|
|
|
function getWorkoutObjectUrl(
|
|
|
|
workout: IWorkout,
|
|
|
|
displaySegment: boolean,
|
|
|
|
segmentId: number | null
|
|
|
|
): Record<string, string | null> {
|
|
|
|
const previousUrl =
|
|
|
|
displaySegment && segmentId && segmentId !== 1
|
|
|
|
? `/workouts/${workout.id}/segment/${segmentId - 1}`
|
|
|
|
: !displaySegment && workout.previous_workout
|
|
|
|
? `/workouts/${workout.previous_workout}`
|
|
|
|
: null
|
|
|
|
const nextUrl =
|
|
|
|
displaySegment && segmentId && segmentId < workout.segments.length
|
|
|
|
? `/workouts/${workout.id}/segment/${segmentId + 1}`
|
|
|
|
: !displaySegment && workout.next_workout
|
|
|
|
? `/workouts/${workout.next_workout}`
|
|
|
|
: null
|
|
|
|
return {
|
|
|
|
previousUrl,
|
|
|
|
nextUrl,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function getWorkoutObject(
|
|
|
|
workout: IWorkout,
|
|
|
|
segment: IWorkoutSegment | null
|
|
|
|
): IWorkoutObject {
|
|
|
|
const urls = getWorkoutObjectUrl(
|
|
|
|
workout,
|
|
|
|
props.displaySegment,
|
|
|
|
segmentId.value ? +segmentId.value : null
|
|
|
|
)
|
|
|
|
const workoutDate = formatWorkoutDate(
|
|
|
|
getDateWithTZ(
|
|
|
|
props.workoutData.workout.workout_date,
|
|
|
|
props.authUser.timezone
|
2021-09-24 15:03:40 +02:00
|
|
|
)
|
2021-11-10 21:19:27 +01:00
|
|
|
)
|
|
|
|
return {
|
|
|
|
ascent: segment ? segment.ascent : workout.ascent,
|
|
|
|
aveSpeed: segment ? segment.ave_speed : workout.ave_speed,
|
|
|
|
distance: segment ? segment.distance : workout.distance,
|
|
|
|
descent: segment ? segment.descent : workout.descent,
|
|
|
|
duration: segment ? segment.duration : workout.duration,
|
|
|
|
maxAlt: segment ? segment.max_alt : workout.max_alt,
|
|
|
|
maxSpeed: segment ? segment.max_speed : workout.max_speed,
|
|
|
|
minAlt: segment ? segment.min_alt : workout.min_alt,
|
|
|
|
moving: segment ? segment.moving : workout.moving,
|
|
|
|
nextUrl: urls.nextUrl,
|
|
|
|
pauses: segment ? segment.pauses : workout.pauses,
|
|
|
|
previousUrl: urls.previousUrl,
|
|
|
|
records: segment ? [] : workout.records,
|
|
|
|
segmentId: segment ? segment.segment_id : null,
|
|
|
|
title: workout.title,
|
|
|
|
type: props.displaySegment ? 'SEGMENT' : 'WORKOUT',
|
|
|
|
workoutDate: workoutDate.workout_date,
|
|
|
|
weatherEnd: segment ? null : workout.weather_end,
|
|
|
|
weatherStart: segment ? null : workout.weather_start,
|
2021-11-29 17:07:51 +01:00
|
|
|
with_gpx: workout.with_gpx,
|
|
|
|
workoutId: workout.id,
|
2021-11-10 21:19:27 +01:00
|
|
|
workoutTime: workoutDate.workout_time,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function updateDisplayModal(value: boolean) {
|
|
|
|
displayModal.value = value
|
|
|
|
}
|
|
|
|
function deleteWorkout(workoutId: string) {
|
|
|
|
store.dispatch(WORKOUTS_STORE.ACTIONS.DELETE_WORKOUT, {
|
|
|
|
workoutId: workoutId,
|
|
|
|
})
|
|
|
|
}
|
2021-09-27 10:01:17 +02:00
|
|
|
|
2021-11-10 21:19:27 +01:00
|
|
|
watch(
|
|
|
|
() => route.params.segmentId,
|
|
|
|
async (newSegmentId) => {
|
|
|
|
if (newSegmentId) {
|
|
|
|
segmentId.value = +newSegmentId
|
2021-09-24 12:11:38 +02:00
|
|
|
}
|
2021-11-10 21:19:27 +01:00
|
|
|
}
|
|
|
|
)
|
2021-09-24 12:11:38 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2021-11-29 11:23:21 +01:00
|
|
|
@import '~@/scss/vars.scss';
|
2021-09-24 12:11:38 +02:00
|
|
|
.workout-detail {
|
2021-09-24 14:10:20 +02:00
|
|
|
display: flex;
|
2021-09-24 12:11:38 +02:00
|
|
|
::v-deep(.card) {
|
2021-09-24 14:10:20 +02:00
|
|
|
width: 100%;
|
2021-09-24 19:51:04 +02:00
|
|
|
.card-content {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
2021-10-02 16:16:58 +02:00
|
|
|
@media screen and (max-width: $medium-limit) {
|
2021-09-24 19:51:04 +02:00
|
|
|
flex-direction: column;
|
|
|
|
}
|
|
|
|
}
|
2021-09-24 12:11:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|