-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
177 lines (170 loc) · 9.03 KB
/
Copy pathindex.html
File metadata and controls
177 lines (170 loc) · 9.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rudern - Rowing tracker</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss/dist/tailwind.min.css" rel="stylesheet">
<style>
html,
body
{
font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
}
</style>
</head>
<body class="bg-gray-100" x-data="initSessions()">
<div class="container mx-auto py-10 px-4">
<h1 class="text-3xl font-bold mb-6">Rowing session tracker</h1>
<div class="bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4">
<div class="mb-4">
<label class="block text-gray-700 text-sm font-bold mb-2" for="date">
Date
</label>
<input class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" id="date" type="date" placeholder="session date" x-model="date">
</div>
<div class="mb-4">
<label class="block text-gray-700 text-sm font-bold mb-2" for="time">
Time
</label>
<input x-mask="99:99" placeholder="00:00" class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" id="time" type="text" x-model="time" pattern="[0-9][0-9]:[0-5][0-9]">
</div>
<div class="mb-4">
<label class="block text-gray-700 text-sm font-bold mb-2" for="distance">
Distance
</label>
<input placeholder="0000" class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" id="distance" type="number" x-model="distance">
</div>
<div class="mb-4">
<label class="block text-gray-700 text-sm font-bold mb-2" for="count">
Count
</label>
<input placeholder="000" class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" id="count" type="number" x-model="count">
</div>
<div class="mb-4">
<label class="block text-gray-700 text-sm font-bold mb-2" for="calories">
Calories
</label>
<input placeholder="000.0" class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" id="calories" type="number" x-model="calories">
</div>
<div class="mb-4">
<label class="block text-gray-700 text-sm font-bold mb-2" for="level">
Level
</label>
<input placeholder="0" class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" id="level" type="number" x-model="level">
</div>
<div class="flex items-center justify-between space-x-1">
<button class="w-1/3 bg-blue-500 hover:bg-blue-700 text-white text-xs py-2 px-4 rounded focus:outline-none focus:shadow-outline" type="button" @click="saveSession()" :disabled="!time || !count || !distance || !calories">
Save
</button>
<button class="w-1/3 bg-red-500 hover:bg-red-700 text-white text-xs py-2 px-4 rounded focus:outline-none focus:shadow-outline" type="button" @click="deleteAllsessions()">
Delete All
</button>
<button class="w-1/3 bg-green-500 hover:bg-green-700 text-white text-xs py-2 px-4 rounded focus:outline-none focus:shadow-outline" type="button" @click="copySessions()" title="Copy All To Clipboard">
Copy All
</button>
</div>
</div>
<div class="bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4">
<h2 class="text-2xl font-bold mb-4">Sessions</h2>
<div class="overflow-x-auto">
<table class="w-full overflow-x-auto border-collapse border border-gray-400">
<thead>
<tr>
<th class="border px-2 text-left">Date</th>
<th class="border px-2 text-left">Time</th>
<th class="border px-2 text-left">m</th>
<th class="border px-2 text-left">cnt</th>
<th class="border px-2 text-left">cal</th>
<th class="border px-2 text-left">lvl</th>
<th class="border px-2 text-left">cnt/m</th>
<th class="border px-2 text-left">…</th>
</tr>
</thead>
<tbody>
<template x-for="(session, index) in sessions" :key="index">
<tr>
<td class="border px-2 text-xs"><span x-text="session.date"></span></td>
<td class="border px-2"><span x-text="session.time"></span></td>
<td class="border px-2"><span x-text="session.distance"></span></td>
<td class="border px-2"><span x-text="session.count"></span></td>
<td class="border px-2"><span x-text="session.calories"></span></td>
<td class="border px-2"><span x-text="session.level"></span></td>
<td class="border px-2"><span x-text="(session.count / (parseInt(session.time.split(':')[0]) + (parseInt(session.time.split(':')[1]) / 60))).toFixed(2)"></span></td>
<td class="border px-2">
<button class="text-blue-500 hover:text-blue-700" type="button" @click="editsession(index)" title="Edit">✎</button>
<button class="ml-2 text-red-500 hover:text-red-700" type="button" @click="deletesession(index)" title="Delete">⌫</button></td>
</tr>
</template>
</tbody>
</table>
</div>
</div>
</div>
<script defer src="https://cdn.jsdelivr.net/npm/@alpinejs/mask@3.x.x/dist/cdn.min.js"></script>
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
<script>
function initSessions() {
const sessions = JSON.parse(localStorage.getItem('sessions')) || [];
return {
sessions,
date: new Date().toISOString().slice(0, 10),
time: '',
count: '',
distance: '',
calories: '',
level: '',
saveSession() {
const session = {
date: this.date,
time: this.time,
count: parseInt(this.count),
distance: parseFloat(this.distance),
calories: parseFloat(this.calories),
level: parseInt(this.level),
};
this.sessions.push(session);
localStorage.setItem('sessions', JSON.stringify(this.sessions));
this.resetForm();
},
resetForm() {
this.date = '';
this.time = '';
this.count = '';
this.distance = '';
this.calories = '';
this.level = '';
},
copySessions() {
const jsonl = this.sessions.map(({date, time, count, distance, calories, level}) => {
return JSON.stringify({ date, time, count, distance, calories, level });
}).join('\n') + '\n';
if (navigator.clipboard) {
navigator.clipboard.writeText(jsonl);
} else {
console.error(jsonl);
}
},
deleteAllsessions() {
this.sessions = [];
localStorage.setItem('sessions', JSON.stringify([]));
},
editsession(index) {
const {date, time, count, distance, calories, level} = this.sessions[index];
this.date = date;
this.time = time;
this.count = count;
this.distance = distance;
this.calories = calories;
this.level = level;
this.deletesession(index);
},
deletesession(index) {
this.sessions.splice(index, 1);
localStorage.setItem('sessions', JSON.stringify(this.sessions));
}
};
}
</script>
</body>
</html>