Working search feature.
This commit is contained in:
parent
07512aee93
commit
9a39ae25df
3 changed files with 53 additions and 25 deletions
|
|
@ -21,14 +21,15 @@ def init_search_routes(app):
|
||||||
|
|
||||||
inventory_columns = [
|
inventory_columns = [
|
||||||
{"field": "label"},
|
{"field": "label"},
|
||||||
{"field": "barcode"},
|
{"field": "barcode", "label": "Bar Code #"},
|
||||||
{"field": "name"},
|
{"field": "name"},
|
||||||
{"field": "serial"},
|
{"field": "serial", "label": "Serial #"},
|
||||||
{"field": "brand.name"},
|
{"field": "brand.name", "label": "Brand"},
|
||||||
{"field": "model"},
|
{"field": "model"},
|
||||||
{"field": "device_type.description"},
|
{"field": "device_type.description", "label": "Device Type"},
|
||||||
{"field": "owner.label"},
|
{"field": "owner.label", "label": "Contact",
|
||||||
{"field": "location.label"}
|
"link": {"endpoint": "entry.entry", "params": {"id": "{owner.id}", "model": "user"}}},
|
||||||
|
{"field": "location.label", "label": "Location"},
|
||||||
]
|
]
|
||||||
inventory_results = inventory_service.list({
|
inventory_results = inventory_service.list({
|
||||||
'notes|label|owner.label__icontains': q,
|
'notes|label|owner.label__icontains': q,
|
||||||
|
|
@ -49,7 +50,9 @@ def init_search_routes(app):
|
||||||
{"field": "last_name"},
|
{"field": "last_name"},
|
||||||
{"field": "first_name"},
|
{"field": "first_name"},
|
||||||
{"field": "title"},
|
{"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({
|
user_results = user_service.list({
|
||||||
'supervisor.label|label__icontains': q,
|
'supervisor.label|label__icontains': q,
|
||||||
|
|
@ -58,12 +61,34 @@ def init_search_routes(app):
|
||||||
"first_name",
|
"first_name",
|
||||||
"title",
|
"title",
|
||||||
"supervisor.label",
|
"supervisor.label",
|
||||||
|
"location.label",
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
inventory_results = render_table(inventory_results, inventory_columns)
|
worklog_columns = [
|
||||||
user_results = render_table(user_results, user_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)
|
app.register_blueprint(bp_search)
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
{% if rows %}
|
{% if rows %}
|
||||||
{% for row in 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 %}
|
{% for cell in row.cells %}
|
||||||
{% if cell.href %}
|
{% 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>
|
<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>
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,29 @@
|
||||||
{% extends 'base.html' %}
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
{% block main %}
|
{% block main %}
|
||||||
<div class="display-6 mb-3">
|
<div class="display-4 mb-3 text-center">
|
||||||
Search for "{{ q }}":
|
Search results for "{{ q }}"
|
||||||
</div>
|
</div>
|
||||||
<!--div class="flex-container mb-3">
|
<ul class="nav nav-pills nav-fill justify-content-center fw-bold px-5 mx-5 mb-3" id="resultsTab">
|
||||||
<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">
|
|
||||||
<li class="nav-item">
|
<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>
|
||||||
<li class="nav-item">
|
<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>
|
||||||
<li class="nav-item">
|
<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>
|
</li>
|
||||||
</ul>
|
</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 %}
|
{% endblock %}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue