Compare commits
No commits in common. "85fa719b963885b499a4d17d2084d70a623b95a5" and "555397452c493cb80362e4d94db6950ab9c59a3f" have entirely different histories.
85fa719b96
...
555397452c
@ -0,0 +1,2 @@
|
|||||||
|
def hello() -> None:
|
||||||
|
print("Hello from tt!")
|
@ -1,52 +0,0 @@
|
|||||||
import sys
|
|
||||||
import csv
|
|
||||||
from datetime import datetime
|
|
||||||
from tt.db import initialize_db, Task, Category, TaskStatus
|
|
||||||
|
|
||||||
|
|
||||||
def import_tasks_from_csv(filename: str):
|
|
||||||
initialize_db()
|
|
||||||
|
|
||||||
with open(filename, "r") as f:
|
|
||||||
reader = csv.DictReader(f)
|
|
||||||
|
|
||||||
for row in reader:
|
|
||||||
# Parse the due date if it exists and isn't empty
|
|
||||||
due_date = None
|
|
||||||
if row["due"] and row["due"].strip():
|
|
||||||
try:
|
|
||||||
due_date = datetime.strptime(row["due"].strip(), "%Y-%m-%d")
|
|
||||||
except ValueError:
|
|
||||||
print(
|
|
||||||
f"Warning: Couldn't parse date '{row['due']}', skipping due date"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Validate status
|
|
||||||
status = row["status"].lower() if row["status"] else "zero"
|
|
||||||
try:
|
|
||||||
TaskStatus(status)
|
|
||||||
except ValueError:
|
|
||||||
print(f"Warning: Invalid status '{status}', defaulting to 'zero'")
|
|
||||||
status = "zero"
|
|
||||||
|
|
||||||
category_id = None
|
|
||||||
if row["category"].strip():
|
|
||||||
category_name = row["category"].strip()
|
|
||||||
category, _ = Category.get_or_create(
|
|
||||||
name=category_name, defaults={"description": None}
|
|
||||||
)
|
|
||||||
category_id = category.id
|
|
||||||
|
|
||||||
Task.create(
|
|
||||||
text=row["task"],
|
|
||||||
type=row["type"],
|
|
||||||
status=status,
|
|
||||||
due=due_date,
|
|
||||||
category_id=category_id,
|
|
||||||
)
|
|
||||||
print(f"Imported task: {row['task']}")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
import_tasks_from_csv(sys.argv[1])
|
|
||||||
print("Import complete!")
|
|
@ -7,6 +7,7 @@ from datetime import datetime
|
|||||||
from .controller import get_tasks, add_task, update_task, TaskStatus
|
from .controller import get_tasks, add_task, update_task, TaskStatus
|
||||||
from .db import initialize_db
|
from .db import initialize_db
|
||||||
|
|
||||||
|
# TODO: add footer w/ filter status
|
||||||
# TODO: toggle status with 't'
|
# TODO: toggle status with 't'
|
||||||
# TODO: add way to filter on other columns
|
# TODO: add way to filter on other columns
|
||||||
# TODO: safe DB mode
|
# TODO: safe DB mode
|
||||||
@ -48,11 +49,8 @@ def get_colored_category(category: str) -> str:
|
|||||||
|
|
||||||
class TT(App):
|
class TT(App):
|
||||||
CSS = """
|
CSS = """
|
||||||
#footer {
|
|
||||||
dock: bottom;
|
|
||||||
max-height: 2;
|
|
||||||
}
|
|
||||||
#input_bar {
|
#input_bar {
|
||||||
|
dock: bottom;
|
||||||
height: 2;
|
height: 2;
|
||||||
border-top: solid green;
|
border-top: solid green;
|
||||||
layout: grid;
|
layout: grid;
|
||||||
@ -60,7 +58,7 @@ class TT(App):
|
|||||||
grid-columns: 10 1fr;
|
grid-columns: 10 1fr;
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
#prompt_label {
|
#prompt_label {
|
||||||
width: 10;
|
width: 10;
|
||||||
content-align: left middle;
|
content-align: left middle;
|
||||||
@ -71,26 +69,6 @@ class TT(App):
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
border: none;
|
border: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
#status_bar {
|
|
||||||
border-top: solid white;
|
|
||||||
height: 2;
|
|
||||||
margin: 0;
|
|
||||||
layout: grid;
|
|
||||||
grid-size: 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
#left_status {
|
|
||||||
height: 1;
|
|
||||||
margin: 0;
|
|
||||||
padding-left: 1;
|
|
||||||
}
|
|
||||||
#right_status {
|
|
||||||
height: 1;
|
|
||||||
margin: 0;
|
|
||||||
padding-right: 1;
|
|
||||||
text-align: right;
|
|
||||||
}
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
BINDINGS = [
|
BINDINGS = [
|
||||||
@ -103,7 +81,6 @@ class TT(App):
|
|||||||
("G", "cursor_bottom", "Bottom"),
|
("G", "cursor_bottom", "Bottom"),
|
||||||
# filtering & editing
|
# filtering & editing
|
||||||
("/", "start_search", "Search"),
|
("/", "start_search", "Search"),
|
||||||
("f", "start_filter", "Filter"),
|
|
||||||
("c", "start_edit", "Edit Cell"),
|
("c", "start_edit", "Edit Cell"),
|
||||||
("escape", "cancel_edit", "Cancel Edit"),
|
("escape", "cancel_edit", "Cancel Edit"),
|
||||||
# other
|
# other
|
||||||
@ -115,7 +92,6 @@ class TT(App):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.search_query = ""
|
self.search_query = ""
|
||||||
self.search_category = ""
|
|
||||||
self.saved_cursor_pos = (0, 0)
|
self.saved_cursor_pos = (0, 0)
|
||||||
|
|
||||||
def compose(self):
|
def compose(self):
|
||||||
@ -124,18 +100,11 @@ class TT(App):
|
|||||||
self.input_widget = Input(id="input_widget")
|
self.input_widget = Input(id="input_widget")
|
||||||
self.input_label = Static("label", id="prompt_label")
|
self.input_label = Static("label", id="prompt_label")
|
||||||
self.input_bar = Container(id="input_bar")
|
self.input_bar = Container(id="input_bar")
|
||||||
self.status_bar = Container(id="status_bar")
|
|
||||||
self.left_status = Static("LEFT", id="left_status")
|
|
||||||
self.right_status = Static("RIGHT", id="right_status")
|
|
||||||
yield self.header
|
yield self.header
|
||||||
yield Container(self.table)
|
yield Container(self.table)
|
||||||
with Container(id="footer"):
|
with self.input_bar:
|
||||||
with self.input_bar:
|
yield self.input_label
|
||||||
yield self.input_label
|
yield self.input_widget
|
||||||
yield self.input_widget
|
|
||||||
with self.status_bar:
|
|
||||||
yield self.left_status
|
|
||||||
yield self.right_status
|
|
||||||
|
|
||||||
def on_mount(self):
|
def on_mount(self):
|
||||||
self.table.add_columns("ID", "Task", "Status", "Type", "Due", "Category")
|
self.table.add_columns("ID", "Task", "Status", "Type", "Due", "Category")
|
||||||
@ -164,10 +133,9 @@ class TT(App):
|
|||||||
self.table.move_cursor(row=self.table.row_count - 1)
|
self.table.move_cursor(row=self.table.row_count - 1)
|
||||||
|
|
||||||
def refresh_tasks(self, *, restore_cursor=True):
|
def refresh_tasks(self, *, restore_cursor=True):
|
||||||
# show table
|
|
||||||
self.table.clear()
|
self.table.clear()
|
||||||
|
|
||||||
tasks = get_tasks(self.search_query, category=self.search_category)
|
tasks = get_tasks(self.search_query)
|
||||||
for task in tasks:
|
for task in tasks:
|
||||||
due_str = task.due.strftime("%Y-%m-%d") if task.due else " - "
|
due_str = task.due.strftime("%Y-%m-%d") if task.due else " - "
|
||||||
category = get_colored_category(
|
category = get_colored_category(
|
||||||
@ -184,16 +152,6 @@ class TT(App):
|
|||||||
category,
|
category,
|
||||||
key=str(task.id),
|
key=str(task.id),
|
||||||
)
|
)
|
||||||
|
|
||||||
# update footer
|
|
||||||
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:
|
if restore_cursor:
|
||||||
self.table.move_cursor(
|
self.table.move_cursor(
|
||||||
row=self.saved_cursor_pos[0], column=self.saved_cursor_pos[1]
|
row=self.saved_cursor_pos[0], column=self.saved_cursor_pos[1]
|
||||||
@ -223,11 +181,13 @@ class TT(App):
|
|||||||
|
|
||||||
def move_cursor_to_task(self, task_id):
|
def move_cursor_to_task(self, task_id):
|
||||||
# ick, but only way to search table?
|
# ick, but only way to search table?
|
||||||
for row in range(self.table.row_count):
|
for row in range(len(self.table.rows)):
|
||||||
data = self.table.get_row_at(row)
|
data = self.table.get_row_at(row)
|
||||||
if data[0] == str(task_id):
|
if data[0] == str(task_id):
|
||||||
self.table.move_cursor(row=row, column=1)
|
self.table.move_cursor(row=row, column=1)
|
||||||
break
|
break
|
||||||
|
else:
|
||||||
|
raise Exception("nope")
|
||||||
|
|
||||||
# Control of edit bar ####################
|
# Control of edit bar ####################
|
||||||
|
|
||||||
@ -237,12 +197,8 @@ class TT(App):
|
|||||||
self.input_widget.value = start_value
|
self.input_widget.value = start_value
|
||||||
if mode == "search":
|
if mode == "search":
|
||||||
self.input_label.update("search: ")
|
self.input_label.update("search: ")
|
||||||
elif mode == "edit":
|
|
||||||
self.input_label.update("edit: ")
|
|
||||||
elif mode == "filter":
|
|
||||||
self.input_label.update("filter: ")
|
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"unknown mode: {mode}")
|
self.input_label.update("edit: ")
|
||||||
self.set_focus(self.input_widget)
|
self.set_focus(self.input_widget)
|
||||||
|
|
||||||
def _hide_input(self):
|
def _hide_input(self):
|
||||||
@ -255,9 +211,6 @@ class TT(App):
|
|||||||
def action_start_search(self):
|
def action_start_search(self):
|
||||||
self._show_input("search", "")
|
self._show_input("search", "")
|
||||||
|
|
||||||
def action_start_filter(self):
|
|
||||||
self._show_input("filter", self.search_category)
|
|
||||||
|
|
||||||
def _save_cursor(self):
|
def _save_cursor(self):
|
||||||
self.saved_cursor_pos = (self.table.cursor_row, self.table.cursor_column)
|
self.saved_cursor_pos = (self.table.cursor_row, self.table.cursor_column)
|
||||||
|
|
||||||
@ -276,13 +229,8 @@ class TT(App):
|
|||||||
if self.mode == "search":
|
if self.mode == "search":
|
||||||
self.search_query = event.value
|
self.search_query = event.value
|
||||||
self.refresh_tasks(restore_cursor=False)
|
self.refresh_tasks(restore_cursor=False)
|
||||||
elif self.mode == "filter":
|
|
||||||
self.search_category = event.value
|
|
||||||
self.refresh_tasks(restore_cursor=False)
|
|
||||||
elif self.mode == "edit":
|
elif self.mode == "edit":
|
||||||
self.apply_change(event.value)
|
self.apply_change(event.value)
|
||||||
else:
|
|
||||||
raise ValueError(f"unknown mode: {self.mode}")
|
|
||||||
self._hide_input()
|
self._hide_input()
|
||||||
|
|
||||||
def apply_change(self, new_value):
|
def apply_change(self, new_value):
|
||||||
|
Loading…
Reference in New Issue
Block a user