From 9a39ae25dfa7a81687ee7dcc5041db2476287576 Mon Sep 17 00:00:00 2001 From: Yaro Kasear Date: Mon, 29 Sep 2025 14:20:48 -0500 Subject: [PATCH] Working search feature. --- inventory/routes/search.py | 45 ++++++++++++++++++++------ inventory/templates/crudkit/table.html | 2 +- inventory/templates/search.html | 31 ++++++++++-------- 3 files changed, 53 insertions(+), 25 deletions(-) diff --git a/inventory/routes/search.py b/inventory/routes/search.py index 40d37d3..aae6e00 100644 --- a/inventory/routes/search.py +++ b/inventory/routes/search.py @@ -21,14 +21,15 @@ def init_search_routes(app): inventory_columns = [ {"field": "label"}, - {"field": "barcode"}, + {"field": "barcode", "label": "Bar Code #"}, {"field": "name"}, - {"field": "serial"}, - {"field": "brand.name"}, + {"field": "serial", "label": "Serial #"}, + {"field": "brand.name", "label": "Brand"}, {"field": "model"}, - {"field": "device_type.description"}, - {"field": "owner.label"}, - {"field": "location.label"} + {"field": "device_type.description", "label": "Device Type"}, + {"field": "owner.label", "label": "Contact", + "link": {"endpoint": "entry.entry", "params": {"id": "{owner.id}", "model": "user"}}}, + {"field": "location.label", "label": "Location"}, ] inventory_results = inventory_service.list({ 'notes|label|owner.label__icontains': q, @@ -49,7 +50,9 @@ def init_search_routes(app): {"field": "last_name"}, {"field": "first_name"}, {"field": "title"}, - {"field": "supervisor.label"}, + {"field": "supervisor.label", "label": "Supervisor", + "link": {"endpoint": "entry.entry", "params": {"id": "{supervisor.id}", "model": "user"}}}, + {"field": "location.label", "label": "Location"}, ] user_results = user_service.list({ 'supervisor.label|label__icontains': q, @@ -58,12 +61,34 @@ def init_search_routes(app): "first_name", "title", "supervisor.label", + "location.label", ] }) - inventory_results = render_table(inventory_results, inventory_columns) - user_results = render_table(user_results, user_columns) + worklog_columns = [ + {"field": "contact.label", "label": "Contact", + "link": {"endpoint": "entry.entry", "params": {"id": "{contact.id}", "model": "user"}}}, + {"field": "work_item.label", "label": "Work Item", + "link": {"endpoint": "entry.entry", "params": {"id": "{work_item.id}", "model": "inventory"}}}, + {"field": "complete", "format": "yesno"}, + {"field": "start_time", "format": "datetime"}, + {"field": "end_time", "format": "datetime"} + ] + worklog_results = worklog_service.list({ + 'contact.label|work_item.label__icontains': q, + 'fields': [ + "contact.label", + "work_item.label", + "complete", + "start_time", + "end_time" + ] + }) - return render_template('search.html', q=q, inventory_results=inventory_results, user_results=user_results) + inventory_results = render_table(inventory_results, inventory_columns, opts={"object_class": "inventory"}) + user_results = render_table(user_results, user_columns, opts={"object_class": "user"}) + worklog_results = render_table(worklog_results, worklog_columns, opts={"object_class": "worklog"}) + + return render_template('search.html', q=q, inventory_results=inventory_results, user_results=user_results, worklog_results=worklog_results) app.register_blueprint(bp_search) diff --git a/inventory/templates/crudkit/table.html b/inventory/templates/crudkit/table.html index 2e12374..fb27052 100644 --- a/inventory/templates/crudkit/table.html +++ b/inventory/templates/crudkit/table.html @@ -10,7 +10,7 @@ {% if rows %} {% for row in rows %} - + {% for cell in row.cells %} {% if cell.href %} {{ cell.text if cell.text is not none else '-' }} diff --git a/inventory/templates/search.html b/inventory/templates/search.html index 4c786d5..e9b32dc 100644 --- a/inventory/templates/search.html +++ b/inventory/templates/search.html @@ -1,26 +1,29 @@ {% extends 'base.html' %} {% block main %} -
- Search for "{{ q }}": +
+ Search results for "{{ q }}"
- -