From abfc3c1548a2ef88529231118c50a670e165287c Mon Sep 17 00:00:00 2001 From: Christian Heller <c.heller@plomlompom.de> 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; } <form action="/ledger_{% if raw %}raw{% else %}structured{% endif %}" method="POST"> <table class="ledger"> {% for dat_line in dat_lines %} - <tr class="alternating{% if dat_line.is_questionable %} warning{% endif %}"> - - <td{% if dat_line.is_intro %} id="{{dat_line.booking_id}}"{% endif %}> - {% if dat_line.is_intro %} - <a href="#{{dat_line.booking_id}}">[#]</a> - {{ table_dat_lines_action_button(dat_line, "move", "up", "^", dat_line.booking.can_move(1)) }} - {% elif dat_line.booking_line.idx == 1 %} - <a href="/balance?up_incl={{dat_line.booking_id}}">[b]</a> - {{ 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 %} - </td> + {% if raw or dat_line.code or dat_line.comment %} + + {% if (not raw) and dat_line.prev_line_empty %} + <tr ><td> </td></tr> + {% endif %} + <tr class="alternating{% if dat_line.is_questionable %} warning{% endif %}"> - {% if raw %} - <td{% if dat_line.error %} class="invalid"{% endif %}> + <td{% if dat_line.is_intro %} id="{{dat_line.booking_id}}"{% endif %}> {% if dat_line.is_intro %} - <a href="/bookings/{{dat_line.booking_id}}"/>{{dat_line.raw_nbsp|safe}}</a> - {% else %} - {{dat_line.raw_nbsp|safe}} + <a href="#{{dat_line.booking_id}}">[#]</a> + {{ table_dat_lines_action_button(dat_line, "move", "up", "^", dat_line.booking.can_move(1)) }} + {% elif dat_line.booking_line.idx == 1 %} + <a href="/balance?up_incl={{dat_line.booking_id}}">[b]</a> + {{ 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 %} </td> - {% else %} - {% if dat_line.is_intro %} - <td class="date {% if dat_line.error %} invalid{% endif %}" colspan=2> - <a href="/bookings/{{dat_line.booking_id}}">{{dat_line.booking.date}}</a> + + {% if raw %} + <td{% if dat_line.error %} class="invalid"{% endif %}> + {% if dat_line.is_intro %} + <a href="/bookings/{{dat_line.booking_id}}"/>{{dat_line.raw_nbsp|safe}}</a> + {% else %} + {{dat_line.raw_nbsp|safe}} + {% endif %} </td> - <td{% if dat_line.error %} class="invalid"{% endif %}>{{dat_line.booking.target}}</td> - <td>{{dat_line.comment}}</td> - {% elif dat_line.error %} - <td class="invalid" colspan=3>{{dat_line.code}}</td> - <td>{{dat_line.comment}}</td> - {% elif dat_line.booking_line %} - <td class="amt">{{dat_line.booking_line.amount_short}}</td> - <td class="curr">{{dat_line.booking_line.currency|truncate(4,true,"â¦")}}</td> - <td>{{dat_line.booking_line.account}}</td> - <td>{{dat_line.comment}}</td> {% else %} - <td colspan=2></td> - <td colspan=2>{{dat_line.comment}} </td> + {% if dat_line.is_intro %} + <td class="date {% if dat_line.error %} invalid{% endif %}" colspan=2> + <a href="/bookings/{{dat_line.booking_id}}">{{dat_line.booking.date}}</a> + </td> + <td{% if dat_line.error %} class="invalid"{% endif %}>{{dat_line.booking.target}}</td> + <td>{{dat_line.comment}}</td> + {% elif dat_line.error %} + <td class="invalid" colspan=3>{{dat_line.code}}</td> + <td>{{dat_line.comment}}</td> + {% elif dat_line.booking_line %} + <td class="amt">{{dat_line.booking_line.amount_short}}</td> + <td class="curr">{{dat_line.booking_line.currency|truncate(4,true,"â¦")}}</td> + <td>{{dat_line.booking_line.account}}</td> + <td>{{dat_line.comment}}</td> + {% else %} + <td colspan=2></td> + <td colspan=2>{{dat_line.comment}} </td> + {% endif %} {% endif %} - {% endif %} - </tr> - - {% if (not raw) and dat_line.error %} - <tr class="alternating warning"> - <td></td> - <td class="invalid" colspan=3>{{dat_line.error}}</td> - <td></td> </tr> - {% endif %} + {% if (not raw) and dat_line.error %} + <tr class="alternating warning"> + <td></td> + <td class="invalid" colspan=3>{{dat_line.error}}</td> + <td></td> + </tr> + {% endif %} + + {% endif %} {% endfor %} </table> </form> -- 2.30.2