This commit is contained in:
James Turk 2025-01-03 22:16:41 -06:00
parent d4cba93834
commit 89a8afbd6a
3 changed files with 31 additions and 10 deletions

View File

@ -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()))

View File

@ -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()

View File

@ -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()