From 1b3271d71d2bc98585e6d15af7961dad42c2145e Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Mon, 24 Feb 2025 13:38:46 +0100
Subject: [PATCH] Hide ;def comments in /ledger_structured.

---
 src/run.py                 | 31 ++++++++++++++++++++-----------
 src/templates/_macros.tmpl | 10 +++++-----
 2 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/src/run.py b/src/run.py
index db54b77..8c26685 100755
--- a/src/run.py
+++ b/src/run.py
@@ -138,6 +138,12 @@ class DatLine(Dictable):
         self.comment = halves[1] if len(halves) > 1 else ''
         self.code = halves[0]
         self.booking_line: Optional[BookingLine] = None
+        self.hide_comment_in_ledger = False
+
+    @property
+    def comment_in_ledger(self) -> str:
+        """What to show in structured ledger view (as per .hide_comment…)."""
+        return '' if self.hide_comment_in_ledger else self.comment
 
     @property
     def is_intro(self) -> bool:
@@ -548,15 +554,16 @@ class Server(PlomHttpServer):
                     booked_lines.clear()
                 gap_lines += [dat_line]
         self.paths_to_descs = {}
-        for comment in [dl.comment for dl in self.dat_lines if dl.comment]:
-            if comment.startswith(PREFIX_DEF):
-                parts = [part.strip() for part
-                         in comment[len(PREFIX_DEF):].split(';')]
-                first_part_parts = parts[0].split(maxsplit=1)
-                account_name = first_part_parts[0]
-                desc = first_part_parts[1] if len(first_part_parts) > 1 else ''
-                if desc:
-                    self.paths_to_descs[account_name] = desc
+        for dat_line in [dl for dl in self.dat_lines
+                         if dl.comment.startswith(PREFIX_DEF)]:
+            parts = [part.strip() for part
+                     in dat_line.comment[len(PREFIX_DEF):].split(';')]
+            first_part_parts = parts[0].split(maxsplit=1)
+            account_name = first_part_parts[0]
+            desc = first_part_parts[1] if len(first_part_parts) > 1 else ''
+            if desc:
+                self.paths_to_descs[account_name] = desc
+            dat_line.hide_comment_in_ledger = True
         for booking in self.bookings:
             booking.recalc_prev_next(self.bookings)
         if booking:
@@ -604,8 +611,10 @@ class Server(PlomHttpServer):
         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
+                line.prev_line_empty = not (prev_line.code
+                                            + prev_line.comment_in_ledger)
+            if prev_line or line.code + line.comment_in_ledger:  # jump over
+                prev_line = line                                 # empty start
 
     def _recalc_dat_lines(self) -> None:
         self.dat_lines = self.initial_gap_lines[:]
diff --git a/src/templates/_macros.tmpl b/src/templates/_macros.tmpl
index 614a7fa..a3187c9 100644
--- a/src/templates/_macros.tmpl
+++ b/src/templates/_macros.tmpl
@@ -32,7 +32,7 @@ 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 %}
-  {% if raw or dat_line.code or dat_line.comment %}
+  {% if raw or dat_line.code or dat_line.comment_in_ledger %}
 
     {% if (not raw) and dat_line.prev_line_empty %}
       <tr ><td>&nbsp;</td></tr>
@@ -66,18 +66,18 @@ table.ledger tr > td:first-child { background-color: white; }
         <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>
+        <td>{{dat_line.comment_in_ledger}}</td>
       {% elif dat_line.error %}
         <td class="invalid" colspan=3>{{dat_line.code}}</td>
-        <td>{{dat_line.comment}}</td>
+        <td>{{dat_line.comment_in_ledger}}</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>
+        <td>{{dat_line.comment_in_ledger}}</td>
       {% else %}
         <td colspan=2></td>
-        <td colspan=2>{{dat_line.comment}}&nbsp;</td>
+        <td colspan=2>{{dat_line.comment_in_ledger}}&nbsp;</td>
       {% endif %}
     {% endif %}
     </tr>
-- 
2.30.2