deletion
This commit is contained in:
parent
d4cba93834
commit
89a8afbd6a
@ -44,7 +44,7 @@ def get_tasks(
|
|||||||
status: str | None = None,
|
status: str | None = None,
|
||||||
include_done: bool = False,
|
include_done: bool = False,
|
||||||
) -> list[Task]:
|
) -> list[Task]:
|
||||||
query = Task.select()
|
query = Task.select().where(~Task.deleted)
|
||||||
|
|
||||||
if search_text:
|
if search_text:
|
||||||
query = query.where(fn.Lower(Task.text).contains(search_text.lower()))
|
query = query.where(fn.Lower(Task.text).contains(search_text.lower()))
|
||||||
|
10
src/tt/db.py
10
src/tt/db.py
@ -1,12 +1,13 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from peewee import (
|
from peewee import (
|
||||||
Model,
|
BooleanField,
|
||||||
SqliteDatabase,
|
|
||||||
CharField,
|
CharField,
|
||||||
TextField,
|
|
||||||
DateTimeField,
|
DateTimeField,
|
||||||
ForeignKeyField,
|
ForeignKeyField,
|
||||||
|
Model,
|
||||||
|
SqliteDatabase,
|
||||||
|
TextField,
|
||||||
)
|
)
|
||||||
|
|
||||||
db = SqliteDatabase("tasks.db")
|
db = SqliteDatabase("tasks.db")
|
||||||
@ -42,6 +43,7 @@ class Task(BaseModel):
|
|||||||
type = CharField()
|
type = CharField()
|
||||||
created_at = DateTimeField(default=datetime.now)
|
created_at = DateTimeField(default=datetime.now)
|
||||||
updated_at = DateTimeField(default=datetime.now)
|
updated_at = DateTimeField(default=datetime.now)
|
||||||
|
deleted = BooleanField(default=False)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
self.updated_at = datetime.now()
|
self.updated_at = datetime.now()
|
||||||
@ -52,7 +54,7 @@ def initialize_db():
|
|||||||
db.connect()
|
db.connect()
|
||||||
db.create_tables([Category, Task])
|
db.create_tables([Category, Task])
|
||||||
if not Category.select().exists():
|
if not Category.select().exists():
|
||||||
Category.create(name="main")
|
Category.create(name="default")
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,12 +1,18 @@
|
|||||||
import re
|
import re
|
||||||
from textual.app import App
|
from textual.app import App
|
||||||
from textual.widgets import DataTable, Header, Input, Static
|
from textual.widgets import DataTable, Header, Input, Static
|
||||||
from textual.containers import Container, Horizontal
|
from textual.containers import Container
|
||||||
from datetime import datetime
|
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: add way to filter on other columns
|
||||||
|
# TODO: nicer editor for some fields
|
||||||
|
# TODO: auto edit on add
|
||||||
|
|
||||||
column_to_field = {
|
column_to_field = {
|
||||||
1: "text",
|
1: "text",
|
||||||
2: "status",
|
2: "status",
|
||||||
@ -38,14 +44,16 @@ def get_colored_category(category: str) -> str:
|
|||||||
return f"[{color}]{category}[/]"
|
return f"[{color}]{category}[/]"
|
||||||
|
|
||||||
|
|
||||||
class TaskManagerApp(App):
|
class TT(App):
|
||||||
CSS = """
|
CSS = """
|
||||||
#input_bar {
|
#input_bar {
|
||||||
dock: bottom;
|
dock: bottom;
|
||||||
height: 1;
|
height: 2;
|
||||||
|
border-top: solid green;
|
||||||
layout: grid;
|
layout: grid;
|
||||||
grid-size: 2;
|
grid-size: 2;
|
||||||
grid-columns: 10 1fr;
|
grid-columns: 10 1fr;
|
||||||
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
#prompt_label {
|
#prompt_label {
|
||||||
@ -73,7 +81,8 @@ class TaskManagerApp(App):
|
|||||||
("c", "start_edit", "Edit Cell"),
|
("c", "start_edit", "Edit Cell"),
|
||||||
("escape", "cancel_edit", "Cancel Edit"),
|
("escape", "cancel_edit", "Cancel Edit"),
|
||||||
# other
|
# other
|
||||||
("a", "add_task", "Add Task"),
|
("a", "add_task", "Add"),
|
||||||
|
("d", "delete_task", "Delete"),
|
||||||
("q", "quit", "Quit"),
|
("q", "quit", "Quit"),
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -101,9 +110,13 @@ class TaskManagerApp(App):
|
|||||||
|
|
||||||
def action_cursor_left(self):
|
def action_cursor_left(self):
|
||||||
self.table.move_cursor(column=self.table.cursor_column - 1)
|
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):
|
def action_cursor_right(self):
|
||||||
self.table.move_cursor(column=self.table.cursor_column + 1)
|
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):
|
def action_cursor_up(self):
|
||||||
self.table.move_cursor(row=self.table.cursor_row - 1)
|
self.table.move_cursor(row=self.table.cursor_row - 1)
|
||||||
@ -138,6 +151,12 @@ class TaskManagerApp(App):
|
|||||||
key=str(task.id),
|
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):
|
def action_add_task(self):
|
||||||
"""Add a new task with default values."""
|
"""Add a new task with default values."""
|
||||||
add_task(
|
add_task(
|
||||||
@ -221,7 +240,7 @@ class TaskManagerApp(App):
|
|||||||
|
|
||||||
def run():
|
def run():
|
||||||
initialize_db()
|
initialize_db()
|
||||||
app = TaskManagerApp()
|
app = TT()
|
||||||
app.run()
|
app.run()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user