home · contact · privacy
Add text-based search/filter for Conditions and Processes.
[plomtask] / plomtask / http.py
index 080af8ce1a127880368c8c4bedb3cf4e0aebaffc..484147239ae8f3ef91d2ece69458d4b94c27e596 100644 (file)
@@ -123,19 +123,24 @@ class TaskHandler(BaseHTTPRequestHandler):
         todays_todos = Todo.by_date(self.conn, date)
         conditions_present = []
         enablers_for = {}
+        disablers_for = {}
         for todo in todays_todos:
-            for condition in todo.conditions:
+            for condition in todo.conditions + todo.blockers:
                 if condition not in conditions_present:
                     conditions_present += [condition]
                     enablers_for[condition.id_] = [p for p in
                                                    Process.all(self.conn)
                                                    if condition in p.enables]
+                    disablers_for[condition.id_] = [p for p in
+                                                    Process.all(self.conn)
+                                                    if condition in p.disables]
         seen_todos: set[int] = set()
         top_nodes = [t.get_step_tree(seen_todos)
                      for t in todays_todos if not t.parents]
         return {'day': Day.by_id(self.conn, date, create=True),
                 'top_nodes': top_nodes,
                 'enablers_for': enablers_for,
+                'disablers_for': disablers_for,
                 'conditions_present': conditions_present,
                 'processes': Process.all(self.conn)}
 
@@ -149,7 +154,8 @@ class TaskHandler(BaseHTTPRequestHandler):
 
     def do_GET_conditions(self) -> dict[str, object]:
         """Show all Conditions."""
-        conditions = Condition.all(self.conn)
+        pattern = self.params.get_str('pattern')
+        conditions = Condition.matching(self.conn, pattern)
         sort_by = self.params.get_str('sort_by')
         if sort_by == 'is_active':
             conditions.sort(key=lambda c: c.is_active)
@@ -159,7 +165,9 @@ class TaskHandler(BaseHTTPRequestHandler):
             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}
+        return {'conditions': conditions,
+                'sort_by': sort_by,
+                'pattern': pattern}
 
     def do_GET_condition(self) -> dict[str, object]:
         """Show Condition of ?id=."""
@@ -208,7 +216,8 @@ class TaskHandler(BaseHTTPRequestHandler):
 
     def do_GET_processes(self) -> dict[str, object]:
         """Show all Processes."""
-        processes = Process.all(self.conn)
+        pattern = self.params.get_str('pattern')
+        processes = Process.matching(self.conn, pattern)
         sort_by = self.params.get_str('sort_by')
         if sort_by == 'steps':
             processes.sort(key=lambda c: len(c.explicit_steps))
@@ -218,7 +227,7 @@ class TaskHandler(BaseHTTPRequestHandler):
             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}
+        return {'processes': processes, 'sort_by': sort_by, 'pattern': pattern}
 
     def do_POST(self) -> None:
         """Handle any POST request."""
@@ -301,6 +310,7 @@ class TaskHandler(BaseHTTPRequestHandler):
         effort = self.form_data.get_str('effort', ignore_strict=True)
         todo.effort = float(effort) if effort else None
         todo.set_conditions(self.conn, self.form_data.get_all_int('condition'))
+        todo.set_blockers(self.conn, self.form_data.get_all_int('blocker'))
         todo.set_enables(self.conn, self.form_data.get_all_int('enables'))
         todo.set_disables(self.conn, self.form_data.get_all_int('disables'))
         todo.is_done = len(self.form_data.get_all_str('done')) > 0
@@ -326,6 +336,7 @@ class TaskHandler(BaseHTTPRequestHandler):
         process.effort.set(self.form_data.get_float('effort'))
         process.set_conditions(self.conn,
                                self.form_data.get_all_int('condition'))
+        process.set_blockers(self.conn, self.form_data.get_all_int('blocker'))
         process.set_enables(self.conn, self.form_data.get_all_int('enables'))
         process.set_disables(self.conn, self.form_data.get_all_int('disables'))
         process.calendarize = self.form_data.get_all_str('calendarize') != []