Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve facet layout, max 8, sort by count, reset #1068

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pycsw/ogc/api/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import json
import logging
from operator import itemgetter
import os
from urllib.parse import urlencode, quote

Expand Down Expand Up @@ -1099,6 +1100,8 @@ def get_facets(self, filters=None) -> dict:
'count': fq[1]
})

facets_results[facet]['buckets'].sort(key=itemgetter('count'), reverse=True)

return facets_results


Expand Down
25 changes: 19 additions & 6 deletions pycsw/ogc/api/templates/items.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,14 @@
for at in attrs.keys() %}{%
if at != 'offset' %}{%
if attrs[at] not in [None,''] %}{%
if key not in [None,''] and key == at %}&{{ at }}={{ val }}{%
if key not in [None,''] and key == at %}{%
if val != '' %}&{{ at }}={{ val }}{% endif %}{%
else %}&{{ at }}={{ attrs[at] }}{%
endif %}{%
endif %}{%
endif %}{%
if key not in attrs.keys() %}&{{ key }}={{ val }}{% endif %}{%
endfor %}{%
endfor %}{%
if key not in attrs.keys() %}&{{ key }}={{ val }}{% endif %}{%
endmacro %}

{% macro reseturl(key,val) %}{{
Expand Down Expand Up @@ -122,18 +123,30 @@
</div>
{% if data['facets'] %}
{% for facet in data['facets'].keys() %}
{% if data['facets'][facet]['buckets']|length > 0 %}
<div class="card mt-3">
<div class="card-header text-capitalize">{{ facet }}</div>
<div class="card-header text-capitalize">{{ facet }} {% if facet in attrs.keys() %}
<a href="{{ updateurl(facet,'') }}"
class="btn btn-sm btn-outline-secondary" style="float:right">Reset</a>
{% endif %}</div>
<div class="card-body">
{% for bucket in data['facets'][facet].buckets %}
{% for bucket in data['facets'][facet]['buckets'] %}
{% if loop.index == 8 %}
<div id="more-{{facet}}" class="collapse">
{% endif %}
{% if bucket['value'] %}
<a href="{{ updateurl(facet,bucket['value']) }}" title="{{bucket['value']}}"
>{{(bucket['value'] or "") | truncate(20, False, '..') | capitalize }}</a>
<span class="badge rounded-pill bg-secondary" style="float:right">{{bucket['count']}}</span><br>
{% endif %}
{% endfor %}
{% if data['facets'][facet]['buckets']|length > 7 %}</div>
<button onclick="$('#more-{{facet}}').toggle()"
class="btn btn-sm btn-outline-secondary mt-2">Show more</button>
{% endif %}
</div>
</div>
{% endif %}
{% endfor %}
{% endif %}
</div>
Expand Down Expand Up @@ -334,4 +347,4 @@
}
}
</script>
{% endblock %}
{% endblock %}