Making tables a little smarter.

This commit is contained in:
Yaro Kasear 2025-09-15 15:25:26 -05:00
parent cf795086f1
commit 3f677fceee
4 changed files with 157 additions and 14 deletions

View file

@ -19,6 +19,7 @@ def init_listing_routes(app):
spec = {}
columns = []
row_classes = []
if model.lower() == 'inventory':
spec = {"fields": [
"label",
@ -44,22 +45,49 @@ def init_listing_routes(app):
{"field": "owner.label", "label": "Contact", "link": {"endpoint": "user.get_item", "params": {"id": "{owner.id}"}}},
{"field": "location.label", "label": "Room"},
]
if model.lower() == 'user':
elif model.lower() == 'user':
spec = {"fields": [
"label",
"last_name",
"first_name",
"supervisor.label",
"robot.overlord",
"staff",
"active",
]}
], "sort": "first_name,last_name"}
columns = [
{"field": "label", "label": "Full Name"},
{"field": "last_name"},
{"field": "first_name"},
{"field": "supervisor.label", "label": "Supervisor", "link": {"endpoint": "user.get_item", "params": {"id": "{supervisor.id}"}}},
{"field": "staff"},
{"field": "active"},
{"field": "staff", "format": "yesno"},
{"field": "active", "format": "yesno"},
]
row_classes = [
{"when": {"field": "active", "is": False}, "class": "table-secondary"},
{"when": {"all": [
{"field": "staff", "is": False},
{"field": "active", "is": True}
]}, "class": "table-success"},
]
elif model.lower() == 'worklog':
spec = {"fields": [
"work_item.label",
"contact.label",
"start_time",
"end_time",
"complete",
]}
columns = [
{"field": "work_item.label", "label": "Work Item", "link": {"endpoint": "inventory.get_item", "params": {"id": "{work_item.id}"}}},
{"field": "contact.label", "label": "Contact", "link": {"endpoint": "user.get_item", "params": {"id": "{contact.id}"}}},
{"field": "start_time", "format": "datetime"},
{"field": "end_time", "format": "datetime"},
{"field": "complete", "format": "yesno"},
]
row_classes = [
{"when": {"field": "complete", "is": True}, "class": "table-success"},
{"when": {"field": "complete", "is": False}, "class": "table-danger"}
]
spec["limit"] = 15
spec["offset"] = (page_num - 1) * 15
@ -67,7 +95,7 @@ def init_listing_routes(app):
service = crudkit.crud.get_service(cls)
rows = service.list(spec)
table = render_table(rows, columns=columns, opts={"object_class": model})
table = render_table(rows, columns=columns, opts={"object_class": model, "row_classes": row_classes})
return render_template("listing.html", model=model, table=table)