deployment, frontend updates

This commit is contained in:
buenosairesam
2026-01-26 15:11:03 -03:00
parent bf7bcbc37a
commit 3122facaba
16 changed files with 1692 additions and 113 deletions

View File

@@ -1,8 +1,18 @@
from datetime import datetime, timedelta
from flask import Blueprint, render_template, jsonify
from flask import Blueprint, jsonify, render_template
from .get_period_times import get_period_totals, task_or_none, timezone, get_work_period_totals, get_current_task_info, convert_seconds, get_task_time_seconds, get_task_blocks_calendar, get_raw_switches
from .get_period_times import (
convert_seconds,
get_current_task_info,
get_period_totals,
get_raw_switches,
get_task_blocks_calendar,
get_task_time_seconds,
get_work_period_totals,
task_or_none,
timezone,
)
dmbp = Blueprint("deskmeter", __name__, url_prefix="/", template_folder="templates")
@@ -22,7 +32,7 @@ def calendar_view(scope="daily", year=None, month=None, day=None):
from flask import request
task = None
grid = int(request.args.get('grid', 1)) # Grid hours: 1, 3, or 6
grid = int(request.args.get("grid", 1)) # Grid hours: 1, 3, or 6
if grid not in [1, 3, 6]:
grid = 1
@@ -33,12 +43,16 @@ def calendar_view(scope="daily", year=None, month=None, day=None):
if not day:
day = datetime.today().day
base_date = datetime(year, month, day).replace(hour=0, minute=0, second=0, tzinfo=timezone)
base_date = datetime(year, month, day).replace(
hour=0, minute=0, second=0, tzinfo=timezone
)
if scope == "daily":
start = base_date
end = base_date.replace(hour=23, minute=59, second=59)
blocks = get_task_blocks_calendar(start, end, task, min_block_seconds=60, grid_hours=grid)
blocks = get_task_blocks_calendar(
start, end, task, min_block_seconds=60, grid_hours=grid
)
prev_date = base_date - timedelta(days=1)
next_date = base_date + timedelta(days=1)
days = [base_date]
@@ -46,7 +60,9 @@ def calendar_view(scope="daily", year=None, month=None, day=None):
elif scope == "weekly":
start = base_date - timedelta(days=base_date.weekday())
end = start + timedelta(days=6, hours=23, minutes=59, seconds=59)
blocks = get_task_blocks_calendar(start, end, task, min_block_seconds=300, grid_hours=grid)
blocks = get_task_blocks_calendar(
start, end, task, min_block_seconds=300, grid_hours=grid
)
prev_date = start - timedelta(days=7)
next_date = start + timedelta(days=7)
days = [start + timedelta(days=i) for i in range(7)]
@@ -57,7 +73,9 @@ def calendar_view(scope="daily", year=None, month=None, day=None):
end = datetime(year + 1, 1, 1, tzinfo=timezone) - timedelta(seconds=1)
else:
end = datetime(year, month + 1, 1, tzinfo=timezone) - timedelta(seconds=1)
blocks = get_task_blocks_calendar(start, end, task, min_block_seconds=600, grid_hours=grid)
blocks = get_task_blocks_calendar(
start, end, task, min_block_seconds=600, grid_hours=grid
)
if month == 1:
prev_date = datetime(year - 1, 12, 1, tzinfo=timezone)
else:
@@ -75,7 +93,9 @@ def calendar_view(scope="daily", year=None, month=None, day=None):
scope = "daily"
start = base_date
end = base_date.replace(hour=23, minute=59, second=59)
blocks = get_task_blocks_calendar(start, end, task, min_block_seconds=60, grid_hours=grid)
blocks = get_task_blocks_calendar(
start, end, task, min_block_seconds=60, grid_hours=grid
)
prev_date = base_date - timedelta(days=1)
next_date = base_date + timedelta(days=1)
days = [base_date]
@@ -91,7 +111,7 @@ def calendar_view(scope="daily", year=None, month=None, day=None):
next_date=next_date,
days=days,
grid=grid,
auto_refresh=False
auto_refresh=False,
)
@@ -111,7 +131,9 @@ def switches_view(scope="daily", year=None, month=None, day=None):
if not day:
day = datetime.today().day
base_date = datetime(year, month, day).replace(hour=0, minute=0, second=0, tzinfo=timezone)
base_date = datetime(year, month, day).replace(
hour=0, minute=0, second=0, tzinfo=timezone
)
if scope == "daily":
start = base_date
@@ -157,7 +179,7 @@ def switches_view(scope="daily", year=None, month=None, day=None):
base_date=base_date,
prev_date=prev_date,
next_date=next_date,
auto_refresh=False
auto_refresh=False,
)
@@ -176,13 +198,17 @@ def index(task=None):
# Get current task info
current_task_id, current_task_path = get_current_task_info()
current_task_time = None
if current_task_id:
total_seconds = get_task_time_seconds(start, end, current_task_id)
if total_seconds > 0:
current_task_time = convert_seconds(total_seconds)
return render_template("main.html", rows=rows, current_task_path=current_task_path, current_task_time=current_task_time, auto_refresh=True)
# Get all tasks worked on today
task_rows = get_work_period_totals(start, end)
return render_template(
"main.html",
rows=rows,
current_task_path=current_task_path,
task_rows=task_rows,
auto_refresh=True,
)
@dmbp.route("/api/current_task")
@@ -191,10 +217,9 @@ def api_current_task():
JSON API endpoint returning current task information
"""
current_task_id, current_task_path = get_current_task_info()
return jsonify({
"task_id": current_task_id,
"task_path": current_task_path or "no task"
})
return jsonify(
{"task_id": current_task_id, "task_path": current_task_path or "no task"}
)
@dmbp.route("/api/today")
@@ -212,13 +237,16 @@ def api_today(task=None):
# Get current task info
current_task_id, current_task_path = get_current_task_info()
current_task_time = None
if current_task_id:
total_seconds = get_task_time_seconds(start, end, current_task_id)
if total_seconds > 0:
current_task_time = convert_seconds(total_seconds)
return render_template("main_content.html", rows=rows, current_task_path=current_task_path, current_task_time=current_task_time)
# Get all tasks worked on today
task_rows = get_work_period_totals(start, end)
return render_template(
"main_content.html",
rows=rows,
current_task_path=current_task_path,
task_rows=task_rows,
)
@dmbp.route("/day/<int:month>/<int:day>")