Merge branch 'select_debates_which_display_as_featured' of https://github.com/MaiteHdezRivas/consul into MaiteHdezRivas-select_debates_which_display_as_featured

Conflicts:
	db/schema.rb
This commit is contained in:
Alberto Garcia Cabeza
2016-04-05 14:05:27 +02:00
15 changed files with 107 additions and 22 deletions

View File

@@ -28,6 +28,16 @@ class DebatesController < ApplicationController
set_debate_votes(@debate) set_debate_votes(@debate)
end end
def remove_feature
@debate.update_attribute(:featured_at, nil)
redirect_to request.query_parameters.merge(action: :index)
end
def feature
@debate.update_attribute(:featured_at, Time.now)
redirect_to request.query_parameters.merge(action: :index)
end
private private
def debate_params def debate_params

View File

@@ -0,0 +1,6 @@
module DebatesHelper
def has_featured
Debate.all.featured.count > 0
end
end

View File

@@ -30,6 +30,10 @@ module Abilities
can :confirm_hide, User can :confirm_hide, User
cannot :confirm_hide, User, hidden_at: nil cannot :confirm_hide, User, hidden_at: nil
can :feature, Debate
can :remove_feature, Debate
can :comment_as_administrator, [Debate, Comment, Proposal] can :comment_as_administrator, [Debate, Comment, Proposal]
can [:search, :create, :index, :destroy], ::Moderator can [:search, :create, :index, :destroy], ::Moderator

View File

@@ -36,7 +36,8 @@ class Debate < ActiveRecord::Base
scope :sort_by_random, -> { reorder("RANDOM()") } scope :sort_by_random, -> { reorder("RANDOM()") }
scope :sort_by_relevance, -> { all } scope :sort_by_relevance, -> { all }
scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) } scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }
scope :last_week, -> { where("created_at >= ?", 7.days.ago)} scope :last_week, -> { where("created_at >= ?", 7.days.ago)}
scope :featured, -> { where("featured_at is not null")}
# Ahoy setup # Ahoy setup
visitable # Ahoy will automatically assign visit_id on create visitable # Ahoy will automatically assign visit_id on create
@@ -132,4 +133,8 @@ class Debate < ActiveRecord::Base
self.tags.each{ |t| t.increment_custom_counter_for('Debate') } self.tags.each{ |t| t.increment_custom_counter_for('Debate') }
end end
def featured?
! self.featured_at.nil?
end
end end

View File

@@ -25,7 +25,7 @@
<%= t("admin.menu.hidden_debates") %> <%= t("admin.menu.hidden_debates") %>
<% end %> <% end %>
</li> </li>
<% end %> <% end %>
<li <%= "class=active" if controller_name == "comments" %>> <li <%= "class=active" if controller_name == "comments" %>>
<%= link_to admin_comments_path do %> <%= link_to admin_comments_path do %>

View File

@@ -8,3 +8,14 @@
<%= link_to t("admin.actions.hide_author").capitalize, hide_moderation_user_path(debate.author_id), <%= link_to t("admin.actions.hide_author").capitalize, hide_moderation_user_path(debate.author_id),
method: :put, data: { confirm: t('admin.actions.confirm') } %> method: :put, data: { confirm: t('admin.actions.confirm') } %>
<% end %> <% end %>
<% if can? :feature, debate %>
&nbsp;|&nbsp;
<% if debate.featured? %>
<%= link_to t("admin.actions.remove_feature").capitalize, remove_feature_debate_path(debate),
method: :put, data: { confirm: t('admin.actions.confirm') } %>
<% else %>
<%= link_to t("admin.actions.feature").capitalize, feature_debate_path(debate),
method: :put, data: { confirm: t('admin.actions.confirm') } %>
<% end %>
<% end %>

View File

@@ -0,0 +1,13 @@
<div id="featured-debates" class="row featured-debates">
<div class="small-12 column">
<h2><%= t("debates.index.featured_debates") %></h2>
</div>
<% @debates.featured.each do |debate| %>
<div class="small-12 medium-6 column">
<h3><%= link_to debate.title, debate %></h3>
<%= link_to debate.author.name, user_path(debate.author)%>
</div>
<% end %>
</div>

View File

@@ -1,17 +0,0 @@
<div id="featured-debates" class="row featured-debates">
<div class="small-12 column">
<h2><%= t("debates.index.featured_debates") %></h2>
</div>
<div class="small-12 medium-6 column">
<h3><%= link_to "#Túpreguntas: Manuela Carmena, Alcaldesa de Madrid.", "https://decide.madrid.es/debates/4320" %></h3>
<%= link_to "Manuela Carmena ", "https://decide.madrid.es/users/21452"%>
</div>
<div class="small-12 medium-6 column">
<h3><%= link_to "¿Y si pudieras entrevistar a Manuela Carmena o a los otros concejales?", "https://decide.madrid.es/debates/4299" %></h3>
<%= link_to "ParticipaciónYTransparenciaAytoMadrid", "https://decide.madrid.es/users/52055"%>
</div>
</div>

View File

@@ -25,8 +25,8 @@
<% end %> <% end %>
</div> </div>
<% unless @tag_filter || @search_terms %> <% unless @tag_filter || @search_terms || !has_featured %>
<%= render "featured_debates_static" %> <%= render "featured_debates", debate: @debates.featured %>
<% end %> <% end %>
<%= render "shared/advanced_search", search_path: debates_path(page: 1) %> <%= render "shared/advanced_search", search_path: debates_path(page: 1) %>

View File

@@ -7,6 +7,8 @@ en:
hide: Hide hide: Hide
hide_author: Hide author hide_author: Hide author
restore: Restore restore: Restore
feature: Feature
remove_feature: Remove feature
activity: activity:
show: show:
action: Action action: Action
@@ -50,6 +52,7 @@ en:
debate_topics: Debate topics debate_topics: Debate topics
hidden_comments: Hidden comments hidden_comments: Hidden comments
hidden_debates: Hidden debates hidden_debates: Hidden debates
featured_debates: Featured debates
hidden_proposals: Hidden proposals hidden_proposals: Hidden proposals
hidden_users: Hidden users hidden_users: Hidden users
incomplete_verifications: Incomplete verifications incomplete_verifications: Incomplete verifications
@@ -233,4 +236,4 @@ en:
index: index:
phone_not_given: Phone not given phone_not_given: Phone not given
sms_code_not_confirmed: Has not confirmed the sms code sms_code_not_confirmed: Has not confirmed the sms code
title: Incomplete verifications title: Incomplete verifications

View File

@@ -7,6 +7,8 @@ es:
hide: Ocultar hide: Ocultar
hide_author: Bloquear al autor hide_author: Bloquear al autor
restore: Volver a mostrar restore: Volver a mostrar
feature: Destacar
remove_feature: Quitar destacado
activity: activity:
show: show:
action: Acción action: Acción
@@ -50,6 +52,7 @@ es:
debate_topics: Temas de debate debate_topics: Temas de debate
hidden_comments: Comentarios ocultos hidden_comments: Comentarios ocultos
hidden_debates: Debates ocultos hidden_debates: Debates ocultos
featured_debates: Debates destacados
hidden_proposals: Propuestas ocultas hidden_proposals: Propuestas ocultas
hidden_users: Usuarios bloqueados hidden_users: Usuarios bloqueados
incomplete_verifications: Verificaciones incompletas incomplete_verifications: Verificaciones incompletas

View File

@@ -36,6 +36,8 @@ Rails.application.routes.draw do
post :vote post :vote
put :flag put :flag
put :unflag put :unflag
put :remove_feature
put :feature
end end
collection do collection do
get :map get :map

View File

@@ -0,0 +1,5 @@
class AddFeaturedAtToDebates < ActiveRecord::Migration
def change
add_column :debates, :featured_at, :datetime
end
end

View File

@@ -120,6 +120,7 @@ ActiveRecord::Schema.define(version: 20160329160106) do
t.integer "confidence_score", default: 0 t.integer "confidence_score", default: 0
t.integer "geozone_id" t.integer "geozone_id"
t.tsvector "tsv" t.tsvector "tsv"
t.datetime "featured_at"
end end
add_index "debates", ["author_id", "hidden_at"], name: "index_debates_on_author_id_and_hidden_at", using: :btree add_index "debates", ["author_id", "hidden_at"], name: "index_debates_on_author_id_and_hidden_at", using: :btree

View File

@@ -1008,4 +1008,43 @@ feature 'Debates' do
end end
end end
end end
scenario 'Mark debate as featured' do
admin = create(:administrator)
login_as(admin.user)
debate1 = create(:debate)
debate2 = create(:debate, featured_at: Time.now)
visit debate_path(debate1)
expect(page).to have_content("Feature")
visit debate_path(debate2)
expect(page).to have_content("Remove feature")
end
scenario 'Show featured debates' do
admin = create(:administrator)
login_as(admin.user)
debate1 = create(:debate, featured_at: Time.now)
debate2 = create(:debate)
visit debates_path
expect(page).to have_content("Featured")
end
scenario 'Dont show featured debates' do
admin = create(:administrator)
login_as(admin.user)
debate1 = create(:debate)
debate2 = create(:debate)
visit debates_path
expect(page).to_not have_content("Featured")
end
end end