Skip to content

Move footer to Strapi #2425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions app/components/cms/footer_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

class Cms::FooterComponent < ViewComponent::Base
attr_reader :data

def initialize(data:)
@data = data
end

private

def get_model(key)
@data.get_model(key)
end
end
22 changes: 22 additions & 0 deletions app/components/cms/footer_component/footer_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<%= render GovGridRowComponent.new(additional_classes: "cms-footer-component", padding: {top: 0, bottom: 0}) do |row| %>
<%= row.with_column("full") do %>
<div class="cms-footer-component-wrapper">
<div>
<a href="<%= get_model(:company_logo_link).value %>">
<%= render get_model(:company_logo).render %>
</a>
<p class="govuk-body-s cms-footer-component--funding-text">Funded by</p>
<a href="<%= get_model(:funder_logo_link).value %>">
<%= render get_model(:funder_logo).render %>
</a>
</div>
<% get_model(:link_block).link_blocks.each do |block| %>
<div class="cms-footer-component__link-block">
<% block.each do |link| %>
<%= render link.render(additional_classes: ["govuk-footer__link", "ncce-link", "ncce-link--on-dark"]) %>
<% end %>
</div>
<% end %>
</div>
<% end %>
<% end %>
40 changes: 40 additions & 0 deletions app/components/cms/footer_component/footer_component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
.cms-footer-component {
color: $white;
height: 100%;

img {
width: 125px;
}

&--funding-text {
color: $white;
font-size: 14px;
margin: 10px 0;
}

&-wrapper {
display: flex;
justify-content: space-between;

@include govuk-media-query($until: desktop) {
flex-wrap: wrap;
justify-content: flex-start;
gap: 2rem;
}
}

&__link-block {
display: flex;
flex-direction: column;
gap: 12px;

.cms-icon-row {
margin-top: 0;

img {
width: 20px !important;
height: 20px !important;
}
}
}
}
9 changes: 6 additions & 3 deletions app/components/cms/link_with_icon_component.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# frozen_string_literal: true

class Cms::LinkWithIconComponent < ViewComponent::Base
def initialize(link_text:, url:, icon:)
def initialize(link_text:, url:, icon: nil, additional_classes: nil)
@link_text = link_text
@url = url
@icon = icon
@additional_classes = additional_classes
end

def call
content_tag :div, class: "cms-icon-row" do
concat(render(@icon.render))
concat(link_to(@link_text, @url))
if @icon
concat(render(@icon.render))
end
concat(link_to(@link_text, @url, class: @additional_classes))
end
end
end
7 changes: 7 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class ApplicationController < ActionController::Base

before_action :authenticate
before_action :access_cms_header
before_action :access_cms_footer

def authenticate
return unless ENV["BASIC_AUTH_PASSWORD"]
Expand All @@ -20,6 +21,12 @@ def access_cms_header
@cms_header = nil
end

def access_cms_footer
@cms_footer = Cms::Singles::Footer.get
rescue ActiveRecord::RecordNotFound
@cms_footer = nil
end

def authenticate_user!
redirect_to(helpers.create_account_url) unless current_user
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ def initialize(link_text:, url:, icon:)
@icon = icon
end

def render
Cms::LinkWithIconComponent.new(link_text:, url:, icon:)
def render(additional_classes: nil)
Cms::LinkWithIconComponent.new(
link_text: @link_text,
url: @url,
icon: @icon,
additional_classes: additional_classes
)
end
end
end
Expand Down
13 changes: 13 additions & 0 deletions app/services/cms/models/meta/footer_link_block.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Cms
module Models
module Meta
class FooterLinkBlock
attr_accessor :link_blocks

def initialize(link_blocks:)
@link_blocks = link_blocks
end
end
end
end
end
35 changes: 35 additions & 0 deletions app/services/cms/providers/strapi/factories/model_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ module ModelFactory
Models::DynamicZones::EnrichmentDynamicZone => :to_dynamic_zone,
Models::Collections::EnrichmentList => :to_enrichment_list,
Models::Images::FeaturedImage => :to_featured_image,
Models::Images::Image => :to_image,
Models::Meta::HeaderMenu => :to_menu,
Models::Meta::FooterLinkBlock => :to_footer,
Models::DynamicZones::HomepageDynamicZone => :to_dynamic_zone,
Models::Meta::PageTitle => :to_page_title,
Models::Meta::Seo => :to_seo,
Expand Down Expand Up @@ -131,6 +133,19 @@ def self.to_featured_image(strapi_data, _all_data, size = :large)
}
end

def self.to_image(strapi_data, _all_data, default_size = :medium)
return nil unless strapi_data.dig(:data, :attributes)

image_data = strapi_data[:data][:attributes]
{
url: image_data[:url],
alt: image_data[:alternativeText],
caption: image_data[:caption],
formats: image_data[:formats],
default_size:
}
end

def self.to_menu(strapi_data, _all_data)
{
menu_items: strapi_data.map do |menu_item|
Expand All @@ -142,6 +157,26 @@ def self.to_menu(strapi_data, _all_data)
}
end

def self.to_footer(strapi_data, _all_data)
{
link_blocks: strapi_data.map do |link|
link[:link].map {
Models::DynamicComponents::ContentBlocks::LinkWithIcon.new(
link_text: _1[:linkText],
url: _1[:url],
icon: _1[:icon].dig(:data).nil? ? nil : Models::Images::Image.new(
url: _1[:icon][:data][:attributes][:url],
alt: _1[:icon][:data][:attributes][:alternativeText],
caption: _1[:icon][:data][:attributes][:caption],
default_size: :small,
formats: _1[:icon][:data][:attributes][:formats]
)
)
}
end
}
end

def self.to_page_title(strapi_data, _all_data)
{
title: strapi_data[:title],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class LinkWithIcon < StrapiMock
attribute(:linkText) { Faker::Lorem.sentence }
attribute(:url) { Faker::Internet.url }
attribute(:icon) { Images::Image.generate_raw_data }
attribute(:additional_classes) {}
end
end
end
Expand Down
21 changes: 21 additions & 0 deletions app/services/cms/providers/strapi/mocks/singles/footer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Cms
module Providers
module Strapi
module Mocks
module Singles
class Footer < StrapiMock
attribute(:companyLogo) { {data: Mocks::Images::Image.generate_raw_data} }
attribute(:funderLogo) { {data: Mocks::Images::Image.generate_raw_data} }
attribute(:companyLogoLink) { Faker::Internet.url }
attribute(:funderLogoLink) { Faker::Internet.url }
attribute(:linkBlock) { Array.new(4) { FooterLinkBlock.generate_data } }
end

class FooterLinkBlock < StrapiMock
attribute(:link) { Array.new(4) { DynamicComponents::ContentBlocks::LinkWithIcon.generate_data } }
end
end
end
end
end
end
2 changes: 2 additions & 0 deletions app/services/cms/providers/strapi/queries/base_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class BaseQuery
Models::DynamicZones::EnrichmentDynamicZone => EnrichmentDynamicZone,
Models::DynamicZones::HomepageDynamicZone => HomepageDynamicZone,
Models::Images::FeaturedImage => FeaturedImage,
Models::Images::Image => Image,
Models::Meta::FooterLinkBlock => FooterLinkBlock,
Models::Meta::HeaderMenu => HeaderMenu,
Models::Meta::PageTitle => PageTitle,
Models::Meta::Seo => Seo,
Expand Down
21 changes: 21 additions & 0 deletions app/services/cms/providers/strapi/queries/footer_link_block.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Cms
module Providers
module Strapi
module Queries
class FooterLinkBlock
def self.embed(name)
<<~GRAPHQL.freeze
#{name} {
link {
linkText
url
#{SharedFields.image_fields("icon")}
}
}
GRAPHQL
end
end
end
end
end
end
15 changes: 15 additions & 0 deletions app/services/cms/providers/strapi/queries/image.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Cms
module Providers
module Strapi
module Queries
class Image
def self.embed(name)
<<~GRAPHQL.freeze
#{SharedFields.image_fields(name)}
GRAPHQL
end
end
end
end
end
end
7 changes: 7 additions & 0 deletions app/services/cms/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ def method_missing(method_name)
data_models[index]
end

def get_model(key)
index = self.class.param_indexes[key]
return nil unless index

data_models[index]
end

def self.param_name(mapping)
return mapping[:param_name] if mapping.has_key?(:param_name)
mapping[:key].to_s.underscore.to_sym
Expand Down
23 changes: 23 additions & 0 deletions app/services/cms/singles/footer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Cms
module Singles
class Footer < Resource
def self.resource_attribute_mappings
[
{model: Models::Images::Image, key: :companyLogo},
{model: Models::Images::Image, key: :funderLogo},
{model: Models::Data::TextField, key: :companyLogoLink},
{model: Models::Data::TextField, key: :funderLogoLink},
{model: Models::Meta::FooterLinkBlock, key: :linkBlock}
]
end

def self.cache_expiry
15.minutes
end

def self.resource_key = "footer"

def self.graphql_key = "footer"
end
end
end
Loading