mirror of
https://github.com/simon987/od-database.git
synced 2025-04-19 02:16:47 +00:00
113 lines
5.6 KiB
HTML
113 lines
5.6 KiB
HTML
{% extends "layout.html" %}
|
|
{% set current_page = "search" %}
|
|
|
|
{% set title = "OD-Database - Search" %}
|
|
|
|
{% block body %}
|
|
<div class="container">
|
|
|
|
<div class="card">
|
|
<div class="card-header">Search</div>
|
|
<div class="card-body">
|
|
<form action="/search">
|
|
|
|
<div class="form-row">
|
|
<div class="form-group col-md-8">
|
|
<input class="form-control" name="q" id="q" placeholder="Full-text Query" value="{{ q }}">
|
|
</div>
|
|
<div class="form-group col-md-2">
|
|
<select class="form-control" name="sort_order" title="Sort order">
|
|
<option disabled>Select sort order</option>
|
|
<option value="score" {{ "selected" if sort_order == "score" else "" }}>Relevance
|
|
</option>
|
|
<option value="size_asc" {{ "selected" if sort_order == "size_asc" else "" }}>Size
|
|
ascending
|
|
</option>
|
|
<option value="size_dsc" {{ "selected" if sort_order == "size_dsc" else "" }}>Size
|
|
descending
|
|
</option>
|
|
<option value="none" {{ "selected" if sort_order == "none" else "" }}>No order
|
|
(faster)
|
|
</option>
|
|
</select>
|
|
</div>
|
|
<div class="form-group col-md-2">
|
|
<select class="form-control" name="per_page" title="Results per page">
|
|
<option disabled>Results per page</option>
|
|
{% for results in results_set %}
|
|
<option{{ " selected" if per_page == results }}>{{ results }}</option>
|
|
{% endfor %}
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<input class="btn btn-primary btn-shadow" type="submit" value="Search">
|
|
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
{% if results["hits"]["total"] > 0 %}
|
|
<div class="card">
|
|
<div class="card-body">
|
|
|
|
<div class="table-responsive">
|
|
<table class="table">
|
|
<tbody>
|
|
|
|
{% for hit in results["hits"]["hits"] %}
|
|
{% set src = hit["_source"] %}
|
|
{% set hl_name = hit["highlight"]["name"][0] if "name" in hit["highlight"] else src["name"] %}
|
|
{% set hl_path = hit["highlight"]["path"][0] if "path" in hit["highlight"] else src["path"] %}
|
|
|
|
{# TODO: website url + path #}
|
|
{% set path = src["path"] %}
|
|
<tr>
|
|
<td>
|
|
{# File name & link #}
|
|
<a href="{{ path + "/" + src["name"] }}" title="{{ src["name"] }}">
|
|
{{ hl_name |safe }}
|
|
</a>
|
|
{# File type badge #}
|
|
{% set mime = get_mime(src["path"]) %}
|
|
{% if mime %}
|
|
<span class="badge badge-pill {{ get_color(mime) }}">
|
|
{{ src["path"][src["path"].rfind(".") + 1:] }}
|
|
</span>
|
|
{% endif %}
|
|
{# File path #}
|
|
<div class="text-muted" title="{{ path }}" style="font-size: 10px;">
|
|
<a style="color: #6c757d" title="See files from this website"
|
|
{# todo: website url #}
|
|
href="/website/{{ src["website_id"] }}">{{ hl_path | safe }}</a>{{ truncate_path(src["path"], 60) }}
|
|
</div>
|
|
</td>
|
|
{# File size #}
|
|
<td style="white-space: nowrap; vertical-align: top; text-align: right; font-size: 14px">
|
|
{{ src["size"] | filesizeformat if src["size"] >= 0 else "?" }}
|
|
</td>
|
|
</tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
{% if results["hits"]["total"] > (p + 1) * per_page %}
|
|
<a href="/search?q={{ q }}&p={{ p + 1 }}&sort_order={{ sort_order }}&per_page={{ per_page }}"
|
|
class="btn btn-primary" style="float: right">Next</a>
|
|
{% endif %}
|
|
{% if p > 0 %}
|
|
<a href="/search?q={{ q }}&p={{ p - 1 }}&sort_order={{ sort_order }}&per_page={{ per_page }}"
|
|
class="btn btn-primary">Previous</a>
|
|
{% endif %}
|
|
|
|
</div>
|
|
</div>
|
|
{% else %}
|
|
<div class="card">
|
|
<div class="card-body">No results</div>
|
|
</div>
|
|
{% endif %}
|
|
</div>
|
|
|
|
{% endblock body %}
|