Skip to content

Commit 05af0c0

Browse files
Break apart FilterableListControls
1 parent 771cbe3 commit 05af0c0

File tree

15 files changed

+350
-247
lines changed

15 files changed

+350
-247
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,3 @@
1-
{# ==========================================================================
2-
3-
Filter List Controls
4-
5-
==========================================================================
6-
7-
Description:
8-
9-
Create an expandable of filters when given:
10-
11-
controls: Collection of field controls and other settings to determine
12-
what's rendered.
13-
14-
form: Django form that carries the fields that are to be rendered.
15-
16-
17-
========================================================================== #}
18-
{% from 'organisms/expandable.html' import expandable with context %}
19-
201
{% macro _filter_selectable(type, label_text, id, name, value, required=None, group=None) %}
212
<li class="m-form-field m-form-field__checkbox">
223
<input class="{{ 'a-checkbox' if type == 'checkbox' else 'a-radio' }}"
@@ -33,8 +14,8 @@
3314
</li>
3415
{% endmacro %}
3516

36-
{% macro _render_filter_fields(controls, form) -%}
37-
{% if controls.title %}
17+
{% macro _render_filter_fields(value, form) -%}
18+
{% if value.title %}
3819
{% set field_id = 'title' %}
3920
<div class="content-l_col
4021
content-l_col-1">
@@ -54,7 +35,7 @@
5435
</div>
5536
</div>
5637
{% endif %}
57-
{% if controls.categories.filter_category %}
38+
{% if value.categories.filter_category %}
5839
<div class="content-l_col
5940
content-l_col-1-3">
6041
<div class="o-form_group">
@@ -63,19 +44,19 @@
6344
Category
6445
</legend>
6546
<ul class="m-list m-list__unstyled">
66-
{% for slug, name in choices_for_page_type(controls.categories.page_type) %}
47+
{% for slug, name in choices_for_page_type(value.categories.page_type) %}
6748
{{ _filter_selectable('checkbox', category_label(slug), 'categories_' ~ slug, 'categories', slug) }}
6849
{% endfor %}
6950
</ul>
7051
</fieldset>
7152
</div>
7253
</div>
7354
{% endif %}
74-
{% if controls.topics or controls.authors or controls.date_range %}
55+
{% if value.topics or value.authors or value.date_range %}
7556
<div class="content-l_col
7657
content-l_col-2-3">
7758
<div class="content-l">
78-
{% if controls.topics %}
59+
{% if value.topics %}
7960
{% set field_id = 'topics' %}
8061
<div class="content-l_col
8162
content-l_col-1-2">
@@ -95,7 +76,7 @@
9576
</div>
9677
</div>
9778
{% endif %}
98-
{% if controls.authors %}
79+
{% if value.authors %}
9980
{% set field_id = 'authors' %}
10081
<div class="content-l_col
10182
content-l_col-1-2">
@@ -115,7 +96,7 @@
11596
</div>
11697
</div>
11798
{% endif %}
118-
{% if controls.date_range %}
99+
{% if value.date_range %}
119100
<div class="content-l_col
120101
content-l_col-1">
121102
<div class="o-form_group">
@@ -164,19 +145,19 @@
164145
{% endif %}
165146
{% endmacro %}
166147

167-
{% macro _filters_form(controls, form) %}
148+
{% macro _filters_form(value, form) %}
168149
<form
169-
{% if 'filterable-list' in controls.form_type %}
150+
{% if 'filterable-list' in value.form_type %}
170151
method="get"
171152
action=".">
172-
{% elif 'pdf-generator' in controls.form_type %}
153+
{% elif 'pdf-generator' in value.form_type %}
173154
method="post"
174155
action="pdf/">
175156
<input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}">
176157
{% endif %}
177158

178159
<div class="content-l">
179-
{{ _render_filter_fields(controls, form) }}
160+
{{ _render_filter_fields(value, form) }}
180161
<div class="content-l_col
181162
content-l_col-1
182163
m-btn-group">
@@ -192,115 +173,34 @@
192173
</form>
193174
{% endmacro %}
194175

195-
{% from 'molecules/info-unit.html' import info_unit with context %}
196-
{% import 'molecules/notification.html' as notification with context %}
197-
{% import 'organisms/post-preview.html' as post_preview with context %}
176+
{# ==========================================================================
177+
178+
Filterable List Controls
198179

199-
{% macro render_if_any(block_value) %}
200-
<div class="block block__flush-top">
201-
{% if filter_data.form.filterable_pages.first() %}
202-
{{ render(block_value) }}
203-
{% elif block_value.no_posts_message %}
204-
{{ notification.render('default', true,
205-
block_value.no_posts_message,
206-
block_value.no_posts_explanation) }}
207-
{% endif %}
208-
</div>
209-
{% endmacro %}
180+
==========================================================================
210181

211-
{% macro render(controls) %}
212-
<div class="o-filterable-list-controls"
213-
id="o-filterable-list-controls">
214-
{% set form = filter_data.form %}
215-
{% set posts = filter_data.page_set %}
216-
{% if has_active_filters %}
217-
{% do controls.update({'is_expanded':true}) %}
182+
Description:
183+
184+
Create an expandable of filters when given:
185+
186+
value: Collection of field value and other settings to determine
187+
what's rendered.
188+
189+
form: Django form that carries the fields that are to be rendered.
190+
191+
fragment_id: A unique ID for the filter list control.
192+
193+
========================================================================== #}
194+
{% macro render(value, form, fragment_id) %}
195+
{% from 'organisms/expandable.html' import expandable with context %}
196+
<div id="{{ fragment_id }}" class="o-filterable-list-controls">
197+
{% if value.has_active_filters %}
198+
{% do value.update({'is_expanded':true}) %}
218199
{% endif %}
219-
{% set form_markup = _filters_form(controls, form) %}
220-
{% call() expandable(controls, expandable_cue_additional_text='filters') %}
200+
201+
{% set form_markup = _filters_form(value, form) %}
202+
{% call() expandable(value, expandable_cue_additional_text='filters') %}
221203
{{ form_markup | safe }}
222204
{% endcall %}
223-
{% for field in form %}
224-
{% if field.errors %}
225-
{% for error in field.errors %}
226-
{{ notification.render('error', true, error) }}
227-
{% endfor %}
228-
{% endif %}
229-
{% endfor %}
230-
{% if 'filterable-list' in controls.form_type and posts is defined %}
231-
{% if form.is_valid() %}
232-
{% set count = posts.paginator.count %}
233-
{% if not has_active_filters %}
234-
{{ notification.render('default', false, '') }}
235-
{% elif count == 0 %}
236-
{{ notification.render(
237-
'warning',
238-
true,
239-
'Sorry, there were no results based on your filter selections.',
240-
'Please reset the filter or change your selections and try again.'
241-
) }}
242-
{% else %}
243-
{{ notification.render(
244-
'success',
245-
true,
246-
count ~ ' filtered result' ~ count|pluralize('s')
247-
) }}
248-
{% endif %}
249-
{% endif %}
250-
{% endif %}
251-
{% if controls.categories.page_type == 'activity-log' %}
252-
{% import 'activity-log/_activity-list.html' as activity_list with context %}
253-
{{ activity_list.render(posts) }}
254-
{% elif controls.output_5050 %}
255-
<div class="o-info-unit-group u-mb30" data-qa-hook="image-text-50-50">
256-
<div class="content-l">
257-
{% for post in posts %}
258-
<div class="content-l_col
259-
content-l_col-1-2">
260-
{% set post_url = pageurl(post) %}
261-
{% if post.preview_image %}
262-
{% set photo = image(post.preview_image, 'original') %}
263-
{% endif %}
264-
{% set heading = '<a href="' ~ post_url ~ '"><h2 class="h3">' ~
265-
post.preview_title ~
266-
'</h2></a>'
267-
if post.preview_title else null %}
268-
{% set sub_heading = '<a href="' ~ post_url ~ '"><h2 class="h4">' ~
269-
post.preview_subheading ~
270-
'</h2></a>'
271-
if post.preview_subheading else null %}
272-
{% if post.secondary_link_url and post.secondary_link_text %}
273-
{% set links = [
274-
{
275-
'url': post.secondary_link_url,
276-
'text': post.secondary_link_text
277-
}
278-
] %}
279-
{% endif %}
280-
{{ info_unit( {
281-
'image': {
282-
'url': photo.url if photo else '/',
283-
'alt': post.preview_image.alt if post.preview_image.alt else '',
284-
},
285-
'heading': heading,
286-
'sub_heading': sub_heading,
287-
'body': post.preview_description,
288-
'links': links or null,
289-
'link_image_and_heading': controls.link_image_and_heading
290-
} ) }}
291-
</div>
292-
{% endfor %}
293-
</div>
294-
</div>
295-
{% else %}
296-
{% for post in posts %}
297-
{{ post_preview.render(post, controls) }}
298-
{% endfor %}
299-
{% endif %}
300-
<div class="block block__flush-top block__flush-bottom block__padded-top">
301-
{% import 'molecules/pagination.html' as pagination with context %}
302-
{% set fragment_id = 'o-filterable-list-controls' %}
303-
{{ pagination.render( posts.paginator.num_pages, posts.number, fragment_id) }}
304-
</div>
305205
</div>
306206
{% endmacro %}

0 commit comments

Comments
 (0)