Skip to content

Commit 64f1558

Browse files
Merge pull request #2380 from NCCE/3018-curriculum-embed-component-for-strapi
New Curriculum Key stages component
2 parents 2d52cad + 11a1e45 commit 64f1558

File tree

15 files changed

+289
-2
lines changed

15 files changed

+289
-2
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
3+
class Cms::CurriculumKeyStagesComponent < ViewComponent::Base
4+
delegate :cms_color_theme_class, to: :helpers
5+
6+
def initialize(title:, background_color:)
7+
@title = title
8+
@background_color = background_color
9+
10+
@key_stages = begin
11+
CurriculumClient::Queries::KeyStage.all.key_stages
12+
rescue
13+
[]
14+
end
15+
end
16+
17+
def box_classes(key_stage)
18+
classes = ["curriculum-card"]
19+
classes << if ["1", "2"].include?(key_stage.level)
20+
cms_color_theme_class("orange", "left")
21+
else
22+
cms_color_theme_class("green", "left")
23+
end
24+
end
25+
26+
def render?
27+
@key_stages.any?
28+
end
29+
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<%= render GovGridRowComponent.new(background_color: @background_color, additional_classes: "cms-curriculum-key-stages") do |row| %>
2+
<%= row.with_column("full") do %>
3+
<h2 class="govuk-heading-m"><%= @title %></h2>
4+
<div class="govuk-grid-row">
5+
<% @key_stages.each do |key_stage| %>
6+
<div class="govuk-grid-column-one-quarter">
7+
<%= content_tag :div, class: box_classes(key_stage) do %>
8+
<h3 class="govuk-heading-m curriculum-card__title">
9+
<%= link_to key_stage.title, curriculum_key_stage_units_path(key_stage_slug: key_stage.slug), class: 'govuk-link ncce-link' %>
10+
</h3>
11+
<p class="govuk-body-s curriculum-card__details">
12+
<span class='curriculum-card__year'><strong>Year <%= key_stage.years %></strong>,&nbsp;</span>
13+
<span class='curriculum-card__age'>Age <%= key_stage.ages %></span>
14+
</p>
15+
<p class='govuk-body-s curriculum-card__counts'>
16+
<span class='curriculum-card__unit'>Units: <%= key_stage.unit_count %></span>
17+
<span class='curriculum-card__lesson'>Lessons: <%= key_stage.lesson_count %></span>
18+
</p>
19+
<% end %>
20+
</div>
21+
<% end %>
22+
</div>
23+
<% end %>
24+
<% end %>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
.cms-curriculum-key-stages {
2+
3+
.curriculum-card {
4+
background-color: $concrete;
5+
border-left-style: solid;
6+
border-left-width: 9px;
7+
display: flex;
8+
flex-direction: column;
9+
justify-content: center;
10+
11+
padding: 20px 10px;
12+
position: relative;
13+
14+
@include govuk-media-query($from: tablet) {
15+
margin-bottom: 0;
16+
min-height: 5.5rem;
17+
}
18+
19+
@include govuk-media-query($from: desktop) {
20+
padding: 20px 10px 20px 25px;
21+
min-height: inherit;
22+
}
23+
24+
&__title {
25+
font-weight: 500;
26+
margin-bottom: 0.5rem;
27+
margin-top: 0;
28+
29+
@include govuk-media-query($from: desktop) {
30+
margin-bottom: 1rem;
31+
}
32+
}
33+
34+
&__details {
35+
display: flex;
36+
flex-wrap: wrap;
37+
margin-bottom: 0;
38+
flex-direction: row;
39+
40+
@include govuk-media-query($from: tablet) {
41+
flex-direction: column;
42+
}
43+
44+
@include govuk-media-query($from: desktop) {
45+
flex-direction: row;
46+
}
47+
}
48+
49+
&__counts {
50+
padding-top: 16px;
51+
display: flex;
52+
flex-wrap: wrap;
53+
margin-bottom: 0;
54+
flex-direction: column;
55+
}
56+
}
57+
}

app/components/cms/horizontal_link_card_component/horizontal_link_card_component.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
padding: 20px;
44
border-left-width: 13px;
55

6+
.ncce-link {
7+
color: $hyper-link-blue;
8+
&:visited {
9+
color: $hyper-link-blue;
10+
}
11+
}
12+
613
h2 {
714
@extend .govuk-heading-m;
815
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module Cms
2+
module DynamicComponents
3+
module Blocks
4+
class CurriculumKeyStages
5+
attr_accessor :title, :background_color
6+
7+
def initialize(title:, background_color:)
8+
@title = title
9+
@background_color = background_color
10+
end
11+
12+
def render
13+
Cms::CurriculumKeyStagesComponent.new(title:, background_color:)
14+
end
15+
end
16+
end
17+
end
18+
end

app/services/cms/providers/strapi/factories/blocks_factory.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ def self.generate_component(component_name, strapi_data)
6969
to_button_block(strapi_data)
7070
when "feedback-banner"
7171
to_feedback_banner(strapi_data)
72+
when "curriculum-key-stages"
73+
to_curriculum_key_stages(strapi_data)
7274
end
7375
end
7476

@@ -99,6 +101,13 @@ def self.to_text_with_testimonial(strapi_data)
99101
)
100102
end
101103

104+
def self.to_curriculum_key_stages(strapi_data)
105+
DynamicComponents::Blocks::CurriculumKeyStages.new(
106+
title: strapi_data[:title],
107+
background_color: extract_color_name(strapi_data, :bkColor)
108+
)
109+
end
110+
102111
def self.to_full_width_image_banner(strapi_data)
103112
DynamicComponents::Blocks::FullWidthImageBanner.new(
104113
background_image: to_image(strapi_data, :backgroundImage, default_size: :original),
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module Cms
2+
module Providers
3+
module Strapi
4+
module Mocks
5+
module DynamicComponents
6+
module Blocks
7+
class CurriculumKeyStages < StrapiMock
8+
strapi_component "blocks.curriculum-key-stages"
9+
10+
attribute(:title) { Faker::Lorem.sentence }
11+
attribute(:bkColor) { nil }
12+
end
13+
end
14+
end
15+
end
16+
end
17+
end
18+
end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module Cms
2+
module Providers
3+
module Strapi
4+
module Queries
5+
module Components
6+
module Blocks
7+
class CurriculumKeyStages < BaseComponentQuery
8+
def self.name = "ComponentBlocksCurriculumKeyStages"
9+
10+
def self.base_fields
11+
<<~GRAPHQL.freeze
12+
cks__title: title
13+
bkColor
14+
GRAPHQL
15+
end
16+
end
17+
end
18+
end
19+
end
20+
end
21+
end
22+
end

app/services/cms/providers/strapi/queries/dynamic_zone.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class DynamicZone
77
Components::Blocks::ButtonBlock,
88
Components::Blocks::CommunityActivityList,
99
Components::Blocks::CourseCardsSection,
10+
Components::Blocks::CurriculumKeyStages,
1011
Components::Blocks::EnrolmentSplitCourseCard,
1112
Components::Blocks::EnrolmentTestimonial,
1213
Components::Blocks::FeedbackBanner,

app/webpacker/stylesheets/components/cms/_shared.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
"standard": $lime-green,
1313
"i-belong": $orange,
1414
"isaac": $brand-yellow,
15-
"cqf": $pink
15+
"cqf": $pink,
16+
"orange": $orange,
17+
"green": $lime-green
1618
);
1719

1820
$sides: ("left", "right", "top", "bottom");

0 commit comments

Comments
 (0)