fe improvements
This commit is contained in:
@@ -1,17 +1,19 @@
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from flask import Blueprint, jsonify, render_template
|
||||
from flask import Blueprint, jsonify, render_template, request
|
||||
|
||||
from .get_period_times import (
|
||||
SUPPORTED_TIMEZONES,
|
||||
convert_seconds,
|
||||
default_timezone,
|
||||
get_current_task_info,
|
||||
get_period_totals,
|
||||
get_raw_switches,
|
||||
get_task_blocks_calendar,
|
||||
get_task_time_seconds,
|
||||
get_timezone,
|
||||
get_work_period_totals,
|
||||
task_or_none,
|
||||
timezone,
|
||||
)
|
||||
|
||||
dmbp = Blueprint("deskmeter", __name__, url_prefix="/", template_folder="templates")
|
||||
@@ -29,13 +31,14 @@ def calendar_view(scope="daily", year=None, month=None, day=None):
|
||||
"""
|
||||
Google Calendar-style view showing task blocks at their actual times.
|
||||
"""
|
||||
from flask import request
|
||||
|
||||
task = None
|
||||
grid = int(request.args.get("grid", 1)) # Grid hours: 1, 3, or 6
|
||||
if grid not in [1, 3, 6]:
|
||||
grid = 1
|
||||
|
||||
tz_name = request.args.get("tz")
|
||||
tz = get_timezone(tz_name)
|
||||
|
||||
if not year:
|
||||
year = datetime.today().year
|
||||
if not month:
|
||||
@@ -44,14 +47,14 @@ def calendar_view(scope="daily", year=None, month=None, day=None):
|
||||
day = datetime.today().day
|
||||
|
||||
base_date = datetime(year, month, day).replace(
|
||||
hour=0, minute=0, second=0, tzinfo=timezone
|
||||
hour=0, minute=0, second=0, tzinfo=tz
|
||||
)
|
||||
|
||||
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
|
||||
start, end, task, min_block_seconds=60, grid_hours=grid, tz=tz
|
||||
)
|
||||
prev_date = base_date - timedelta(days=1)
|
||||
next_date = base_date + timedelta(days=1)
|
||||
@@ -61,7 +64,7 @@ def calendar_view(scope="daily", year=None, month=None, day=None):
|
||||
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
|
||||
start, end, task, min_block_seconds=300, grid_hours=grid, tz=tz
|
||||
)
|
||||
prev_date = start - timedelta(days=7)
|
||||
next_date = start + timedelta(days=7)
|
||||
@@ -70,20 +73,20 @@ def calendar_view(scope="daily", year=None, month=None, day=None):
|
||||
elif scope == "monthly":
|
||||
start = base_date.replace(day=1)
|
||||
if month == 12:
|
||||
end = datetime(year + 1, 1, 1, tzinfo=timezone) - timedelta(seconds=1)
|
||||
end = datetime(year + 1, 1, 1, tzinfo=tz) - timedelta(seconds=1)
|
||||
else:
|
||||
end = datetime(year, month + 1, 1, tzinfo=timezone) - timedelta(seconds=1)
|
||||
end = datetime(year, month + 1, 1, tzinfo=tz) - timedelta(seconds=1)
|
||||
blocks = get_task_blocks_calendar(
|
||||
start, end, task, min_block_seconds=600, grid_hours=grid
|
||||
start, end, task, min_block_seconds=600, grid_hours=grid, tz=tz
|
||||
)
|
||||
if month == 1:
|
||||
prev_date = datetime(year - 1, 12, 1, tzinfo=timezone)
|
||||
prev_date = datetime(year - 1, 12, 1, tzinfo=tz)
|
||||
else:
|
||||
prev_date = datetime(year, month - 1, 1, tzinfo=timezone)
|
||||
prev_date = datetime(year, month - 1, 1, tzinfo=tz)
|
||||
if month == 12:
|
||||
next_date = datetime(year + 1, 1, 1, tzinfo=timezone)
|
||||
next_date = datetime(year + 1, 1, 1, tzinfo=tz)
|
||||
else:
|
||||
next_date = datetime(year, month + 1, 1, tzinfo=timezone)
|
||||
next_date = datetime(year, month + 1, 1, tzinfo=tz)
|
||||
days = []
|
||||
current = start
|
||||
while current <= end:
|
||||
@@ -94,7 +97,7 @@ def calendar_view(scope="daily", year=None, month=None, day=None):
|
||||
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
|
||||
start, end, task, min_block_seconds=60, grid_hours=grid, tz=tz
|
||||
)
|
||||
prev_date = base_date - timedelta(days=1)
|
||||
next_date = base_date + timedelta(days=1)
|
||||
@@ -111,6 +114,8 @@ def calendar_view(scope="daily", year=None, month=None, day=None):
|
||||
next_date=next_date,
|
||||
days=days,
|
||||
grid=grid,
|
||||
tz_name=tz_name,
|
||||
timezones=SUPPORTED_TIMEZONES,
|
||||
auto_refresh=False,
|
||||
)
|
||||
|
||||
@@ -124,6 +129,9 @@ def switches_view(scope="daily", year=None, month=None, day=None):
|
||||
"""
|
||||
task = None
|
||||
|
||||
tz_name = request.args.get("tz")
|
||||
tz = get_timezone(tz_name)
|
||||
|
||||
if not year:
|
||||
year = datetime.today().year
|
||||
if not month:
|
||||
@@ -132,7 +140,7 @@ def switches_view(scope="daily", year=None, month=None, day=None):
|
||||
day = datetime.today().day
|
||||
|
||||
base_date = datetime(year, month, day).replace(
|
||||
hour=0, minute=0, second=0, tzinfo=timezone
|
||||
hour=0, minute=0, second=0, tzinfo=tz
|
||||
)
|
||||
|
||||
if scope == "daily":
|
||||
@@ -150,17 +158,17 @@ def switches_view(scope="daily", year=None, month=None, day=None):
|
||||
elif scope == "monthly":
|
||||
start = base_date.replace(day=1)
|
||||
if month == 12:
|
||||
end = datetime(year + 1, 1, 1, tzinfo=timezone) - timedelta(seconds=1)
|
||||
end = datetime(year + 1, 1, 1, tzinfo=tz) - timedelta(seconds=1)
|
||||
else:
|
||||
end = datetime(year, month + 1, 1, tzinfo=timezone) - timedelta(seconds=1)
|
||||
end = datetime(year, month + 1, 1, tzinfo=tz) - timedelta(seconds=1)
|
||||
if month == 1:
|
||||
prev_date = datetime(year - 1, 12, 1, tzinfo=timezone)
|
||||
prev_date = datetime(year - 1, 12, 1, tzinfo=tz)
|
||||
else:
|
||||
prev_date = datetime(year, month - 1, 1, tzinfo=timezone)
|
||||
prev_date = datetime(year, month - 1, 1, tzinfo=tz)
|
||||
if month == 12:
|
||||
next_date = datetime(year + 1, 1, 1, tzinfo=timezone)
|
||||
next_date = datetime(year + 1, 1, 1, tzinfo=tz)
|
||||
else:
|
||||
next_date = datetime(year, month + 1, 1, tzinfo=timezone)
|
||||
next_date = datetime(year, month + 1, 1, tzinfo=tz)
|
||||
else:
|
||||
scope = "daily"
|
||||
start = base_date
|
||||
@@ -168,7 +176,7 @@ def switches_view(scope="daily", year=None, month=None, day=None):
|
||||
prev_date = base_date - timedelta(days=1)
|
||||
next_date = base_date + timedelta(days=1)
|
||||
|
||||
raw_switches = get_raw_switches(start, end, task)
|
||||
raw_switches = get_raw_switches(start, end, task, tz=tz)
|
||||
|
||||
return render_template(
|
||||
"switches_view.html",
|
||||
@@ -179,6 +187,8 @@ def switches_view(scope="daily", year=None, month=None, day=None):
|
||||
base_date=base_date,
|
||||
prev_date=prev_date,
|
||||
next_date=next_date,
|
||||
tz_name=tz_name,
|
||||
timezones=SUPPORTED_TIMEZONES,
|
||||
auto_refresh=False,
|
||||
)
|
||||
|
||||
@@ -191,8 +201,12 @@ def index(task=None):
|
||||
"""
|
||||
task = task_or_none(task)
|
||||
|
||||
start = datetime.today().replace(hour=0, minute=0, second=0, tzinfo=timezone)
|
||||
end = datetime.today().replace(hour=23, minute=59, second=59, tzinfo=timezone)
|
||||
start = datetime.today().replace(
|
||||
hour=0, minute=0, second=0, tzinfo=default_timezone
|
||||
)
|
||||
end = datetime.today().replace(
|
||||
hour=23, minute=59, second=59, tzinfo=default_timezone
|
||||
)
|
||||
|
||||
rows = get_period_totals(start, end, task)
|
||||
|
||||
@@ -230,8 +244,12 @@ def api_today(task=None):
|
||||
"""
|
||||
task = task_or_none(task)
|
||||
|
||||
start = datetime.today().replace(hour=0, minute=0, second=0, tzinfo=timezone)
|
||||
end = datetime.today().replace(hour=23, minute=59, second=59, tzinfo=timezone)
|
||||
start = datetime.today().replace(
|
||||
hour=0, minute=0, second=0, tzinfo=default_timezone
|
||||
)
|
||||
end = datetime.today().replace(
|
||||
hour=23, minute=59, second=59, tzinfo=default_timezone
|
||||
)
|
||||
|
||||
rows = get_period_totals(start, end, task)
|
||||
|
||||
@@ -259,11 +277,11 @@ def oneday(
|
||||
task = task_or_none(task)
|
||||
|
||||
start = datetime(2025, month, day).replace(
|
||||
hour=0, minute=0, second=0, tzinfo=timezone
|
||||
hour=0, minute=0, second=0, tzinfo=default_timezone
|
||||
)
|
||||
|
||||
end = datetime(2025, month, day).replace(
|
||||
hour=23, minute=59, second=59, tzinfo=timezone
|
||||
hour=23, minute=59, second=59, tzinfo=default_timezone
|
||||
)
|
||||
|
||||
rows = get_period_totals(start, end)
|
||||
@@ -274,11 +292,11 @@ def oneday(
|
||||
@dmbp.route("/period/<start>/<end>")
|
||||
def period(start, end):
|
||||
start = datetime(*map(int, start.split("-"))).replace(
|
||||
hour=0, minute=0, second=0, tzinfo=timezone
|
||||
hour=0, minute=0, second=0, tzinfo=default_timezone
|
||||
)
|
||||
|
||||
end = datetime(*map(int, end.split("-"))).replace(
|
||||
hour=23, minute=59, second=59, tzinfo=timezone
|
||||
hour=23, minute=59, second=59, tzinfo=default_timezone
|
||||
)
|
||||
|
||||
rows = get_period_totals(start, end)
|
||||
@@ -291,8 +309,12 @@ def work():
|
||||
"""
|
||||
Show total time used per work project for today
|
||||
"""
|
||||
start = datetime.today().replace(hour=0, minute=0, second=0, tzinfo=timezone)
|
||||
end = datetime.today().replace(hour=23, minute=59, second=59, tzinfo=timezone)
|
||||
start = datetime.today().replace(
|
||||
hour=0, minute=0, second=0, tzinfo=default_timezone
|
||||
)
|
||||
end = datetime.today().replace(
|
||||
hour=23, minute=59, second=59, tzinfo=default_timezone
|
||||
)
|
||||
|
||||
rows = get_work_period_totals(start, end)
|
||||
|
||||
@@ -308,9 +330,13 @@ def totals(task=None):
|
||||
|
||||
task = task_or_none(task)
|
||||
|
||||
start = datetime(2020, 1, 1).replace(hour=0, minute=0, second=0, tzinfo=timezone)
|
||||
start = datetime(2020, 1, 1).replace(
|
||||
hour=0, minute=0, second=0, tzinfo=default_timezone
|
||||
)
|
||||
|
||||
end = datetime(2030, 1, 1).replace(hour=23, minute=59, second=59, tzinfo=timezone)
|
||||
end = datetime(2030, 1, 1).replace(
|
||||
hour=23, minute=59, second=59, tzinfo=default_timezone
|
||||
)
|
||||
|
||||
rows = get_period_totals(start, end)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user