[Small win] Add display name to campaign settings (#16653)
* Add display name to campaign settings * Update app/models/settings/campaign.rb * Update app/views/admin/settings/forms/_campaign.html.erb
This commit is contained in:
parent
ec41d12246
commit
8649eaed0f
7 changed files with 38 additions and 2 deletions
|
|
@ -5,12 +5,21 @@ class CampaignDecorator < ApplicationDecorator
|
|||
def sidebar_image(options)
|
||||
return unless show_in_sidebar?
|
||||
|
||||
img = image_tag(object.sidebar_image, options)
|
||||
image_url = Images::Optimizer.call(object.sidebar_image, width: 500)
|
||||
img = image_tag(image_url, options)
|
||||
return link_to(img, url) if url
|
||||
|
||||
img
|
||||
end
|
||||
|
||||
def header_text(count)
|
||||
if display_name.present?
|
||||
"#{Campaign.current.display_name} (#{count})"
|
||||
else
|
||||
I18n.t("views.campaign.subtitle", count: count)
|
||||
end
|
||||
end
|
||||
|
||||
def main_tag
|
||||
@main_tag ||= featured_tags.first
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,6 +10,10 @@ module Constants
|
|||
description: "",
|
||||
placeholder: "Campaign stories show up on sidebar with approval?"
|
||||
},
|
||||
display_name: {
|
||||
description: "This text is displayed in reference to the campaign in titles, etc.",
|
||||
placeholder: "My great campaign"
|
||||
},
|
||||
call_to_action: {
|
||||
description: "This text populates the call to action button on the campaign sidebar",
|
||||
placeholder: "Share your project"
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ class Campaign
|
|||
articles_expiry_time
|
||||
articles_require_approval?
|
||||
call_to_action
|
||||
display_name
|
||||
featured_tags
|
||||
hero_html_variant_name
|
||||
sidebar_enabled?
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ module Settings
|
|||
setting :articles_expiry_time, type: :integer, default: 4
|
||||
setting :articles_require_approval, type: :boolean, default: 0
|
||||
setting :call_to_action, type: :string, default: -> { I18n.t("models.settings.campaign.share_your_project") }
|
||||
setting :display_name, type: :string, default: ""
|
||||
setting :featured_tags, type: :array, default: %w[]
|
||||
setting :hero_html_variant_name, type: :string, default: ""
|
||||
setting :sidebar_enabled, type: :boolean, default: 0
|
||||
|
|
|
|||
|
|
@ -11,6 +11,15 @@
|
|||
} %>
|
||||
<div id="campaignBodyContainer" class="card-body collapse hide" aria-labelledby="campaignBodyContainer">
|
||||
<fieldset class="grid gap-4">
|
||||
<div class="crayons-field">
|
||||
<%= admin_config_label :display_name, "Display Name" %>
|
||||
<%= admin_config_description Constants::Settings::Campaign::DETAILS[:display_name][:description] %>
|
||||
<%= f.text_field :display_name,
|
||||
class: "crayons-textfield",
|
||||
value: Settings::Campaign.display_name,
|
||||
placeholder: Constants::Settings::Campaign::DETAILS[:display_name][:placeholder] %>
|
||||
</div>
|
||||
|
||||
<div class="crayons-field">
|
||||
<%= admin_config_label :hero_html_variant_name, "Campaign hero HTML variant name" %>
|
||||
<%= admin_config_description Constants::Settings::Campaign::DETAILS[:hero_html_variant_name][:description] %>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
<section class="crayons-card crayons-card--secondary">
|
||||
<%= campaign.sidebar_image(class: "block w-100 h-auto radius-default", width: 1000, height: 420) %>
|
||||
<header class="crayons-card__header">
|
||||
<h3 class="crayons-subtitle-2"><%= link_to t("views.campaign.subtitle", count: @campaign_articles_count), "/t/#{campaign.main_tag}", class: "crayons-link" %></h3>
|
||||
<h3 class="crayons-subtitle-2"><%= link_to campaign.header_text(@campaign_articles_count), "/t/#{campaign.main_tag}", class: "crayons-link" %></h3>
|
||||
</header>
|
||||
<div>
|
||||
<%= render partial: "articles/widget_list_item", collection: @latest_campaign_articles,
|
||||
|
|
|
|||
|
|
@ -231,6 +231,18 @@ RSpec.describe "StoriesIndex", type: :request do
|
|||
create(:article, approved: false, body_markdown: u_body, score: 1)
|
||||
end
|
||||
|
||||
it "displays display name when it is set" do
|
||||
allow(Settings::Campaign).to receive(:display_name).and_return("Backstreet is back")
|
||||
get "/"
|
||||
expect(response.body).not_to include("Backstreet is back (0)")
|
||||
end
|
||||
|
||||
it "displays Stories fallback when display name is not set" do
|
||||
allow(Settings::Campaign).to receive(:display_name).and_return("")
|
||||
get "/"
|
||||
expect(response.body).not_to include("Stories (0)")
|
||||
end
|
||||
|
||||
it "doesn't display posts with the campaign tags when sidebar is disabled" do
|
||||
allow(Settings::Campaign).to receive(:sidebar_enabled).and_return(false)
|
||||
get "/"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue