home · contact · privacy
In /ledger_structured view, hide gap lines except where reasonable.
authorChristian Heller <c.heller@plomlompom.de>
Mon, 24 Feb 2025 12:19:52 +0000 (13:19 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 24 Feb 2025 12:19:52 +0000 (13:19 +0100)
src/run.py
src/templates/_macros.tmpl

index e27a438441bcd8304bee7e4837de9fc5a6a2e12c..db54b7704acccfb31519b19bd210f8f84985956f 100755 (executable)
@@ -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]
index a1a2764955d2a2eb361c4a43ef385930f795355a..614a7fa39693a958f02d9f77f2185d07af27bc28 100644 (file)
@@ -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>&nbsp;</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}}&nbsp;</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}}&nbsp;</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>