Skip to content

Commit 7ccb224

Browse files
committed
chore: implement package search
1 parent 7ebc2c8 commit 7ccb224

16 files changed

Lines changed: 231 additions & 52 deletions

File tree

ckanext/theming/themes/bare/templates/macros/ui.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,5 @@
101101
{% set package_item = component.package_item %}
102102
{% set resource_item = component.resource_item %}
103103
{% set search_form = component.search_form %}
104+
{% set facet_group = component.facet_group %}
105+
{% set facet_item = component.facet_item %}

ckanext/theming/themes/bare/templates/macros/ui/component.html

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -30,62 +30,43 @@
3030
{%- endmacro %}
3131

3232

33-
{%- macro search_form(query, query_name="q") -%}
33+
{%- macro search_form(query, sorting, sorting_options, query_name="q", sorting_name="sort", hidden_filters=[] ) -%}
3434
{%- set facets = {
3535
'fields': fields_grouped,
3636
'search': search_facets,
3737
'titles': facet_titles,
3838
'translated_fields': translated_fields,
3939
'remove_field': remove_field }
4040
%}
41-
{%- set sorting = [
42-
(_('Relevance'), 'score desc, metadata_modified desc'),
43-
(_('Name Ascending'), 'title_string asc'),
44-
(_('Name Descending'), 'title_string desc'),
45-
(_('Last Modified'), 'metadata_modified desc')
46-
]
47-
%}
4841

4942
{%- call ui.util.call(ui.form, **kwargs) -%}
50-
{{ ui.input(query_name, value=query, type="search", placeholder=_('Search...')) }}
51-
{{ ui.button(_('Search'), type="submit") }}
52-
{%- endcall %}
43+
{{ ui.input(query_name, label=_("Search"), value=query, type="search") }}
44+
{{ ui.select(sorting_name, label=_("Order by"), selected=sorting, options=sorting_options) if sorting }}
45+
{{ ui.form_actions(ui.button(_('Search'), type="submit")) }}
5346

47+
{%- for name, value in hidden_filters -%}
48+
{{ ui.hidden_input(name, value=value) }}
49+
{%- endfor %}
5450

51+
{%- endcall %}
52+
{%- endmacro %}
5553

56-
{%- if fields %}
57-
{%- for field_name, field_value in fields %}
58-
<input type="hidden" name="{{ field_name }}" value="{{ field_value }}">
59-
{%- endfor %}
60-
{%- endif %}
54+
{%- macro facet_item(key, value, label, count, active) -%}
55+
{% set url = h.remove_url_param(key, value) if active else h.add_url_param(new_params={key: value}) %}
6156

62-
{%- if sorting %}
63-
<div class="form-group">
64-
<label for="field-order-by">{{ _('Order by') }}</label>
65-
{{ ui.select("sort", "field-order-by", label="", options=sorting, selected=sort_by_selected) }}
66-
{{ ui.button(_('Go'), type="submit", attrs={"class": "btn btn-secondary"}) }}
57+
{%- call ui.util.call(ui.link, href=url) -%}
58+
<div style="display: flex; justify-content: space-between;">
59+
<span>{{ label }}</span>
60+
<span>{{ "&times;"|safe if active else count }}</span>
6761
</div>
68-
{%- endif %}
69-
70-
71-
{%- if fields_grouped %}
72-
<p {{ ui.util.attrs({"class": "filter-list"}) }}>
73-
{%- for field in fields_grouped %}
74-
{%- set search_facets_items = search_facets.get(field).items if search_facets and field in search_facets else [] %}
75-
<span {{ ui.util.attrs({"class": "facet"}) }}>{{ facet_titles.get(field) }}:</span>
76-
{%- for value in fields_grouped[field] %}
77-
<span {{ ui.util.attrs({"class": "filtered pill"}) }}>
78-
{%- if translated_fields and (field,value) in translated_fields -%}
79-
{{ translated_fields[(field,value)] }}
80-
{%- else -%}
81-
{{ h.list_dict_filter(search_facets_items, 'name', 'display_name', value) }}
82-
{%- endif %}
83-
{{ ui.link(_('Remove'), href=remove_field(field, value), **{"class": "remove"}) }}
84-
</span>
85-
{%- endfor %}
86-
{%- endfor %}
87-
</p>
88-
{%- endif %}
62+
{%- endcall %}
8963

64+
{%- endmacro %}
9065

66+
{%- macro facet_group(content, title) -%}
67+
{%- call ui.util.call(ui.section) -%}
68+
{{ ui.heading(title, level=3) }}
69+
{{ content }}
70+
{{ ui.divider() }}
71+
{%- endcall %}
9172
{%- endmacro %}

ckanext/theming/themes/bare/templates/macros/ui/element.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
{%- endmacro %}
3535

3636

37-
{%- macro tag(content, id, href) -%}
37+
{%- macro tag(content, href, id) -%}
3838
<a {{ ui.util.attrs(kwargs) }} href="{{ href or h.url_for('dataset.search', tags=id or content) }}">{{ content }}</a>
3939
{%- endmacro %}
4040

ckanext/theming/themes/bare/templates/package/search.html

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,30 @@
55
{%- endblock %}
66

77
{%- block page_header -%}
8-
{%- endblock %}
9-
10-
{%- block primary_content_inner %}
8+
{%- set sorting_options = [
9+
{"text": _('Relevance'), "value": "score desc, metadata_modified desc"},
10+
{"text": _('Name Ascending'), "value": "title_string asc"},
11+
{"text": _('Name Descending'), "value": "title_string desc"},
12+
{"text": _('Last Modified'), "value": "metadata_modified desc"}
13+
] %}
1114

12-
{{ fields }}
15+
{{ ui.search_form(q, sorting_options=sorting_options, sorting=sort_by_selected, hidden_filters=fields) }}
1316

14-
{{ ui.search_form(q) }}
17+
{%- call ui.util.call(ui.listing) -%}
18+
{%- for key, values in fields_grouped.items() -%}
19+
<div>
20+
<strong>{{ facet_titles.get(key, key) }}:</strong>
21+
{%- for value in values %}
22+
<del>
23+
{%- with label=h.list_dict_filter(search_facets[key]["items"], 'name', 'display_name', value) -%}
24+
{{ ui.link(label, h.remove_url_param(key, value)) }}
25+
{%- endwith %}
26+
</del>
27+
{% endfor %}
28+
</div>
1529

30+
{%- endfor %}
31+
{%- endcall %}
1632
<h2>
1733
{%- if not query_error %}
1834
{%- if page.item_count %}
@@ -24,6 +40,9 @@ <h2>
2440
{{ _('Error') }}
2541
{%- endif %}
2642
</h2>
43+
{%- endblock %}
44+
45+
{%- block primary_content_inner %}
2746

2847
{%- block package_list %}
2948
{%- if page.items %}
@@ -41,3 +60,18 @@ <h2>
4160
{{ ui.pagination(page.page, page.last_page, page._url_generator) }}
4261
{%- endblock %}
4362
{%- endblock %}
63+
64+
{%- block secondary_content -%}
65+
{%- for key, facets in search_facets.items() -%}
66+
{%- call ui.util.call(ui.facet_group, facet_titles.get(key, key)) -%}
67+
68+
{% set items = h.get_facet_items_dict(key, search_facets) %}
69+
{%- call ui.util.call(ui.listing) -%}
70+
{%- for item in items -%}
71+
{{ ui.facet_item(key=key, value=item.name, label=item.display_name, count=item.count, active=item.active) }}
72+
{%- endfor %}
73+
{%- endcall %}
74+
75+
{%- endcall %}
76+
{%- endfor %}
77+
{%- endblock %}

ckanext/theming/themes/bs5/templates/macros/ui.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
{% set organization_item = component.organization_item %}
117117
{% set package_item = component.package_item %}
118118
{% set resource_item = component.resource_item %}
119+
{% set search_form = component.search_form %}
119120

120121
{# Miscellaneous macros #}
121122
{% set datetime = misc.datetime %}

ckanext/theming/themes/bs5/templates/macros/ui/component.html

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,34 @@ <h5 class="card-title">{{ res.name or res.description or res.url[:50] ~ '...' }}
7575
</div>
7676
</div>
7777
{%- endmacro %}
78+
79+
{%- macro search_form(query, sorting, sorting_options, query_name="q", sorting_name="sort", active_filters=[] ) -%}
80+
{%- set facets = {
81+
'fields': fields_grouped,
82+
'search': search_facets,
83+
'titles': facet_titles,
84+
'translated_fields': translated_fields,
85+
'remove_field': remove_field }
86+
%}
87+
88+
{%- call ui.util.call(ui.form, **kwargs) -%}
89+
{{ ui.input(query_name, label=_("Search"), value=query, type="search", class="mb-2") }}
90+
{{ ui.select(sorting_name, label=_("Order by"), selected=sorting, options=sorting_options) if sorting }}
91+
{{ ui.form_actions(ui.button(_('Search'), type="submit")) }}
92+
93+
{%- if active_filters %}
94+
{%- call ui.util.call(ui.listing) -%}
95+
{%- for group, fields in active_filters|groupby(0) -%}
96+
<div class="mb-1">
97+
<strong>{{ group }}:</strong>
98+
{%- for name, value in fields -%}
99+
{{ ui.hidden_input(name, value=value) }}
100+
<del>{{ ui.tag(value, href=h.remove_url_param(name, value)) }}</del>
101+
{%- endfor %}
102+
</div>
103+
{%- endfor %}
104+
{%- endcall %}
105+
{%- endif %}
106+
107+
{%- endcall %}
108+
{%- endmacro %}

ckanext/theming/themes/bs5/templates/macros/ui/element.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<video {{ ui.util.attrs(kwargs) }} src="{{ src }}" {{ "controls" if controls }} class="img-fluid"></video>
4848
{%- endmacro %}
4949

50-
{%- macro tag(content, id, href) -%}
50+
{%- macro tag(content, href, id) -%}
5151
<a {{ ui.util.attrs(kwargs) }} class="badge bg-primary text-decoration-none" href="{{ href or h.url_for('dataset.search', tags=id or content) }}">{{ content }}</a>
5252
{%- endmacro %}
5353

ckanext/theming/themes/bulma/templates/macros/ui.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
{% set organization_item = component.organization_item %}
117117
{% set package_item = component.package_item %}
118118
{% set resource_item = component.resource_item %}
119+
{% set search_form = component.search_form %}
119120

120121
{# Miscellaneous macros #}
121122
{% set datetime = misc.datetime %}

ckanext/theming/themes/bulma/templates/macros/ui/component.html

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,44 @@
8585
</article>
8686
</div>
8787
{%- endmacro %}
88+
89+
{%- macro search_form(query, sorting, sorting_options, query_name="q", sorting_name="sort", active_filters=[] ) -%}
90+
{%- set facets = {
91+
'fields': fields_grouped,
92+
'search': search_facets,
93+
'titles': facet_titles,
94+
'translated_fields': translated_fields,
95+
'remove_field': remove_field }
96+
%}
97+
98+
{%- call ui.util.call(ui.form, **kwargs) -%}
99+
<div class="field">
100+
{{ ui.input(query_name, label=_("Search"), value=query, type="search", class="input") }}
101+
</div>
102+
{%- if sorting %}
103+
<div class="field">
104+
{{ ui.select(sorting_name, label=_("Order by"), selected=sorting, options=sorting_options, class="select") }}
105+
</div>
106+
{%- endif %}
107+
<div class="field">
108+
{{ ui.form_actions(ui.button(_('Search'), type="submit", class="button is-primary")) }}
109+
</div>
110+
111+
{%- if active_filters %}
112+
<div class="content">
113+
{%- call ui.util.call(ui.listing) -%}
114+
{%- for group, fields in active_filters|groupby(0) -%}
115+
<div>
116+
<strong>{{ group }}:</strong>
117+
{%- for name, value in fields -%}
118+
{{ ui.hidden_input(name, value=value) }}
119+
<del>{{ ui.tag(value, href=h.remove_url_param(name, value)) }}</del>
120+
{%- endfor %}
121+
</div>
122+
{%- endfor %}
123+
{%- endcall %}
124+
</div>
125+
{%- endif %}
126+
127+
{%- endcall %}
128+
{%- endmacro %}

ckanext/theming/themes/bulma/templates/macros/ui/element.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<video {{ ui.util.attrs(kwargs) }} src="{{ src }}" {{ "controls" if controls }}></video>
4444
{%- endmacro %}
4545

46-
{%- macro tag(content, id, href) -%}
46+
{%- macro tag(content, href, id) -%}
4747
{%- do kwargs -%}
4848
<a class="tag is-link" href="{{ href or h.url_for('dataset.search', tags=id or content) }}">{{ content }}</a>
4949
{%- endmacro %}

0 commit comments

Comments
 (0)