From cf25fd1826e2028f1a3ac67abd7e158b47313c59 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Sun, 29 Dec 2024 10:38:25 +0100 Subject: [PATCH] Enable archiving accounts --- nummi/account/forms.py | 1 + .../account/migrations/0003_account_archived.py | 17 +++++++++++++++++ nummi/account/models.py | 1 + nummi/main/static/main/css/table.css | 3 +++ nummi/main/static/main/js/index.js | 8 ++++++++ nummi/main/templates/main/index.html | 8 +++++++- nummi/main/templatetags/main_extras.py | 5 +++++ 7 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 nummi/account/migrations/0003_account_archived.py create mode 100644 nummi/main/static/main/js/index.js diff --git a/nummi/account/forms.py b/nummi/account/forms.py index 3225ab0..4b66f90 100644 --- a/nummi/account/forms.py +++ b/nummi/account/forms.py @@ -10,4 +10,5 @@ class AccountForm(NummiForm): "name", "icon", "default", + "archived", ] diff --git a/nummi/account/migrations/0003_account_archived.py b/nummi/account/migrations/0003_account_archived.py new file mode 100644 index 0000000..564297f --- /dev/null +++ b/nummi/account/migrations/0003_account_archived.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2 on 2024-12-29 09:24 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("account", "0002_alter_account_table"), + ] + + operations = [ + migrations.AddField( + model_name="account", + name="archived", + field=models.BooleanField(default=False, verbose_name="Archived"), + ), + ] diff --git a/nummi/account/models.py b/nummi/account/models.py index 4709ef5..5321ad5 100644 --- a/nummi/account/models.py +++ b/nummi/account/models.py @@ -15,6 +15,7 @@ class Account(UserModel): verbose_name=_("Icon"), ) default = models.BooleanField(default=False, verbose_name=_("Default")) + archived = models.BooleanField(default=False, verbose_name=_("Archived")) def save(self, *args, **kwargs): if self.default: diff --git a/nummi/main/static/main/css/table.css b/nummi/main/static/main/css/table.css index e93c777..478dd33 100644 --- a/nummi/main/static/main/css/table.css +++ b/nummi/main/static/main/css/table.css @@ -33,6 +33,9 @@ table { border-style: dashed; } } + &:not(.show-archive) tr.archived { + display: none; + } td, th { padding: 0 var(--gap); diff --git a/nummi/main/static/main/js/index.js b/nummi/main/static/main/js/index.js new file mode 100644 index 0000000..d506bf1 --- /dev/null +++ b/nummi/main/static/main/js/index.js @@ -0,0 +1,8 @@ +for (let table of document.querySelectorAll("table")) { + let btn = table.querySelector("button.show-archive"); + if (btn) { + btn.addEventListener("click", (event) => { + table.classList.toggle("show-archive"); + }); + } +} diff --git a/nummi/main/templates/main/index.html b/nummi/main/templates/main/index.html index 19a5b54..5a55b85 100644 --- a/nummi/main/templates/main/index.html +++ b/nummi/main/templates/main/index.html @@ -6,6 +6,7 @@ {{ block.super }} {% css "main/css/table.css" %} {% css "main/css/plot.css" %} + {% js "main/js/index.js" %} {% endblock %} {% block body %}
@@ -22,7 +23,7 @@ {% for acc in accounts %} - + {{ acc.icon|remix }} {{ acc }} @@ -52,6 +53,11 @@ {% translate "Create account" %} + + + + +
diff --git a/nummi/main/templatetags/main_extras.py b/nummi/main/templatetags/main_extras.py index 8234b3f..15cc7d0 100644 --- a/nummi/main/templatetags/main_extras.py +++ b/nummi/main/templatetags/main_extras.py @@ -61,6 +61,11 @@ def css(href): ) +@register.simple_tag +def js(href): + return mark_safe(f"""""") + + @register.filter def balance(accounts): return sum(