From 80025e0b2d278a44852b6a397184d1f71c2075fe Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Wed, 5 Jun 2024 19:18:04 +0200
Subject: [PATCH] Improve day done tree display.

---
 plomtask/todos.py  | 12 ++++++++++++
 templates/day.html | 37 ++++++++++++++-----------------------
 2 files changed, 26 insertions(+), 23 deletions(-)

diff --git a/plomtask/todos.py b/plomtask/todos.py
index 775ef48..69a19c9 100644
--- a/plomtask/todos.py
+++ b/plomtask/todos.py
@@ -214,6 +214,18 @@ class Todo(BaseModel[int], ConditionsRelations):
         assert isinstance(effort_then, float)
         return effort_then
 
+    @property
+    def has_doneness_in_path(self) -> bool:
+        """Check whether self is done or has any children that are."""
+        if self.is_done:
+            return True
+        for child in self.children:
+            if child.is_done:
+                return True
+            if child.has_doneness_in_path:
+                return True
+        return False
+
     def get_step_tree(self, seen_todos: set[int]) -> TodoNode:
         """Return tree of depended-on Todos."""
 
diff --git a/templates/day.html b/templates/day.html
index 627923b..3b2e96a 100644
--- a/templates/day.html
+++ b/templates/day.html
@@ -16,11 +16,11 @@ th {
 }
 td.cond_line_0 {
   border-top: 1px solid white;
-  background-color: #dddddd;
+  background-color: #bfbfbf;
 }
 td.cond_line_1 {
   border-top: 1px solid white;
-  background-color: #efefef;
+  background-color: #dfdfdf;
 }
 td.cond_line_2 {
   border-top: 1px solid white;
@@ -33,11 +33,14 @@ td.cond_line_corner {
   text-overflow: clip;
 }
 td.todo_line {
-  border-bottom: 1px solid #dddddd;
+  border-bottom: 1px solid #bfbfbf;
   height: 1.7em;
 }
 tr.inactive td.todo_line {
-  background-color: #dddddd;
+  background-color: #bfbfbf;
+}
+tr.hidden_undone td, tr.hidden_undone a {
+  color: #9f9f9f;
 }
 td.left_border {
   border-left: 1px solid black;
@@ -110,33 +113,21 @@ O&nbsp;
 
 
 {% macro show_node_done(node, indent, path) %}
-{% if node.todo.is_done %}
-
-<tr>
-{% if path|length > 0 and not path[-1].todo.is_done %}
-<td>
-({% for path_node in path %}<a href="todo?id={{path_node.todo.id_}}">{{path_node.todo.title_then|e}}</a>  &lt;- {% endfor %})
-</td>
-</tr>
-
-<tr>
+{% if node.todo.has_doneness_in_path %}
+<tr{% if not node.todo.is_done %} class="hidden_undone"{% endif %}>
 <td>
-&nbsp; +
-{% else %}
-<td>
-{% for i in range(indent) %}&nbsp; {% endfor %} +
-{% endif %}
-{% if node.seen %}({% endif %}<a href="todo?id={{node.todo.id_}}">{{node.todo.title_then|e}}</a> {% if node.todo.comment|length > 0 %}[{{node.todo.comment|e}}]{% endif %}{% if node.seen %}){% endif %}
+{% for i in range(indent) %}&nbsp; &nbsp; {% endfor %} +
+{% if not node.todo.is_done %}({% endif %}<a href="todo?id={{node.todo.id_}}">{{node.todo.title_then|e}}</a>{% if not node.todo.is_done %}){% endif %}
 </td>
+<td>{{node.todo.comment|e}}</td>
 </tr>
 
-{% endif %}
 {% if not node.seen %}
 {% for child in node.children %}
-{{ show_node_done(child, indent+1, path + [node]) }}
+{{ show_node_done(child, indent+1) }}
 {% endfor %}
 {% endif %}
-
+{% endif %}
 {% endmacro %}
 
 
-- 
2.30.2