workouts list + delete
Gitea Actions Demo / build_and_push (push) Successful in 1m49s Details

This commit is contained in:
artem 2024-09-24 21:07:10 +03:00
parent d5446b6ae9
commit 40d2a3083b
1 changed files with 62 additions and 19 deletions

View File

@ -3,19 +3,22 @@
<h1 class="page-title">Тренировки</h1> <h1 class="page-title">Тренировки</h1>
<section class="news-feed"> <section class="news-feed">
<template v-if="!workoutItems"> <template v-if="workoutItems.length==0">
<div>Тренировки не найдены</div> <div>Тренировки не найдены</div>
</template> </template>
<template v-if="workoutItems" v-for="(item, index) in workoutItems" :key="item.id"> <template v-if="workoutItems.length>0" v-for="(item, index) in workoutItems" :key="item.id">
<article class="news-item"> <article class="news-item">
<div class="news-item-header" >
<h3>{{ item.name }}</h3> <h3>{{ item.name }}</h3>
<VaIcon name="delete_forever" size="22px" color="#bbc1c3" class="news-item-icon" @click="deleteItem(item.id)"/>
</div>
<ul class="metadata"> <ul class="metadata">
<li><span>Скорость:</span> {{ item.speed }} км/ч</li> <li><span>Скорость:</span> {{ speedConvert(item.speed) }} км/ч</li>
<li><span>Пульс:</span> {{ item.heart_rate }} уд /мин</li> <li><span>Пульс:</span> {{ item.heart_rate }} уд /мин</li>
<li><span>Каденс:</span> {{ item.cadence }} об/мин</li> <li><span>Каденс:</span> {{ item.cadence }} об/мин</li>
<li><span>Расстояние:</span> 5 км</li> <li><span>Расстояние:</span> {{ distConvert(item.distantion) }} км</li>
<li><span>Продолжительность:</span> {{ secondsToDuration(item.duraion_sec) }} </li> <li><span>Продолжительность:</span> {{ secondsToDuration(item.duraion_sec) }} </li>
<li><span>Мощность:</span> {{ item.power }} км</li> <li><span>Мощность:</span> {{ Math.round(item.power) }}</li>
</ul> </ul>
<!-- <img src="img/first_workout.jpg" alt="Изображение первой тренировки"> --> <!-- <img src="img/first_workout.jpg" alt="Изображение первой тренировки"> -->
</article> </article>
@ -28,14 +31,39 @@ import { AxiosResponse, AxiosInstance } from "axios";
import { ref, inject } from 'vue'; import { ref, inject } from 'vue';
import { useToast } from "vuestic-ui/web-components"; import { useToast } from "vuestic-ui/web-components";
const deleteItem = (id: string) => {
axiosAuth
.delete(`/api/v0/workouts/${id}`)
.then((_: AxiosResponse) => {
init({
message: "Тренировка успешно удалена.",
color: "success",
});
initWorkouts();
})
.catch((error: any) => {
console.log(error);
init({
message: "Что-то пошло не так.",
color: "error",
});
});
};
const secondsToDuration = (seconds: number) => {
function secondsToDuration(seconds: number) : string {
var hours = Math.floor(seconds / 3600); var hours = Math.floor(seconds / 3600);
var minutes = Math.floor((seconds % 3600) / 60); var minutes = Math.floor((seconds % 3600) / 60);
return `${hours} ч. ${minutes} мин.`; return `${hours} ч. ${minutes} мин.`;
} }
const distConvert = (speed: number) => {
return Math.round(speed/1000)
}
const speedConvert = (speed: number) => {
return Math.round(speed*3.6)
}
type WorkoutItem = { type WorkoutItem = {
id: string; id: string;
@ -50,12 +78,14 @@ type WorkoutItem = {
speed: number; speed: number;
power: number; power: number;
duraion_sec: number; duraion_sec: number;
distantion: number;
}; };
const axiosAuth= inject('axiosAuth') as AxiosInstance; const axiosAuth= inject('axiosAuth') as AxiosInstance;
let workoutItems = ref<Array<WorkoutItem>>([]); let workoutItems = ref<Array<WorkoutItem>>([]);
const { init } = useToast(); const { init } = useToast();
const initWorkouts = () => {
axiosAuth axiosAuth
.get(`/api/v0/workouts`) .get(`/api/v0/workouts`)
.then((response: AxiosResponse) => { .then((response: AxiosResponse) => {
@ -68,6 +98,8 @@ axiosAuth
color: "error", color: "error",
}); });
}); });
}
initWorkouts();
</script> </script>
<style> <style>
@ -100,6 +132,15 @@ axiosAuth
width: 100%; width: 100%;
} }
.news-item-header {
display: flex;
justify-content: space-between;
}
.news-item-icon {
cursor: pointer;
}
.news-item img { .news-item img {
width: 100%; width: 100%;
height: auto; height: auto;
@ -112,9 +153,11 @@ axiosAuth
font-weight: bold; font-weight: bold;
color: #3d3d3d; color: #3d3d3d;
} }
.metadata { .metadata {
border-top: #9c9a9a 1px solid; border-top: #9c9a9a 1px solid;
} }
.metadata li { .metadata li {
list-style: none; list-style: none;
display: inline-block; display: inline-block;