From 89a8afbd6a070e2d3ff074a2f4a6bcededd14dc1 Mon Sep 17 00:00:00 2001 From: James Turk Date: Fri, 3 Jan 2025 22:16:41 -0600 Subject: [PATCH] deletion --- src/tt/controller.py | 2 +- src/tt/db.py | 10 ++++++---- src/tt/tui.py | 29 ++++++++++++++++++++++++----- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/tt/controller.py b/src/tt/controller.py index 67da4c0..a1eca29 100644 --- a/src/tt/controller.py +++ b/src/tt/controller.py @@ -44,7 +44,7 @@ def get_tasks( status: str | None = None, include_done: bool = False, ) -> list[Task]: - query = Task.select() + query = Task.select().where(~Task.deleted) if search_text: query = query.where(fn.Lower(Task.text).contains(search_text.lower())) diff --git a/src/tt/db.py b/src/tt/db.py index 9cb2131..50a7d7e 100644 --- a/src/tt/db.py +++ b/src/tt/db.py @@ -1,12 +1,13 @@ from datetime import datetime from enum import Enum from peewee import ( - Model, - SqliteDatabase, + BooleanField, CharField, - TextField, DateTimeField, ForeignKeyField, + Model, + SqliteDatabase, + TextField, ) db = SqliteDatabase("tasks.db") @@ -42,6 +43,7 @@ class Task(BaseModel): type = CharField() created_at = DateTimeField(default=datetime.now) updated_at = DateTimeField(default=datetime.now) + deleted = BooleanField(default=False) def save(self, *args, **kwargs): self.updated_at = datetime.now() @@ -52,7 +54,7 @@ def initialize_db(): db.connect() db.create_tables([Category, Task]) if not Category.select().exists(): - Category.create(name="main") + Category.create(name="default") db.close() diff --git a/src/tt/tui.py b/src/tt/tui.py index 6a2f122..cf8f381 100644 --- a/src/tt/tui.py +++ b/src/tt/tui.py @@ -1,12 +1,18 @@ import re from textual.app import App from textual.widgets import DataTable, Header, Input, Static -from textual.containers import Container, Horizontal +from textual.containers import Container from datetime import datetime from .controller import get_tasks, add_task, update_task, TaskStatus from .db import initialize_db +# TODO: add footer w/ filter status +# TODO: toggle status with 't' +# TODO: add way to filter on other columns +# TODO: nicer editor for some fields +# TODO: auto edit on add + column_to_field = { 1: "text", 2: "status", @@ -38,14 +44,16 @@ def get_colored_category(category: str) -> str: return f"[{color}]{category}[/]" -class TaskManagerApp(App): +class TT(App): CSS = """ #input_bar { dock: bottom; - height: 1; + height: 2; + border-top: solid green; layout: grid; grid-size: 2; grid-columns: 10 1fr; + display: none; } #prompt_label { @@ -73,7 +81,8 @@ class TaskManagerApp(App): ("c", "start_edit", "Edit Cell"), ("escape", "cancel_edit", "Cancel Edit"), # other - ("a", "add_task", "Add Task"), + ("a", "add_task", "Add"), + ("d", "delete_task", "Delete"), ("q", "quit", "Quit"), ] @@ -101,9 +110,13 @@ class TaskManagerApp(App): def action_cursor_left(self): self.table.move_cursor(column=self.table.cursor_column - 1) + if self.table.cursor_column == 0: + self.table.cursor_type = "row" def action_cursor_right(self): self.table.move_cursor(column=self.table.cursor_column + 1) + if self.table.cursor_column != 0: + self.table.cursor_type = "cell" def action_cursor_up(self): self.table.move_cursor(row=self.table.cursor_row - 1) @@ -138,6 +151,12 @@ class TaskManagerApp(App): key=str(task.id), ) + def action_delete_task(self): + if self.table.cursor_column == 0: + task_id = int(self.table.get_cell_at((self.table.cursor_row, 0))) + update_task(task_id, deleted=True) + self.refresh_tasks() + def action_add_task(self): """Add a new task with default values.""" add_task( @@ -221,7 +240,7 @@ class TaskManagerApp(App): def run(): initialize_db() - app = TaskManagerApp() + app = TT() app.run()