Compare commits

..

No commits in common. "34220a5ea653d56c8c3d12888afe381501c8f965" and "bff65bfff0b261d7591fd2d932062f0b462c5640" have entirely different histories.

3 changed files with 15 additions and 42 deletions

View File

@ -31,6 +31,7 @@ def update_task(
) -> Task:
with db.atomic():
task = Task.get_by_id(task_id)
query = Task.update(kwargs).where(Task.id == task_id)
query.execute()
task = Task.get_by_id(task_id)

View File

@ -14,7 +14,6 @@ from .controller import get_tasks, add_task, update_task, TaskStatus
from .db import initialize_db
from .utils import (
remove_rich_tag,
filter_to_string,
advance_enum_val,
get_colored_category,
get_colored_status,
@ -22,6 +21,7 @@ from .utils import (
)
# Parity
# TODO: add filtering on status
# TODO: saved searches
# Nice to Have
# TODO: CLI
@ -32,12 +32,11 @@ from .utils import (
COLUMNS = ("ID", "Task", "Status", "Type", "Due", "Category")
column_to_field = {
0: "ID",
1: "text",
2: "status",
3: "type",
4: "due",
5: "category",
5: "category_name",
}
@ -114,7 +113,7 @@ class TT(App):
def __init__(self):
super().__init__()
self.search_query = ""
self.filters = {}
self.search_category = ""
self.sort_string = "due,status"
self.saved_cursor_pos = (0, 0)
self.save_on_move = None
@ -175,12 +174,7 @@ class TT(App):
self.table.clear()
tasks = get_tasks(
self.search_query,
category=self.filters.get("category"),
statuses=self.filters.get("status", "").split(",")
if "status" in self.filters
else None,
sort=self.sort_string,
self.search_query, category=self.search_category, sort=self.sort_string
)
for task in tasks:
category = get_colored_category(
@ -200,8 +194,12 @@ class TT(App):
)
# update footer
filter_display = filter_to_string(self.filters, self.search_query)
self.left_status.update(f"{len(tasks)} |{filter_display}")
if self.search_query:
self.left_status.update(
f"{len(tasks)} |{' ' if self.search_category else ''}{self.search_category} matching '{self.search_query}'"
)
else:
self.left_status.update(f"{len(tasks)} | {self.search_category}")
# restore cursor
if restore_cursor:
@ -290,21 +288,12 @@ class TT(App):
def action_cancel_edit(self):
self._hide_input()
self.table.cursor_type = "cell"
def action_start_search(self):
self._show_input("search", "")
def action_start_filter(self):
# filter the currently selected column
cur_col = self.table.cursor_column
active_col_name = column_to_field[cur_col]
# # only allow filtering these columns
if active_col_name not in ("status", "type", "due", "category"):
return
cur_filter_val = self.filters.get(active_col_name) or ""
self._show_input("filter", cur_filter_val)
self.table.cursor_type = "column"
self._show_input("filter", self.search_category)
def action_start_sort(self):
self._show_input("sort", self.sort_string)
@ -328,11 +317,8 @@ class TT(App):
self.search_query = event.value
self.refresh_tasks(restore_cursor=False)
elif self.mode == "filter":
cur_col = self.table.cursor_column
active_col_name = column_to_field[cur_col]
self.filters[active_col_name] = event.value
self.search_category = event.value
self.refresh_tasks(restore_cursor=False)
self.table.cursor_type = "cel"
elif self.mode == "sort":
self.sort_string = event.value
self.refresh_tasks(restore_cursor=False)
@ -370,7 +356,6 @@ class TT(App):
except Exception as e:
self.notify(f"Error updating task: {str(e)}")
finally:
# no longer in edit mode
self.action_cancel_edit()
def action_show_keys(self):

View File

@ -2,19 +2,6 @@ import re
import datetime
def filter_to_string(filters, search_query):
pieces = []
category = filters.get("category")
status = filters.get("status")
if category:
pieces += [f" category:{category}"]
if status:
pieces += [f" status:{status}"]
if search_query:
pieces += [f" search:'{search_query}"]
return "".join(pieces)
def remove_rich_tag(text):
"""remove rich styling from a string"""
pattern = r"\[[^\]]*\](.*?)\[/\]"
@ -52,14 +39,14 @@ def get_colored_date(date: datetime.date) -> str:
as_str = date.strftime("%Y-%m-%d")
today = datetime.date.today()
if date.date() < today:
return f"[#eeeeee on #dd1111]{as_str}[/]"
color = "#FF0000"
else:
# Calculate weeks into future
delta = date.date() - today
weeks = delta.days // 7
colors = [
# "#FF4000",
"#FF4000",
"#FF8000",
"#FFA533",
"#FFD24D",