From 1b32e9a8e32a009a6c5cba72de067a85d8da9d27 Mon Sep 17 00:00:00 2001 From: Lawrence Date: Thu, 18 May 2023 12:37:32 -0500 Subject: [PATCH] Hero Billboard Placement (#19467) * init * add option to swagger docs * in_house validation * filtered ad quesry changes * styling and prioritizing home hero banner over campaign banner * rubocop * typo * broken spec * more spec fixes * found the spec break culprit * derp * Update app/views/shared/_display_ad.html.erb Co-authored-by: Ridhwana * Update app/controllers/stories_controller.rb Co-authored-by: Ridhwana * remove immediate return * styling feedback and moving banner to articles index * remove nil * updated styling * add signed in bool * add feature flag * remove feature flag data scripts --------- Co-authored-by: Ridhwana --- app/assets/stylesheets/billboards.scss | 42 +++++++++++++++++++ app/controllers/stories_controller.rb | 5 +++ app/models/display_ad.rb | 10 ++++- app/views/articles/index.html.erb | 3 ++ app/views/layouts/application.html.erb | 6 +-- app/views/shared/_display_ad.html.erb | 12 ++++++ spec/models/display_ad_spec.rb | 14 +++++++ .../display_ads/filtered_ads_query_spec.rb | 26 +++++++++--- .../user_views_an_organization_spec.rb | 2 +- spec/system/search/search_title_spec.rb | 4 +- spec/system/user/view_user_index_spec.rb | 4 +- swagger/v1/api_v1.json | 1 + 12 files changed, 115 insertions(+), 14 deletions(-) diff --git a/app/assets/stylesheets/billboards.scss b/app/assets/stylesheets/billboards.scss index 1cc28afd5..216eeaecf 100644 --- a/app/assets/stylesheets/billboards.scss +++ b/app/assets/stylesheets/billboards.scss @@ -40,6 +40,48 @@ display: block; } +.crayons-card.hero-billboard .ltag_cta { + display: block; +} + +.hero-billboard { + margin: var(--su-2) 0 0; + h1, + h2, + h3, + p { + text-align: center; + } + + @media (max-width: $breakpoint-s) { + display: block; + } + + @media (min-width: $breakpoint-m) { + margin: var(--su-2) var(--su-2) 0; + } + + @media (min-width: $breakpoint-l) { + margin: var(--su-4) var(--su-4) 0; + } + + @media (min-width: $breakpoint-xl) { + max-width: var(--site-width); + margin: var(--su-4) var(--su-4) 0; + } + + @media (min-width: 1284px) { + max-width: var(--site-width); + margin: var(--su-4) auto 0; + } +} + +@media (min-width: $breakpoint-s) { + .hero-billboard h1 { + font-size: var(--fs-3xl); + } +} + // these are inline CTA's //refers to the below the comments billboard on the article page //refers to the feed/stories where we use story diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index 949034f80..83c82b243 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -48,6 +48,10 @@ class StoriesController < ApplicationController private + def assign_hero_banner + @hero_display_ad = DisplayAd.for_display(area: "home_hero", user_signed_in: user_signed_in?) + end + def assign_hero_html return if Campaign.current.hero_html_variant_name.blank? @@ -125,6 +129,7 @@ class StoriesController < ApplicationController def handle_base_index @home_page = true assign_feed_stories unless user_signed_in? # Feed fetched async for signed-in users + assign_hero_banner assign_hero_html assign_podcasts get_latest_campaign_articles if Campaign.current.show_in_sidebar? diff --git a/app/models/display_ad.rb b/app/models/display_ad.rb index 6f5e340ce..8542f904b 100644 --- a/app/models/display_ad.rb +++ b/app/models/display_ad.rb @@ -6,7 +6,7 @@ class DisplayAd < ApplicationRecord belongs_to :audience_segment, optional: true # rubocop:disable Layout/LineLength - ALLOWED_PLACEMENT_AREAS = %w[sidebar_left sidebar_left_2 sidebar_right feed_first feed_second feed_third post_sidebar post_comments].freeze + ALLOWED_PLACEMENT_AREAS = %w[sidebar_left sidebar_left_2 sidebar_right feed_first feed_second feed_third home_hero post_sidebar post_comments].freeze # rubocop:enable Layout/LineLength ALLOWED_PLACEMENT_AREAS_HUMAN_READABLE = ["Sidebar Left (First Position)", "Sidebar Left (Second Position)", @@ -14,6 +14,7 @@ class DisplayAd < ApplicationRecord "Home Feed First", "Home Feed Second", "Home Feed Third", + "Home Hero", "Sidebar Right (Individual Post)", "Below the comment section"].freeze @@ -35,6 +36,7 @@ class DisplayAd < ApplicationRecord validates :body_markdown, presence: true validates :organization, presence: true, if: :community? validate :validate_tag + validate :validate_in_house_hero_ads before_save :process_markdown after_save :generate_display_ad_name @@ -96,6 +98,12 @@ class DisplayAd < ApplicationRecord validate_tag_name(tag_list) end + def validate_in_house_hero_ads + return unless placement_area == "home_hero" && type_of != "in_house" + + errors.add(:type_of, "must be in_house if display ad is a Home Hero") + end + def audience_segment_type=(type) self.audience_segment = if type.blank? nil diff --git a/app/views/articles/index.html.erb b/app/views/articles/index.html.erb index 717a3e7e7..a1d992a53 100644 --- a/app/views/articles/index.html.erb +++ b/app/views/articles/index.html.erb @@ -26,6 +26,9 @@ <%= javascript_packs_with_chunks_tag "homePage", defer: true %> <% cache(release_adjusted_cache_key("main-stories-index-#{params}-#{user_signed_in?}"), expires_in: 90.seconds) do %> + <% if @hero_display_ad && FeatureFlag.enabled?(:hero_billboard) %> + <%= render partial: "shared/display_ad", locals: { display_ad: @hero_display_ad, data_context_type: DisplayAdEvent::CONTEXT_TYPE_HOME } %> + <% end %>
" data-which="<%= @list_of %>" data-tag="" diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 2dda4fa87..4492ab813 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -55,8 +55,7 @@ data-deployed-at="<%= j(ForemInstance.deployed_at) %>" data-latest-commit-id="<%= j(ForemInstance.latest_commit_id) %>" data-ga-tracking="<%= j(Settings::General.ga_tracking_id) %>" - data-ga4-tracking-id="<%= j(Settings::General.ga_analytics_4_id) %>" - > + data-ga4-tracking-id="<%= j(Settings::General.ga_analytics_4_id) %>"> <%# Repeat of stylesheets in to fix rendering glitch: https://github.com/forem/forem/issues/12377 %> <%= render "layouts/styles", qualifier: "secondary" %>
@@ -89,7 +88,8 @@ <% end %>
- <% if @hero_html %> + + <% if @hero_html && @hero_display_ad.blank? %>