diff --git a/Gemfile.lock b/Gemfile.lock
index 94e26694c..cd2ae196d 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -130,7 +130,7 @@ GEM
mail (~> 2.2)
errbase (0.0.3)
erubis (2.7.0)
- execjs (2.5.2)
+ execjs (2.6.0)
factory_girl (4.5.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.5.0)
@@ -338,7 +338,7 @@ GEM
coffee-rails
tzinfo (1.2.2)
thread_safe (~> 0.1)
- uglifier (2.7.1)
+ uglifier (2.7.2)
execjs (>= 0.3.0)
json (>= 1.8.0)
unf (0.1.4)
diff --git a/app/assets/fonts/icons.eot b/app/assets/fonts/icons.eot
index a1cc83d43..81c974cd3 100644
Binary files a/app/assets/fonts/icons.eot and b/app/assets/fonts/icons.eot differ
diff --git a/app/assets/fonts/icons.svg b/app/assets/fonts/icons.svg
index 049938913..da328ba6e 100644
--- a/app/assets/fonts/icons.svg
+++ b/app/assets/fonts/icons.svg
@@ -30,4 +30,9 @@
+
+
+
+
+
diff --git a/app/assets/fonts/icons.ttf b/app/assets/fonts/icons.ttf
index aa9c63faa..207ad475e 100644
Binary files a/app/assets/fonts/icons.ttf and b/app/assets/fonts/icons.ttf differ
diff --git a/app/assets/fonts/icons.woff b/app/assets/fonts/icons.woff
index b17f63445..fe9c25404 100644
Binary files a/app/assets/fonts/icons.woff and b/app/assets/fonts/icons.woff differ
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index a5aaf5c01..6e5b1df3d 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -32,6 +32,7 @@ var initialize_modules = function() {
App.Tags.initialize();
App.Stats.initialize();
App.LocaleSwitcher.initialize();
+ App.DebatesOrderSelector.initialize();
};
$(function(){
diff --git a/app/assets/javascripts/debates_order_selector.js.coffee b/app/assets/javascripts/debates_order_selector.js.coffee
new file mode 100644
index 000000000..94002f5ac
--- /dev/null
+++ b/app/assets/javascripts/debates_order_selector.js.coffee
@@ -0,0 +1,17 @@
+App.DebatesOrderSelector =
+
+ href_with_params: (query_params) ->
+ loc = window.location
+
+ loc.protocol + "//" + loc.hostname +
+ (if loc.port then ':' + loc.port else '') +
+ loc.pathname +
+ loc.hash +
+ '?' + $.param(query_params)
+
+ initialize: ->
+ $('.js-order-selector').on 'change', ->
+ query_params = window.getQueryParameters()
+ query_params['order'] = $(this).val()
+ window.location.assign(App.DebatesOrderSelector.href_with_params(query_params))
+
diff --git a/app/assets/stylesheets/icons.scss b/app/assets/stylesheets/icons.scss
index 6a014579c..5d521a9ce 100644
--- a/app/assets/stylesheets/icons.scss
+++ b/app/assets/stylesheets/icons.scss
@@ -106,4 +106,18 @@
.icon-flag:before {
content: "w";
}
-
+.icon-notification:before {
+ content: "x";
+}
+.icon-comment:before {
+ content: "y";
+}
+.icon-reply:before {
+ content: "z";
+}
+.icon-facebook:before {
+ content: "A";
+}
+.icon-google-plus:before {
+ content: "B";
+}
\ No newline at end of file
diff --git a/app/assets/stylesheets/participacion.scss b/app/assets/stylesheets/participacion.scss
index e20a2cb36..116b57ff8 100644
--- a/app/assets/stylesheets/participacion.scss
+++ b/app/assets/stylesheets/participacion.scss
@@ -14,6 +14,7 @@
// 12. Official levels
// 13. Pagination
// 14. Tables
+// 15. Social
//
// 01. Variables
@@ -856,4 +857,122 @@ table {
}
}
+// 15. Social
+// - - - - - - - - - - - - - - - - - - - - - - - - -
+.button.button-twitter {
+ background: #45B0E3;
+
+ &:before {
+ background: #40A2D1;
+ content: "f";
+ font-family: "icons" !important;
+ font-size: rem-calc(24);
+ left: 0;
+ line-height: $line-height*2;
+ padding: 0 rem-calc(20);
+ position: absolute;
+ top: 0;
+ }
+}
+
+.social-share-button-twitter {
+ background: #45B0E3;
+ color: white;
+ height: rem-calc(48);
+ position: relative;
+ width: rem-calc(48);
+
+ &:before {
+ content: "f";
+ font-family: "icons" !important;
+ font-size: rem-calc(24);
+ left: 50%;
+ line-height: $line-height*2;
+ margin-left: rem-calc(-11);
+ position: absolute;
+ top: 0;
+ }
+
+ &:hover {
+ color: #40A2D1;
+ }
+}
+
+.button.button-facebook {
+ background: #3B5998;
+
+ &:before {
+ background: #354F88;
+ content: "A";
+ font-family: "icons" !important;
+ font-size: rem-calc(24);
+ left: 0;
+ line-height: $line-height*2;
+ padding: 0 rem-calc(20);
+ position: absolute;
+ top: 0;
+ }
+}
+
+.social-share-button-facebook {
+ background: #3B5998;
+ color: white;
+ height: rem-calc(48);
+ position: relative;
+ width: rem-calc(48);
+
+ &:before {
+ content: "A";
+ font-family: "icons" !important;
+ font-size: rem-calc(24);
+ left: 50%;
+ line-height: $line-height*2;
+ margin-left: rem-calc(-11);
+ position: absolute;
+ top: 0;
+ }
+
+ &:hover {
+ color: #354F88;
+ }
+}
+
+.button.button-google {
+ background: #DE4C34;
+
+ &:before {
+ background: #CE3E26;
+ content: "B";
+ font-family: "icons" !important;
+ font-size: rem-calc(24);
+ left: 0;
+ line-height: $line-height*2;
+ padding: 0 rem-calc(20);
+ position: absolute;
+ top: 0;
+ }
+}
+
+.social-share-button-google_plus {
+ background: #DE4C34;
+ color: white;
+ height: rem-calc(48);
+ position: relative;
+ width: rem-calc(48);
+
+ &:before {
+ content: "B";
+ font-family: "icons" !important;
+ font-size: rem-calc(24);
+ left: 50%;
+ line-height: $line-height*2;
+ margin-left: rem-calc(-11);
+ position: absolute;
+ top: 0;
+ }
+
+ &:hover {
+ color: #CE3E26;
+ }
+}
diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb
index 6bea23ffd..60819fcf6 100644
--- a/app/controllers/debates_controller.rb
+++ b/app/controllers/debates_controller.rb
@@ -1,11 +1,12 @@
class DebatesController < ApplicationController
+ before_action :parse_order, only: :index
before_action :authenticate_user!, except: [:index, :show]
load_and_authorize_resource
respond_to :html, :js
def index
- @debates = Debate.search(params).page(params[:page]).for_render
+ @debates = Debate.search(params).page(params[:page]).for_render.send("sort_by_#{@order}")
set_debate_votes(@debates)
end
@@ -71,4 +72,9 @@ class DebatesController < ApplicationController
@featured_tags = ActsAsTaggableOn::Tag.where(featured: true)
end
+ def parse_order
+ @valid_orders = ['total_votes', 'created_at', 'likes']
+ @order = @valid_orders.include?(params[:order]) ? params[:order] : 'created_at'
+ end
+
end
diff --git a/app/helpers/debates_helper.rb b/app/helpers/debates_helper.rb
new file mode 100644
index 000000000..c594a8fa6
--- /dev/null
+++ b/app/helpers/debates_helper.rb
@@ -0,0 +1,12 @@
+module DebatesHelper
+ def available_options_for_order_selector(valid_orders, current_order)
+ options_for_select(available_order_filters_array(valid_orders), current_order)
+ end
+
+ private
+
+ def available_order_filters_array(orders)
+ orders.map { |f| [t("debates.index.orders.#{f}"), f] }
+ end
+
+end
diff --git a/app/models/debate.rb b/app/models/debate.rb
index 14c229827..fdf939b2f 100644
--- a/app/models/debate.rb
+++ b/app/models/debate.rb
@@ -28,6 +28,10 @@ class Debate < ActiveRecord::Base
scope :with_ignored_flag, -> { where("ignored_flag_at IS NOT NULL AND hidden_at IS NULL") }
scope :flagged, -> { where("flags_count > 0") }
scope :for_render, -> { includes(:tags) }
+ scope :sort_by_total_votes, -> { reorder(cached_votes_total: :desc) }
+ scope :sort_by_likes , -> { reorder(cached_votes_up: :desc) }
+ scope :sort_by_created_at, -> { reorder(created_at: :desc) }
+
# Ahoy setup
visitable # Ahoy will automatically assign visit_id on create
diff --git a/app/views/debates/_order_selector.erb b/app/views/debates/_order_selector.erb
new file mode 100644
index 000000000..de18cfc45
--- /dev/null
+++ b/app/views/debates/_order_selector.erb
@@ -0,0 +1,5 @@
+
diff --git a/app/views/debates/index.html.erb b/app/views/debates/index.html.erb
index 59d11f37c..13600160c 100644
--- a/app/views/debates/index.html.erb
+++ b/app/views/debates/index.html.erb
@@ -4,18 +4,7 @@
<%= t("debates.index.showing") %>
-
-
+ <%= render 'order_selector' %>
diff --git a/app/views/devise/_omniauth_form.html.erb b/app/views/devise/_omniauth_form.html.erb
index fdd812b4f..63e73d160 100644
--- a/app/views/devise/_omniauth_form.html.erb
+++ b/app/views/devise/_omniauth_form.html.erb
@@ -1,7 +1,11 @@
-
-
-<%= link_to t("omniauth.twitter.sign_in"), user_omniauth_authorize_path(:twitter), class: 'button radius expand' %>
-<%= link_to t("omniauth.facebook.sign_in"), user_omniauth_authorize_path(:facebook), class: 'button radius expand' %>
-<%= link_to t("omniauth.google_oauth2.sign_in"), user_omniauth_authorize_path(:google_oauth2), class: 'button radius expand' %>
-
-
+<% if current_page?(new_user_session_path) %>
+ <%= link_to t("omniauth.twitter.sign_in"), user_omniauth_authorize_path(:twitter), class: "button-twitter button radius expand" %>
+ <%= link_to t("omniauth.facebook.sign_in"), user_omniauth_authorize_path(:facebook), class: "button-facebook button radius expand" %>
+ <%= link_to t("omniauth.google_oauth2.sign_in"), user_omniauth_authorize_path(:google_oauth2), class: "button-google button radius expand" %>
+
+<% elsif current_page?(new_user_registration_path) %>
+ <%= link_to t("omniauth.twitter.sign_up"), user_omniauth_authorize_path(:twitter), class: "button-twitter button radius expand" %>
+ <%= link_to t("omniauth.facebook.sign_up"), user_omniauth_authorize_path(:facebook), class: "button-facebook button radius expand" %>
+ <%= link_to t("omniauth.google_oauth2.sign_up"), user_omniauth_authorize_path(:google_oauth2), class: "button-google button radius expand" %>
+
+<% end %>
\ No newline at end of file
diff --git a/config/environments/production.rb b/config/environments/production.rb
index e84606f73..7a21a1df4 100644
--- a/config/environments/production.rb
+++ b/config/environments/production.rb
@@ -42,7 +42,7 @@ Rails.application.configure do
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
- # config.force_ssl = true
+ config.force_ssl = true
# Use the lowest log level to ensure availability of diagnostic information
# when problems arise.
diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml
index dd5b7f0c4..d45c73d9b 100644
--- a/config/i18n-tasks.yml
+++ b/config/i18n-tasks.yml
@@ -102,6 +102,7 @@ ignore_unused:
- 'admin.officials.level_*'
- 'helpers.page_entries_info.*' # kaminari
- 'views.pagination.*' # kaminari
+ - 'debates.index.orders.*' #order filters for debates
# - '{devise,kaminari,will_paginate}.*'
# - 'simple_form.{yes,no}'
# - 'simple_form.{placeholders,hints,labels}.*'
diff --git a/config/locales/devise_views.en.yml b/config/locales/devise_views.en.yml
index 08a303834..79676f2ee 100644
--- a/config/locales/devise_views.en.yml
+++ b/config/locales/devise_views.en.yml
@@ -58,7 +58,7 @@ en:
password_label: "Password"
password_confirmation_label: "Confirm password"
submit: "Sign up"
- organization_signup: "Do you represent an organization / group?"
+ organization_signup: "Do you represent an organization / group? Enter here"
organizations:
registrations:
new:
diff --git a/config/locales/devise_views.es.yml b/config/locales/devise_views.es.yml
index 6ab6ebbb5..a1ab6dcd3 100644
--- a/config/locales/devise_views.es.yml
+++ b/config/locales/devise_views.es.yml
@@ -58,7 +58,7 @@ es:
password_label: "Contraseña"
password_confirmation_label: "Confirmar contraseña"
submit: "Registrarse"
- organization_signup: "¿Representas a una organización / colectivo?"
+ organization_signup: "¿Representas a una organización / colectivo? Entra aquí"
organizations:
registrations:
new:
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 03e0f900e..866f4d4a0 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -33,9 +33,10 @@ en:
index:
create_debate: Create a debate
showing: You are seeing debates
- filter_news: the newest
- filter_votes: the most voted
- filter_rated: the best rated
+ orders:
+ created_at: newest
+ total_votes: most voted
+ likes: best rated
filter_topic: "You are seeing %{number} debates with the topic '%{topic}'"
debate:
debate: Debate
@@ -152,7 +153,10 @@ en:
title: Add Email
twitter:
sign_in: Sign in with Twitter
+ sign_up: Sign up with Twitter
facebook:
sign_in: Sign in with Facebook
+ sign_up: Sign up with Facebook
google_oauth2:
sign_in: Sign in with Google
+ sign_up: Sign up with Google
diff --git a/config/locales/es.yml b/config/locales/es.yml
index 3ef3a5113..a7da1d278 100644
--- a/config/locales/es.yml
+++ b/config/locales/es.yml
@@ -33,9 +33,10 @@ es:
index:
create_debate: Crea un debate
showing: "Estás viendo los debates"
- filter_news: "más nuevos"
- filter_votes: "más votados"
- filter_rated: mejor valorados
+ orders:
+ created_at: "más nuevos"
+ total_votes: "más votados"
+ likes: mejor valorados
filter_topic: "Estás viendo %{number} debates con el tema '%{topic}'"
debate:
debate: Debate
@@ -152,7 +153,10 @@ es:
title: Añade tu email
twitter:
sign_in: Entra con Twitter
+ sign_up: Regístrate con Twitter
facebook:
sign_in: Entra con Facebook
+ sign_up: Regístrate con Facebook
google_oauth2:
sign_in: Entra con Google
+ sign_up: Regístrate con Google
diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb
index 2fd114adc..3f01bd312 100644
--- a/spec/features/debates_spec.rb
+++ b/spec/features/debates_spec.rb
@@ -350,4 +350,61 @@ feature 'Debates' do
expect(Flag.flagged?(user, debate)).to_not be
end
+ feature 'Debate index order filters', :js do
+
+ before do
+ @most_voted_debate = create(:debate)
+ @most_liked_debate = create(:debate)
+ @most_recent_debate = create(:debate)
+ create_list(:vote, 2, votable: @most_liked_debate)
+ create_list(:vote, 2, votable: @most_voted_debate, vote_flag: false)
+ create(:vote, votable: @most_voted_debate)
+ end
+
+ scenario 'Default order is created_at' do
+ visit debates_path
+
+ expect(page).to have_select('order-selector', selected: 'newest')
+ expect(@most_recent_debate.title).to appear_before(@most_liked_debate.title)
+ end
+
+ scenario 'Debates are ordered by most voted' do
+ visit debates_path
+
+ select 'most voted', from: 'order-selector'
+ expect(page).to have_select('order-selector', selected: 'most voted')
+ expect(find("#debates .debate", match: :first)).to have_content(@most_voted_debate.title)
+
+ expect(current_url).to include('order=total_votes')
+ expect(@most_voted_debate.title).to appear_before(@most_liked_debate.title)
+ expect(@most_liked_debate.title).to appear_before(@most_recent_debate.title)
+ end
+
+ scenario 'Debates are ordered by best rated' do
+ visit debates_path
+
+ select 'best rated', from: 'order-selector'
+ expect(page).to have_select('order-selector', selected: 'best rated')
+ expect(find("#debates .debate", match: :first)).to have_content(@most_liked_debate.title)
+
+ expect(current_url).to include('order=likes')
+ expect(@most_liked_debate.title).to appear_before(@most_voted_debate.title)
+ expect(@most_voted_debate.title).to appear_before(@most_recent_debate.title)
+ end
+
+ scenario 'Debates are ordered by newest' do
+ visit debates_path
+
+ select 'most voted', from: 'order-selector'
+ expect(find("#debates .debate", match: :first)).to have_content(@most_voted_debate.title)
+
+ select 'newest', from: 'order-selector'
+ expect(page).to have_select('order-selector', selected: 'newest')
+ expect(find("#debates .debate", match: :first)).to have_content(@most_recent_debate.title)
+
+ expect(current_url).to include('order=created_at')
+ expect(@most_recent_debate.title).to appear_before(@most_liked_debate.title)
+ expect(@most_liked_debate.title).to appear_before(@most_voted_debate.title)
+ end
+ end
end
diff --git a/spec/features/users_spec.rb b/spec/features/users_spec.rb
index 1fa30bcbe..829dcba03 100644
--- a/spec/features/users_spec.rb
+++ b/spec/features/users_spec.rb
@@ -74,7 +74,7 @@ feature 'Users' do
expect do
expect do
expect do
- click_link 'Sign in with Twitter'
+ click_link 'Sign up with Twitter'
end.not_to change { ActionMailer::Base.deliveries.size }
end.to change { Identity.count }.by(1)
end.to change { User.count }.by(1)
@@ -109,7 +109,7 @@ feature 'Users' do
expect do
expect do
expect do
- click_link 'Sign in with Twitter'
+ click_link 'Sign up with Twitter'
end.not_to change { ActionMailer::Base.deliveries.size }
end.to change { Identity.count }.by(1)
end.to change { User.count }.by(1)
diff --git a/spec/support/matchers/appear_before.rb b/spec/support/matchers/appear_before.rb
new file mode 100644
index 000000000..bb1d65072
--- /dev/null
+++ b/spec/support/matchers/appear_before.rb
@@ -0,0 +1,6 @@
+RSpec::Matchers.define :appear_before do |later_content|
+ match do |earlier_content|
+ page.body.index(earlier_content) < page.body.index(later_content)
+ end
+end
+