Apply banner default colors to dev seeds
Banners created through the admin form were getting the default color. However, banners created by other means (like the `db:dev_seed` rake task) were not getting these default values. This feature was originally implemented when we were using Rails 4. With Rails 5, we can provide default values to all new banners and simplify the code at the same time thanks to its `attribute` method. Now, when creating a new banner, instead of getting a blank space, we get an empty line with the banner's default background color, which most users won't know what it's about until they fill in the banner's title. So we're not displaying the content of the banner when it's empty, thanks to the `:empty` CSS pseudoclass.
This commit is contained in:
@@ -2292,6 +2292,10 @@ table {
|
||||
a > * {
|
||||
@include grid-row;
|
||||
padding: 0 rem-calc(16);
|
||||
|
||||
&:empty {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
+ .budget.expanded,
|
||||
|
||||
@@ -3,22 +3,6 @@ module BannersHelper
|
||||
@banners.present? && @banners.count > 0
|
||||
end
|
||||
|
||||
def banner_default_bg_color
|
||||
"#e7f2fc"
|
||||
end
|
||||
|
||||
def banner_default_font_color
|
||||
"#222222"
|
||||
end
|
||||
|
||||
def banner_bg_color_or_default
|
||||
@banner.background_color.presence || banner_default_bg_color
|
||||
end
|
||||
|
||||
def banner_font_color_or_default
|
||||
@banner.font_color.presence || banner_default_font_color
|
||||
end
|
||||
|
||||
def banner_target_link(banner)
|
||||
link_to banner.target_url do
|
||||
tag.h2(banner.title, style: "color:#{banner.font_color}") +
|
||||
|
||||
@@ -2,6 +2,9 @@ class Banner < ApplicationRecord
|
||||
acts_as_paranoid column: :hidden_at
|
||||
include ActsAsParanoidAliases
|
||||
|
||||
attribute :background_color, default: "#e7f2fc"
|
||||
attribute :font_color, default: "#222222"
|
||||
|
||||
translates :title, touch: true
|
||||
translates :description, touch: true
|
||||
include Globalizable
|
||||
|
||||
@@ -56,8 +56,7 @@
|
||||
<p class="help-text"><%= t("admin.shared.color_help") %></p>
|
||||
<div class="row collapse">
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= f.text_field :background_color, label: false, type: :color,
|
||||
value: banner_bg_color_or_default %>
|
||||
<%= f.text_field :background_color, label: false, type: :color %>
|
||||
</div>
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= f.text_field :background_color, label: false, id: "background_color_input" %>
|
||||
@@ -70,8 +69,7 @@
|
||||
<p class="help-text"><%= t("admin.shared.color_help") %></p>
|
||||
<div class="row collapse">
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= f.text_field :font_color, label: false, type: :color,
|
||||
value: banner_font_color_or_default %>
|
||||
<%= f.text_field :font_color, label: false, type: :color %>
|
||||
</div>
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= f.text_field :font_color, label: false, id: "font_color_input" %>
|
||||
|
||||
@@ -11,4 +11,11 @@ describe Banner do
|
||||
it "is valid" do
|
||||
expect(banner).to be_valid
|
||||
end
|
||||
|
||||
it "assigns default values to new banners" do
|
||||
banner = Banner.new
|
||||
|
||||
expect(banner.background_color).to be_present
|
||||
expect(banner.font_color).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user