From dd50d6dd40526e382d592c0ab8e0a731dbd51946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Sun, 15 Jan 2023 23:14:28 +0100 Subject: [PATCH] Allow filtering by platform and game Fixes #32 --- CHANGELOG.md | 5 +++ Dockerfile | 2 +- pyproject.toml | 2 +- src/input.css | 2 +- src/web/tracker/static/base.css | 44 ++++++++++++++++++-- src/web/tracker/templates/list_sessions.html | 34 +++++++++------ src/web/tracker/urls.py | 15 ++++++- src/web/tracker/views.py | 10 ++++- 8 files changed, 93 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df4904e..a6818fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.2.3 / 2023-01-15 23:13+01:00 + +* Allow filtering by platform and game on session list (https://git.kucharczyk.xyz/lukas/timetracker/issues/32) +* Order session by newest as preparation for https://git.kucharczyk.xyz/lukas/timetracker/issues/33 + ## 0.2.2 / 2023-01-15 17:59+01:00 * Display playtime graph on session list (https://git.kucharczyk.xyz/lukas/timetracker/issues/29) diff --git a/Dockerfile b/Dockerfile index 7389595..5ddb5bf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ RUN npm install && \ FROM python:3.10.9-slim-bullseye -ENV VERSION_NUMBER 0.2.2 +ENV VERSION_NUMBER 0.2.3 ENV PROD 1 ENV PYTHONUNBUFFERED=1 diff --git a/pyproject.toml b/pyproject.toml index e52b7e7..4f44a19 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "timetracker" -version = "0.2.2" +version = "0.2.3" description = "A simple time tracker." authors = ["Lukáš Kucharczyk "] license = "GPL" diff --git a/src/input.css b/src/input.css index e0e71c1..a37820a 100644 --- a/src/input.css +++ b/src/input.css @@ -14,7 +14,7 @@ textarea { #session-table { display: grid; - grid-template-columns: repeat(3, 2fr) 0.5fr 1fr; + grid-template-columns: 3fr 1fr repeat(2, 2fr) 0.5fr 1fr; } #button-container button { diff --git a/src/web/tracker/static/base.css b/src/web/tracker/static/base.css index 91d562c..6e5ceb8 100644 --- a/src/web/tracker/static/base.css +++ b/src/web/tracker/static/base.css @@ -786,6 +786,11 @@ select { margin-right: auto; } +.my-5 { + margin-top: 1.25rem; + margin-bottom: 1.25rem; +} + .mb-4 { margin-bottom: 1rem; } @@ -794,14 +799,26 @@ select { margin-top: 1rem; } -.mb-5 { - margin-bottom: 1.25rem; +.mb-3 { + margin-bottom: 0.75rem; } .ml-1 { margin-left: 0.25rem; } +.mt-5 { + margin-top: 1.25rem; +} + +.mb-2 { + margin-bottom: 0.5rem; +} + +.mt-10 { + margin-top: 2.5rem; +} + .block { display: block; } @@ -842,6 +859,10 @@ select { display: none !important; } +.h-6 { + height: 1.5rem; +} + .h-5 { height: 1.25rem; } @@ -858,6 +879,10 @@ select { width: 100%; } +.w-6 { + width: 1.5rem; +} + .w-5 { width: 1.25rem; } @@ -910,12 +935,20 @@ select { align-self: center; } +.overflow-hidden { + overflow: hidden; +} + .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.text-ellipsis { + text-overflow: ellipsis; +} + .whitespace-nowrap { white-space: nowrap; } @@ -1052,6 +1085,11 @@ select { color: rgb(248 113 113 / var(--tw-text-opacity)); } +.text-red-700 { + --tw-text-opacity: 1; + color: rgb(185 28 28 / var(--tw-text-opacity)); +} + .shadow-md { --tw-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1); --tw-shadow-colored: 0 4px 6px -1px var(--tw-shadow-color), 0 2px 4px -2px var(--tw-shadow-color); @@ -1122,7 +1160,7 @@ textarea { #session-table { display: grid; - grid-template-columns: repeat(3, 2fr) 0.5fr 1fr; + grid-template-columns: 3fr 1fr repeat(2, 2fr) 0.5fr 1fr; } #button-container button { diff --git a/src/web/tracker/templates/list_sessions.html b/src/web/tracker/templates/list_sessions.html index 7129e2a..a5ca87c 100644 --- a/src/web/tracker/templates/list_sessions.html +++ b/src/web/tracker/templates/list_sessions.html @@ -5,29 +5,39 @@ {% block content %}
{% if dataset.count >= 2 %} - - - - {% else %} - Playtime chart will be displayed when there are 2 or more sessions. - {% endif %} - {% if purchase %} -

Listing sessions only for purchase "{{ purchase }}"

-

Total playtime: {{ total_duration }} over {{ dataset.count }} sessions.

- View all sessions {% endif %}
Name
+
Platform
Start
End
Duration
Manage
{% for data in dataset %} -
{{ data.purchase }}
+ +
{{ data.timestamp_start | date:"d/m/Y H:i" }}
{% if data.unfinished %} diff --git a/src/web/tracker/urls.py b/src/web/tracker/urls.py index 4aa0f72..0210b35 100644 --- a/src/web/tracker/urls.py +++ b/src/web/tracker/urls.py @@ -27,6 +27,19 @@ urlpatterns = [ path( "list-sessions/by-purchase/", views.list_sessions, - name="list_sessions", + {"filter": "purchase"}, + name="list_sessions_by_purchase", + ), + path( + "list-sessions/by-platform/", + views.list_sessions, + {"filter": "platform"}, + name="list_sessions_by_platform", + ), + path( + "list-sessions/by-game/", + views.list_sessions, + {"filter": "game"}, + name="list_sessions_by_game", ), ] diff --git a/src/web/tracker/views.py b/src/web/tracker/views.py index 2bd1a37..042b932 100644 --- a/src/web/tracker/views.py +++ b/src/web/tracker/views.py @@ -53,12 +53,18 @@ def delete_session(request, session_id=None): return redirect("list_sessions") -def list_sessions(request, purchase_id=None): +def list_sessions(request, filter="", purchase_id="", platform_id="", game_id=""): context = {} - if purchase_id != None: + if filter == "purchase": dataset = Session.objects.filter(purchase=purchase_id) context["purchase"] = Purchase.objects.get(id=purchase_id) + elif filter == "platform": + dataset = Session.objects.filter(purchase__platform=platform_id) + context["platform"] = Platform.objects.get(id=platform_id) + elif filter == "game": + dataset = Session.objects.filter(purchase__game=game_id) + context["game"] = Platform.objects.get(id=game_id) else: dataset = Session.objects.all().order_by("timestamp_start")