-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
201 lines (188 loc) · 6.19 KB
/
index.html
File metadata and controls
201 lines (188 loc) · 6.19 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>GymNote</title>
<!-- Tailwind via CDN -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Dexie.js for IndexedDB -->
<script src="https://unpkg.com/dexie@3/dist/dexie.min.js"></script>
<!-- Chart.js for graphs -->
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body class="bg-gray-100 p-4 min-h-screen flex items-center justify-center">
<div class="w-full max-w-4xl">
<h1 class="text-3xl font-bold mb-4 text-center">GymNote</h1>
<!-- MOBILE “Machines” TOGGLE BUTTON -->
<button
id="toggleListBtn"
class="md:hidden fixed top-4 left-4 z-50 px-3 py-1 bg-gray-800 text-white rounded"
>
Machines
</button>
<div class="flex flex-col md:flex-row md:space-x-4 space-y-4 md:space-y-0">
<!-- MACHINE LIST -->
<div
id="machineListContainer"
class="w-full md:w-1/3 bg-white p-4 rounded-2xl shadow-md"
>
<h2 class="text-xl mb-2">Machines</h2>
<button
id="addMachineBtn"
class="mb-2 px-3 py-1 bg-blue-500 text-white rounded w-full"
>
+ Add Machine
</button>
<ul
id="machineList"
class="space-y-2 h-64 overflow-y-auto"
></ul>
</div>
<!-- MACHINE DETAIL & CHART -->
<div
id="machineDetailContainer"
class="w-full md:w-2/3 bg-white p-4 rounded-2xl shadow-md"
>
<div id="machineDetail">
<p class="text-gray-500">Select a machine to see details.</p>
</div>
</div>
</div>
</div>
<script>
// Set up DB
const db = new Dexie("GymTrackerDB");
db.version(1).stores({
machines: "++id, label, image",
entries: "++id, machineId, date, weight, reps, sets"
});
// UI elements
const listContainerEl = document.getElementById("machineListContainer");
const machineListEl = document.getElementById("machineList");
const detailEl = document.getElementById("machineDetail");
const addMachineBtn = document.getElementById("addMachineBtn");
const toggleListBtn = document.getElementById("toggleListBtn");
let selectedMachineId = null;
// Toggle function (mobile only)
function toggleList() {
if (window.innerWidth < 768) {
listContainerEl.classList.toggle("hidden");
}
}
toggleListBtn.addEventListener("click", toggleList);
// Add machine: open camera/picker first, then prompt for label
addMachineBtn.addEventListener("click", () => {
const input = document.createElement("input");
input.type = "file";
input.accept = "image/*";
input.capture = "environment";
input.onchange = e => {
const file = e.target.files[0];
const reader = new FileReader();
reader.onload = async () => {
const label = prompt("Machine name:");
if (!label) return;
await db.machines.add({ label, image: reader.result });
loadMachines();
};
reader.readAsDataURL(file);
};
input.click();
});
// Load machines
async function loadMachines() {
const machines = await db.machines.toArray();
machineListEl.innerHTML = "";
machines.forEach(m => {
const li = document.createElement("li");
li.className =
"cursor-pointer p-2 hover:bg-gray-100 flex items-center space-x-2";
li.innerHTML = `
<img src="${m.image}" class="w-12 h-12 rounded object-cover"/>
<span>${m.label}</span>
`;
li.onclick = () => selectMachine(m.id);
machineListEl.appendChild(li);
});
}
// Select machine & show detail
async function selectMachine(id) {
selectedMachineId = id;
const m = await db.machines.get(id);
if (window.innerWidth < 768) {
listContainerEl.classList.add("hidden");
}
detailEl.innerHTML = `
<h2 class="text-2xl font-semibold mb-2">${m.label}</h2>
<img
id="detailImage"
src="${m.image}"
class="w-full h-48 object-cover rounded mb-4 cursor-pointer"
/>
<button
id="addEntryBtn"
class="mb-4 px-3 py-1 bg-green-500 text-white rounded w-full"
>
+ Add Entry
</button>
<div class="relative h-64">
<canvas id="progressChart" class="w-full h-full"></canvas>
</div>
`;
document
.getElementById("detailImage")
.addEventListener("click", toggleList);
document.getElementById("addEntryBtn").onclick = showEntryForm;
await renderChart();
}
// Add entry
async function showEntryForm() {
const today = new Date().toISOString().slice(0, 10);
const date = prompt("Date (YYYY-MM-DD):", today);
const weight= prompt("Weight:");
const reps = prompt("Reps:");
const sets = prompt("Sets:");
if (!date||!weight||!reps||!sets) return;
await db.entries.add({
machineId: selectedMachineId,
date,
weight: Number(weight),
reps: Number(reps),
sets: Number(sets)
});
selectMachine(selectedMachineId);
}
// Render chart
async function renderChart() {
const entries = await db.entries
.where("machineId").equals(selectedMachineId)
.sortBy("date");
const dates = entries.map(e => e.date);
const weights = entries.map(e => e.weight);
const reps = entries.map(e => e.reps);
const ctx = document.getElementById("progressChart").getContext("2d");
new Chart(ctx, {
type: "line",
data: {
labels: dates,
datasets: [
{ label: "Weight", data: weights, borderWidth: 2 },
{ label: "Reps", data: reps, borderWidth: 2 }
]
},
options: {
responsive: true,
maintainAspectRatio: false,
scales: {
x: { title: { display: true, text: "Date" } }
}
}
});
}
// Initial load
loadMachines();
</script>
</body>
</html>