Files
OpenTimeTracker/templates/dashboard.html
2026-02-10 19:16:33 +01:00

130 lines
5.6 KiB
HTML

{% extends "layout.html" %}
{% block content %}
<!-- Active Timer Section -->
{% if current_entry %}
<div class="card active-section">
<h3 style="text-align: center; color: {{ current_entry.activity_color }}">
Currently Tracking: {{ current_entry.activity_name }}
</h3>
{% if current_entry.note %}
<p style="text-align: center; color: #666; font-style: italic;">"{{ current_entry.note }}"</p>
{% endif %}
<div class="timer-display" id="timer">00:00:00</div>
<!-- Tasks for current activity -->
{% if tasks %}
<div style="margin: 1rem 0; padding: 1rem; background: rgba(255,255,255,0.7); border-radius: 5px;">
<h4>Active Tasks:</h4>
{% for task in tasks %}
<div style="margin-bottom: 5px; display: flex; align-items: center;">
<input type="checkbox" id="task_{{ task._id }}"
{% if task.status == 'completed' %}checked{% endif %}
onchange="toggleTask('{{ task._id }}', this)">
<label for="task_{{ task._id }}" style="margin-left: 10px; flex-grow: 1; {% if task.status == 'completed' %}text-decoration: line-through;{% endif %}">
<a href="{{ url_for('task_detail', task_id=task._id) }}">{{ task.name }}</a>
</label>
</div>
{% endfor %}
</div>
{% endif %}
<form action="{{ url_for('stop_timer') }}" method="POST" style="text-align: center;">
<button type="submit" class="btn btn-danger" style="font-size: 1.2rem; width: 100%;">Stop Activity</button>
</form>
<script>
// Timer Logic
const startTime = new Date("{{ current_entry.start_time }}").getTime();
function updateTimer() {
const now = new Date().getTime();
const diff = now - startTime;
const hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((diff % (1000 * 60)) / 1000);
document.getElementById("timer").innerHTML =
(hours < 10 ? "0" + hours : hours) + ":" +
(minutes < 10 ? "0" + minutes : minutes) + ":" +
(seconds < 10 ? "0" + seconds : seconds);
}
setInterval(updateTimer, 1000);
updateTimer(); // run immediately
// AJAX for Tasks
function toggleTask(taskId, checkbox) {
const formData = new FormData();
formData.append('task_id', taskId);
formData.append('is_checked', checkbox.checked);
fetch('/complete_task', { method: 'POST', body: formData })
.then(r => r.json())
.then(data => {
const label = checkbox.nextElementSibling;
if(checkbox.checked) {
label.style.textDecoration = "line-through";
} else {
label.style.textDecoration = "none";
}
});
}
</script>
</div>
{% endif %}
<!-- Start Activity Section -->
<div class="activity-grid">
{% for act in activities %}
<!-- Clicking opens a small modal or submits form directly. Let's do a form with a prompt for note -->
<div class="activity-card"
style="background-color: {{ act.color }}"
onclick="startActivity('{{ act._id }}', '{{ act.name }}')">
<span>{{ act.name }}</span>
</div>
{% endfor %}
<!-- Add New Button -->
<div class="activity-card" style="background-color: #95a5a6; color: white;" onclick="document.getElementById('newActivityForm').style.display='block'">
<span>+ New Activity</span>
</div>
</div>
<!-- Hidden Form for Starting Activity with Note -->
<form id="startForm" method="POST" style="display:none;">
<input type="hidden" name="note" id="startNote">
</form>
<script>
function startActivity(id, name) {
let note = prompt("Start " + name + "?\nAdd a note (optional):");
if (note === null) return; // Cancelled
let form = document.getElementById('startForm');
form.action = "/toggle_timer/" + id;
document.getElementById('startNote').value = note;
form.submit();
}
</script>
<!-- Create Activity Form -->
<div id="newActivityForm" class="card" style="display:none; margin-top: 2rem;">
<h3>Create New Activity Category</h3>
<form action="{{ url_for('add_activity') }}" method="POST">
<label>Name</label>
<input type="text" name="name" required placeholder="e.g. Household">
<label>Color</label>
<input type="color" name="color" value="#3498db" style="width:100%; height:40px; border:none;">
<label>Default Tasks (comma separated)</label>
<input type="text" name="tasks" placeholder="e.g. Laundry, Dishes, Trash">
<button type="submit" class="btn">Create</button>
<button type="button" class="btn" style="background: #7f8c8d" onclick="this.parentElement.parentElement.style.display='none'">Cancel</button>
</form>
</div>
{% endblock %}