move columns to global level

This commit is contained in:
jpt 2025-05-03 17:43:19 -05:00
parent ddf4662d78
commit 2bf3d126e9
4 changed files with 19 additions and 5 deletions

View File

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

View File

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

View File

@ -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"]

View File

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