Skip to content

Commit 3e9cf6f

Browse files
authored
improve facet layout, max 8, sort by count, reset (#1068)
1 parent 07bd28b commit 3e9cf6f

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

pycsw/ogc/api/records.py

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import json
3333
import logging
34+
from operator import itemgetter
3435
import os
3536
from urllib.parse import urlencode, quote
3637

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

1103+
facets_results[facet]['buckets'].sort(key=itemgetter('count'), reverse=True)
1104+
11021105
return facets_results
11031106

11041107

pycsw/ogc/api/templates/items.html

+19-6
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,14 @@
5858
for at in attrs.keys() %}{%
5959
if at != 'offset' %}{%
6060
if attrs[at] not in [None,''] %}{%
61-
if key not in [None,''] and key == at %}&{{ at }}={{ val }}{%
61+
if key not in [None,''] and key == at %}{%
62+
if val != '' %}&{{ at }}={{ val }}{% endif %}{%
6263
else %}&{{ at }}={{ attrs[at] }}{%
6364
endif %}{%
6465
endif %}{%
6566
endif %}{%
66-
if key not in attrs.keys() %}&{{ key }}={{ val }}{% endif %}{%
67-
endfor %}{%
67+
endfor %}{%
68+
if key not in attrs.keys() %}&{{ key }}={{ val }}{% endif %}{%
6869
endmacro %}
6970

7071
{% macro reseturl(key,val) %}{{
@@ -122,18 +123,30 @@
122123
</div>
123124
{% if data['facets'] %}
124125
{% for facet in data['facets'].keys() %}
126+
{% if data['facets'][facet]['buckets']|length > 0 %}
125127
<div class="card mt-3">
126-
<div class="card-header text-capitalize">{{ facet }}</div>
128+
<div class="card-header text-capitalize">{{ facet }} {% if facet in attrs.keys() %}
129+
<a href="{{ updateurl(facet,'') }}"
130+
class="btn btn-sm btn-outline-secondary" style="float:right">Reset</a>
131+
{% endif %}</div>
127132
<div class="card-body">
128-
{% for bucket in data['facets'][facet].buckets %}
133+
{% for bucket in data['facets'][facet]['buckets'] %}
134+
{% if loop.index == 8 %}
135+
<div id="more-{{facet}}" class="collapse">
136+
{% endif %}
129137
{% if bucket['value'] %}
130138
<a href="{{ updateurl(facet,bucket['value']) }}" title="{{bucket['value']}}"
131139
>{{(bucket['value'] or "") | truncate(20, False, '..') | capitalize }}</a>
132140
<span class="badge rounded-pill bg-secondary" style="float:right">{{bucket['count']}}</span><br>
133141
{% endif %}
134142
{% endfor %}
143+
{% if data['facets'][facet]['buckets']|length > 7 %}</div>
144+
<button onclick="$('#more-{{facet}}').toggle()"
145+
class="btn btn-sm btn-outline-secondary mt-2">Show more</button>
146+
{% endif %}
135147
</div>
136148
</div>
149+
{% endif %}
137150
{% endfor %}
138151
{% endif %}
139152
</div>
@@ -334,4 +347,4 @@
334347
}
335348
}
336349
</script>
337-
{% endblock %}
350+
{% endblock %}

0 commit comments

Comments
 (0)