Add ability to move forward/back on week/month view and improve UI

This commit is contained in:
Peter Stockings
2026-03-09 22:13:56 +11:00
parent 31203cd551
commit 4f1add9154
3 changed files with 254 additions and 50 deletions

View File

@@ -34,15 +34,36 @@ def dashboard():
# Pagination for list view
page = request.args.get('page', 1, type=int)
# Weekly View Navigation Offset
week_offset = request.args.get('week_offset', 0, type=int)
# Monthly View Navigation Offset
month_offset = request.args.get('month_offset', 0, type=int)
# Fetch paginated readings for the list view
paginated = fetch_readings_paginated(current_user.id, start_date, end_date, user_tz, page, PAGE_SIZE)
# For calendar/graph/badges, fetch only current month + week readings (much smaller set)
now = datetime.now(user_tz)
# Calculate target week date for weekly view
target_week_date = now + timedelta(weeks=week_offset)
# Ensure we fetch enough data back to cover the week_offset
month_start = now.replace(day=1, hour=0, minute=0, second=0, microsecond=0)
month_start_utc = month_start.astimezone(utc)
calendar_readings = fetch_readings_for_range(current_user.id, month_start_utc)
target_week_start = target_week_date - timedelta(days=target_week_date.weekday())
target_week_start_utc = target_week_start.replace(hour=0, minute=0, second=0, microsecond=0).astimezone(utc)
# Calculate target month date for monthly view
target_month_year = now.year + (now.month + month_offset - 1) // 12
target_month_month = (now.month + month_offset - 1) % 12 + 1
target_month_date = now.replace(year=target_month_year, month=target_month_month, day=1, hour=0, minute=0, second=0, microsecond=0)
target_month_start_utc = target_month_date.astimezone(utc)
# Fetch from the earliest of the current month OR the requested target week/month
fetch_start_utc = min(month_start_utc, target_week_start_utc, target_month_start_utc)
calendar_readings = fetch_readings_for_range(current_user.id, fetch_start_utc)
# Annotate all readings with relative and localized timestamps
annotate_readings(paginated.items, user_tz)
@@ -52,8 +73,8 @@ def dashboard():
readings_by_day = build_readings_by_day(calendar_readings, user_tz)
# Generate calendar views from the shared lookup
week_view = generate_weekly_calendar(readings_by_day, now, user_tz)
month_view = generate_monthly_calendar(readings_by_day, now, user_tz)
week_view = generate_weekly_calendar(readings_by_day, target_week_date, user_tz)
month_view = generate_monthly_calendar(readings_by_day, target_month_date, user_tz)
# Calculate weekly averages via SQL (much faster than Python)
systolic_avg, diastolic_avg, heart_rate_avg = calculate_weekly_summary_sql(current_user.id)
@@ -79,6 +100,10 @@ def dashboard():
month=month_view,
week=week_view,
date=date,
target_month_date=target_month_date,
week_offset=week_offset,
month_offset=month_offset,
active_view=request.args.get('activeView', 'list'),
**graph_data
)