Making tables a little smarter.
This commit is contained in:
parent
cf795086f1
commit
3f677fceee
4 changed files with 157 additions and 14 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -15,11 +15,22 @@
|
|||
<body class="pb-5">
|
||||
|
||||
<header>
|
||||
<nav class="navbar bg-body-tertiary border border-top-0">
|
||||
<nav class="navbar navbar-expand-sm bg-body-tertiary border border-top-0">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="{{ url_for('index.index') }}">
|
||||
{{ title if title else "Inventory Manager" }}
|
||||
</a>
|
||||
<ul class="navbar-nav me-auto">
|
||||
<li class="nav-item">
|
||||
<a href="{{ url_for('listing.show_list', model='inventory') }}" class="nav-link link-success fw-semibold">Inventory</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a href="{{ url_for('listing.show_list', model='worklog') }}" class="nav-link link-success fw-semibold">Work Log</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a href="{{ url_for('listing.show_list', model='user') }}" class="nav-link link-success fw-semibold">Users</a>
|
||||
</li>
|
||||
</ul>
|
||||
{% block header %}
|
||||
{% endblock %}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<div class="table-responsive mx-5" style="max-height: 80vh;">
|
||||
<table class="table table-light table-striped table-hover table-bordered border-tertiary text-nowrap overflow-x-auto mx-auto">
|
||||
<table class="table table-info table-striped table-hover table-bordered border-tertiary text-nowrap overflow-x-auto mx-auto">
|
||||
<thead>
|
||||
<tr>
|
||||
{% for col in columns %}
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
<tbody>
|
||||
{% if rows %}
|
||||
{% for row in rows %}
|
||||
<tr onclick="location.href='{{ url_for( 'crudkit.' + kwargs['opts']['object_class'] + '.get_item', id=row.id) }}'" style="cursor: pointer;">
|
||||
<tr onclick="location.href='{{ url_for( 'crudkit.' + kwargs['object_class'] + '.get_item', id=row.id) }}'" style="cursor: pointer;" class="{{ row.class or '' }}">
|
||||
{% for cell in row.cells %}
|
||||
{% if cell.href %}
|
||||
<td class="{{ cell.class or '' }}"><a href="{{ cell.href }}" class="link-success link-underline link-underline-opacity-0 fw-semibold">{{ cell.text if cell.text is not none else '-' }}</a></td>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue