Admin option to add banners and show banners

This commit is contained in:
MaiteHdezRivas
2016-05-19 12:47:50 +02:00
parent b375e696c0
commit 3b2bfc46cf
41 changed files with 760 additions and 6 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View File

@@ -23,6 +23,8 @@ App.AdvancedSearch =
$('.js-calendar').datepicker
regional: locale
maxDate: "+0d"
$('.js-calendar-full').datepicker
regional: locale
initialize: ->
App.AdvancedSearch.init_calendar()

View File

@@ -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(){

View File

@@ -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())

View File

@@ -106,6 +106,7 @@ body.admin {
a {
color: white\9 !important;
color: red\9 !important;
}
ul {

View File

@@ -13,3 +13,4 @@
@import "annotator_overrides";
@import "jquery-ui/datepicker";
@import "datepicker_overrides";
@import "banners";

View File

@@ -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%;
}
}
}

View File

@@ -51,7 +51,7 @@
border-right: 1px solid $dark;
tr th {
color: white;
color: $dark;
}
}

View File

@@ -77,6 +77,7 @@ $budget: #454372;
$budget-hover: #7571BF;
$highlight: #E7F2FC;
$highlight-dark: #33DADF;
$featured: #FED900;
$footer-bg: #DEE0E2;

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,5 @@
module BannersHelper
def has_banners
@banners.count > 0
end
end

View File

@@ -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

View File

@@ -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

20
app/models/banner.rb Normal file
View File

@@ -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

View File

@@ -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

View File

@@ -43,6 +43,13 @@
</li>
<% end %>
<li <%= "class=active" if controller_name == "banners" %>>
<%= link_to admin_banners_path do %>
<span class="icon-eye"></span>
<%= t("admin.menu.banner") %>
<% end %>
</li>
<li <%= "class=active" if controller_name == "users" %>>
<%= link_to admin_users_path do %>
<span class="icon-eye"></span>

View File

@@ -0,0 +1,15 @@
<% if @banner.errors.any? %>
<div id="error_explanation" data-alert class="callout alert" data-closable>
<button class="close-button" aria-label="<%= t("application.close") %>" type="button" data-close>
<span aria-hidden="true">&times;</span>
</button>
<strong>
<%= @banner.errors.count %>
<%= t("admin.banners.errors.form.error", count: @banner.errors.count) %>
</strong>
</div>
<% end %>

View File

@@ -0,0 +1,69 @@
<%= form_for [:admin, @banner] do |f| %>
<%= render 'errors' %>
<div class="row">
<div class="small-3 column">
<%= f.label :style, t("admin.banners.banner.style") %>
<%= f.select :style, options_for_select(@banner_styles, @banner.style),:include_blank => '-',
label: false,placeholder: t("admin.banners.banner.style") %>
</div>
<div class="small-3 column">
<%= f.label :image, t("admin.banners.banner.image") %>
<%= f.select :image, options_for_select(@banner_imgs, @banner.image),:include_blank => '-',
label: false, placeholder: t("admin.banners.banner.image") %>
</div>
<div class="small-12 column">
<%= f.label :title, t("admin.banners.banner.title") %>
<%= f.text_field :title, placeholder: t("admin.banners.banner.title"), label: false,
data: {js_banner_title: "js_banner_title"} %>
</div>
<div class="small-12 column">
<%= f.label :description, t("admin.banners.banner.description") %>
<%= f.text_field :description,
label: false,
data: {js_banner_description: "js_banner_description"},
placeholder: t("admin.banners.banner.description") %>
</div>
<div class="small-12 column">
<%= f.label :target_url, t("admin.banners.banner.target_url") %>
<%= f.text_field :target_url,
label: false,
placeholder: t("admin.banners.banner.target_url") %>
</div>
<% date_started_at = @banner.post_started_at.present? ? I18n.localize(@banner.post_started_at) : "" %>
<div class="small-3 column">
<%= f.label :post_started_at, t("admin.banners.banner.post_started_at") %>
<%= f.text_field :post_started_at,
label: false,
placeholder: t("admin.banners.banner.post_started_at"),
value: date_started_at,
class: "js-calendar-full",
id: "post_started_at" %>
</div>
<% date_ended_at = @banner.post_ended_at.present? ? I18n.localize(@banner.post_ended_at) : ""%>
<div class="small-3 column">
<%= f.label :post_ended_at, t("admin.banners.banner.post_ended_at") %>
<%= f.text_field :post_ended_at,
label: false,
placeholder: t("admin.banners.banner.post_ended_at"),
value: date_ended_at,
class: "js-calendar-full",
id: "post_ended_at" %>
</div>
<div class="actions small-12 column">
<%= f.submit(class: "button", value: t("admin.banners.edit.form.submit_button")) %>
</div>
</div>
<div id="js-banner-style" class="<%= @banner.style %>">
<div id="js-banner-image" class="<%= @banner.image %>">
<%= link_to @banner.target_url do %>
<h2 id="js-banner-title"><%= @banner.title %></h2>
<h3 id="js-banner-description"><%= @banner.description %></h3>
<% end %>
</div>
</div>
<% end %>

View File

@@ -0,0 +1,13 @@
<div class="banner-edit row">
<div class="small-12 column">
<%= link_to admin_banners_path, class: "back" do %>
<span class="icon-angle-left"></span>
<%= t("admin.banners.edit.back") %>
<% end %>
<h1><%= t("admin.banners.edit.editing") %></h1>
<%= render "form" %>
</div>
</div>

View File

@@ -0,0 +1,45 @@
<%= link_to t("admin.banners.index.create"),
new_admin_banner_path, class: "button large success float-right" %>
<h2 class="inline-block"><%= t("admin.banners.index.title") %></h2>
<%= render 'shared/filter_subnav', i18n_namespace: "admin.banners.index" %>
<h3><%= page_entries_info @banners %></h3>
<table>
<% @banners.each do |banner| %>
<tr id="<%= dom_id(banner) %>">
<td class="samll-12 medium-9">
<div class="<%= banner.style %>">
<div class="<%= banner.image %>">
<%= link_to banner.target_url do %>
<h2><%= banner.title %></h2>
<h3><%= banner.description %></h3>
<% end %>
</div>
</div>
<%= t("admin.banners.banner.post_started_at")%> <strong><%= banner.post_started_at %></strong>
&nbsp;|&nbsp;
<%= t("admin.banners.banner.post_ended_at")%> <strong><%= banner.post_ended_at%></strong>
</td>
<td class="text-center">
<%= link_to edit_admin_banner_path(banner),
class: 'edit-banner button' do %>
<span class="icon-edit"></span>
<%= t("admin.banners.index.edit") %>
<% end %>
</td>
<td>
<%= link_to admin_banner_path(banner), method: :delete,
class: 'delete' do %>
<span class="icon-delete"></span>
<%= t("admin.banners.index.delete") %>
<% end %>
</td>
</tr>
<% end %>
</table>
<%= paginate @banners %>

View File

@@ -0,0 +1,13 @@
<div class="banner-new row">
<div class="small-12 column">
<%= link_to admin_banners_path, class: "back" do %>
<span class="icon-angle-left"></span>
<%= t("admin.banners.new.back") %>
<% end %>
<h1><%= t("admin.banners.new.creating") %></h1>
<%= render "form" %>
</div>
</div>

View File

@@ -32,3 +32,37 @@
</li>
<% end %>
</ul>
<% if @banner_styles.present? %>
<h2><%= t("admin.settings.index.banners") %></h2>
<ul class="admin-list">
<% @banner_styles.each do |setting| %>
<li>
<strong><%= t("settings.#{setting.key}") %></strong>
<%= form_for(setting, url: admin_setting_path(setting), html: { id: "edit_#{dom_id(setting)}"}) do |f| %>
<%= f.text_area :value, label: false, id: dom_id(setting), lines: 1 %>
<%= f.submit(t('admin.settings.index.update_setting'), class: "button small success") %>
<% end %>
</li>
<% end %>
</ul>
<% end %>
<% if @banner_imgs.present?%>
<h2><%= t("admin.settings.index.banner_imgs") %></h2>
<ul class="admin-list">
<% @banner_imgs.each do |setting| %>
<li>
<strong><%= t("settings.#{setting.key}") %></strong>
<%= form_for(setting, url: admin_setting_path(setting), html: { id: "edit_#{dom_id(setting)}"}) do |f| %>
<%= f.text_area :value, label: false, id: dom_id(setting), lines: 1 %>
<%= f.submit(t('admin.settings.index.update_setting'), class: "button small success") %>
<% end %>
</li>
<% end %>
</ul>
<% end %>

View File

@@ -25,6 +25,10 @@
<% end %>
</div>
<% if has_banners %>
<%= render "shared/banner" %>
<% end %>
<% unless @tag_filter || @search_terms || !has_featured? %>
<%= render "featured_debates" %>
<% end %>

View File

@@ -27,6 +27,10 @@
<% end %>
</div>
<% if has_banners %>
<%= render "shared/banner" %>
<% end %>
<% if @featured_proposals.present? %>
<div id="featured-proposals" class="row featured-proposals">
<div class="small-12 column">

View File

@@ -0,0 +1,9 @@
<% banner = @banners.sample%>
<div class="<%= banner.style %>">
<div class="<%= banner.image %>">
<%= link_to banner.target_url do %>
<h2><%=banner.title%></h2>
<h3><%=banner.description%></h3>
<% end %>
</div>
</div>

View File

@@ -107,6 +107,7 @@ ignore_unused:
- 'unauthorized.*'
- 'admin.officials.level_*'
- 'admin.comments.index.filter*'
- 'admin.banners.index.filters.*'
- 'admin.debates.index.filter*'
- 'admin.proposals.index.filter*'
- 'admin.spending_proposals.index.filter*'

View File

@@ -9,6 +9,39 @@ en:
restore: Restore
mark_featured: Featured
unmark_featured: Unmark featured
banners:
index:
title: Post banners
create: Create a banner
edit: Edit a banner
delete: Delete a banner
filters:
all: Todos
with_active: Actives
with_inactive: Inactives
banner:
title: Title
description: Description
target_url: Link
style: Style
image: Image
post_started_at: Post started at
post_ended_at: Post ended at
edit:
back: Back
editing: Edit banner
form:
submit_button: Save changes
errors:
form:
errors:
form:
error:
one: "prevented this banner from being saved"
other: 'prevented this banner from being saved'
new:
back: Back
creating: Create banner
activity:
show:
action: Action
@@ -59,6 +92,7 @@ en:
user_not_found: User not found
menu:
activity: Moderator activity
banner: Publish banner
debate_topics: Debate topics
hidden_comments: Hidden comments
hidden_debates: Hidden debates
@@ -155,6 +189,8 @@ en:
flash:
updated: Value updated
index:
banners: Estilos de banners
banner_imgs: Imágenes para los banners
title: Configuration settings
update_setting: Update
feature_flags: Features

View File

@@ -9,6 +9,37 @@ es:
restore: Volver a mostrar
mark_featured: Destacar
unmark_featured: Quitar destacado
banners:
index:
title: Publicar anuncios
create: Crear un banner
edit: Editar banner
delete: Eliminar banner
filters:
all: Todos
with_active: Activos
with_inactive: Inactivos
banner:
title: Título
description: Descripción
target_url: Enlace
style: Estilo
image: Imagen
post_started_at: Inicio de publicación
post_ended_at: Fin de publicación
edit:
back: Volver
editing: Editar el banner
form:
submit_button: Guardar Cambios
errors:
form:
error:
one: "error impidió guardar el banner"
other: "errores impidieron guardar el banner."
new:
back: Volver
creating: Crear banner
activity:
show:
action: Acción
@@ -59,6 +90,7 @@ es:
user_not_found: Usuario no encontrado
menu:
activity: Actividad de moderadores
banner: Publicar banner
debate_topics: Temas de debate
hidden_comments: Comentarios ocultos
hidden_debates: Debates ocultos
@@ -155,6 +187,8 @@ es:
flash:
updated: Valor actualizado
index:
banners: Banner style
banner_imgs: Banner images
title: Configuración global
update_setting: Actualizar
feature_flags: Funcionalidades

View File

@@ -143,6 +143,10 @@ Rails.application.routes.draw do
get :summary, on: :collection
end
resources :banners, only: [:index, :new, :create, :edit, :update, :destroy] do
collection { get :search}
end
resources :comments, only: :index do
member do
put :restore

View File

@@ -318,3 +318,21 @@ puts "Confirming hiding in debates, comments & proposals"
Comment.only_hidden.flagged.reorder("RANDOM()").limit(10).each(&:confirm_hide)
Debate.only_hidden.flagged.reorder("RANDOM()").limit(5).each(&:confirm_hide)
Proposal.only_hidden.flagged.reorder("RANDOM()").limit(5).each(&:confirm_hide)
puts "Creating banners"
Proposal.last(3).each do |proposal|
title = Faker::Lorem.sentence(word_count = 3)
description = Faker::Lorem.sentence(word_count = 12)
banner = Banner.create!(title: title,
description: description,
style: ["banner-style.banner-style-one", "banner-style.banner-style-two",
"banner-style.banner-style-three"].sample,
image: ["banner-img.banner-img-one", "banner-img.banner-img-two",
"banner-img.banner-img-three"].sample,
target_url: Rails.application.routes.url_helpers.proposal_path(proposal),
post_started_at: rand((Time.now - 1.week) .. (Time.now - 1.day)),
post_ended_at: rand((Time.now - 1.day) .. (Time.now + 1.week)),
created_at: rand((Time.now - 1.week) .. Time.now))
puts " #{banner.title}"
end

View File

@@ -0,0 +1,18 @@
class CreateBanners < ActiveRecord::Migration
def change
create_table :banners do |t|
t.string :title, limit: 80
t.string :description
t.string :target_url
t.string :style
t.string :image
t.date :post_started_at
t.date :post_ended_at
t.datetime :hidden_at
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index :banners, :hidden_at
end
end

View File

@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160510161858) do
ActiveRecord::Schema.define(version: 20160518141543) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -63,6 +63,21 @@ ActiveRecord::Schema.define(version: 20160510161858) do
add_index "annotations", ["legislation_id"], name: "index_annotations_on_legislation_id", using: :btree
add_index "annotations", ["user_id"], name: "index_annotations_on_user_id", using: :btree
create_table "banners", force: :cascade do |t|
t.string "title", limit: 80
t.string "description"
t.string "target_url"
t.string "style"
t.string "image"
t.date "post_started_at"
t.date "post_ended_at"
t.datetime "hidden_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "banners", ["hidden_at"], name: "index_banners_on_hidden_at", using: :btree
create_table "campaigns", force: :cascade do |t|
t.string "name"
t.string "track_id"
@@ -235,6 +250,21 @@ ActiveRecord::Schema.define(version: 20160510161858) do
add_index "notifications", ["user_id"], name: "index_notifications_on_user_id", using: :btree
create_table "open_answers", force: :cascade do |t|
t.text "text"
t.integer "question_code"
t.integer "user_id"
t.integer "survey_code"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "cached_votes_total", default: 0
t.integer "cached_votes_up", default: 0
t.integer "cached_votes_down", default: 0
t.integer "confidence_score", default: 0
end
add_index "open_answers", ["user_id"], name: "index_open_answers_on_user_id", using: :btree
create_table "organizations", force: :cascade do |t|
t.integer "user_id"
t.string "name", limit: 60
@@ -285,6 +315,16 @@ ActiveRecord::Schema.define(version: 20160510161858) do
add_index "proposals", ["title"], name: "index_proposals_on_title", using: :btree
add_index "proposals", ["tsv"], name: "index_proposals_on_tsv", using: :gin
create_table "redeemable_codes", force: :cascade do |t|
t.string "token"
t.integer "geozone_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "redeemable_codes", ["geozone_id"], name: "index_redeemable_codes_on_geozone_id", using: :btree
add_index "redeemable_codes", ["token"], name: "index_redeemable_codes_on_token", using: :btree
create_table "settings", force: :cascade do |t|
t.string "key"
t.string "value"
@@ -313,7 +353,7 @@ ActiveRecord::Schema.define(version: 20160510161858) do
t.integer "price_first_year", limit: 8
t.string "time_scope"
t.datetime "unfeasible_email_sent_at"
t.integer "cached_votes_up", default: 0
t.integer "cached_votes_up"
t.tsvector "tsv"
t.string "responsible_name", limit: 60
t.integer "physical_votes", default: 0
@@ -323,6 +363,16 @@ ActiveRecord::Schema.define(version: 20160510161858) do
add_index "spending_proposals", ["geozone_id"], name: "index_spending_proposals_on_geozone_id", using: :btree
add_index "spending_proposals", ["tsv"], name: "index_spending_proposals_on_tsv", using: :gin
create_table "survey_answers", force: :cascade do |t|
t.string "survey_code"
t.json "answers"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "survey_answers", ["user_id"], name: "index_survey_answers_on_user_id", using: :btree
create_table "taggings", force: :cascade do |t|
t.integer "tag_id"
t.integer "taggable_id"
@@ -520,6 +570,7 @@ ActiveRecord::Schema.define(version: 20160510161858) do
add_foreign_key "moderators", "users"
add_foreign_key "notifications", "users"
add_foreign_key "organizations", "users"
add_foreign_key "survey_answers", "users"
add_foreign_key "users", "geozones"
add_foreign_key "valuators", "users"
end

View File

@@ -64,3 +64,14 @@ Setting['feature.public_stats'] = true
# Spending proposals feature flags
Setting['feature.spending_proposal_features.voting_allowed'] = true
# Banner styles
Setting['banner-style.banner-style-one'] = "Banner con estilo uno"
Setting['banner-style.banner-style-two'] = "Banner con estilo dos"
Setting['banner-style.banner-style-three'] = "Banner con estilo tres"
# Banner images
Setting['banner-img.banner-img-one'] = "Banner con imagen uno"
Setting['banner-img.banner-img-two'] = "Banner con imagen dos"
Setting['banner-img.banner-img-three'] = "Banner con imagen tres"

View File

@@ -316,4 +316,14 @@ FactoryGirl.define do
sequence(:name) { |n| "District #{n}" }
census_code { '01' }
end
factory :banner do
sequence(:title) { |n| "Banner title #{n}" }
sequence(:description) { |n| "This is the text of Banner #{n}" }
style {["banner-style-one", "banner-style-two", "banner-style-three"].sample}
image {["banner.banner-img-one", "banner.banner-img-two", "banner.banner-img-three"].sample}
target_url {["/proposals", "/debates" ].sample}
post_started_at Time.now - 7.days
post_ended_at Time.now + 7.days
end
end

View File

@@ -0,0 +1,105 @@
require 'rails_helper'
feature 'Admin add banners' do
background do
@banner1 = create(:banner, title: "Banner number one",
description: "This is the text of banner number one and is not active yet",
target_url: "http://www.url.com",
style: "banner-style.banner-one",
image: "banner-img.banner-one",
post_started_at: (Time.now + 4.days),
post_ended_at: (Time.now + 10.days))
@banner2 = create(:banner, title: "Banner number two",
description: "This is the text of banner number two and is not longer active",
target_url: "http://www.url.com",
style: "banner-style.banner-two",
image: "banner-img.banner-two",
post_started_at: (Time.now - 10.days),
post_ended_at: (Time.now - 3.days))
@banner3 = create(:banner, title: "Banner number three",
description: "This is the text of banner number three and has style banner-three",
target_url: "http://www.url.com",
style: "banner-style.banner-three",
image: "banner-img.banner-three",
post_started_at: (Time.now - 1.days),
post_ended_at: (Time.now + 10.days))
@banner4 = create(:banner, title: "Banner number four",
description: "This is the text of banner number four and has style banner-one",
target_url: "http://www.url.com",
style: "banner-style.banner-one",
image: "banner-img.banner-one",
post_started_at: (DateTime.now - 10.days),
post_ended_at: (DateTime.now + 10.days))
@banner5 = create(:banner, title: "Banner number five",
description: "This is the text of banner number five and has style banner-two",
target_url: "http://www.url.com",
style: "banner-style.banner-one",
image: "banner-img.banner-one",
post_started_at: (DateTime.now - 10.days),
post_ended_at: (DateTime.now + 10.days))
login_as(create(:administrator).user)
end
scenario 'option publish banners is listed on admin menu' do
visit admin_root_path
within('#admin_menu') do
expect(page).to have_link "Publish banner"
end
end
scenario 'index show active banners' do
visit admin_banners_path(filter: 'with_active')
expect(page).to have_content("There are 3 banners")
end
scenario 'index show inactive banners' do
visit admin_banners_path(filter: 'with_inactive')
expect(page).to have_content("There are 2 banners")
end
scenario 'index show all banners' do
visit admin_banners_path
expect(page).to have_content("There are 5 banners")
end
scenario 'refresh changes on edit banner', :js do
visit edit_admin_banner_path(@banner1)
fill_in 'banner_title', with: 'Titulo modificado'
fill_in 'banner_description', with: 'Texto modificado'
within('div#js-banner-style') do
expect(page).to have_selector('h2', :text => 'Titulo modificado')
expect(page).to have_selector('h3', :text => 'Texto modificado')
end
end
scenario 'refresh changes on edit banner', :js do
visit edit_admin_banner_path(@banner1)
fill_in 'banner_title', with: 'Titulo modificado'
fill_in 'banner_description', with: 'Texto modificado'
within('div#js-banner-style') do
expect(page).to have_selector('h2', :text => 'Titulo modificado')
expect(page).to have_selector('h3', :text => 'Texto modificado')
end
end
scenario 'option Publish banners is listed on admin menu' do
visit admin_banners_path
within('#admin_menu') do
expect(page).to have_link "Publish banner"
end
end
end

View File

@@ -54,4 +54,28 @@ describe Setting do
expect(setting.enabled?).to eq false
end
end
describe "#banner_style?" do
it "should be true if key starts with 'banner-style.'" do
setting = Setting.create(key: 'banner-style.whatever')
expect(setting.banner_style?).to eq true
end
it "should be false if key does not start with 'banner-style.'" do
setting = Setting.create(key: 'whatever')
expect(setting.banner_style?).to eq false
end
end
describe "#banner_img?" do
it "should be true if key starts with 'banner-img.'" do
setting = Setting.create(key: 'banner-img.whatever')
expect(setting.banner_img?).to eq true
end
it "should be false if key does not start with 'banner-img.'" do
setting = Setting.create(key: 'whatever')
expect(setting.banner_img?).to eq false
end
end
end