Merge pull request #311

refactor(yearly): convert into a single page instead of two
This commit is contained in:
Herculino Trotta
2025-08-06 11:45:07 -03:00
committed by GitHub
4 changed files with 48 additions and 4 deletions

View File

@@ -3,6 +3,7 @@ from django.urls import path
from . import views
urlpatterns = [
path("yearly/", views.index, name="yearly_index"),
path("yearly/currency/", views.index_by_currency, name="yearly_index_currency"),
path("yearly/account/", views.index_by_account, name="yearly_index_account"),
path(

View File

@@ -16,6 +16,22 @@ from apps.transactions.utils.calculations import (
)
@login_required
def index(request):
if "view_type" in request.GET:
view_type = request.GET["view_type"]
request.session["yearly_view_type"] = view_type
else:
view_type = request.session.get("yearly_view_type", "currency")
now = timezone.localdate(timezone.now())
if view_type == "currency":
return redirect(to="yearly_overview_currency", year=now.year)
else:
return redirect(to="yearly_overview_account", year=now.year)
@login_required
def index_by_currency(request):
now = timezone.localdate(timezone.now())
@@ -32,6 +48,8 @@ def index_by_account(request):
@login_required
def index_yearly_overview_by_currency(request, year: int):
request.session["yearly_view_type"] = "currency"
next_year = year + 1
previous_year = year - 1
@@ -49,6 +67,7 @@ def index_yearly_overview_by_currency(request, year: int):
"previous_year": previous_year,
"months": month_options,
"currencies": currency_options,
"type": "currency",
},
)
@@ -95,6 +114,7 @@ def yearly_overview_by_currency(request, year: int):
@login_required
def index_yearly_overview_by_account(request, year: int):
request.session["yearly_view_type"] = "account"
next_year = year + 1
previous_year = year - 1
@@ -115,6 +135,7 @@ def index_yearly_overview_by_account(request, year: int):
"previous_year": previous_year,
"months": month_options,
"accounts": account_options,
"type": "account",
},
)

View File

@@ -12,7 +12,18 @@
{% endblock %}
{% block content %}
<div class="container px-md-3 py-3 column-gap-5">
<div class="h-100 text-center mb-4 pt-2">
<div class="btn-group gap-3" role="group">
<a href="{% url 'yearly_overview_currency' year=year %}" class="btn {% if type != 'currency' %}btn-outline-primary{% else %}btn-primary{% endif %} rounded-5" hx-boost>
<i class="fa-solid fa-solid fa-coins fa-fw me-2"></i>{% trans 'Currency' %}
</a>
<a href="{% url 'yearly_overview_account' year=year %}" class="btn {% if type != 'account' %}btn-outline-primary{% else %}btn-primary{% endif %} rounded-5" hx-boost>
<i class="fa-solid fa-wallet fa-fw me-2"></i>{% trans 'Account' %}
</a>
</div>
</div>
<div class="container px-md-3 py-3 column-gap-5" id="yearly-content">
<div class="row mb-3 gx-xl-4 gy-3 mb-4">
{# Date picker#}
<div class="col-12 col-xl-2 flex-row align-items-center d-flex">
@@ -113,7 +124,7 @@
<div id="data-content"
class="show-loading"
hx-get="{% url 'yearly_overview_account_data' year=year %}"
hx-trigger="load, every 10m"
hx-trigger="load, every 10m, updated from:window"
hx-include="[name='account'], [name='month']"
hx-swap="innerHTML">
</div>

View File

@@ -14,7 +14,18 @@
{% endblock %}
{% block content %}
<div class="container px-md-3 py-3 column-gap-5">
<div class="h-100 text-center mb-4 pt-2">
<div class="btn-group gap-3" role="group">
<a href="{% url 'yearly_overview_currency' year=year %}" class="btn {% if type != 'currency' %}btn-outline-primary{% else %}btn-primary{% endif %} rounded-5" hx-boost>
<i class="fa-solid fa-solid fa-coins fa-fw me-2"></i>{% trans 'Currency' %}
</a>
<a href="{% url 'yearly_overview_account' year=year %}" class="btn {% if type != 'account' %}btn-outline-primary{% else %}btn-primary{% endif %} rounded-5" hx-boost>
<i class="fa-solid fa-wallet fa-fw me-2"></i>{% trans 'Account' %}
</a>
</div>
</div>
<div class="container px-md-3 py-3 column-gap-5" id="yearly-content">
<div class="row mb-3 gx-xl-4 gy-3 mb-4">
{# Date picker#}
<div class="col-12 col-xl-2 flex-row align-items-center d-flex">
@@ -115,7 +126,7 @@
<div id="data-content"
class="show-loading"
hx-get="{% url 'yearly_overview_currency_data' year=year %}"
hx-trigger="load, every 10m"
hx-trigger="load, every 10m, updated from:window"
hx-include="[name='currency'], [name='month']"
hx-swap="innerHTML">
</div>