home · contact · privacy
Improve todo accounting script.
authorChristian Heller <c.heller@plomlompom.de>
Sat, 20 Jan 2024 06:34:46 +0000 (07:34 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sat, 20 Jan 2024 06:34:46 +0000 (07:34 +0100)
todo.py
todo_templates/base.html
todo_templates/calendar.html
todo_templates/do_todos.html
todo_templates/pick_tasks.html
todo_templates/tagfilters.html
todo_templates/task.html
todo_templates/todo.html
todo_templates/watch_form.html

diff --git a/todo.py b/todo.py
index 1e493acd982473be9958703d861722c8e7d24515..3ea09b0d7b7e42b4893c15b7274b7de85c7343bf 100644 (file)
--- a/todo.py
+++ b/todo.py
@@ -189,7 +189,6 @@ class Day:
         for todo in [todo for todo in self.linked_todos.values()
                      if self.date in todo.efforts.keys()]:
             day_effort = todo.efforts[self.date]
-            # print("DEBUG b", day_effort, todo.task.default_effort_at(self.date))
             if todo.done:
                 s += day_effort if day_effort else todo.task.default_effort.at(self.date)
             elif include_undone:
@@ -200,10 +199,6 @@ class Day:
     def todos_sum(self):
         return self._todos_sum()
 
-    # @property
-    # def todos_sum2(self):
-    #     return self._todos_sum(True)
-
 
 class Todo:
 
@@ -227,7 +222,7 @@ class Todo:
         self.importance = importance
         self.child_ids = child_ids if child_ids else [] 
 
-        self.parent = None 
+        self.parents = [] 
 
     @classmethod
     def from_dict(cls, db, d, id_):
@@ -253,6 +248,10 @@ class Todo:
                 'efforts': self.efforts,
                 'children': self.child_ids}
 
+    @property
+    def parent(self):
+        return self.parents[0] if len(self.parents) > 0 else None 
+
     @property
     def title(self):
         return self.task.title.at(self.earliest_date)
@@ -261,6 +260,10 @@ class Todo:
     def children(self):
         return [self.db.todos[id_] for id_ in self.child_ids]
 
+    @children.setter
+    def children(self, children):
+        self.child_ids = [child.id_ for child in children]
+
     @property
     def default_effort(self):
         return self.task.default_effort.at(self.earliest_date)
@@ -375,7 +378,7 @@ class TodoDB(PlomDB):
             hide_unchosen=False,
             hide_done=False):
         self.prefix = prefix
-        self.selected_date = selected_date if selected_date else today_date() #str(datetime.now())[:10]
+        self.selected_date = selected_date if selected_date else today_date()
         self.t_filter_and = t_filter_and if t_filter_and else []
         self.t_filter_not = t_filter_not if t_filter_not else []
         self.hide_unchosen = hide_unchosen
@@ -387,6 +390,8 @@ class TodoDB(PlomDB):
         self.todos = {}
         super().__init__(db_path)
 
+    # savefile I/O
+
     def read_db_file(self, f):
         d = json.load(f)
         for id_, t_dict in d['tasks'].items():
@@ -402,7 +407,7 @@ class TodoDB(PlomDB):
             self.add_day(dict_source=day_dict, date=date)
         for todo in self.todos.values():
             for child in todo.children:
-                child.parent = todo
+                child.parents += [todo]
             for date in todo.efforts.keys():
                 if not date in self.days.keys():
                     self.add_day(date)
@@ -410,21 +415,6 @@ class TodoDB(PlomDB):
                     self.days[date].linked_todos_as_list += [todo]
         self.set_visibilities()
 
-    def set_visibilities(self):
-        for uuid, t in self.tasks.items():
-            t.visible = len([tag for tag in self.t_filter_and if not tag in t.tags.now]) == 0\
-                    and len([tag for tag in self.t_filter_not if tag in t.tags.now]) == 0\
-                    and ((not self.hide_unchosen) or uuid in self.selected_day.todos.keys())
-        # for day in self.days.values():
-        #     for todo in day.todos.values():
-        #         todo.visible = len([tag for tag in self.t_filter_and if not tag in todo.day_tags | todo.task.tags ]) == 0\
-        #             and len([tag for tag in self.t_filter_not if tag in todo.day_tags | todo.task.tags ]) == 0\
-        #             and ((not self.hide_done) or (not todo.done))
-        for todo in self.todos.values():
-            todo.visible = len([tag for tag in self.t_filter_and if not tag in todo.day_tags | todo.task.tags.now ]) == 0\
-                and len([tag for tag in self.t_filter_not if tag in todo.day_tags | todo.task.tags.now ]) == 0\
-                and ((not self.hide_done) or (not todo.done))
-
     def to_dict(self):
         d = {'tasks': {}, 'days': {}, 'todos': {}}
         for uuid, t in self.tasks.items():
@@ -437,13 +427,6 @@ class TodoDB(PlomDB):
             d['todos'][id_] = todo.to_dict()
         return d
 
-    @property
-    def selected_day(self):
-        if not self.selected_date in self.days.keys():
-            self.days[self.selected_date] = self.add_day(date=self.selected_date)
-            # print("DEBUG selected_day", self.days[self.selected_date].date)
-        return self.days[self.selected_date]
-
     def write(self):
         dates_to_purge = []
         for date, day in self.days.items():
@@ -453,12 +436,35 @@ class TodoDB(PlomDB):
             del self.days[date]
         self.write_text_to_db(json.dumps(self.to_dict()))
 
+    # properties 
+
+    @property
+    def selected_day(self):
+        if not self.selected_date in self.days.keys():
+            self.days[self.selected_date] = self.add_day(date=self.selected_date)
+        return self.days[self.selected_date]
+
+    # table manipulations 
+
+    def add_day(self, date, dict_source=None):
+        day = Day.from_dict(self, dict_source, date) if dict_source else Day(self, date)
+        self.days[date] = day 
+        return day
+
     def add_task(self, id_=None, dict_source=None):
         id_ = id_ if id_ else str(uuid4())
         t = Task.from_dict(self, dict_source, id_) if dict_source else Task(self, id_)
         self.tasks[id_] = t
         return t
 
+    def update_task(self, id_, title, default_effort, tags, subtask_ids, comment):
+        task = self.tasks[id_] if id_ in self.tasks.keys() else self.add_task(id_)
+        task.title.set(title)
+        task.default_effort.set(default_effort)
+        task.tags.set(tags)
+        task.subtask_ids.set(subtask_ids)
+        task.comment = comment 
+
     def add_todo(self, todo_dict=None, id_=None, task=None, efforts=None):
         id_ = id_ if id_ else str(uuid4())
         if todo_dict:
@@ -472,115 +478,29 @@ class TodoDB(PlomDB):
         self.todos[id_] = todo 
         return todo
 
-    def add_day(self, date, dict_source=None):
-        day = Day.from_dict(self, dict_source, date) if dict_source else Day(self, date)
-        self.days[date] = day 
-        return day
-
-    def neighbor_dates(self):
-        current_date = datetime.strptime(self.selected_date, DATE_FORMAT)
-        prev_date = current_date - timedelta(days=1)
-        prev_date_str = prev_date.strftime(DATE_FORMAT)
-        next_date = current_date + timedelta(days=1)
-        next_date_str = next_date.strftime(DATE_FORMAT)
-        return prev_date_str, next_date_str
-
-    def show_do_todos(self, sort_order=None):
-        prev_date_str, next_date_str = self.neighbor_dates()
-        todos = [t for t in self.selected_day.linked_todos_as_list if t.visible]
-        if sort_order == 'title':
-            todos.sort(key=lambda t: t.task.title.then)
-        elif sort_order == 'done':
-            todos.sort(key=lambda t: t.day_effort if t.day_effort else t.default_effort.then if t.done else 0, reverse=True)
-        elif sort_order == 'default_effort':
-            todos.sort(key=lambda t: t.default_effort, reverse=True)
-        elif sort_order == 'importance':
-            todos.sort(key=lambda t: t.importance, reverse=True)
-        return j2env.get_template('do_todos.html').render(
-                day=self.selected_day,
-                tags=self.t_tags,
-                filter_and=self.t_filter_and,
-                filter_not=self.t_filter_not,
-                prev_date=prev_date_str,
-                next_date=next_date_str,
-                todos=todos,
-                sort=sort_order,
-                hide_done=self.hide_done)
-
-    def show_calendar(self, start_date_str, end_date_str):
-        self.t_filter_and = ['calendar']
-        self.t_filter_not = ['deleted']
-        self.set_visibilities()
-        days_to_show = {}
-        todays_date_str = today_date() # str(datetime.now())[:10]
-        todays_date_obj = datetime.strptime(todays_date_str, DATE_FORMAT) 
-        yesterdays_date_obj = todays_date_obj - timedelta(1)
-        yesterdays_date_str = yesterdays_date_obj.strftime(DATE_FORMAT) 
-        start_date_obj = datetime.strptime(sorted(self.days.keys())[0], DATE_FORMAT)
-        if start_date_str and len(start_date_str) > 0:
-            if start_date_str in {'today', 'yesterday'}:
-                start_date_obj = todays_date_obj if start_date_str == 'today' else yesterdays_date_obj
-            else:
-                start_date_obj = datetime.strptime(start_date_str, DATE_FORMAT)
-        end_date_obj = datetime.strptime(sorted(self.days.keys())[-1], DATE_FORMAT)
-        if end_date_str and len(end_date_str) > 0:
-            if end_date_str in {'today', 'yesterday'}:
-                end_date_obj = todays_date_obj if end_date_str == 'today' else yesterdays_date_obj
-            else:
-                end_date_obj = datetime.strptime(end_date_str, DATE_FORMAT)
-        for n in range(int((end_date_obj - start_date_obj).days) + 1):
-            current_date_obj = start_date_obj + timedelta(n)
-            current_date_str = current_date_obj.strftime(DATE_FORMAT)
-            if current_date_str not in self.days.keys():
-                days_to_show[current_date_str] = self.add_day(current_date_str)
-            else:
-                days_to_show[current_date_str] = self.days[current_date_str]
-            days_to_show[current_date_str].weekday = datetime.strptime(current_date_str, DATE_FORMAT).strftime('%A')[:2]
-        return j2env.get_template('calendar.html').render(
-                db=self,
-                days=days_to_show,
-                start_date=start_date_str,
-                end_date=end_date_str)
-
-    def show_todo(self, id_, return_to):
-        todo = self.todos[id_]
-        filtered_todos = [] #[t for t in self.todos.values() if t.visible and t != self and (t not in linked_todos) and (len(search) == 0 or t.matches(search))] 
-        return j2env.get_template('todo.html').render(
-                db=self,
-                todo=todo,
-                filtered_todos=filtered_todos,
-                child_todos=todo.children,
-                return_to=return_to)
-
-    def collect_tags(self, tags_joined, tags_checked):
-        tags = set()
-        for tag in [tag.strip() for tag in tags_joined.split(';') if tag.strip() != '']:
-            tags.add(tag)
-        for tag in tags_checked:
-            tags.add(tag)
-        return tags
-
-    def update_todo_for_day(self, id_, date, effort, done, comment, importance):
+    def _update_todo_shared(self, id_, done, comment, importance):
         todo = self.todos[id_]
         todo.done = done
-        todo.efforts[date] = effort 
         todo.comment = comment 
         todo.importance = importance 
+        return todo
 
-    def update_todo(self, id_, efforts, done, comment, day_tags_joined, day_tags_checked, importance):
-        todo = self.todos[id_]
+    def update_todo_for_day(self, id_, date, effort, done, comment, importance):
+        todo = self._update_todo_shared(id_, done, comment, importance)
+        todo.efforts[date] = effort 
+
+    def update_todo(self, id_, efforts, done, comment, tags, importance, children):
+        todo = self._update_todo_shared(id_, done, comment, importance)
         if len(efforts) == 0 and not todo.children:
             raise PlomException('todo must have at least one effort!')
-        todo.done = done
+        todo.children = children
         todo.efforts = efforts 
         for date in todo.efforts:
             if not date in self.days.keys():
                 self.add_day(date=date) 
             if not self in self.days[date].linked_todos_as_list:
                 self.days[date].linked_todos_as_list += [todo]
-        todo.comment = comment 
-        todo.day_tags = self.collect_tags(day_tags_joined, day_tags_checked) 
-        todo.importance = importance 
+        todo.day_tags = tags
 
     def delete_todo(self, id_):
         todo = self.todos[id_]
@@ -589,8 +509,8 @@ class TodoDB(PlomDB):
             dates_to_delete += [date]
         for date in dates_to_delete:
             self.delete_effort(todo, date, force=True)
-        if todo.parent:
-            todo.parent.child_ids.remove(todo.id_)
+        for parent in todo.parents:
+            parent.child_ids.remove(todo.id_)
         del self.todos[id_]
 
     def delete_effort(self, todo, date, force=False):
@@ -599,12 +519,95 @@ class TodoDB(PlomDB):
         self.days[date].linked_todos_as_list.remove(todo)
         del todo.efforts[date]
 
+    # views
+
+    def show_calendar(self, start_date_str, end_date_str):
+        self.t_filter_and = ['calendar']
+        self.t_filter_not = ['deleted']
+        self.set_visibilities()
+        start_date_obj, end_date_obj = self.get_limit_days_from_date_strings(start_date_str, end_date_str)
+        days_to_show = {}
+        for n in range(int((end_date_obj - start_date_obj).days) + 1):
+            date_obj = start_date_obj + timedelta(n)
+            date_str = date_obj.strftime(DATE_FORMAT)
+            if date_str not in self.days.keys():
+                days_to_show[date_str] = self.add_day(date_str)
+            else:
+                days_to_show[date_str] = self.days[date_str]
+            days_to_show[date_str].month_title = date_obj.strftime('%B') if date_obj.day == 1 else None 
+            days_to_show[date_str].weekday = datetime.strptime(date_str, DATE_FORMAT).strftime('%A')[:2]
+
+        return j2env.get_template('calendar.html').render(
+                selected_date=self.selected_date,
+                days=days_to_show,
+                start_date=start_date_str,
+                end_date=end_date_str)
+
+    def show_do_todos(self, sort_order=None):
+        prev_date_str, next_date_str = self.neighbor_dates()
+        todos = [t for t in self.selected_day.linked_todos_as_list
+                 if t.visible
+                 and not t.children]
+        if sort_order == 'title':
+            todos.sort(key=lambda t: t.task.title.then)
+        elif sort_order == 'done':
+            todos.sort(key=lambda t: t.day_effort if t.day_effort else t.default_effort if t.done else 0, reverse=True)
+        elif sort_order == 'default_effort':
+            todos.sort(key=lambda t: t.default_effort, reverse=True)
+        elif sort_order == 'importance':
+            todos.sort(key=lambda t: t.importance, reverse=True)
+        return j2env.get_template('do_todos.html').render(
+                day=self.selected_day,
+                tags=self.t_tags,
+                filter_and=self.t_filter_and,
+                filter_not=self.t_filter_not,
+                prev_date=prev_date_str,
+                next_date=next_date_str,
+                todos=todos,
+                sort=sort_order,
+                hide_done=self.hide_done)
+
+    def show_todo(self, id_, return_to, search, start_date, end_date):
+        todo = self.todos[id_]
+        start_day, end_day = self.get_limit_days_from_date_strings(start_date, end_date)
+        if start_day < datetime.now() - timedelta(days=2):
+            end_day = start_day + timedelta(days=3)
+            end_date = end_day.strftime(DATE_FORMAT)
+        legal_dates = []
+        for n in range(int((end_day - start_day).days) + 1):
+            day = start_day + timedelta(n)
+            legal_dates += [day.strftime(DATE_FORMAT)]
+        filtered_todos = [t for t in self.todos.values()
+                          if t.visible
+                          and t != todo
+                          and (len(search) == 0 or t.matches(search))] 
+        date_filtered_todos = [] 
+        for date in legal_dates:
+            for filtered_todo in filtered_todos:
+                if filtered_todo in date_filtered_todos:
+                    continue
+                if date in filtered_todo.efforts.keys():
+                    date_filtered_todos += [filtered_todo]
+        return j2env.get_template('todo.html').render(
+                filter_and=self.t_filter_and,
+                filter_not=self.t_filter_not,
+                tags=self.t_tags,
+                todo=todo,
+                filtered_todos=date_filtered_todos,
+                child_todos=todo.children,
+                return_to=return_to,
+                start_date=start_date,
+                end_date=end_date)
+
     def show_task(self, id_, return_to='', search=''):
         task = self.tasks[id_] if id_ else self.add_task()
         selected = task.id_ in self.selected_day.todos.keys()
-        filtered_tasks = [t for t in self.tasks.values() if t.visible and t != self and (t not in task.subtasks) and (len(search) == 0 or t.matches(search))] 
+        filtered_tasks = [t for t in self.tasks.values()
+                          if t.visible
+                          and t != task
+                          and (t not in task.subtasks)
+                          and (len(search) == 0 or t.matches(search))] 
         return j2env.get_template('task.html').render(
-                db=self,
                 search=search,
                 tags=self.t_tags, 
                 filter_and=self.t_filter_and,
@@ -613,14 +616,6 @@ class TodoDB(PlomDB):
                 task=task,
                 return_to=return_to)
 
-    def update_task(self, id_, title, default_effort, tags_joined, tags_checked, subtask_ids, comment):
-        task = self.tasks[id_] if id_ in self.tasks.keys() else self.add_task(id_)
-        task.title.set(title)
-        task.default_effort.set(float(default_effort) if len(default_effort) > 0 else None)
-        task.tags.set(self.collect_tags(tags_joined, tags_checked)) 
-        task.subtask_ids.set(subtask_ids)
-        task.comment = comment 
-
     def show_tasks(self, expand_uuid):
         expanded_tasks = {}
         if expand_uuid:
@@ -635,26 +630,38 @@ class TodoDB(PlomDB):
 
     def show_pick_tasks(self, search, hide_chosen_tasks, sort_order=None):
         prev_date_str, next_date_str = self.neighbor_dates()
+
         chosen_todos = self.selected_day.linked_todos_as_list
+
         relevant_todos = []
         for todo in self.todos.values():
-            if todo.done or (not todo.visible) or (not todo.matches(search)) or todo.earliest_date >= self.selected_date:
+            if todo.done\
+                    or (not todo.visible)\
+                    or (not todo.matches(search))\
+                    or todo.earliest_date >= self.selected_date:
                 continue
             relevant_todos += [todo] 
+
         tasks = []
         chosen_tasks = [todo.task for todo in self.selected_day.linked_todos_as_list]
         for uuid, task in self.tasks.items():
-            if (not task.visible) or (not task.matches(search)) or (hide_chosen_tasks and task in chosen_tasks):
+            if (not task.visible)\
+                    or (not task.matches(search))\
+                    or (hide_chosen_tasks and task in chosen_tasks):
                 continue
             tasks += [task]
+
         if sort_order == 'title':
             chosen_todos.sort(key=lambda t: t.title)
             relevant_todos.sort(key=lambda t: t.title)
             tasks.sort(key=lambda t: t.title.then)
         elif sort_order == 'effort':
-            chosen_todos.sort(key=lambda t: t.day_effort if t.day_effort else t.default_effort if t.done else 0, reverse=True)
+            chosen_todos.sort(key=lambda t:
+                              t.day_effort if t.day_effort else (t.default_effort if t.done else 0),
+                              reverse=True)
             relevant_todos.sort(key=lambda t: t.all_days_effort, reverse=True)
             tasks.sort(key=lambda t: t.default_effort.then, reverse=True)
+
         return j2env.get_template('pick_tasks.html').render(
                 sort=sort_order,
                 tags=self.t_tags,
@@ -669,6 +676,42 @@ class TodoDB(PlomDB):
                 relevant_todos=relevant_todos,
                 search=search)
 
+    # helpers
+
+    def set_visibilities(self):
+        for uuid, t in self.tasks.items():
+            t.visible = len([tag for tag in self.t_filter_and if not tag in t.tags.now]) == 0\
+                    and len([tag for tag in self.t_filter_not if tag in t.tags.now]) == 0\
+                    and ((not self.hide_unchosen) or uuid in self.selected_day.todos.keys())
+        for todo in self.todos.values():
+            todo.visible = len([tag for tag in self.t_filter_and if not tag in todo.day_tags | todo.task.tags.now ]) == 0\
+                and len([tag for tag in self.t_filter_not if tag in todo.day_tags | todo.task.tags.now ]) == 0\
+                and ((not self.hide_done) or (not todo.done))
+
+    def get_limit_days_from_date_strings(self, start_date_str, end_date_str):
+        todays_date_obj = datetime.strptime(today_date(), DATE_FORMAT) 
+        yesterdays_date_obj = todays_date_obj - timedelta(1)
+        def get_day_limit_obj(index, day_limit_string):
+            date_obj = datetime.strptime(sorted(self.days.keys())[index], DATE_FORMAT)
+            if day_limit_string and len(day_limit_string) > 0:
+                if day_limit_string in {'today', 'yesterday'}:
+                    date_obj = todays_date_obj if day_limit_string == 'today' else yesterdays_date_obj
+                else:
+                    date_obj = datetime.strptime(day_limit_string, DATE_FORMAT)
+            return date_obj
+        start_date_obj = get_day_limit_obj(0, start_date_str)
+        end_date_obj = get_day_limit_obj(-1, end_date_str)
+        return start_date_obj, end_date_obj
+
+    def neighbor_dates(self):
+        current_date = datetime.strptime(self.selected_date, DATE_FORMAT)
+        prev_date = current_date - timedelta(days=1)
+        prev_date_str = prev_date.strftime(DATE_FORMAT)
+        next_date = current_date + timedelta(days=1)
+        next_date_str = next_date.strftime(DATE_FORMAT)
+        return prev_date_str, next_date_str
+
+
 
 class ParamsParser:
 
@@ -696,7 +739,6 @@ class ParamsParser:
         return param
 
     def get_cookied_chain(self, key, default=None):
-        # default = default if default else ['-']
         params = self.params.get(key, default)
         if params == ['-']:
             params = None 
@@ -709,6 +751,51 @@ class ParamsParser:
         return params
 
 
+class PostvarsParser:
+
+    def __init__(self, postvars):
+        self.postvars = postvars
+
+    def has(self, key):
+        return key in self.postvars.keys()
+
+    def get(self, key, on_empty=None):
+        return self.get_at_index(key, 0, on_empty)
+
+    def get_at_index(self, key, i, on_empty=None):
+        if self.has(key) and len(self.postvars[key][i]) > 0:
+            return self.postvars[key][i] 
+        return on_empty 
+
+    def get_float_if_possible(self, key):
+        s = self.get(key)
+        if s is not None:
+            return float(s)
+        else:
+            return None
+
+    def get_all(self, key, on_empty=None):
+        if self.has(key) and len(self.postvars[key]) > 0:
+            return self.postvars[key] 
+        return on_empty
+
+    def get_defined_tags(self, joined_key, key_prefix):
+        tags = set()
+        tags_checked = []
+        for k in self.postvars.keys():
+            if k.startswith(key_prefix):
+                tags_checked += [k[len(key_prefix):]]
+        tags_joined = self.get(joined_key, '')
+        for tag in [tag.strip() for tag in tags_joined.split(';') if tag.strip() != '']:
+            tags.add(tag)
+        for tag in tags_checked:
+            tags.add(tag)
+        return tags
+
+    def set(self, key, value):
+        self.postvars[key] = [value]
+
+
 class TodoHandler(PlomHandler):
 
     def config_init(self):
@@ -725,44 +812,44 @@ class TodoHandler(PlomHandler):
         return 'todo', {'cookie_name': 'todo_cookie', 'prefix': default_path, 'cookie_path': default_path}
 
     def do_POST(self):
-        self.try_do(self.config_init)
         self.try_do(self.write_db)
 
     def write_db(self):
         from urllib.parse import urlencode
         config = self.apps['todo'] if hasattr(self, 'apps') else self.config_init()
-        length = int(self.headers['content-length'])
-        postvars = parse_qs(self.rfile.read(length).decode(), keep_blank_values=1)
         parsed_url = urlparse(self.path)
-        site = path_split(urlparse(self.path).path)[1]
+        site = path_split(parsed_url.path)[1]
+        length = int(self.headers['content-length'])
+        postvars = PostvarsParser(parse_qs(self.rfile.read(length).decode(), keep_blank_values=1))
+
         db = TodoDB(prefix=config['prefix'])
         redir_params = []
+        # if we do encounter a filter post, we repost it (and if empty, the emptying command '-')
         for param_name, filter_db_name in {('t_and', 't_filter_and'), ('t_not', 't_filter_not')}:
             filter_db = getattr(db, filter_db_name)
-            if param_name in postvars.keys():
-                for target in postvars[param_name]:
+            if postvars.has(param_name): 
+                for target in postvars.get_all(param_name, []):
                     if len(target) > 0 and not target in filter_db:
                         filter_db += [target]
                 if len(filter_db) == 0:
                     redir_params += [(param_name, '-')]
             redir_params += [(param_name, f) for f in filter_db]
-
-        def collect_checked(prefix, postvars):
-            tags_checked = []
-            for k in postvars.keys():
-                if k.startswith(prefix):
-                    tags_checked += [k[len(prefix):]]
-            return tags_checked
+        if site in {'calendar', 'todo'}:
+            redir_params += [('end', postvars.get('end', '-'))]
+            redir_params += [('start', postvars.get('start', '-'))]
+        if site in {'todo', 'task', 'pick_tasks'}:
+            redir_params += [('search', postvars.get('search', ''))]
+            redir_params += [('search', postvars.get('search', ''))]
+            redir_params += [('search', postvars.get('search', ''))]
+        if postvars.has('filter'): 
+            postvars.set('return_to', '')
         
-        if 'calendar' == site:
-            redir_params += [('start', postvars['start'][0] if len(postvars['start'][0]) > 0 else '-')]
-            redir_params += [('end', postvars['end'][0] if len(postvars['end'][0]) > 0 else '-')]
-
-        elif 'todo' == site:
-            todo_id = postvars['todo_id'][0]
-            old_todo = db.todos[todo_id] 
+        if 'todo' == site:
+            todo_id = postvars.get('todo_id')
+            redir_params += [('id', todo_id)]
+            old_todo = db.todos[todo_id] if todo_id in db.todos.keys() else None
             efforts = {}
-            for i, date in enumerate(postvars['effort_date']):
+            for i, date in enumerate(postvars.get_all('effort_date', [])):
                 if '' == date:
                     continue
                 try:
@@ -770,166 +857,141 @@ class TodoHandler(PlomHandler):
                 except ValueError:
                     raise PlomException(f'bad date string')
                 efforts[date] = None
-                if not old_todo.children:
-                    efforts[date] = float(postvars['effort'][i]) if len(postvars['effort'][i]) > 0 else None 
-            if 'delete' in postvars.keys():
-                has_day_effort = False 
-                for effort in efforts.values():
-                    if effort is not None:
-                        has_day_effort = True 
-                        break
-                if 'done' in postvars or postvars['comment'][0] != '' or len(collect_checked('day_tag_', postvars)) > 0 or postvars['joined_day_tags'][0] != '' or has_day_effort:
+                if not (old_todo and old_todo.children):
+                    efforts[date] = postvars.get_at_index('effort', i, None) 
+            if postvars.has('delete'): 
+                has_day_effort = len([e for e in efforts.values() if e is not None]) > 0
+                if postvars.has('done')\
+                        or postvars.get('comment')\
+                        or len(postvars.get_defined_tags('joined_day_tags', 'day_tag_')) > 0\
+                        or has_day_effort:
                     raise PlomException('will not remove todo of preserve-worthy values')
                 db.delete_todo(todo_id) 
-            else:
-                redir_params += [('id', todo_id)]
-                if 'delete_effort' in postvars.keys():
-                    for date in postvars['delete_effort']:
+                if not postvars.get('return_to'):
+                    postvars.set('return_to', 'calendar')
+            elif postvars.has('update'):
+                if postvars.has('delete_effort'):
+                    for date in postvars.get_all('delete_effort'):
                         db.delete_effort(old_todo, date)
                         del efforts[date]
+                children = [db.todos[id_] for id_ in postvars.get_all('adopt_child', [])] 
                 db.update_todo(id_=todo_id,
                                efforts=efforts,
-                               done='done' in postvars.keys(),
-                               comment=postvars['comment'][0],
-                               day_tags_joined=postvars['joined_day_tags'][0],
-                               day_tags_checked=collect_checked('day_tag_', postvars),
-                               importance=float(postvars['importance'][0]))
+                               done=postvars.has('done'),
+                               comment=postvars.get('comment', ''),
+                               tags=postvars.get_defined_tags('joined_day_tags', 'day_tag_'),
+                               importance=float(postvars.get('importance')),
+                               children=children)
 
         elif 'task' == site:
-            id_ = postvars['id'][0]
-            if 'filter' in postvars.keys():
-                redir_params += [('search', postvars['search'][0])]
-            elif 'title' in postvars.keys():
-                subtask_ids = [] if not 'subtask' in postvars.keys() else postvars['subtask']
-                default_effort = '0' if not 'default_effort' in postvars.keys() else postvars['default_effort'][0]
-                db.update_task(id_, postvars['title'][0], default_effort, postvars['joined_tags'][0], collect_checked('tag_', postvars), subtask_ids, postvars['comment'][0])
-            redir_params += [('id', id_)]
+            task_id = postvars.get('task_id')
+            if postvars.has('update'):
+                db.update_task(
+                        id_=task_id,
+                        title=postvars.get('title', ''),
+                        default_effort=postvars.get_float_if_possible('default_effort'), 
+                        tags=postvars.get_defined_tags('joined_tags', 'tag_'),
+                        subtask_ids=postvars.get_all('subtask', []),
+                        comment=postvars.get('comment', ''))
+            redir_params += [('id', task_id)]
 
         elif 'pick_tasks' == site:
-            if 'filter' in postvars.keys():
-                redir_params += [('search', postvars['search'][0])]
-                redir_params += [('hide_chosen_tasks', int('hide_chosen_tasks' in postvars.keys()))]
-            else:
-                db.selected_date = postvars['date'][0]
+            redir_params += [('hide_chosen_tasks', int(postvars.has('hide_chosen_tasks')))]
+            if postvars.has('update'):
+                db.selected_date = postvars.get('date')
                 todos_to_shrink = []
                 todos_to_delete = []
                 for todo in db.selected_day.linked_todos_as_list:
-                    if todo.visible and not ('chosen_todo' in postvars.keys() and todo.id_ in postvars['chosen_todo']):
-                        if len(todo.comment) > 0 or len(todo.day_tags) > 0 or not todo.is_effort_removable(db.selected_date):
-                            # print("DEBUG", len(todo.comment) > 0, len(todo.day_tags) > 0, todo.is_effort_removable(db.selected_date))
+                    if todo.visible and not todo.id_ in postvars.get_all('chosen_todo', []):
+                        if len(todo.comment) > 0\
+                                or len(todo.day_tags) > 0\
+                                or not todo.is_effort_removable(db.selected_date):
                             raise PlomException('will not remove effort of preserve-worthy values')
                         if len(todo.efforts) > 1:
                             todos_to_shrink += [todo]
-                            # db.delete_effort(todo, db.selected_date)
                         else:
                             todos_to_delete += [todo]
-                            # db.delete_todo(todo.id_)
                 for todo in todos_to_shrink:
                     db.delete_effort(todo, db.selected_date)
                 for todo in todos_to_delete:
                     db.delete_todo(todo.id_)
-                if 'choose_task' in postvars.keys():
-                    for id_ in postvars['choose_task']:
-                        db.add_todo(task=db.tasks[id_], efforts={db.selected_date: None})
-                if 'choose_todo' in postvars.keys():
-                    for id_ in postvars['choose_todo']:
-                        todo = db.todos[id_]
-                        todo.efforts[db.selected_date] = None
+                for id_ in postvars.get_all('choose_task', []):
+                    db.add_todo(task=db.tasks[id_], efforts={db.selected_date: None})
+                for id_ in postvars.get_all('choose_todo', []):
+                    db.todos[id_].efforts[db.selected_date] = None
 
         elif 'do_todos' == site:
-            if 'filter' in postvars.keys():
-                redir_params += [('hide_done', int('hide_done' in postvars.keys()))]
-            else:
-                db.selected_date = postvars['date'][0]
+            redir_params += [('hide_done', int(postvars.has('hide_done')))]
+            if postvars.has('update'): 
+                db.selected_date = postvars.get('date') 
                 redir_params += [('date', db.selected_date)]
-                db.selected_day.comment = postvars['day_comment'][0]
-                if 'todo_id' in postvars.keys():
-                    for i, todo_id in enumerate(postvars['todo_id']):
-                        old_todo = None if not todo_id in db.todos.keys() else db.todos[todo_id]
-                        done = ('done' in postvars) and (todo_id in postvars['done'])
-                        day_effort_input = postvars['effort'][i]
-                        day_effort = float(day_effort_input) if len(day_effort_input) > 0 else None
-                        comment = postvars['effort_comment'][i]
-                        importance = float(postvars['importance'][i])
-                        if old_todo and old_todo.done == done and old_todo.day_effort == day_effort and comment == old_todo.comment and old_todo.importance == importance:
-                            continue
-                        db.update_todo_for_day(todo_id, db.selected_date, day_effort, done, comment, importance)
-
-        elif 'day' == site:
-            # always store the two hide params in the URL if possible … TODO: find out if really necessary
-            if 'expect_unchosen_done' in postvars.keys():
-                redir_params += [('hide_unchosen', int('hide_unchosen' in postvars.keys()))] + [('hide_done', int('hide_done' in postvars.keys()))]
-
-            if 'date' in postvars.keys():
-                db.selected_date = postvars['date'][0]
-                if 'day_comment' in postvars.keys():
-                    db.selected_day.comment = postvars['day_comment'][0]
-                redir_params += [('date', db.selected_date)]
-
-                # handle todo list updates via task UUIDs
-                if 't_uuid' in postvars.keys():
-                    for i, uuid in enumerate(postvars['t_uuid']):
-                        task = db.tasks[uuid]
-                        old_todo = None if not uuid in db.selected_day.todos.keys() else db.selected_day.todos[uuid]
-                        selects_as_todo = 'choose' in postvars and uuid in postvars['choose']
-                        too_much_keepworthy_data = ('done' in postvars and uuid in postvars['done']) or postvars['day_effort'][i] != '' or (old_todo and not old_todo.internals_empty())
-                        if old_todo and too_much_keepworthy_data and not selects_as_todo:
-                            raise PlomException('cannot deselect task as todo of preserve-worthy values')
-                        elif old_todo and not selects_as_todo:
-                            del db.selected_day.todos[uuid]
-                        elif too_much_keepworthy_data or selects_as_todo:
-                            done = ('done' in postvars) and (uuid in postvars['done'])
-                            day_effort_input = postvars['day_effort'][i]
-                            day_effort = float(day_effort_input) if len(day_effort_input) > 0 else None
-                            importance = float(postvars['importance'][i])
-                            if old_todo and old_todo.done == done and old_todo.day_effort == day_effort and old_todo.importance == importance:
-                                continue
-                            db.update_todo_mini(uuid, db.selected_date, day_effort, done, importance)
-
-        if 'return_to' in postvars.keys() and len(postvars['return_to'][0]) > 0:
-            homepage = postvars['return_to'][0]
-        else:
+                db.selected_day.comment = postvars.get('day_comment', '') 
+                for i, todo_id in enumerate(postvars.get_all('todo_id')):
+                    old_todo = None if not todo_id in db.todos.keys() else db.todos[todo_id]
+                    done = todo_id in postvars.get_all('done', [])
+                    day_effort_input = postvars.get_at_index('effort', i, '') 
+                    day_effort = float(day_effort_input) if len(day_effort_input) > 0 else None
+                    comment = postvars.get_at_index('effort_comment', i, '') 
+                    importance = float(postvars.get_at_index('importance', i))
+                    if old_todo\
+                            and old_todo.done == done\
+                            and old_todo.day_effort == day_effort\
+                            and comment == old_todo.comment\
+                            and old_todo.importance == importance:
+                        continue
+                    db.update_todo_for_day(
+                            todo_id,
+                            db.selected_date,
+                            day_effort,
+                            done,
+                            comment,
+                            importance)
+
+        homepage = postvars.get('return_to')
+        if not homepage:
             encoded_params = urlencode(redir_params)
             homepage = f'{site}?{encoded_params}'
         db.write()
         self.redirect(homepage)
 
     def do_GET(self):
-        self.try_do(self.config_init)
         self.try_do(self.show_db)
 
     def show_db(self):
         config = self.apps['todo'] if hasattr(self, 'apps') else self.config_init()
-        cookie_db = self.get_cookie_db(config['cookie_name'])
         parsed_url = urlparse(self.path)
         site = path_split(parsed_url.path)[1]
-
+        cookie_db = self.get_cookie_db(config['cookie_name'])
         params = ParamsParser(parsed_url.query, cookie_db)
+
         selected_date = t_filter_and = t_filter_not = None
         hide_unchosen = hide_done = False
         return_to = params.get('return_to', '')
-        if site in {'do_todos', 'pick_tasks'}:
+        if site in {'do_todos', 'pick_tasks', 'calendar'}:
             selected_date = params.get_cookied('date')
-        if site in {'do_todos', 'pick_tasks', 'task', 'tasks'}:
+        if site in {'do_todos', 'pick_tasks', 'task', 'todo'}:
             t_filter_and = params.get_cookied_chain('t_and')
             t_filter_not = params.get_cookied_chain('t_not')
         if 'do_todos' == site:
             hide_done = params.get('hide_done', False) 
         db = TodoDB(config['prefix'], selected_date, t_filter_and, t_filter_not, hide_unchosen, hide_done)
-        if 'do_todos' == site:
+        if site in {'todo', 'task'}:
+            id_ = params.get('id')
+        if site in {'todo', 'task', 'pick_tasks'}:
+            search = params.get('search', '')
+        if site in {'do_todos', 'pick_tasks'}:
             sort_order = params.get_cookied('sort')
+        if site in {'calendar', 'todo'}:
+            start_date = params.get_cookied('start')
+            end_date = params.get_cookied('end')
+        if 'do_todos' == site:
             page = db.show_do_todos(sort_order)
         elif 'pick_tasks' == site:
-            sort_order = params.get_cookied('sort')
             hide_chosen_tasks = params.get('hide_chosen_tasks', False)
-            search = params.get('search', '')
             page = db.show_pick_tasks(search, hide_chosen_tasks, sort_order)
         elif site == 'todo':
-            todo_id = params.get('id')
-            page = db.show_todo(todo_id, return_to)
+            page = db.show_todo(id_, return_to, search, start_date, end_date)
         elif 'task' == site:
-            id_ = params.get('id')
-            search = params.get('search', '')
             page = db.show_task(id_, return_to, search)
         elif 'tasks' == site:
             expand_uuid = params.get('expand_uuid')
@@ -942,8 +1004,6 @@ class TodoHandler(PlomHandler):
                 self.unset_cookie(config['cookie_name'], config['cookie_path'])
                 page = 'cookie unset!'
         else:
-            start_date = params.get_cookied('start')
-            end_date = params.get_cookied('end')
             page = db.show_calendar(start_date, end_date)
 
         if 'unset_cookie' != site:
index 92cdff01b7482761f9588358ff075f0b200b4daf..b010333d452eaea28b160467398702c0e382d9bd 100644 (file)
@@ -1,6 +1,19 @@
 <style>
-body { font-family: monospace; }
+body { font-family: monospace; background: white; color: black; }
 input { font-family: monospace; padding: 0em; margin: 0em; }
+table.alternating tr:nth-child(even) {
+    background-color: #cccccc;
+}
+table.alternating tr:nth-child(odd) {
+    background-color: white;
+}
+th, td { vertical-align: top; text-align: left}
+input[type="number"], td.number { text-align: right; }
+input[type="checkbox"] { height: 1.3em; width: 1.3em; }
+th.desc { background: linear-gradient(to bottom, white, grey); }
+input[type="submit"] { background-color: #cccccc; }
+button { background-color: #cccccc; }
+input[type="submit"].update { background-color: #aaffaa; }
 {% block css %}
 {% endblock %}
 </style>
index 82a9ca2e487e16517ef127f7a41859aedede051f..bc77ccdb0669aed74dd67be1fa6ff7828301958a 100644 (file)
@@ -1,30 +1,70 @@
 {% extends 'base.html' %}
+
 {% block css %}
-tr td { background-color: white; }
+#filter { margin-bottom: 1em; }
+tr.month_row td { color: white; background-color: #555555; text-align: center; }
 tr.week_row td { height: 0.1em; background-color: black; }
-tr.day_row td { background-color: #cccccc }
-td.checkbox { width: 0.1em; height: 0.1em; padding: 0em; text-align: center; }
+tr.day_row td { background-color: #cccccc; }
+span.selected_date { font-weight: bold; }
 {% endblock %}
+
 {% block content %}
+<h3>calendar</h3>
 <form action="calendar" method="POST">
-<p>
+
+<div id="filter">
 from: <input name="start" {% if start_date %}value="{{ start_date }}"{% endif %} placeholder="yesterday" />
 to: <input name="end" {% if end_date %}value="{{ end_date }}"{% endif %} placeholder="2030-12-31" />
 <input type="submit" value="OK" />
-</p>
+</div>
+
 <table>
-{% for date, day in days.items() | sort() %}
-{% if day.weekday == 'Mo' %}<tr class="week_row"><td colspan=3></td></tr>{% endif %}
-<tr class="day_row"><td colspan=3><a href="do_tasks?date={{date}}&hide_unchosen=1">{{ day.weekday }} {{ date }}</a> |{{ "%5.1f" |format(day.todos_sum)}}| {{ day.comment|e }}</td></tr>
-{% for todo in day.linked_todos_as_list %}
+{% for date, day in days.items() %}
 
-{% if todo.visible %}
-<tr><td class="checkbox">{% if todo.done and not "cancelled" in todo.tags%}✓{% else %}&nbsp;&nbsp;{% endif %}</td><td><a href="todo?id={{todo.id_}}">{% if "cancelled" in todo.tags %}<s>{% endif %}{% if "deadline" in todo.tags %}DEADLINE: {% endif %}{{ todo.title|e }}{%if "cancelled" in todo.tags%}</s>{% endif %}</a></td><td>{{ todo.comment|e }}</td></tr>
+{% if day.month_title %}
+<tr class="month_row">
+<td colspan=3>{{ day.month_title }}</td>
+</tr>
+{% endif %}
+
+{% if day.weekday == 'Mo' %}
+<tr class="week_row">
+<td colspan=3></td>
+</tr>
 {% endif %}
 
+<tr class="day_row">
+<td colspan=3>
+<span {% if date == selected_date %}class="selected_date"{% endif %}>
+<a href="do_todos?date={{date}}&hide_unchosen=1">{{ day.weekday }} {{ date }}</a>
+</span>
+<span style="white-space: pre; ">|{{ '{:5.1f}'.format(day.todos_sum)}}|</span>
+{{ day.comment|e }}
+</td>
+</tr>
+
+{% for todo in day.linked_todos_as_list %}
+{% if todo.visible %}
+<tr>
+<td>
+{% if "cancelled" in todo.tags %}<s>{% endif %}
+[{% if todo.done and not "cancelled" in todo.tags %}✓{% else %} {% endif %}]
+<a href="todo?id={{todo.id_}}">
+{% if "deadline" in todo.tags %}DEADLINE: {% endif %}
+{{ todo.title|e }}
+</a>
+{%if "cancelled" in todo.tags%}</s>{% endif %}
+</td>
+<td>
+{{ todo.comment|e }}
+</td>
+</tr>
+{% endif %}
 {% endfor %}
+
 {% endfor %}
 </table>
+
 </form>
 {% endblock %}
 
index 7a8ae82158217427993f414e4f9ee13b7aa70b1c..129018f257e77ad2e0b4b38056fefe39bfd468c3 100644 (file)
@@ -1,69 +1,72 @@
 {% extends 'base.html' %}
+
 {% block css %}
-table.alternating tr:nth-child(even) {
-    background-color: #cccccc;
-}
-table.alternating tr:nth-child(odd) {
-    background-color: #ffffff;
-}
-th, td { text-align: left}
-th.desc { background: linear-gradient(to bottom, white, grey); }
-th.center { text-align: center; }
-td.checkbox, td.number { height: 0.1em; padding: 0em; text-align: center; }
-td.checkbox { width: 0.1em; text-align: center; }
-td button { height: 1.5em; padding: 0em; margin: 0em }
-input[type="number"] { text-align: right; }
-th.desc { background: linear-gradient(to bottom, white, grey); }
+td.number, td.checkbox { text-align: center; }
+td { vertical-align: middle; }
+td button { padding: 0em; }
+th.centered { text-align: center; }
 {% endblock %}
+
 {% block content %}
-<form action="do_todos" method="POST">
+<h3>do todos</h3>
+
+<form id="form_to_watch" action="do_todos" method="POST">
 {% include 'tagfilters.html' %}
 <br />
 <input name="hide_done" type="checkbox" {% if hide_done %}checked{% endif %} /> hide done
 <input type="submit" name="filter" value="filter" />
-</form>
-<h3>do day</h3>
-<form id="form_to_watch" action="do_todos" method="POST">
 <p>
 | <a href="do_todos?date={{prev_date}}">prev</a> | {{day.date}} | <a href="do_todos?date={{next_date}}">next</a> | 
 comment: <input name="day_comment" value="{{day.comment|e}}">
-<input type="submit" value="update">
+<input class="update" type="submit" name="update" value="update">
 <input type="hidden" name="date" value="{{day.date}}" />
 </p>
+
 <table class="alternating">
 <tr>
-<th {% if sort=='done' %}class="desc"{% endif %}><a href="?sort=done">done</a></th>
-<th class="center{% if sort=='default_effort' %} desc{% endif %}"><a href="?sort=default_effort">effort</a></th>
-<th {% if sort=='importance' %}class ="desc"{% endif %}><a href="?sort=importance">importance</a></th>
-<th {% if sort=='title' %}class="desc"{% endif %}><a href="?sort=title">todo</a></th>
+<th {% if sort=='done' %}class="desc"{% endif %}>
+<a href="?sort=done">done</a>
+</th>
+<th class="centered{% if sort=='default_effort' %} desc{% endif %}">
+<a href="?sort=default_effort">effort</a>
+</th>
+<th {% if sort=='importance' %}class ="desc"{% endif %}>
+<a href="?sort=importance">importance</a>
+</th>
+<th {% if sort=='title' %}class="desc"{% endif %}>
+<a href="?sort=title">todo</a>
+</th>
 <th>comment</th>
+</tr>
+
 {% for todo in todos %}
 <tr>
 <input name="todo_id" value="{{todo.id_}}" type="hidden" >
 <td class="checkbox">
-{% if todo.children %}
-{% if todo.done %}✓{% else %}&nbsp;&nbsp;{% endif %}
-{% else %}
 <input name="done" type="checkbox" value="{{todo.id_}}" {% if todo.done %}checked{% endif %}>
-{% endif %}
 </td>
 <td class="number">
-{% if todo.children %}
-<input type="hidden" name="effort" value="0" />
-{% else %}
 <input class="effort_input" name="effort" type="number" step=0.1 size=7 value="{% if todo.day_effort is not none %}{{todo.day_effort}}{% endif %}" placeholder={{"%.1f"|format(todo.task.default_effort.then)}} >
-{% endif %}
 </td>
-<td class="number"><input name="importance" type="number" step=0.1 size=7 value={{todo.importance}} } ></td>
-<td><a href="todo?id={{todo.id_}}">{{todo.path}}{{todo.title}}</a></td>
-<td><input name="effort_comment" type="text" size=100 value="{{todo.comment|e}}" /></td>
+<td class="number">
+<input name="importance" type="number" step=0.1 size=7 value={{todo.importance}} } >
+</td>
+<td>
+<a href="todo?id={{todo.id_}}&return_to=do_todos">{{todo.path}}{{todo.title}}</a>
+</td>
+<td>
+<input name="effort_comment" type="text" size=100 value="{{todo.comment|e}}" />
+</td>
 </tr>
 {% endfor %}
+
 </table>
-<input type="submit" value="update">
+<input class="update" type="submit" name="update" value="update">
 </form>
+
 {% include 'watch_form.html' %}
 <script>
+mere_filter_inputs = mere_filter_inputs.concat(['hide_done']);
 var effort_inputs = document.getElementsByClassName("effort_input");
 for (let i = 0; i < effort_inputs.length; i++) {
     let input = effort_inputs[i];
@@ -77,7 +80,7 @@ for (let i = 0; i < effort_inputs.length; i++) {
             input.value = parseFloat(input.placeholder);
         }
         input.value = parseFloat(input.value).toFixed(1);
-        formHasChanged = true; 
+        changes_to_commit = true; 
     };
     input.insertAdjacentElement('afterend', button);
 }
index ea1b324c3c76af56642842a5b3adaa6b819a3d2b..3ffbf79f70ee91a7f7eb94d547c3536b784db099 100644 (file)
 {% extends 'base.html' %}
+
 {% block css %}
-td.number { text-align: right; }
-table.alternating tr:nth-child(even) {
-    background-color: #cccccc;
-}
-table.alternating tr:nth-child(odd) {
-    background-color: #ffffff;
-}
-th { text-align: left; background-color: white; border: 1px solid black; }
-th.desc { background: linear-gradient(to bottom, white, grey); }
+#pick_upper, #pick_lower { margin-right: 1em; }
 {% endblock %}
+
 {% block content %}
-<form action="pick_tasks" method="POST">
+<h3>pick todos for day</h3>
+
+<form id="form_to_watch" action="pick_tasks" method="POST">
 {% include 'tagfilters.html' %}
 <br />
 <input name="hide_chosen_tasks" type="checkbox" {% if hide_chosen_tasks %}checked{% endif %} /> hide chosen tasks<br />
 search: <input name="search" value="{{search|e}}" />
 <input type="submit" name="filter" value="filter" />
-</form>
 
-<h3>pick todos for day</h3>
-<p><a href="pick_tasks?date={{prev_date}}">prev</a> | {{day.date}} | <a href="pick_tasks?date={{next_date}}">next</a> | {{day.comment}}</p>
-<form id="form_to_watch" action="{{action|e}}" method="POST">
+<p>
+<a href="pick_tasks?date={{prev_date}}">prev</a> | {{day.date}} | <a href="pick_tasks?date={{next_date}}">next</a> | {{day.comment}}
+</p>
+
 <input type="hidden" name="date" value="{{day.date}}" />
-<input id="pick_upper" type="submit" value="pick" />
+<input class="update" id="pick_upper" name="update" type="submit" value="pick" />
+<input type="hidden" name="search" value="{{search|e}}" />
 <table class="alternating">
 <tr>
 <th>do</th>
-<th {% if sort=='effort' %}class="desc"{% endif %}><a href="?sort=effort">effort</a></th>
-<th {% if sort=='title' %}class="desc"{% endif %}><a href="?sort=title">what</a></th>
+<th {% if sort=='effort' %}class="desc"{% endif %}>
+<a href="?sort=effort">effort</a>
+</th>
+<th {% if sort=='title' %}class="desc"{% endif %}>
+<a href="?sort=title">what</a>
+</th>
 <th>comment</th>
 </tr>
+
 {% for todo in chosen_todos %}
 <tr>
 <td class="checkbox">
 <input name="chosen_todo" {% if todo.done or todo.day_effort %}class="protected"{% endif %} type="checkbox" value="{{todo.id_}}" checked>
 </td>
 <td class="number">
-{% if todo.day_effort %}{{todo.day_effort}}&nbsp;{% else %}({{todo.default_effort}}){% endif %}{% if todo.done and not "cancelled" in todo.contemporary_tags%}✓{% else %}&nbsp;{% endif %}</td>
-<td><a href="todo?id={{todo.id_}}">{% if "cancelled" in todo.contemporary_tags %}<s>{% endif %}{% if "deadline" in todo.contemporary_tags %}DEADLINE: {% endif %}<a href="todo?id={{todo.id_}}&return_to=pick_tasks" />{{todo.path|e}}{{todo.title|e}}</a>{%if "cancelled" in todo.contemporary_tags%}</s>{% endif %}</a></td>
-<td>{{todo.comment|e}}</td>
+{% if todo.day_effort %}{{todo.day_effort}}&nbsp;{% else %}({{todo.default_effort}}){% endif %}{% if todo.done and not "cancelled" in todo.contemporary_tags%}✓{% else %}&nbsp;{% endif %}
+</td>
+<td>
+<a href="todo?id={{todo.id_}}&return_to=pick_tasks">
+{% if "cancelled" in todo.tags.now %}<s>{% endif %}
+{{todo.path|e}}{{todo.title|e}}
+{%if "cancelled" in todo.tags.now %}</s>{% endif %}
+</a>
+</td>
+<td>
+{{todo.comment|e}}
+</td>
 </tr>
 {% endfor %}
+
 <tr>
 <th colspan=4>earlier todos to continue</th>
 </tr>
+
 {% for todo in relevant_todos %}
 <tr>
 <td class="checkbox">
 <input name="choose_todo" type="checkbox" value="{{todo.id_}}">
 </td>
-<td class="number">{{todo.all_days_effort}}/{{todo.default_effort}}</td>
-<td><a href="todo?id={{todo.id_}}">{{todo.day.date}} {{todo.task.title.then|e}}</a></td>
-<td>{{todo.comment|e}}</td>
+<td class="number">
+{{todo.all_days_effort}}/{{todo.default_effort}}
+</td>
+<td>
+<a href="todo?id={{todo.id_}}">{{todo.day.date}} {{todo.task.title.then|e}}</a>
+</td>
+<td>
+{{todo.comment|e}}
+</td>
 </tr>
 {% endfor %}
+
+<tr>
 <th colspan=4>tasks</th>
+</tr>
+
 {% for task in tasks %}
 <tr>
 <td class="checkbox">
 <input name="choose_task" type="checkbox" value="{{task.id_}}">
 </td>
-<td class="number">({{task.default_effort.then}})&nbsp;</td>
-<td><a href="task?id={{ task.id_ }}&return_to=pick_tasks" />{{ task.title.then|e }}</a></td>
-<td>{{task.comment|e}}</td>
+<td class="number">
+({{task.default_effort.then}})&nbsp;
+</td>
+<td>
+<a href="task?id={{ task.id_ }}&return_to=pick_tasks" />{{ task.title.then|e }}</a>
+</td>
+<td>
+{{task.comment|e}}
+</td>
 </tr>
 {% endfor %}
+
 </table>
-<input type="hidden" name="search" value="{{search|e}}" />
-<input id="pick_lower" type="submit" value="pick" />
+<input class="update" id="pick_lower" name="update" type="submit" value="pick" />
 </form>
+
 {% include 'watch_form.html' %}
 <script>
 function make_selectables_toggler(neighbor_id, input_name) {
@@ -84,7 +114,7 @@ function make_selectables_toggler(neighbor_id, input_name) {
                 continue;      
        }
             checkboxes[i].click();
-            formHasChanged = true;
+            changes_to_comit = true;
         }
     }
     neighbor.insertAdjacentElement('afterend', button);
@@ -93,4 +123,3 @@ make_selectables_toggler('pick_upper', 'chosen_todo');
 make_selectables_toggler('pick_lower', 'choose_task');
 </script>
 {% endblock %}
-
index 869cf54a8715fbef9a057182523e688d72cf6c8f..21333f6d6b98940994ef77876209cf0fbc74ce95 100644 (file)
@@ -1,4 +1,4 @@
-mandatory tags:
+need:
 {% for and_filter in filter_and %}
 <select name="t_and">
 <option></option>
@@ -14,7 +14,7 @@ mandatory tags:
 {% endfor %}
 </select>
 <br />
-forbidden tags:
+hide:
 {% for not_filter in filter_not %}
 <select name="t_not">
 <option></option>
index 11f45377caab0d42ebe1bac09ff7cb7e7f3defb4..7a8f981fef608cbad413a66b866ad452cbbfdc88 100644 (file)
 {% extends 'base.html' %}
+
 {% block css %}
-th, td { vertical-align: top; text-align: left}
-td.input { width: 100%; }
-td.checkbox { width: 0.1em; height: 0.1em; padding: 0em; text-align: center; }
-input[type="number"] { text-align: right; }
-input[type="text"] { width: 100% }
-textarea { width: 100% };
+th { padding-right: 1em; }
 {% endblock %}
+
 {% block content %}
-<form id="form_to_watch" action="task" method="POST">
 <h3>edit task</h3>
-<input type="hidden" name="id" value="{{ task.id_ }}" />
+
+<form id="form_to_watch" action="task" method="POST">
+<input type="hidden" name="task_id" value="{{ task.id_ }}" />
 <input type="hidden" name="return_to" value="{{ return_to }}" />
 <table>
-<tr><th>title</th><td class="input"><input name="title" type="text" value="{{ task.title.now|e }}" /><details><summary>history</summary><ul>{% for k,v in task.title.history.items() | sort(attribute='0', reverse=True) %}<li>{{ k }}: {{ v|e }}{% endfor %}</ul></details></td></tr>
-<tr><th></th><td><input type="checkbox" name="as_todo" {% if selected %}checked{% endif%}> selected for {{db.selected_date}}</td></tr>
-<tr><th>comment</th><td class="input"><textarea name="comment">{{task.comment|e}}</textarea></td></tr>
+
+<tr>
+<th>title</th>
+<td class="input">
+<input name="title" type="text" value="{{ task.title.now|e }}" size=100 />
+<details>
+<summary>history</summary>
+<ul>
+{% for k,v in task.title.history.items() | sort(attribute='0', reverse=True) %}
+<li>{{ k }}: {{ v|e }}
+{% endfor %}
+</ul>
+</details>
+</td>
+</tr>
+
+<tr>
+<th>comment</th>
+<td class="input">
+<textarea name="comment" cols=100>{{task.comment|e}}</textarea>
+</td>
+</tr>
+
 <tr>
 <th>default effort</th>
 <td class="input">
 {% if task.subtasks %}
 {{ task.default_effort.now }}
 {% else %}
-<input type="number" name="default_effort" value="{{ task.default_effort.now }}" step=0.1 size=8 required /><details><summary>history</summary><ul>{% for k,v in task.default_effort.history.items() | sort(attribute='0', reverse=True) %}<li>{{ k }}: {{ v|e }}{% endfor %}</ul></details>
+<input type="number" name="default_effort" value="{{ task.default_effort.now }}" step=0.1 size=8 required />
+<details>
+<summary>history</summary>
+<ul>
+{% for k,v in task.default_effort.history.items() | sort(attribute='0', reverse=True) %}
+<li>{{ k }}: {{ v|e }}
+{% endfor %}
+</ul>
+</details>
 {% endif %}
 </td>
 </tr>
-<tr><th>tags</th>
+
+<tr>
+<th>tags</th>
 <td>
-{% for tag in db.t_tags | sort %}
-<input type="checkbox" name="tag_{{tag|e}}"{% if tag in task.tags.now %} checked{% endif %}/> {{ tag }}<br />
+{% for tag in tags | sort %}
+<input type="checkbox" name="tag_{{tag|e}}"{% if tag in task.tags.now %} checked{% endif %}/> {{ tag }}
+<br />
 {% endfor %}
-add: <input name="joined_tags" type="text" value="" ><br />
-<details><summary>history</summary><ul>{% for k,v in task.tags.history.items() | sort(attribute='0', reverse=True) %}<li>{{ k }}: {{ v|e }}{% endfor %}</ul></details>
-</td></tr>
-<tr><th>children</th>
+add: <input name="joined_tags" type="text" value="" size=100>
+<br />
+<details>
+<summary>history</summary>
+<ul>
+{% for k,v in task.tags.history.items() | sort(attribute='0', reverse=True) %}
+<li>{{ k }}: {{ v|e }}
+{% endfor %}
+</ul>
+</details>
+</td>
+</tr>
+
+<tr>
+<th>children</th>
 <td>
 <table>
+
 {% for subtask in task.subtasks %}
 <tr>
-<td><input name="subtask" type="checkbox" value="{{subtask.id_}}" checked/></td>
-<td><a href="task?id={{subtask.id_}}">{{subtask.title.now}}</a></td>
+<td>
+<input name="subtask" type="checkbox" value="{{subtask.id_}}" checked/>
+</td>
+<td>
+<a href="task?id={{subtask.id_}}">{{subtask.title.now}}</a>
+</td>
 </tr>
 {% endfor %}
+
 <tr>
 <th colspan=2>---</th>
 </tr>
+
 {% for subtask in filtered_tasks %}
 <tr>
-<td><input name="subtask" type="checkbox" value="{{subtask.id_}}"/></td>
-<td><a href="task?id={{subtask.id_}}">{{subtask.title.now}}</a></td>
+<td>
+<input name="subtask" type="checkbox" value="{{subtask.id_}}"/>
+</td>
+<td>
+<a href="task?id={{subtask.id_}}">{{subtask.title.now}}</a>
+</td>
 </tr>
 {% endfor %}
+
 </table>
 </td>
 </tr>
+
 </table>
-<input type="submit" value="update" />
-</form>
-<form action="task" method="POST">
-<input type="hidden" name="id" value="{{task.id_}}" />
+<input class="update" type="submit" name="update" value="update" />
+<hr />
 {% include 'tagfilters.html' %}
 <br />
 search: <input name="search" value="{{search|e}}" />
 <input type="submit" name="filter" value="filter" />
 </form>
+
 {% include 'watch_form.html' %}
+<script>
+mere_filter_inputs = mere_filter_inputs.concat(['search']);
+</script> 
 {% endblock %}
index beccb75e2d051d5446b9adce9018ef7b3d5f3dce..404ac1c496e32e3fdff533ccb634b2973029a1f6 100644 (file)
 {% extends 'base.html' %}
+
 {% block css %}
-th, td { vertical-align: top; text-align: left}
-td.checkbox { width: 0.1em; height: 0.1em; padding: 0em; text-align: center; }
-input[type="number"] { text-align: right; }
+th.toplevel { padding-right: 1em; }
+input[type="submit"].delete { background-color: #ff7777; }
+div.delete { float: right; }
+td.center { text-align: center; }
 {% endblock %}
+
 {% block content %}
-<form action="todo" method="POST">
 <h3>edit todo</h3>
+
+<form id="form_to_watch" action="todo" method="POST">
 <input type="hidden" name="todo_id" value="{{todo.id_}}" />
 <input type="hidden" name="return_to" value="{{return_to}}" />
 <table>
-<tr><th>task</th><td><a href="{{db.prefix}}/task?id={{ todo.task.id_ }}">{{ todo.task.title.then|e }}</a></td></tr>
-<tr><th>default effort</th><td>{{ todo.default_effort }}</td></tr>
+
 <tr>
-<th>efforts</th>
+<th class="toplevel">task</th>
+<td><a href="task?id={{ todo.task.id_ }}">{{ todo.task.title.then|e }}</a></td>
+</tr>
+
+<tr>
+<th class="toplevel">default effort</th>
+<td>{{ todo.default_effort }}</td>
+</tr>
+
+<tr>
+<th class="toplevel">efforts</th>
 <td>
 <table>
-<tr><th>date</th><th>effort</th><th>delete</th>
+<tr><th>date</th><th>effort</th><th>delete</th></tr>
 {% for date, effort in todo.efforts.items() %}
 <tr>
-<td><input name="effort_date" size=10 value="{{date}}" {% if todo.children and effort %}disabled{% endif %}></td>
-<td><input type="number" name="effort" step=0.1 size=8 value="{{effort}}" placeholder="{{todo.default_effort}}" {% if todo.children and effort %}disabled{% endif %} /></td>
-<td>{% if not (todo.children and effort) %}<input type="checkbox" name="delete_effort" value="{{date}}" />{% endif %}</td>
+<td>
+<input name="effort_date" size=10 value="{{date}}" {% if todo.children and effort %}disabled{% endif %}>
+</td>
+<td>
+<input type="number" name="effort" step=0.1 size=8 value="{{effort}}" placeholder="{{todo.default_effort}}" {% if todo.children and effort %}disabled{% endif %} />
+</td>
+<td>
+{% if not (todo.children and effort) %}<input type="checkbox" name="delete_effort" value="{{date}}" />{% endif %}
+</td>
 </tr>
 {% endfor %}
 <tr>
-<td><input name="effort_date" size=10 value=""></td>
-<td><input type="number" name="effort" step=0.1 size=8 value="" {% if todo.children %} disabled {% else %} placeholder="{{todo.default_effort}}" {% endif %} /></td>
+<td>
+<input name="effort_date" size=10 value="">
+</td>
+<td>
+<input type="number" name="effort" step=0.1 size=8 value="" {% if todo.children %} disabled {% else %} placeholder="{{todo.default_effort}}" {% endif %} />
+</td>
 </tr>
 </table>
 </td>
 </tr>
+
 <tr>
-<th>total effort</th><td>{{todo.all_days_effort}}</td>
+<th class="toplevel">total effort</th>
+<td>{{todo.all_days_effort}}</td>
 </tr>
-<tr><th>importance</th><td class="input"><input type="number" name="importance" step=0.1 size=8 value="{{ todo.importance }}" /></td></tr>
-<tr><th>comment</th><td class="input"><textarea name="comment" rows=3 cols=100>{{todo.comment|e}}</textarea></td></tr>
+
+<tr>
+<th class="toplevel">importance</th>
+<td class="input">
+<input type="number" name="importance" step=0.1 size=8 value="{{ todo.importance }}" />
+</td>
+</tr>
+
+<tr>
+<th class="toplevel">comment</th>
+<td class="input">
+<textarea name="comment" rows=3 cols=100>{{todo.comment|e}}</textarea>
+</td>
+</tr>
+
 <tr>
 <th>done</th>
 <td class="input">
 {% if todo.children %}✓{% else %}<input type="checkbox" name="done" {% if todo.done %}checked{% endif %}/>{% endif %}
 </td>
 </tr>
-<tr><th>day tags</th>
+
+<tr>
+<th class="toplevel">day tags</th>
 <td>
-{% for tag in db.t_tags | sort %}
-{% if tag in todo.task.tags.now %}&nbsp;✓{% else %}<input type="checkbox" name="day_tag_{{tag|e}}"{% if tag in todo.day_tags %} checked{% endif %}/>{% endif %} {{ tag }}<br />
+{% for tag in tags | sort %}
+{% if tag in todo.task.tags.now %}
+&nbsp;✓
+{% else %}
+<input type="checkbox" name="day_tag_{{tag|e}}"{% if tag in todo.day_tags %} checked{% endif %}/>
+{% endif %} {{ tag }}
+<br />
 {% endfor %}
 add: <input name="joined_day_tags" value="" size=100 >
 </td>
 </tr>
-<tr><th>parent</th><td>{% if todo.parent %}<a href="todo?id={{todo.parent.id_}}">{{todo.parent.title}}</a>{% else %}–{% endif %}</td></tr>
-<tr><th>children</th>
+
+<tr>
+<th class="toplevel">parents</th>
 <td>
-<table>
+<ul>
+{% for parent in todo.parents %}
+<li><a href="todo?id={{parent.id_}}">{{parent.title}}</a>
+{% endfor %}
+</ul>
+</td>
+</tr>
+
+<tr>
+<th class="toplevel">children</th>
+<td>
+<table class="alternating">
+<tr>
+<th>adopt</th><th>effort</th><th>title</th><th>comments</th>
+</tr>
 {% for todo in child_todos %}
 <tr>
-       <!-- <td><input name="link_child" type="checkbox" value="{{todo.id_}}" checked disabled/></td> -->
-       <td>{% if todo.done %}✓{% endif %}</td><td>{{todo.all_days_effort}}</td>
-<td><a href="todo?id={{todo.id_}}">{{todo.title}}</a></td>
+<td class="center"><input name="adopt_child" type="checkbox" value="{{todo.id_}}" checked/></td>
+<td class="number">{{ '{:2.1f}'.format(todo.all_days_effort) }} {% if todo.done %}✓{% else %}&nbsp;{% endif %}</td>
+<td><a href="todo?id={{todo.id_}}">{{todo.day.date}} {{todo.title}}</a></td>
 </tr>
 {% endfor %}
-<!--
 <tr>
-<th colspan=2>---</th>
+<th colspan=4>--------</th>
 </tr>
 {% for todo in filtered_todos %}
 <tr>
-<td><input name="link_todo" type="checkbox" value="{{todo.id_}}" disabled/></td>
-<td><a href="todo?id={{todo.id_}}">{{todo.title}}</a></td>
+<td class="center"><input name="adopt_child" type="checkbox" value="{{todo.id_}}" /></td>
+<td class="number">{{ '{:2.1f}'.format(todo.all_days_effort) }} {% if todo.done %}✓{% else %}&nbsp;{% endif %}</td>
+<td><a href="todo?id={{todo.id_}}">{{todo.day.date}} {{todo.title}}</a></td>
 </tr>
 {% endfor %}
--->
 </table>
 </td>
+</tr>
+
 </table>
-<input type="submit" value="update" />
-<div style="text-align: right">
-<input type="submit" name="delete" value="delete" />
+<input class="update" name="update" type="submit" value="update" />
+<div class="delete">
+<input class="delete" type="submit" name="delete" value="delete" />
 </div>
+
+<hr />
+{% include 'tagfilters.html' %}
+<br />
+from: <input name="start" {% if start_date %}value="{{ start_date }}"{% endif %} placeholder="yesterday" />
+to: <input name="end" {% if end_date %}value="{{ end_date }}"{% endif %} placeholder="2030-12-31" />
+search: <input name="search" value="{{search|e}}" />
+<input type="submit" name="filter" value="filter" />
+
 </form>
+{% include 'watch_form.html' %}
+<script>
+mere_filter_inputs = mere_filter_inputs.concat(['search', 'start', 'end']);
+</script> 
 {% endblock %}
index 979c1da38417fa68c899788aedca2ef6d320dd43..62fee481a6300995cae94527b70262bb096cc927 100644 (file)
@@ -1,19 +1,29 @@
 <script>
-    var formHasChanged = false;
-    var submitted = false;
-    var form_to_watch = document.getElementById('form_to_watch');
-    form_to_watch.addEventListener('input', function() {
-        formHasChanged = true;
-    });
-    form_to_watch.addEventListener('submit', function() {
-        submitted = true;
-    });
-    window.addEventListener('beforeunload', function(event) {
-        if (formHasChanged && !submitted) {
-            var confirmationMessage = 'You have unsaved changes. Are you sure you want to leave?';
-            event.returnValue = confirmationMessage;
-            return confirmationMessage;
-        }
-    });
+var mere_filter_inputs = ['t_and', 't_not', 'filter'];
+var sending_commits = false;
+var changes_to_commit = false;
+var form_to_watch = document.getElementById('form_to_watch');
+for (let i = 0; i < form_to_watch.elements.length; i++) {
+    let el = form_to_watch.elements[i];
+    if (['INPUT', 'TEXTAREA', 'SELECT'].includes(el.tagName)) {
+        el.addEventListener('change', function(event) {
+            if (!mere_filter_inputs.includes(event.target.name)) { 
+              changes_to_commit = true; 
+           };
+       });
+    };
+};
+form_to_watch.addEventListener('submit', function(event) {
+    if ('update' == event.submitter.name) {
+       sending_commits = true; 
+    };
+});
+window.addEventListener('beforeunload', function(event) {
+    if (changes_to_commit && !sending_commits) {
+        var warning = 'about to lose unsaved changes, continue?';
+        event.returnValue = warning;
+        return warning;
+    }
+});
 </script>