Skip to content

Commit 1a10958

Browse files
committed
Merge branch 'feature/TMI-48-add-featured-services-block-to-service-area-page' into staging
2 parents 43df39d + ce4ed1b commit 1a10958

File tree

4 files changed

+70
-6
lines changed

4 files changed

+70
-6
lines changed

tbx/core/blocks.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from collections import defaultdict
1+
from collections import OrderedDict, defaultdict
22
from datetime import datetime
33
import logging
44

@@ -307,6 +307,10 @@ class Meta:
307307
icon = "breadcrumb-expand"
308308

309309

310+
class ServiceAreaFeaturedPageCardBlock(FeaturedPageCardBlock):
311+
image = ImageChooserBlock(required=False)
312+
313+
310314
class FeaturedServicesBlock(blocks.StructBlock):
311315
title = blocks.CharBlock(max_length=255, required=False)
312316
intro = blocks.RichTextBlock(
@@ -324,6 +328,54 @@ class Meta:
324328
template = "patterns/molecules/streamfield/blocks/featured_services_block.html"
325329

326330

331+
class ServiceAreaFeaturedServicesBlock(FeaturedServicesBlock):
332+
def __init__(self, *args, **kwargs):
333+
super().__init__(*args, **kwargs)
334+
# Get all child blocks
335+
child_blocks = self.child_blocks
336+
# Define the desired order of fields
337+
field_order = ["title", "intro", "is_displaying_card_images", "cards"]
338+
# Create new OrderedDict with fields in desired order
339+
self.child_blocks = OrderedDict(
340+
[(name, child_blocks[name]) for name in field_order]
341+
)
342+
343+
is_displaying_card_images = blocks.BooleanBlock(
344+
default=True,
345+
help_text="Hide images from all cards when unchecked",
346+
label="Display card images?",
347+
required=False,
348+
)
349+
cards = blocks.ListBlock(
350+
ServiceAreaFeaturedPageCardBlock(),
351+
max_num=8,
352+
min_num=6,
353+
)
354+
355+
def clean(self, value):
356+
cleaned_data = super().clean(value)
357+
358+
if cleaned_data.get("is_displaying_card_images"):
359+
errors = {}
360+
361+
for i, card in enumerate(cleaned_data.get("cards", [])):
362+
if not card.get("image"):
363+
errors[i] = blocks.StructBlockValidationError(
364+
{
365+
"image": ValidationError(
366+
"Image is required when 'Display images' is selected"
367+
)
368+
}
369+
)
370+
371+
if errors:
372+
raise blocks.StructBlockValidationError(
373+
{"cards": blocks.ListBlockValidationError(errors)}
374+
)
375+
376+
return cleaned_data
377+
378+
327379
class FourPhotoCollageBlock(blocks.StructBlock):
328380
"""
329381
Accepts 4 photos shown as a collage + text below.

tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/featured_services_block.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ <h2 class="motif-heading motif-heading--half-width">{{ value.title }}</h2>
99
<ul class="featured-services__cards">
1010
{% for card in value.cards %}
1111
<li class="featured-services__card">
12-
{% srcset_image card.image format-webp fill-{750x420,650x420} sizes="(max-width: 750px) 100vw, (min-width: 751px) 650px" alt="" %}
12+
{# The ServiceAreaFeaturedServicesBlock supports optional image display, other blocks always show images #}
13+
{% if value.is_displaying_card_images or value.is_displaying_card_images is None %}
14+
{% if card.image %}
15+
{% srcset_image card.image format-webp fill-{750x420,650x420} sizes="(max-width: 750px) 100vw, (min-width: 751px) 650px" alt="" %}
16+
{% endif %}
17+
{% endif %}
1318
<div class="featured-services__text">
1419
<h3 class="featured-services__heading heading heading--two-b{% if value.cards|length >= 4 %} heading--three{% endif %}">{% firstof card.heading card.page.title %}</h3>
1520
{% if card.subheading %}

tbx/services/blocks.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
PartnersBlock,
1414
PhotoCollageBlock,
1515
PromoBlock,
16+
ServiceAreaFeaturedServicesBlock,
1617
ShowcaseBlock,
1718
StoryBlock,
1819
StructBlockValidationError,
@@ -95,6 +96,7 @@ def clean(self, value):
9596

9697
class ServiceAreaStoryBlock(StoryBlock):
9798
partners_block = PartnersBlock()
99+
featured_services = ServiceAreaFeaturedServicesBlock()
98100
blog_chooser = BlogChooserBlock()
99101
four_photo_collage = FourPhotoCollageBlock()
100102
key_points = IconKeyPointsBlock(label="Key points with icons")

tbx/static_src/sass/components/_featured-services.scss

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,21 @@
66
}
77

88
&__cards {
9-
display: grid;
9+
display: flex;
1010
gap: $spacer-mini-plus;
11-
grid-template-columns: repeat(1, 1fr);
11+
flex-wrap: wrap;
1212

1313
@include media-query(medium) {
14-
grid-template-columns: repeat(2, 1fr);
14+
> * {
15+
flex: 1 1 40%;
16+
}
1517
}
1618

1719
@include media-query(x-large) {
18-
grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
20+
> * {
21+
flex: 1 1 20%;
22+
min-width: 20%;
23+
}
1924
}
2025
}
2126

0 commit comments

Comments
 (0)