home · contact · privacy
Add basic sorting features to Condition, Process table views.
authorChristian Heller <c.heller@plomlompom.de>
Sat, 18 May 2024 04:00:36 +0000 (06:00 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Sat, 18 May 2024 04:00:36 +0000 (06:00 +0200)
plomtask/http.py
templates/conditions.html
templates/processes.html

index d5da1d7e4d914a17b2a27a67e80db762e83f8403..c16fddd0e0926f4c97454f0e755c9e3b17319513 100644 (file)
@@ -147,7 +147,17 @@ class TaskHandler(BaseHTTPRequestHandler):
 
     def do_GET_conditions(self) -> dict[str, object]:
         """Show all Conditions."""
-        return {'conditions': Condition.all(self.conn)}
+        conditions = Condition.all(self.conn)
+        sort_by = self.params.get_str('sort_by')
+        if sort_by == 'is_active':
+            conditions.sort(key=lambda c: c.is_active)
+        elif sort_by == '-is_active':
+            conditions.sort(key=lambda c: c.is_active, reverse=True)
+        elif sort_by == '-title':
+            conditions.sort(key=lambda c: c.title.newest, reverse=True)
+        else:
+            conditions.sort(key=lambda c: c.title.newest)
+        return {'conditions': conditions, 'sort_by': sort_by}
 
     def do_GET_condition(self) -> dict[str, object]:
         """Show Condition of ?id=."""
@@ -196,7 +206,17 @@ class TaskHandler(BaseHTTPRequestHandler):
 
     def do_GET_processes(self) -> dict[str, object]:
         """Show all Processes."""
-        return {'processes': Process.all(self.conn)}
+        processes = Process.all(self.conn)
+        sort_by = self.params.get_str('sort_by')
+        if sort_by == 'steps':
+            processes.sort(key=lambda c: len(c.explicit_steps))
+        elif sort_by == '-steps':
+            processes.sort(key=lambda c: len(c.explicit_steps), reverse=True)
+        elif sort_by == '-title':
+            processes.sort(key=lambda c: c.title.newest, reverse=True)
+        else:
+            processes.sort(key=lambda c: c.title.newest)
+        return {'processes': processes, 'sort_by': sort_by}
 
     def do_POST(self) -> None:
         """Handle any POST request."""
index 88d1cc7244a32e91b7265c4f715af6a9161ebbe8..e8e9fed7fcf5a46b3b39b04ca134a54e94d29f05 100644 (file)
@@ -5,8 +5,8 @@
 
 <table>
 <tr>
-<th>active</th>
-<th>title</th>
+<th><a href="?sort_by={% if sort_by == "is_active" %}-{% endif %}is_active">active</a></th>
+<th><a href="?sort_by={% if sort_by == "title" %}-{% endif %}title">title</a></th>
 </tr>
 {% for condition in conditions %}
 <tr>
index 5cd00b5c279b0f14b25cb258549a05596230422b..977ac405ac89c57fd66d65bf8dd71d7c78cbfb67 100644 (file)
@@ -5,8 +5,8 @@
 
 <table>
 <tr>
-<th>steps</th>
-<th>title</th>
+<th><a href="?sort_by={% if sort_by == "steps" %}-{% endif %}steps">steps</a></th>
+<th><a href="?sort_by={% if sort_by == "title" %}-{% endif %}title">title</a></th>
 </tr>
 {% for process in processes %}
 <tr>