diff --git a/app/assets/javascripts/banners.js.coffee b/app/assets/javascripts/banners.js.coffee index 66d3a8df7..d38587083 100644 --- a/app/assets/javascripts/banners.js.coffee +++ b/app/assets/javascripts/banners.js.coffee @@ -7,6 +7,14 @@ App.Banners = $(selector).removeClass($(selector).attr("class"), true) .addClass(style, true) + update_background_color: (selector, text_selector, background_color) -> + $(selector).css('background-color', background_color); + $(text_selector).val(background_color); + + update_font_color: (selector, text_selector, font_color) -> + $(selector).css('color', font_color); + $(text_selector).val(font_color); + initialize: -> $('[data-js-banner-title]').on change: -> @@ -16,10 +24,20 @@ App.Banners = change: -> App.Banners.update_banner("#js-banner-description", $(this).val()) - $("#banner_style").on + $("#banner_background_color_picker").on change: -> - App.Banners.update_style("#js-banner-style", $(this).val()) + App.Banners.update_background_color("#js-banner-background", "#banner_background_color", $(this).val()); - $("#banner_image").on + $("#banner_background_color").on change: -> - App.Banners.update_style("#js-banner-image", $(this).val()) + App.Banners.update_background_color("#js-banner-background", "#banner_background_color_picker", $(this).val()); + + $("#banner_font_color_picker").on + change: -> + App.Banners.update_font_color("#js-banner-title", "#banner_font_color", $(this).val()); + App.Banners.update_font_color("#js-banner-description", "#banner_font_color", $(this).val()); + + $("#banner_font_color").on + change: -> + App.Banners.update_font_color("#js-banner-title", "#banner_font_color_picker", $(this).val()); + App.Banners.update_font_color("#js-banner-description", "#banner_font_color_picker", $(this).val()); diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index 8ef6ebb7f..e7e917be8 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -2226,7 +2226,8 @@ table { .banner-style-one, .banner-style-two, -.banner-style-three { +.banner-style-three, +.banner { margin: 0; margin-bottom: $line-height; diff --git a/app/controllers/admin/banners_controller.rb b/app/controllers/admin/banners_controller.rb index 281fc9360..25038b80f 100644 --- a/app/controllers/admin/banners_controller.rb +++ b/app/controllers/admin/banners_controller.rb @@ -2,8 +2,7 @@ class Admin::BannersController < Admin::BaseController has_filters %w{all with_active with_inactive}, only: :index - before_action :banner_styles, only: [:edit, :new, :create, :update] - before_action :banner_imgs, only: [:edit, :new, :create, :update] + before_action :banner_sections, only: [:edit, :new, :create, :update] respond_to :html, :js @@ -38,8 +37,10 @@ class Admin::BannersController < Admin::BaseController private def banner_params - attributes = [:title, :description, :target_url, :style, :image, - :post_started_at, :post_ended_at] + attributes = [:title, :description, :target_url, + :post_started_at, :post_ended_at, + :background_color, :font_color, + web_section_ids: []] params.require(:banner).permit(*attributes) end @@ -55,4 +56,7 @@ class Admin::BannersController < Admin::BaseController end end + def banner_sections + @banner_sections = WebSection.all + end end diff --git a/app/controllers/budgets_controller.rb b/app/controllers/budgets_controller.rb index 298425174..70efd04e9 100644 --- a/app/controllers/budgets_controller.rb +++ b/app/controllers/budgets_controller.rb @@ -16,6 +16,7 @@ class BudgetsController < ApplicationController def index @finished_budgets = @budgets.finished.order(created_at: :desc) @budgets_coordinates = current_budget_map_locations + @banners = Banner.in_section('budgets').with_active end end diff --git a/app/controllers/concerns/commentable_actions.rb b/app/controllers/concerns/commentable_actions.rb index 826d90da9..f3aadc2f7 100644 --- a/app/controllers/concerns/commentable_actions.rb +++ b/app/controllers/concerns/commentable_actions.rb @@ -16,7 +16,7 @@ module CommentableActions index_customization if index_customization.present? @tag_cloud = tag_cloud - @banners = Banner.with_active + @banners = Banner.in_section(section(resource_model.name)).with_active set_resource_votes(@resources) @@ -114,4 +114,13 @@ module CommentableActions nil end + def section(resource_name) + case resource_name + when "Proposal" + 'proposals' + when "Debate" + 'debates' + end + end + end diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 654fe2ff8..5ea596f9a 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -3,6 +3,7 @@ class PagesController < ApplicationController def show @custom_page = SiteCustomization::Page.published.find_by(slug: params[:id]) + @banners = Banner.in_section('help_page').with_active if @custom_page.present? render action: :custom_page diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 1ac4fd51a..8d19394d7 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -8,6 +8,7 @@ class WelcomeController < ApplicationController @header = Widget::Card.header.first @feeds = Widget::Feed.active @cards = Widget::Card.body + @banners = Banner.in_section('homepage').with_active end def welcome diff --git a/app/helpers/banners_helper.rb b/app/helpers/banners_helper.rb index b8b5864c9..3e78764a9 100644 --- a/app/helpers/banners_helper.rb +++ b/app/helpers/banners_helper.rb @@ -4,4 +4,4 @@ module BannersHelper @banners.present? && @banners.count > 0 end -end \ No newline at end of file +end diff --git a/app/models/banner.rb b/app/models/banner.rb index 8e816d446..26d683e9c 100644 --- a/app/models/banner.rb +++ b/app/models/banner.rb @@ -7,13 +7,15 @@ class Banner < ActiveRecord::Base length: { minimum: 2 } validates :description, presence: true validates :target_url, presence: true - validates :style, presence: true - validates :image, presence: true validates :post_started_at, presence: true validates :post_ended_at, presence: true + has_many :sections + has_many :web_sections, through: :sections + scope :with_active, -> { where("post_started_at <= ?", Time.current).where("post_ended_at >= ?", Time.current) } scope :with_inactive, -> { where("post_started_at > ? or post_ended_at < ?", Time.current, Time.current) } + scope :in_section, ->(section_name) { joins(:web_sections, :sections).where("web_sections.name ilike ?", section_name) } end diff --git a/app/models/banner/section.rb b/app/models/banner/section.rb new file mode 100644 index 000000000..493093731 --- /dev/null +++ b/app/models/banner/section.rb @@ -0,0 +1,4 @@ +class Banner::Section < ActiveRecord::Base + belongs_to :banner + belongs_to :web_section +end diff --git a/app/models/web_section.rb b/app/models/web_section.rb new file mode 100644 index 000000000..ffeca96f2 --- /dev/null +++ b/app/models/web_section.rb @@ -0,0 +1,4 @@ +class WebSection < ActiveRecord::Base + has_many :sections + has_many :banners, through: :sections +end diff --git a/app/views/admin/banners/_form.html.erb b/app/views/admin/banners/_form.html.erb index 9c8d20612..d9ab0e609 100644 --- a/app/views/admin/banners/_form.html.erb +++ b/app/views/admin/banners/_form.html.erb @@ -3,18 +3,8 @@ <%= render 'errors' %>