From 2bf3d126e9af213db4cfc943591af4a23b3321a3 Mon Sep 17 00:00:00 2001 From: jpt Date: Sat, 3 May 2025 17:43:19 -0500 Subject: [PATCH] move columns to global level --- src/tt/cli.py | 4 ++-- src/tt/config.py | 10 ++++++++++ src/tt/tui/editor.py | 6 +++++- src/tt/tui/things.py | 4 ++-- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/tt/cli.py b/src/tt/cli.py index ede1237..a9aae2b 100644 --- a/src/tt/cli.py +++ b/src/tt/cli.py @@ -41,11 +41,11 @@ def new( typer.echo("Created new thing!") @app.command() -def things( +def table( view: Annotated[str, typer.Option("-v", "--view", help="saved view")] = "default", ): initialize_db() - things_tui(view) + things_tui("tasks") @app.command() diff --git a/src/tt/config.py b/src/tt/config.py index eed611a..96b5fb5 100644 --- a/src/tt/config.py +++ b/src/tt/config.py @@ -42,6 +42,16 @@ def get_view(name): raise ValueError(f"no such view! {name}") +def get_column(name): + if name == "id": + return {"field_name": "id", "display_name": "ID", "read_only": True} + + for col in _load_config().get("columns", []): + if col["field_name"] == name: + return col + + raise ValueError(f"no such column! {name}") + # Valid statuses & projects are read dynamically from the user's config. STATUSES = get_enum("status") PROJECTS = get_enum("projects") diff --git a/src/tt/tui/editor.py b/src/tt/tui/editor.py index 719b1e6..8b8544d 100644 --- a/src/tt/tui/editor.py +++ b/src/tt/tui/editor.py @@ -107,8 +107,12 @@ class TableEditor(App): self.table_config = [] view = config.get_view(name) + # FIXME: special case during things conversion + # if recurring, different column definition + # set up columns - for col in view["columns"]: + for col_name in view["columns"]: + col = config.get_column(col_name) field_type = col.get("field_type", "text") field_cls = get_col_cls(field_type) field_name = col["field_name"] diff --git a/src/tt/tui/things.py b/src/tt/tui/things.py index f26dee3..7137db6 100644 --- a/src/tt/tui/things.py +++ b/src/tt/tui/things.py @@ -15,8 +15,8 @@ class ThingTable(TableEditor): # ("ctrl+o", "load_view", "load saved view"), # ] - def __init__(self, default_view="default"): - super().__init__("things") + def __init__(self, view="default"): + super().__init__(view) self.update_item_callback = update_thing self.add_item_callback = add_thing self.get_item_callback = get_thing