From 6344975f7ede424be5f18041ad31b66bbf435cfb Mon Sep 17 00:00:00 2001 From: calboo Date: Tue, 10 Feb 2026 19:20:19 +0100 Subject: [PATCH] tasks work better now --- app.py | 24 ++++++++++---- templates/logbook.html | 59 +++++++++++++++++++++-------------- templates/logbook_detail.html | 55 ++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 30 deletions(-) create mode 100644 templates/logbook_detail.html 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.activity.name }}

- - {{ entry.start_time.strftime('%Y-%m-%d %H:%M') }} - {{ entry.end_time.strftime('%H:%M') }} - - {% if entry.note %} -

"{{ entry.note }}"

- {% endif %} + + +
+
+
+

{{ entry.activity.name }}

+ + {{ entry.start_time.strftime('%Y-%m-%d %H:%M') }} - {{ entry.end_time.strftime('%H:%M') }} + + {% if entry.note %} +

"{{ entry.note }}"

+ {% endif %} +
+
+ {{ entry.duration_str }} +
-
- {{ entry.duration_str }} + + {% if entry.tasks %} +
+ Tasks Completed: +
    + {% for task in entry.tasks %} +
  • {{ task.name }} ({{ task.completed_at.strftime('%H:%M') if task.completed_at else 'Done' }})
  • + {% endfor %} +
+ {% endif %}
- - {% if entry.tasks %} -
- Tasks Completed: -
    - {% for task in entry.tasks %} -
  • {{ task.name }} ({{ task.completed_at.strftime('%H:%M') if task.completed_at else 'Done' }})
  • - {% endfor %} -
-
- {% endif %} -
+
{% endfor %} {% endif %} + + {% endblock %} diff --git a/templates/logbook_detail.html b/templates/logbook_detail.html new file mode 100644 index 0000000..cb3dc0e --- /dev/null +++ b/templates/logbook_detail.html @@ -0,0 +1,55 @@ +{% extends "layout.html" %} +{% block content %} +
+
+
+

{{ entry.activity.name }}

+

+ {{ 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 %} +

+
+
+
{{ entry.duration_str }}
+ Back to Log +
+
+
+ +
+

Session Notes

+
+ +
+ +
+
+
+ +
+

Tasks in this Session

+ {% if not tasks %} +

No tasks were tracked for this session.

+ {% else %} +
    + {% for task in tasks %} +
  • + + {% if task.status == 'completed' %}✅{% else %}⬜{% endif %} + +
    + {{ task.name }} + {% if task.completed_at %} + Completed at {{ task.completed_at.strftime('%H:%M') }} + {% else %} + Not completed + {% endif %} +
    + View Task > +
  • + {% endfor %} +
+ {% endif %} +
+{% endblock %}