diff --git a/app.py b/app.py index 331aeb5..d6db2f8 100644 --- a/app.py +++ b/app.py @@ -192,19 +192,31 @@ def stop_timer(): def complete_task(): if not is_logged_in(): return jsonify({'error': 'auth'}), 401 + user_id = get_user_id() task_id = request.form['task_id'] is_checked = request.form['is_checked'] == 'true' status = 'completed' if is_checked else 'open' completed_at = datetime.now() if is_checked else None - db.tasks.update_one( - {'_id': ObjectId(task_id), 'user_id': get_user_id()}, - {'$set': {'status': status, 'completed_at': completed_at}} - ) + update_doc = { + 'status': status, + 'completed_at': completed_at + } - # If it was a generic activity task, bind it to current entry if one acts so it shows in log - # (Optional logic, skipping for simplicity) + # If the task is being completed, try to link it to the currently active timer + if is_checked: + current_entry = db.time_entries.find_one({ + 'user_id': user_id, + 'end_time': None + }) + if current_entry: + update_doc['time_entry_id'] = current_entry['_id'] + + db.tasks.update_one( + {'_id': ObjectId(task_id), 'user_id': user_id}, + {'$set': update_doc} + ) return jsonify({'status': 'success'}) diff --git a/templates/logbook.html b/templates/logbook.html index d7966b7..0085146 100644 --- a/templates/logbook.html +++ b/templates/logbook.html @@ -5,33 +5,44 @@
No activities recorded yet.
{% else %} {% for entry in log %} -"{{ entry.note }}"
- {% endif %} + + +"{{ entry.note }}"
+ {% endif %} +
+ {{ entry.start_time.strftime('%A, %d. %B %Y') }}
+ {{ entry.start_time.strftime('%H:%M') }}
+ {% if entry.end_time %} - {{ entry.end_time.strftime('%H:%M') }} {% endif %}
+
No tasks were tracked for this session.
+ {% else %} +