Working search feature.

This commit is contained in:
Yaro Kasear 2025-09-29 14:20:48 -05:00
parent 07512aee93
commit 9a39ae25df
3 changed files with 53 additions and 25 deletions

View file

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

View file

@ -10,7 +10,7 @@
<tbody>
{% if rows %}
{% for row in rows %}
<tr onclick="location.href='{{ url_for( 'entry.entry', model=kwargs['object_class'], id=row.id) }}'" style="cursor: pointer;" class="{{ row.class or '' }}">
<tr{% if kwargs['object_class'] %} onclick="location.href='{{ url_for( 'entry.entry', model=kwargs['object_class'], id=row.id) }}'" style="cursor: pointer;" {% endif %} 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>

View file

@ -1,26 +1,29 @@
{% extends 'base.html' %}
{% block main %}
<div class="display-6 mb-3">
Search for "{{ q }}":
<div class="display-4 mb-3 text-center">
Search results for "{{ q }}"
</div>
<!--div class="flex-container mb-3">
<p class="fw-bold text-center">Inventory</p>
{{ inventory_results | safe }}
</div>
<div class="flex-container mb-3">
<p class="fw-bold text-center">Users</p>
{{ user_results | safe }}
</div-->
<ul class="nav nav-pills nav-fill justify-content-center fw-bold" id="resultsTab">
<ul class="nav nav-pills nav-fill justify-content-center fw-bold px-5 mx-5 mb-3" id="resultsTab">
<li class="nav-item">
<a class="nav-link active" data-bs-toggle="tab" data-bs-target="#inventory-tab-pane">Inventory</a>
<a class="nav-link active user-select-none" data-bs-toggle="tab" data-bs-target="#inventory-tab-pane">Inventory</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="tab" data-bs-target="#user-tab-pane">Users</a>
<a class="nav-link user-select-none" data-bs-toggle="tab" data-bs-target="#user-tab-pane">Users</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="tab" data-bs-target="#worklog-tab-pane">Work Logs</a>
<a class="nav-link user-select-none" data-bs-toggle="tab" data-bs-target="#worklog-tab-pane">Work Logs</a>
</li>
</ul>
<div class="tab-content" id="resultsContent">
<div class="tab-pane fade show active" id="inventory-tab-pane">
{{ inventory_results | safe }}
</div>
<div class="tab-pane fade" id="user-tab-pane">
{{ user_results | safe }}
</div>
<div class="tab-pane fade" id="worklog-tab-pane">
{{ worklog_results | safe }}
</div>
</div>
{% endblock %}