diff --git a/app/assets/images/banners/banner1.png b/app/assets/images/banners/banner1.png new file mode 100644 index 000000000..eff1cb9d7 Binary files /dev/null and b/app/assets/images/banners/banner1.png differ diff --git a/app/assets/images/banners/banner2.png b/app/assets/images/banners/banner2.png new file mode 100644 index 000000000..5b31f5a3a Binary files /dev/null and b/app/assets/images/banners/banner2.png differ diff --git a/app/assets/images/banners/banner3.png b/app/assets/images/banners/banner3.png new file mode 100644 index 000000000..dca89fe49 Binary files /dev/null and b/app/assets/images/banners/banner3.png differ diff --git a/app/assets/images/banners/banner4.png b/app/assets/images/banners/banner4.png new file mode 100644 index 000000000..e3622b8f1 Binary files /dev/null and b/app/assets/images/banners/banner4.png differ diff --git a/app/assets/javascripts/advanced_search.js.coffee b/app/assets/javascripts/advanced_search.js.coffee index a5e657633..b38efb874 100644 --- a/app/assets/javascripts/advanced_search.js.coffee +++ b/app/assets/javascripts/advanced_search.js.coffee @@ -23,6 +23,8 @@ App.AdvancedSearch = $('.js-calendar').datepicker regional: locale maxDate: "+0d" + $('.js-calendar-full').datepicker + regional: locale initialize: -> App.AdvancedSearch.init_calendar() diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index e24d144bb..a1b8dd70a 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -44,6 +44,7 @@ //= require tracks //= require valuation_spending_proposal_form //= require embed_video +//= require banners var initialize_modules = function() { App.Comments.initialize(); @@ -63,6 +64,7 @@ var initialize_modules = function() { App.Tracks.initialize(); App.ValuationSpendingProposalForm.initialize(); App.EmbedVideo.initialize(); + App.Banners.initialize(); }; $(function(){ diff --git a/app/assets/javascripts/banners.js.coffee b/app/assets/javascripts/banners.js.coffee new file mode 100644 index 000000000..ec00abe95 --- /dev/null +++ b/app/assets/javascripts/banners.js.coffee @@ -0,0 +1,25 @@ +App.Banners = + + update_banner: (selector, text) -> + $(selector).html(text) + + update_style: (selector, style) -> + $(selector).removeClass($(selector).attr("class"), true) + .addClass(style, true) + + initialize: -> + $('[data-js-banner-title]').on + change: -> + App.Banners.update_banner("#js-banner-title", $(this).val()) + + $('[data-js-banner-description]').on + change: -> + App.Banners.update_banner("#js-banner-description", $(this).val()) + + $("#banner_style").on + change: -> + App.Banners.update_style("#js-banner-style", $(this).val()) + + $("#banner_image").on + change: -> + App.Banners.update_style("#js-banner-image", $(this).val()) diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index 48642841d..0def1c8a5 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -106,6 +106,7 @@ body.admin { a { color: white\9 !important; + color: red\9 !important; } ul { diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 71e74c251..92ae33b74 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -13,3 +13,4 @@ @import "annotator_overrides"; @import "jquery-ui/datepicker"; @import "datepicker_overrides"; +@import "banners"; diff --git a/app/assets/stylesheets/banners.scss b/app/assets/stylesheets/banners.scss new file mode 100644 index 000000000..a14ce6257 --- /dev/null +++ b/app/assets/stylesheets/banners.scss @@ -0,0 +1,69 @@ +// Place all the styles related to the banner controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ + +// 01. Banners +// - - - - - - - - - - - - - - - - - - - - - - - - - + +.banner-style-one { + background-color: $brand; +} + +.banner-style-two { + background-color: $budget; +} + +.banner-style-three { + background-color: #33DADF; +} + +@media (min-width: $medium-breakpoint) { + + .banner-img-one { + background-image: image-url('banners/banner1.png'); + } + + .banner-img-two { + background-image: image-url('banners/banner2.png'); + } + + .banner-img-three { + background-image: image-url('banners/banner3.png'); + } +} + +.banner-img-one, .banner-img-two, .banner-img-three { + background-position: bottom right; + background-repeat: no-repeat; +} + +.banner-style-one, .banner-style-two, .banner-style-three { + margin: 0; + margin-bottom: $line-height; + + h2, h3, a { + color: #eaeaf2; + } + + h2 { + padding: $line-height/2; + padding-bottom: 0; + } + + h3 { + padding: $line-height/2; + padding-top: 0; + } + + a:hover h2, a:hover h3 { + color: #eaeaf2 !important; + text-decoration: none; + } + + @media (min-width: $medium-breakpoint) { + + h3 { + width: 80%; + } + } +} \ No newline at end of file diff --git a/app/assets/stylesheets/datepicker_overrides.scss b/app/assets/stylesheets/datepicker_overrides.scss index abab720e0..9e6419243 100644 --- a/app/assets/stylesheets/datepicker_overrides.scss +++ b/app/assets/stylesheets/datepicker_overrides.scss @@ -51,7 +51,7 @@ border-right: 1px solid $dark; tr th { - color: white; + color: $dark; } } diff --git a/app/assets/stylesheets/variables.scss b/app/assets/stylesheets/variables.scss index 5d59ebf8f..9c621fbd2 100644 --- a/app/assets/stylesheets/variables.scss +++ b/app/assets/stylesheets/variables.scss @@ -77,6 +77,7 @@ $budget: #454372; $budget-hover: #7571BF; $highlight: #E7F2FC; +$highlight-dark: #33DADF; $featured: #FED900; $footer-bg: #DEE0E2; diff --git a/app/controllers/admin/banners_controller.rb b/app/controllers/admin/banners_controller.rb new file mode 100644 index 000000000..dbf683b9a --- /dev/null +++ b/app/controllers/admin/banners_controller.rb @@ -0,0 +1,56 @@ +class Admin::BannersController < Admin::BaseController + + has_filters %w{all with_active with_inactive}, only: :index + + before_action :find_banner, only: [:edit, :update, :destroy] + before_action :banner_styles, only: [:edit, :new, :create, :update] + before_action :banner_imgs, only: [:edit, :new, :create, :update] + + respond_to :html, :js + + load_and_authorize_resource + + def index + @banners = Banner.send(@current_filter).page(params[:page]) + end + + def create + @banner = Banner.new(banner_params) + if @banner.save + redirect_to admin_banners_path + else + render :new + end + end + + def update + @banner.assign_attributes(banner_params) + if @banner.update(banner_params) + redirect_to admin_banners_path + else + render :edit + end + end + + def destroy + @banner.destroy + redirect_to admin_banners_path + end + + private + def banner_params + params.require(:banner).permit(:title, :description, :target_url, :style, :image, :post_started_at, :post_ended_at) + end + + def find_banner + @banner = Banner.find(params[:id]) + end + + def banner_styles + @banner_styles = Setting.all.banner_style.map { |banner_style| [banner_style.value, banner_style.key.split('.')[1]] } + end + + def banner_imgs + @banner_imgs = Setting.all.banner_img.map { |banner_img| [banner_img.value, banner_img.key.split('.')[1]] } + end +end \ No newline at end of file diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb index 387f38177..17bd364f3 100644 --- a/app/controllers/admin/settings_controller.rb +++ b/app/controllers/admin/settings_controller.rb @@ -1,9 +1,11 @@ class Admin::SettingsController < Admin::BaseController def index - all_settings = (Setting.all).group_by { |s| s.feature_flag? } - @settings = all_settings[false] - @feature_flags = all_settings[true] + all_settings = (Setting.all).group_by { |s| s.type } + @settings = all_settings['common'] + @feature_flags = all_settings['feature'] + @banner_styles = all_settings['banner-style'] + @banner_imgs = all_settings['banner-img'] end def update diff --git a/app/controllers/concerns/commentable_actions.rb b/app/controllers/concerns/commentable_actions.rb index de2a2276a..3a79238ea 100644 --- a/app/controllers/concerns/commentable_actions.rb +++ b/app/controllers/concerns/commentable_actions.rb @@ -11,6 +11,8 @@ module CommentableActions index_customization if index_customization.present? @tag_cloud = tag_cloud + @banners = Banner.with_active + set_resource_votes(@resources) set_resources_instance end diff --git a/app/helpers/banners_helper.rb b/app/helpers/banners_helper.rb new file mode 100644 index 000000000..548513c7d --- /dev/null +++ b/app/helpers/banners_helper.rb @@ -0,0 +1,5 @@ +module BannersHelper + def has_banners + @banners.count > 0 + end +end \ No newline at end of file diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index 6b77c130d..0dfce6d3e 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -42,6 +42,7 @@ module Abilities can :manage, Annotation can [:read, :update, :destroy, :summary], SpendingProposal + can [:search, :edit, :update, :create, :index, :destroy], Banner end end end diff --git a/app/models/abilities/banner.rb b/app/models/abilities/banner.rb new file mode 100644 index 000000000..db8f10635 --- /dev/null +++ b/app/models/abilities/banner.rb @@ -0,0 +1,20 @@ +class Banner < ActiveRecord::Base + + acts_as_paranoid column: :hidden_at + include ActsAsParanoidAliases + + validates :title, presence: true, + 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 + + scope :with_active, -> {where("post_started_at <= ?", Time.now). + where("post_ended_at >= ?", Time.now) } + + scope :with_inactive,-> {where("post_started_at > ? or post_ended_at < ?", Time.now, Time.now) } + +end \ No newline at end of file diff --git a/app/models/banner.rb b/app/models/banner.rb new file mode 100644 index 000000000..db8f10635 --- /dev/null +++ b/app/models/banner.rb @@ -0,0 +1,20 @@ +class Banner < ActiveRecord::Base + + acts_as_paranoid column: :hidden_at + include ActsAsParanoidAliases + + validates :title, presence: true, + 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 + + scope :with_active, -> {where("post_started_at <= ?", Time.now). + where("post_ended_at >= ?", Time.now) } + + scope :with_inactive,-> {where("post_started_at > ? or post_ended_at < ?", Time.now, Time.now) } + +end \ No newline at end of file diff --git a/app/models/setting.rb b/app/models/setting.rb index 40659ed74..9010abba5 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -2,6 +2,20 @@ class Setting < ActiveRecord::Base validates :key, presence: true, uniqueness: true default_scope { order(id: :asc) } + scope :banner_style, -> { where("key ilike ?", "banner-style.%")} + scope :banner_img, -> { where("key ilike ?", "banner-img.%")} + + def type + if feature_flag? + 'feature' + elsif banner_style? + 'banner-style' + elsif banner_img? + 'banner-img' + else + 'common' + end + end def feature_flag? key.start_with?('feature.') @@ -11,6 +25,14 @@ class Setting < ActiveRecord::Base feature_flag? && value.present? end + def banner_style? + key.start_with?('banner-style.') + end + + def banner_img? + key.start_with?('banner-img.') + end + class << self def [](key) where(key: key).pluck(:value).first.presence diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index bf0382dbd..f8437906f 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb @@ -43,6 +43,13 @@ <% end %> +
| + + + <%= t("admin.banners.banner.post_started_at")%> <%= banner.post_started_at %> + | + <%= t("admin.banners.banner.post_ended_at")%> <%= banner.post_ended_at%> + | ++ <%= link_to edit_admin_banner_path(banner), + class: 'edit-banner button' do %> + + <%= t("admin.banners.index.edit") %> + <% end %> + | ++ <%= link_to admin_banner_path(banner), method: :delete, + class: 'delete' do %> + + <%= t("admin.banners.index.delete") %> + <% end %> + | +