-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
659 lines (627 loc) · 22.5 KB
/
index.html
File metadata and controls
659 lines (627 loc) · 22.5 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Daily Improvement Tracker</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
/* Global Styles */
* {
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
background-color: #f4f4f4;
color: #333;
transition: background-color 0.3s, color 0.3s;
}
.dark-mode {
background-color: #121212;
color: #eee;
}
.container {
max-width: 1000px;
margin: 0 auto;
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
transition: background-color 0.3s, box-shadow 0.3s;
}
.dark-mode .container {
background-color: #1e1e1e;
box-shadow: 0 2px 4px rgba(255, 255, 255, 0.1);
}
h1, h2 {
text-align: center;
margin-bottom: 15px;
}
p.intro {
text-align: center;
margin-bottom: 20px;
font-size: 1em;
}
label {
display: block;
margin-top: 10px;
}
input[type="date"],
input[type="number"],
input[type="text"] {
width: 100%;
padding: 8px;
margin-top: 4px;
border: 1px solid #ccc;
border-radius: 4px;
}
button {
margin-top: 15px;
padding: 10px;
background-color: #4caf50;
border: none;
color: white;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
.actions,
.filter-actions,
.extra-actions {
display: flex;
justify-content: space-between;
margin-top: 20px;
flex-wrap: wrap;
}
.actions button,
.filter-actions button,
.extra-actions button {
margin: 5px;
/* Default: two buttons per row */
flex: 1 0 calc(50% - 10px);
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: center;
}
th {
background-color: #4caf50;
color: white;
}
.dark-mode th {
background-color: #333;
}
.chart-container {
width: 100%;
margin-top: 20px;
}
.btn-small {
padding: 5px 8px;
font-size: 0.9em;
margin: 0 2px;
}
.edit-btn {
background-color: #ffa500;
}
.delete-btn {
background-color: #e74c3c;
}
.cancel-btn {
background-color: #555;
}
.summary,
.filter-container {
margin-top: 30px;
padding: 15px;
background-color: #eef;
border-radius: 4px;
}
.dark-mode .summary,
.dark-mode .filter-container {
background-color: #2e2e2e;
}
.filter-container label {
display: inline-block;
margin-right: 10px;
}
.filter-container input {
width: auto;
margin-right: 20px;
}
/* Notification Styles */
#notification {
margin-top: 10px;
padding: 10px;
text-align: center;
border-radius: 4px;
font-weight: bold;
display: none;
}
.notification-success {
background-color: #d4edda;
color: #155724;
}
/* Default (Desktop and larger than 1080px) */
/* No extra styles: uses base styles */
/* Laptop Adjustments (721px to 1080px) */
@media only screen and (max-width: 1080px) and (min-width: 721px) {
.container {
padding: 20px;
}
h1, h2 {
font-size: 1.6em;
}
label, input, button, th, td {
font-size: 1em;
}
button {
padding: 10px;
}
.actions button,
.filter-actions button,
.extra-actions button {
flex: 1 0 calc(50% - 10px);
}
/* Keep table as a table */
table, thead, tbody, th, td, tr {
display: table;
}
}
/* Tablet Adjustments (481px to 720px) */
@media only screen and (max-width: 720px) and (min-width: 481px) {
.container {
padding: 15px;
}
h1, h2 {
font-size: 1.4em;
}
label, input, button, th, td {
font-size: 0.9em;
}
button {
padding: 8px;
}
.actions button,
.filter-actions button,
.extra-actions button {
flex: 1 0 100%;
}
/* For improved readability, convert the table into a block layout */
table, thead, tbody, th, td, tr {
display: block;
}
thead tr {
position: absolute;
top: -9999px;
left: -9999px;
}
tr {
border: 1px solid #ccc;
margin-bottom: 5px;
}
td {
border: none;
position: relative;
padding-left: 50%;
text-align: left;
}
td:before {
position: absolute;
top: 50%;
left: 10px;
transform: translateY(-50%);
white-space: nowrap;
font-weight: bold;
}
td:nth-of-type(1):before { content: "Date"; }
td:nth-of-type(2):before { content: "CP Hours"; }
td:nth-of-type(3):before { content: "Homework Hours"; }
td:nth-of-type(4):before { content: "Advanced Study Hours"; }
td:nth-of-type(5):before { content: "Total Hours"; }
td:nth-of-type(6):before { content: "Diff CP"; }
td:nth-of-type(7):before { content: "Diff Homework"; }
td:nth-of-type(8):before { content: "Diff Advanced"; }
td:nth-of-type(9):before { content: "Diff Total"; }
td:nth-of-type(10):before { content: "Actions"; }
}
/* Mobile Adjustments (up to 480px) */
@media only screen and (max-width: 480px) {
body {
padding: 10px;
}
.container {
padding: 10px;
}
h1, h2 {
font-size: 1.2em;
}
label, input, button, th, td {
font-size: 0.8em;
}
button {
padding: 6px;
}
.actions button,
.filter-actions button,
.extra-actions button {
flex: 1 0 100%;
}
/* Convert table layout for smaller screens */
table, thead, tbody, th, td, tr {
display: block;
}
thead tr {
position: absolute;
top: -9999px;
left: -9999px;
}
tr {
border: 1px solid #ccc;
margin-bottom: 5px;
}
td {
border: none;
position: relative;
padding-left: 50%;
text-align: left;
}
td:before {
position: absolute;
top: 50%;
left: 10px;
transform: translateY(-50%);
white-space: nowrap;
font-weight: bold;
}
td:nth-of-type(1):before { content: "Date"; }
td:nth-of-type(2):before { content: "CP Hours"; }
td:nth-of-type(3):before { content: "Homework Hours"; }
td:nth-of-type(4):before { content: "Advanced Study Hours"; }
td:nth-of-type(5):before { content: "Total Hours"; }
td:nth-of-type(6):before { content: "Diff CP"; }
td:nth-of-type(7):before { content: "Diff Homework"; }
td:nth-of-type(8):before { content: "Diff Advanced"; }
td:nth-of-type(9):before { content: "Diff Total"; }
td:nth-of-type(10):before { content: "Actions"; }
}
</style>
</head>
<body>
<div class="container">
<h1>Daily Improvement Tracker</h1>
<p class="intro">
Welcome! Use this tracker to record your daily CP practice, homework, and advanced study hours.
Fill in your details below and click "Add Entry" to see your progress.
</p>
<!-- Dark Mode Toggle -->
<div style="text-align: center; margin-bottom: 20px;">
<button id="darkModeToggle" title="Toggle between dark and light mode">Dark Mode</button>
</div>
<!-- Tracker Form -->
<form id="trackerForm">
<label for="date">Date:</label>
<input type="date" id="date" required placeholder="Select a date" />
<label for="cpHours">CP Practice Hours:</label>
<input type="number" id="cpHours" step="0.1" min="0" required placeholder="e.g., 2.5" />
<label for="homeworkHours">Homework/Assignments Hours:</label>
<input type="number" id="homeworkHours" step="0.5" min="0" required placeholder="e.g., 1.0" />
<label for="advancedHours">Study Hours:</label>
<input type="number" id="advancedHours" step="0.1" min="0" required placeholder="e.g., 1.5" />
<button type="submit" id="submitBtn">Add Entry</button>
<button type="button" id="cancelEditBtn" class="cancel-btn" style="display: none;" title="Cancel editing the current entry">Cancel Edit</button>
</form>
<!-- Notification Message -->
<div id="notification"></div>
<!-- Filter Section -->
<div class="filter-container">
<h2>Filter Entries</h2>
<label for="startDate">Start Date:</label>
<input type="date" id="startDate" placeholder="Select start date" />
<label for="endDate">End Date:</label>
<input type="date" id="endDate" placeholder="Select end date" />
<button type="button" id="applyFilterBtn" title="Display entries within the selected date range">Apply Filter</button>
<button type="button" id="clearFilterBtn" style="background-color: #555;" title="Clear the current filter">Clear Filter</button>
</div>
<!-- Primary Actions -->
<div class="actions">
<button type="button" id="exportCSVBtn" title="Download CSV file of your data">Download CSV</button>
<button type="button" id="resetDataBtn" style="background-color: red;" title="Reset all data permanently">Reset Data</button>
</div>
<!-- Extra Actions -->
<div class="extra-actions">
<button type="button" id="toggleChartTypeBtn" title="Switch between bar and line chart views">Change Chart Type</button>
<button type="button" id="resetChartBtn" title="Refresh the chart display">Reset Chart</button>
</div>
<!-- Tracker Table -->
<table id="trackerTable">
<thead>
<tr>
<th>Date</th>
<th>CP Hours</th>
<th>Homework Hours</th>
<th>Advanced Study Hours</th>
<th>Total Hours</th>
<th>Diff CP</th>
<th>Diff Homework</th>
<th>Diff Advanced</th>
<th>Diff Total</th>
<th>Actions</th>
</tr>
</thead>
<tbody></tbody>
</table>
<!-- Chart -->
<div class="chart-container">
<canvas id="progressChart"></canvas>
</div>
<!-- Summary Section -->
<div class="summary">
<h2>Summary Statistics</h2>
<p id="summaryStats">No data available.</p>
</div>
</div>
<script>
(function() {
"use strict";
// DOM Elements
const trackerForm = document.getElementById("trackerForm");
const trackerTableBody = document.querySelector("#trackerTable tbody");
const cancelEditBtn = document.getElementById("cancelEditBtn");
const submitBtn = document.getElementById("submitBtn");
const summaryStats = document.getElementById("summaryStats");
const darkModeToggle = document.getElementById("darkModeToggle");
const applyFilterBtn = document.getElementById("applyFilterBtn");
const clearFilterBtn = document.getElementById("clearFilterBtn");
const exportCSVBtn = document.getElementById("exportCSVBtn");
const resetDataBtn = document.getElementById("resetDataBtn");
const toggleChartTypeBtn = document.getElementById("toggleChartTypeBtn");
const resetChartBtn = document.getElementById("resetChartBtn");
const notification = document.getElementById("notification");
// Application State
let entries = JSON.parse(localStorage.getItem("trackerData")) || [];
let filteredEntries = [];
let chart = null;
let chartType = "bar";
let currentEditIndex = -1;
// Utility Functions
const saveEntries = () => localStorage.setItem("trackerData", JSON.stringify(entries));
const getEntriesList = () => (filteredEntries.length ? filteredEntries : entries);
const round = num => parseFloat(num.toFixed(1));
// Display Notification
const showNotification = (msg, type = "success") => {
notification.textContent = msg;
notification.className = type === "success" ? "notification-success" : "notification-error";
notification.style.display = "block";
setTimeout(() => {
notification.style.display = "none";
}, 2000);
};
// Rebuild Table
const rebuildTable = () => {
const list = getEntriesList();
trackerTableBody.innerHTML = "";
list.forEach((entry, index) => {
const diffCP = index > 0 ? round(entry.cpHours - list[index - 1].cpHours) : "-";
const diffHomework = index > 0 ? round(entry.homeworkHours - list[index - 1].homeworkHours) : "-";
const diffAdvanced = index > 0 ? round(entry.advancedHours - list[index - 1].advancedHours) : "-";
const diffTotal = index > 0 ? round(entry.totalHours - list[index - 1].totalHours) : "-";
const row = document.createElement("tr");
row.innerHTML = `
<td>${entry.date}</td>
<td>${round(entry.cpHours)}</td>
<td>${round(entry.homeworkHours)}</td>
<td>${round(entry.advancedHours)}</td>
<td>${round(entry.totalHours)}</td>
<td>${diffCP}</td>
<td>${diffHomework}</td>
<td>${diffAdvanced}</td>
<td>${diffTotal}</td>
<td>
<button class="btn-small edit-btn" onclick="editEntry('${entry.date}')" title="Edit this entry">Edit</button>
<button class="btn-small delete-btn" onclick="deleteEntry('${entry.date}')" title="Delete this entry">Delete</button>
</td>
`;
trackerTableBody.appendChild(row);
});
};
// Update Chart
const updateChart = () => {
const ctx = document.getElementById("progressChart").getContext("2d");
const list = getEntriesList();
if (chart) chart.destroy();
chart = new Chart(ctx, {
type: chartType,
data: {
labels: list.map(item => item.date),
datasets: [
{
label: "CP Hours",
data: list.map(item => item.cpHours),
backgroundColor: "blue",
borderColor: "blue",
fill: chartType === "line" ? false : true
},
{
label: "Homework Hours",
data: list.map(item => item.homeworkHours),
backgroundColor: "green",
borderColor: "green",
fill: chartType === "line" ? false : true
},
{
label: "Advanced Study Hours",
data: list.map(item => item.advancedHours),
backgroundColor: "red",
borderColor: "red",
fill: chartType === "line" ? false : true
}
]
},
options: {
scales: {
y: { beginAtZero: true }
}
}
});
};
// Update Summary Statistics
const updateSummary = () => {
const list = getEntriesList();
if (!list.length) {
summaryStats.textContent = "No data available.";
return;
}
const totalCP = round(list.reduce((sum, item) => sum + item.cpHours, 0));
const totalHomework = round(list.reduce((sum, item) => sum + item.homeworkHours, 0));
const totalAdvanced = round(list.reduce((sum, item) => sum + item.advancedHours, 0));
const totalHours = round(list.reduce((sum, item) => sum + item.totalHours, 0));
const avgCP = round(totalCP / list.length);
const avgHomework = round(totalHomework / list.length);
const avgAdvanced = round(totalAdvanced / list.length);
const avgTotal = round(totalHours / list.length);
summaryStats.innerHTML = `
Total Entries: ${list.length}<br>
Total CP Hours: ${totalCP} (Avg: ${avgCP})<br>
Total Homework Hours: ${totalHomework} (Avg: ${avgHomework})<br>
Total Advanced Study Hours: ${totalAdvanced} (Avg: ${avgAdvanced})<br>
Total Hours: ${totalHours} (Avg: ${avgTotal})
`;
};
// Toggle Dark Mode
const toggleDarkMode = () => {
document.body.classList.toggle("dark-mode");
};
// Apply Date Filter
const applyFilter = () => {
const startDate = document.getElementById("startDate").value;
const endDate = document.getElementById("endDate").value;
filteredEntries = entries.filter(item => {
if (startDate && item.date < startDate) return false;
if (endDate && item.date > endDate) return false;
return true;
});
rebuildTable();
updateChart();
updateSummary();
};
// Clear Date Filter
const clearFilter = () => {
document.getElementById("startDate").value = "";
document.getElementById("endDate").value = "";
filteredEntries = [];
rebuildTable();
updateChart();
updateSummary();
};
// Export Data as CSV
const exportCSV = () => {
const list = getEntriesList();
let csvContent = "Date,CP Hours,Homework Hours,Advanced Study Hours,Total Hours\n";
list.forEach(item => {
csvContent += `${item.date},${item.cpHours},${item.homeworkHours},${item.advancedHours},${item.totalHours}\n`;
});
const blob = new Blob([csvContent], { type: "text/csv" });
const a = document.createElement("a");
a.href = URL.createObjectURL(blob);
a.download = "improvement_tracker.csv";
a.click();
};
// Reset All Data
const resetData = () => {
if (confirm("Are you sure you want to reset all data? This action cannot be undone.")) {
entries = [];
filteredEntries = [];
localStorage.removeItem("trackerData");
rebuildTable();
updateChart();
updateSummary();
showNotification("All data has been reset.", "success");
}
};
// Expose edit and delete functions to the global scope for inline event handlers
window.editEntry = (date) => {
const index = entries.findIndex(item => item.date === date);
if (index === -1) return;
currentEditIndex = filteredEntries.length ? filteredEntries.findIndex(item => item.date === date) : index;
const entry = entries[index];
document.getElementById("date").value = entry.date;
document.getElementById("cpHours").value = entry.cpHours;
document.getElementById("homeworkHours").value = entry.homeworkHours;
document.getElementById("advancedHours").value = entry.advancedHours;
submitBtn.textContent = "Update Entry";
cancelEditBtn.style.display = "inline-block";
};
window.deleteEntry = (date) => {
if (confirm("Are you sure you want to delete this entry?")) {
entries = entries.filter(item => item.date !== date);
saveEntries();
clearFilter();
rebuildTable();
updateChart();
updateSummary();
showNotification("Entry deleted.", "success");
}
};
// Handle Form Submission
trackerForm.addEventListener("submit", (e) => {
e.preventDefault();
const date = document.getElementById("date").value;
const cpHours = parseFloat(document.getElementById("cpHours").value);
const homeworkHours = parseFloat(document.getElementById("homeworkHours").value);
const advancedHours = parseFloat(document.getElementById("advancedHours").value);
if (!date || isNaN(cpHours) || isNaN(homeworkHours) || isNaN(advancedHours)) {
alert("Please fill in all fields correctly.");
return;
}
const totalHours = round(cpHours + homeworkHours + advancedHours);
const newEntry = { date, cpHours, homeworkHours, advancedHours, totalHours };
if (currentEditIndex > -1) {
const fullIndex = entries.findIndex(item => item.date === filteredEntries[currentEditIndex].date);
if (fullIndex !== -1) {
entries[fullIndex] = newEntry;
}
currentEditIndex = -1;
submitBtn.textContent = "Add Entry";
cancelEditBtn.style.display = "none";
showNotification("Entry updated.", "success");
} else {
entries.push(newEntry);
showNotification("Entry added.", "success");
}
entries.sort((a, b) => new Date(a.date) - new Date(b.date));
saveEntries();
clearFilter();
rebuildTable();
updateChart();
updateSummary();
trackerForm.reset();
});
// Other Event Listeners
darkModeToggle.addEventListener("click", toggleDarkMode);
applyFilterBtn.addEventListener("click", applyFilter);
clearFilterBtn.addEventListener("click", clearFilter);
exportCSVBtn.addEventListener("click", exportCSV);
resetDataBtn.addEventListener("click", resetData);
toggleChartTypeBtn.addEventListener("click", () => {
chartType = chartType === "bar" ? "line" : "bar";
updateChart();
});
resetChartBtn.addEventListener("click", updateChart);
// Initialize App
rebuildTable();
updateChart();
updateSummary();
})();
</script>
</body>
</html>