From aecbcb3430a4dff274c7e6945f47873d368081bd Mon Sep 17 00:00:00 2001 From: Herculino Trotta Date: Mon, 14 Oct 2024 21:01:11 -0300 Subject: [PATCH] feat: add actions --- app/apps/transactions/urls.py | 15 ++++++ app/apps/transactions/views/__init__.py | 1 + app/apps/transactions/views/actions.py | 43 ++++++++++++++++ app/templates/includes/scripts.html | 1 + .../includes/scripts/hyperscript/sounds.html | 16 ++++++ .../includes/scripts/hyperscript/tooltip.html | 18 +++++-- .../monthly_overview/fragments/list.html | 41 +++++++++++++++- app/templates/net_worth/net_worth.html | 2 +- .../transactions/fragments/item.html | 35 +++++-------- frontend/src/styles/_animations.scss | 49 +++++++++++++++++-- frontend/src/styles/style.scss | 7 ++- 11 files changed, 196 insertions(+), 32 deletions(-) create mode 100644 app/apps/transactions/views/actions.py create mode 100644 app/templates/includes/scripts/hyperscript/sounds.html diff --git a/app/apps/transactions/urls.py b/app/apps/transactions/urls.py index ce80380..e9d1adc 100644 --- a/app/apps/transactions/urls.py +++ b/app/apps/transactions/urls.py @@ -2,6 +2,21 @@ from django.urls import path import apps.transactions.views as views urlpatterns = [ + path( + "transactions/actions/pay", + views.bulk_pay_transactions, + name="transactions_bulk_pay", + ), + path( + "transactions/actions/unpay/", + views.bulk_unpay_transactions, + name="transactions_bulk_unpay", + ), + path( + "transactions/actions/delete/", + views.bulk_delete_transactions, + name="transactions_bulk_delete", + ), path( "transaction//pay", views.transaction_pay, diff --git a/app/apps/transactions/views/__init__.py b/app/apps/transactions/views/__init__.py index 9bb4d4d..59f4f98 100644 --- a/app/apps/transactions/views/__init__.py +++ b/app/apps/transactions/views/__init__.py @@ -1,3 +1,4 @@ from .transactions import * from .tags import * from .categories import * +from .actions import * diff --git a/app/apps/transactions/views/actions.py b/app/apps/transactions/views/actions.py new file mode 100644 index 0000000..76906b3 --- /dev/null +++ b/app/apps/transactions/views/actions.py @@ -0,0 +1,43 @@ +from django.contrib.auth.decorators import login_required +from django.http import HttpResponse + +from apps.common.decorators.htmx import only_htmx +from apps.transactions.models import Transaction + + +@only_htmx +@login_required +def bulk_pay_transactions(request): + selected_transactions = request.GET.getlist("transactions", []) + Transaction.objects.filter(id__in=selected_transactions).update(is_paid=True) + + return HttpResponse( + status=204, + headers={"HX-Trigger": "updated, toast, paid"}, + ) + + +@only_htmx +@login_required +def bulk_unpay_transactions(request): + selected_transactions = request.GET.getlist("transactions", []) + Transaction.objects.filter(id__in=selected_transactions).update(is_paid=False) + + return HttpResponse( + status=204, + headers={"HX-Trigger": "updated, toast, unpaid"}, + ) + + +@only_htmx +@login_required +def bulk_delete_transactions(request): + selected_transactions = request.GET.getlist("transactions", []) + Transaction.objects.filter( + id__in=selected_transactions, installment_plan__isnull=True + ).delete() + + return HttpResponse( + status=204, + headers={"HX-Trigger": "updated, toast"}, + ) diff --git a/app/templates/includes/scripts.html b/app/templates/includes/scripts.html index 92c8326..0afd0c3 100644 --- a/app/templates/includes/scripts.html +++ b/app/templates/includes/scripts.html @@ -8,6 +8,7 @@ {% include 'includes/scripts/hyperscript/hide_amount.html' %} {% include 'includes/scripts/hyperscript/tooltip.html' %} {% include 'includes/scripts/hyperscript/htmx_error_handler.html' %} +{% include 'includes/scripts/hyperscript/sounds.html' %} {% javascript_pack 'htmx' attrs="defer" %} diff --git a/app/templates/includes/scripts/hyperscript/sounds.html b/app/templates/includes/scripts/hyperscript/sounds.html new file mode 100644 index 0000000..016631d --- /dev/null +++ b/app/templates/includes/scripts/hyperscript/sounds.html @@ -0,0 +1,16 @@ + diff --git a/app/templates/includes/scripts/hyperscript/tooltip.html b/app/templates/includes/scripts/hyperscript/tooltip.html index 8509123..b44ba74 100644 --- a/app/templates/includes/scripts/hyperscript/tooltip.html +++ b/app/templates/includes/scripts/hyperscript/tooltip.html @@ -1,6 +1,18 @@ diff --git a/app/templates/monthly_overview/fragments/list.html b/app/templates/monthly_overview/fragments/list.html index b618139..965f5b3 100644 --- a/app/templates/monthly_overview/fragments/list.html +++ b/app/templates/monthly_overview/fragments/list.html @@ -2,7 +2,14 @@ {% load i18n %} {% regroup transactions by date|customnaturaldate as transactions_by_date %} -
+
{% for x in transactions_by_date %}
@@ -17,7 +24,7 @@
-
+
{% for trans in x.list %} {% include 'transactions/fragments/item.html' with transaction=trans %} {% endfor %} @@ -36,4 +43,34 @@
{% endfor %} + +
+
+
+ + + +
+
+
diff --git a/app/templates/net_worth/net_worth.html b/app/templates/net_worth/net_worth.html index 4e8a406..a625e5d 100644 --- a/app/templates/net_worth/net_worth.html +++ b/app/templates/net_worth/net_worth.html @@ -54,7 +54,7 @@
- {{ account_data.name }}
+ {{ account_data.name }}
diff --git a/app/templates/transactions/fragments/item.html b/app/templates/transactions/fragments/item.html index 9fd1a40..a334f14 100644 --- a/app/templates/transactions/fragments/item.html +++ b/app/templates/transactions/fragments/item.html @@ -1,32 +1,22 @@ {% load i18n %} {% load currency_display %} -
+ + diff --git a/frontend/src/styles/_animations.scss b/frontend/src/styles/_animations.scss index 2ad9ada..bceabe4 100644 --- a/frontend/src/styles/_animations.scss +++ b/frontend/src/styles/_animations.scss @@ -48,6 +48,49 @@ animation: swing-in-top-fwd 0.5s cubic-bezier(0.175, 0.885, 0.320, 1.275) both; } +/* ---------------------------------------------- + * Generated by Animista on 2024-10-14 20:30:58 + * Licensed under FreeBSD License. + * See http://animista.net/license for more info. + * w: http://animista.net, t: @cssanimista + * ---------------------------------------------- */ + +/** + * ---------------------------------------- + * animation slide-in-left + * ---------------------------------------- + */ +@-webkit-keyframes slide-in-left { + 0% { + -webkit-transform: translateX(-1000px); + transform: translateX(-1000px); + opacity: 0; + } + 100% { + -webkit-transform: translateX(0); + transform: translateX(0); + opacity: 1; + } +} +@keyframes slide-in-left { + 0% { + -webkit-transform: translateX(-1000px); + transform: translateX(-1000px); + opacity: 0; + } + 100% { + -webkit-transform: translateX(0); + transform: translateX(0); + opacity: 1; + } +} + + +.slide-in-left { + -webkit-animation: slide-in-left 0.2s cubic-bezier(0.250, 0.460, 0.450, 0.940) both; + animation: slide-in-left 0.2s cubic-bezier(0.250, 0.460, 0.450, 0.940) both; +} + //HTMX Loading @keyframes spin { 0% { transform: rotate(0deg); } @@ -66,13 +109,13 @@ right: 0; bottom: 0; backdrop-filter: blur(4px); - z-index: 1; + z-index: 1000; } &::after { content: ''; position: absolute; - top: 50%; + top: 10%; left: 50%; width: 40px; height: 40px; @@ -82,6 +125,6 @@ border-top: 4px solid $primary; border-radius: 50%; animation: spin 1s linear infinite; - z-index: 2; + z-index: 1001; } } diff --git a/frontend/src/styles/style.scss b/frontend/src/styles/style.scss index eeb046a..efb7bb8 100644 --- a/frontend/src/styles/style.scss +++ b/frontend/src/styles/style.scss @@ -31,7 +31,7 @@ select[multiple] { position: relative; } -.hierarchy-line-icon-4 { +.hierarchy-line-icon { width: 8px; height: 10px; background-image: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTMiIGhlaWdodD0iNSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48ZyBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIHN0cm9rZS1saW5lY2FwPSJzcXVhcmUiPjxwYXRoIHN0cm9rZT0iIzlCOUI5QiIgc3Ryb2tlLWRhc2hhcnJheT0iNCIgZD0iTS41IDQuNWgxMiIvPjxwYXRoIHN0cm9rZT0iIzk3OTc5NyIgZD0iTS41IDQuNXYtNCIvPjwvZz48L3N2Zz4=); @@ -44,3 +44,8 @@ select[multiple] { margin-top: 4px; padding: 0 8px !important; } + + +.transaction:has(input[type="checkbox"]:checked) > .transaction-item { + background-color: $primary-bg-subtle-dark; /* Change this to your desired background color */ +}