From abfc3c1548a2ef88529231118c50a670e165287c Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Mon, 24 Feb 2025 13:19:52 +0100 Subject: [PATCH] In /ledger_structured view, hide gap lines except where reasonable. --- src/run.py | 11 +++++ src/templates/_macros.tmpl | 94 ++++++++++++++++++++------------------ 2 files changed, 61 insertions(+), 44 deletions(-) diff --git a/src/run.py b/src/run.py index e27a438..db54b77 100755 --- a/src/run.py +++ b/src/run.py @@ -130,6 +130,7 @@ class Account: class DatLine(Dictable): """Line of .dat file parsed into comments and machine-readable data.""" dictables = {'booking_line', 'code', 'comment', 'error', 'is_intro'} + prev_line_empty: bool def __init__(self, line: str) -> None: self.raw = line[:] @@ -560,6 +561,7 @@ class Server(PlomHttpServer): booking.recalc_prev_next(self.bookings) if booking: booking.gap_lines = gap_lines[:-1] + self._recalc_prev_line_empty() def save(self) -> None: """Save current state to ._path_dat.""" @@ -597,11 +599,20 @@ class Server(PlomHttpServer): """If .dat_lines different to those of last .load().""" return self._hash_dat_lines() != self.last_save_hash + def _recalc_prev_line_empty(self) -> None: + prev_line = None + for line in self.dat_lines: + line.prev_line_empty = False + if prev_line: + line.prev_line_empty = not prev_line.code + prev_line.comment + prev_line = line + def _recalc_dat_lines(self) -> None: self.dat_lines = self.initial_gap_lines[:] for booking in self.bookings: self.dat_lines += booking.booked_lines self.dat_lines += booking.gap_lines + self._recalc_prev_line_empty() def _move_booking(self, idx_from, idx_to) -> None: moving = self.bookings[idx_from] diff --git a/src/templates/_macros.tmpl b/src/templates/_macros.tmpl index a1a2764..614a7fa 100644 --- a/src/templates/_macros.tmpl +++ b/src/templates/_macros.tmpl @@ -32,59 +32,65 @@ table.ledger tr > td:first-child { background-color: white; }
{% for dat_line in dat_lines %} - - - - {% if dat_line.is_intro %} - [#] - {{ table_dat_lines_action_button(dat_line, "move", "up", "^", dat_line.booking.can_move(1)) }} - {% elif dat_line.booking_line.idx == 1 %} - [b] - {{ table_dat_lines_action_button(dat_line, "move", "down", "v", dat_line.booking.can_move(0)) }} - {% elif dat_line.booking_line.idx == 2 %} - {{ table_dat_lines_action_button(dat_line, "copy", "here", "c") }} - {{ table_dat_lines_action_button(dat_line, "copy", "to_end", "C") }} - {% endif %} - + {% if raw or dat_line.code or dat_line.comment %} + + {% if (not raw) and dat_line.prev_line_empty %} + + {% endif %} + - {% if raw %} - + {% if dat_line.is_intro %} - {{dat_line.raw_nbsp|safe}} - {% else %} - {{dat_line.raw_nbsp|safe}} + [#] + {{ table_dat_lines_action_button(dat_line, "move", "up", "^", dat_line.booking.can_move(1)) }} + {% elif dat_line.booking_line.idx == 1 %} + [b] + {{ table_dat_lines_action_button(dat_line, "move", "down", "v", dat_line.booking.can_move(0)) }} + {% elif dat_line.booking_line.idx == 2 %} + {{ table_dat_lines_action_button(dat_line, "copy", "here", "c") }} + {{ table_dat_lines_action_button(dat_line, "copy", "to_end", "C") }} {% endif %} - {% else %} - {% if dat_line.is_intro %} - - {{dat_line.booking.target}} - - {% elif dat_line.error %} - - - {% elif dat_line.booking_line %} - - - - {% else %} - - + {% if dat_line.is_intro %} + + {{dat_line.booking.target}} + + {% elif dat_line.error %} + + + {% elif dat_line.booking_line %} + + + + + {% else %} + + + {% endif %} {% endif %} - {% endif %} - - - {% if (not raw) and dat_line.error %} - - - - - {% endif %} + {% if (not raw) and dat_line.error %} + + + + + + {% endif %} + + {% endif %} {% endfor %}
 
- {{dat_line.booking.date}} + + {% if raw %} + + {% if dat_line.is_intro %} + {{dat_line.raw_nbsp|safe}} + {% else %} + {{dat_line.raw_nbsp|safe}} + {% endif %} {{dat_line.comment}}{{dat_line.code}}{{dat_line.comment}}{{dat_line.booking_line.amount_short}}{{dat_line.booking_line.currency|truncate(4,true,"…")}}{{dat_line.booking_line.account}}{{dat_line.comment}}{{dat_line.comment}}  + {{dat_line.booking.date}} + {{dat_line.comment}}{{dat_line.code}}{{dat_line.comment}}{{dat_line.booking_line.amount_short}}{{dat_line.booking_line.currency|truncate(4,true,"…")}}{{dat_line.booking_line.account}}{{dat_line.comment}}{{dat_line.comment}} 
{{dat_line.error}}
{{dat_line.error}}
-- 2.30.2