Skip to content

Commit

Permalink
improve facet layout, max 8, sort by count, reset
Browse files Browse the repository at this point in the history
  • Loading branch information
pvgenuchten committed Jan 10, 2025
1 parent 07bd28b commit 0a705c4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
3 changes: 3 additions & 0 deletions pycsw/ogc/api/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import logging
import os
from urllib.parse import urlencode, quote
from operator import itemgetter

from owslib.ogcapi.records import Records
from pygeofilter.parsers.ecql import parse as parse_ecql
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 %}

0 comments on commit 0a705c4

Please sign in to comment.