From d14e153d38ad9e5e0309f066f18d2ac4e3513668 Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Wed, 22 Jan 2025 16:32:08 +0100
Subject: [PATCH] Refactor templates, improve values display in /balance.

---
 templates/_base.tmpl   |  2 --
 templates/_macros.tmpl |  9 +++++++--
 templates/balance.tmpl | 22 +++++++++++++++++-----
 templates/booking.tmpl |  4 +++-
 templates/index.tmpl   |  4 +++-
 templates/raw.tmpl     |  2 ++
 6 files changed, 32 insertions(+), 11 deletions(-)

diff --git a/templates/_base.tmpl b/templates/_base.tmpl
index 75f33af..8b8dccf 100644
--- a/templates/_base.tmpl
+++ b/templates/_base.tmpl
@@ -6,8 +6,6 @@
 <style>
 body { background-color: white; font-family: sans-serif; }
 tr:nth-child(odd) { background-color: #dcdcdc; }
-tr.warning td { background-color: #ff8888; }
-td.invalid, tr.warning td.invalid { background-color: #ff0000; }
 {% block css %}{% endblock %}
 </style>
 </head>
diff --git a/templates/_macros.tmpl b/templates/_macros.tmpl
index 106e443..2342215 100644
--- a/templates/_macros.tmpl
+++ b/templates/_macros.tmpl
@@ -1,7 +1,12 @@
-{% macro css_value_line() %}
+{% macro css_td_money() %}
 td.amt { text-align: right }
 td.amt, td.curr { font-family: monospace; font-size: 1.3em; }
-td.curr { text-align: center; }
+td.curr { text-align: left; }
+{% endmacro %}
+
+{% macro css_errors() %}
+tr.warning td { background-color: #ff8888; }
+td.invalid, tr.warning td.invalid { background-color: #ff0000; }
 {% endmacro %}
 
 {% macro table_dat_lines(dat_lines, single, raw) %}
diff --git a/templates/balance.tmpl b/templates/balance.tmpl
index da13b34..856b555 100644
--- a/templates/balance.tmpl
+++ b/templates/balance.tmpl
@@ -1,21 +1,33 @@
 {% extends '_base.tmpl' %}
 
-
 {% macro account_with_children(account, indent) %}
 <tr>
-<td>{% for _ in range(indent) %}&nbsp; &nbsp; &nbsp;{% endfor %}{{account.basename}}</td>
-<td>
 {% for curr, amt in account.wealth.moneys.items() %}
-{{amt}}{{curr}} 
+{% if 1 == loop.index %}
+<td class="amt">{{amt}}</td>
+<td class="curr">{{curr|truncate(4,true,"…")}}</td>
+{% endif %}
 {% endfor %}
-</td>
+<td>{% for _ in range(indent) %}&nbsp; &nbsp; &nbsp;{% endfor %}{{account.basename}}</td>
+</tr>
+{% for curr, amt in account.wealth.moneys.items() %}
+{% if 1 < loop.index %}
+<tr>
+<td class="amt">{{amt}}</td>
+<td class="curr">{{curr|truncate(4,true,"…")}}</td>
 </tr>
+{% endif %}
+{% endfor %}
 {% for child in account.children %}
 {{ account_with_children(child, indent=indent+1) }}
 {% endfor %}
 {% endmacro %}
 
 
+{% block css %}
+{{ macros.css_td_money() }}
+{% endblock css %}
+
 {% block content %}
 <table>
 {% for root in roots %}
diff --git a/templates/booking.tmpl b/templates/booking.tmpl
index 86273b9..2e01a75 100644
--- a/templates/booking.tmpl
+++ b/templates/booking.tmpl
@@ -1,7 +1,9 @@
 {% extends '_base.tmpl' %}
 
+
 {% block css %}
-{{ macros.css_value_line() }}
+{{ macros.css_td_money() }}
+{{ macros.css_errors() }}
 {% endblock %}
 
 {% block content %}
diff --git a/templates/index.tmpl b/templates/index.tmpl
index fc24e6e..43be0f4 100644
--- a/templates/index.tmpl
+++ b/templates/index.tmpl
@@ -1,7 +1,9 @@
 {% extends '_base.tmpl' %}
 
+
 {% block css %}
-{{ macros.css_value_line() }}
+{{ macros.css_td_money() }}
+{{ macros.css_errors() }}
 {% endblock %}
 
 {% block content %}
diff --git a/templates/raw.tmpl b/templates/raw.tmpl
index 6851d93..8b2d621 100644
--- a/templates/raw.tmpl
+++ b/templates/raw.tmpl
@@ -1,7 +1,9 @@
 {% extends '_base.tmpl' %}
 
+
 {% block css %}
 table { font-family: monospace; }
+{{ macros.css_errors() }}
 {% endblock %}
 
 {% block content %}
-- 
2.30.2