@@ -4,15 +4,17 @@ class PollsController < ApplicationController
|
|||||||
|
|
||||||
has_filters %w{current expired incoming}
|
has_filters %w{current expired incoming}
|
||||||
|
|
||||||
|
::Poll::Answer # trigger autoload
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@polls = @polls.send(@current_filter).sort_for_list.page(params[:page])
|
@polls = @polls.send(@current_filter).includes(:geozones).sort_for_list.page(params[:page])
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@questions = @poll.questions.for_render.sort_for_list
|
@questions = @poll.questions.for_render.sort_for_list
|
||||||
|
|
||||||
@answers_by_question_id = {}
|
@answers_by_question_id = {}
|
||||||
poll_answers = Poll::Answer.by_question(@poll.question_ids).by_author(current_user.try(:id))
|
poll_answers = ::Poll::Answer.by_question(@poll.question_ids).by_author(current_user.try(:id))
|
||||||
poll_answers.each do |answer|
|
poll_answers.each do |answer|
|
||||||
@answers_by_question_id[answer.question_id] = answer.answer
|
@answers_by_question_id[answer.question_id] = answer.answer
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -53,8 +53,8 @@ module Abilities
|
|||||||
|
|
||||||
can [:index, :create, :edit, :update, :destroy], Geozone
|
can [:index, :create, :edit, :update, :destroy], Geozone
|
||||||
|
|
||||||
can [:manage], Poll
|
can [:read, :create, :update, :destroy, :add_question, :remove_question, :search_booths, :search_questions, :search_officers], Poll
|
||||||
can [:manage], Poll::Booth
|
can [:read, :create, :update, :destroy], Poll::Booth
|
||||||
can [:search, :create, :index, :destroy], ::Poll::Officer
|
can [:search, :create, :index, :destroy], ::Poll::Officer
|
||||||
can [:create, :destroy], ::Poll::BoothAssignment
|
can [:create, :destroy], ::Poll::BoothAssignment
|
||||||
can [:create, :destroy], ::Poll::OfficerAssignment
|
can [:create, :destroy], ::Poll::OfficerAssignment
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class Poll < ActiveRecord::Base
|
|||||||
scope :published, -> { where('published = ?', true) }
|
scope :published, -> { where('published = ?', true) }
|
||||||
scope :by_geozone_id, ->(geozone_id) { where(geozones: {id: geozone_id}.joins(:geozones)) }
|
scope :by_geozone_id, ->(geozone_id) { where(geozones: {id: geozone_id}.joins(:geozones)) }
|
||||||
|
|
||||||
scope :sort_for_list, -> { order(:starts_at) }
|
scope :sort_for_list, -> { order(:geozone_restricted, :starts_at, :name) }
|
||||||
|
|
||||||
def current?(timestamp = DateTime.current)
|
def current?(timestamp = DateTime.current)
|
||||||
starts_at <= timestamp && timestamp <= ends_at
|
starts_at <= timestamp && timestamp <= ends_at
|
||||||
|
|||||||
24
app/views/polls/_reasons_for_not_answering.html.erb
Normal file
24
app/views/polls/_reasons_for_not_answering.html.erb
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<% if poll.incoming? %>
|
||||||
|
<div class="callout alert">
|
||||||
|
<%= t('poll_questions.show.cant_answer_incoming') %>
|
||||||
|
</div>
|
||||||
|
<% elsif poll.expired? %>
|
||||||
|
<div class="callout primary">
|
||||||
|
<%= t('poll_questions.show.cant_answer_expired') %>
|
||||||
|
</div>
|
||||||
|
<% elsif current_user.nil? %>
|
||||||
|
<div class="callout primary">
|
||||||
|
<%= t("poll_questions.show.not_logged_in",
|
||||||
|
signin: link_to(t("poll_questions.show.signin"), new_user_session_path, class: "probe-message"),
|
||||||
|
signup: link_to(t("poll_questions.show.signup"), new_user_registration_path, class: "probe-message")).html_safe %>
|
||||||
|
</div>
|
||||||
|
<% elsif current_user.unverified? %>
|
||||||
|
<div class="callout warning">
|
||||||
|
<%= t('poll_questions.show.cant_answer_verify_html',
|
||||||
|
verify_link: link_to(t('poll_questions.show.verify_link'), verification_path)) %>
|
||||||
|
</div>
|
||||||
|
<% else %>
|
||||||
|
<div class="callout warning">
|
||||||
|
<%= t('poll_questions.show.cant_answer_wrong_geozone') %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
@@ -21,12 +21,19 @@
|
|||||||
<div class="small-12 medium-6 column">
|
<div class="small-12 medium-6 column">
|
||||||
<h3><%= poll.name %></h3>
|
<h3><%= poll.name %></h3>
|
||||||
<p class="dates"><%= poll_dates(poll) %></p>
|
<p class="dates"><%= poll_dates(poll) %></p>
|
||||||
|
<ul class="no-bullet margin-top tags">
|
||||||
|
<% poll.geozones.each do |g| %>
|
||||||
|
<li class="inline-block"><span><%= g.name %></span></li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="small-12 medium-6 column text-right">
|
<div class="small-12 medium-6 column text-right">
|
||||||
<%= link_to t("polls.index.button"),
|
<% if can? :answer, poll %>
|
||||||
poll,
|
<%= link_to t("polls.index.participate_button"), poll, class: "button" %>
|
||||||
class: "button",
|
<% else %>
|
||||||
title: t("polls.index.button") + ": " + (poll.name) %>
|
<%= render 'polls/reasons_for_not_answering', poll: poll %>
|
||||||
|
<%= link_to t("polls.index.view_button"), poll, class: "button info small" %>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -54,30 +54,7 @@
|
|||||||
%>
|
%>
|
||||||
</div>
|
</div>
|
||||||
<% else %>
|
<% else %>
|
||||||
<% if @question.poll.incoming? %>
|
<%= render 'polls/reasons_for_not_answering', poll: @question.poll %>
|
||||||
<div class="callout alert">
|
|
||||||
<%= t('poll_questions.show.cant_answer_incoming') %>
|
|
||||||
</div>
|
|
||||||
<% elsif @question.poll.expired? %>
|
|
||||||
<div class="callout primary">
|
|
||||||
<%= t('poll_questions.show.cant_answer_expired') %>
|
|
||||||
</div>
|
|
||||||
<% elsif current_user.nil? %>
|
|
||||||
<div class="callout primary">
|
|
||||||
<%= t("poll_questions.show.not_logged_in",
|
|
||||||
signin: link_to(t("poll_questions.show.signin"), new_user_session_path, class: "probe-message"),
|
|
||||||
signup: link_to(t("poll_questions.show.signup"), new_user_registration_path, class: "probe-message")).html_safe %>
|
|
||||||
</div>
|
|
||||||
<% elsif current_user.unverified? %>
|
|
||||||
<div class="callout warning">
|
|
||||||
<%= t('poll_questions.show.cant_answer_verify_html',
|
|
||||||
verify_link: link_to(t('poll_questions.show.verify_link'), verification_path)) %>
|
|
||||||
</div>
|
|
||||||
<% else %>
|
|
||||||
<div class="callout warning">
|
|
||||||
<%= t('poll_questions.show.cant_answer_wrong_geozone') %>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<div class="small-12 small-centered text-center column">
|
<div class="small-12 small-centered text-center column">
|
||||||
<div id="<%= dom_id(@question) %>_answers">
|
<div id="<%= dom_id(@question) %>_answers">
|
||||||
|
|||||||
@@ -401,7 +401,8 @@ en:
|
|||||||
incoming: "Incoming"
|
incoming: "Incoming"
|
||||||
expired: "Expired"
|
expired: "Expired"
|
||||||
title: "Polls"
|
title: "Polls"
|
||||||
button: "Participate in this poll"
|
participate_button: "Participate in this poll"
|
||||||
|
view_button: "View details about this poll"
|
||||||
show:
|
show:
|
||||||
dates_title: "Participation dates"
|
dates_title: "Participation dates"
|
||||||
cant_answer_not_logged_in: "You must %{signin} or %{signup} to participate."
|
cant_answer_not_logged_in: "You must %{signin} or %{signup} to participate."
|
||||||
|
|||||||
@@ -401,7 +401,8 @@ es:
|
|||||||
incoming: "Próximamente"
|
incoming: "Próximamente"
|
||||||
expired: "Terminadas"
|
expired: "Terminadas"
|
||||||
title: "Votaciones"
|
title: "Votaciones"
|
||||||
button: "Participar en esta votación"
|
participate_button: "Participar en esta votación"
|
||||||
|
view_button: "Ver detalles de la votación"
|
||||||
show:
|
show:
|
||||||
dates_title: "Fechas de participación"
|
dates_title: "Fechas de participación"
|
||||||
cant_answer_not_logged_in: "Necesitas %{signin} o %{signup} para participar."
|
cant_answer_not_logged_in: "Necesitas %{signin} o %{signup} para participar."
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ feature 'Admin booths assignments' do
|
|||||||
|
|
||||||
fill_in 'search-booths', with: booth.name
|
fill_in 'search-booths', with: booth.name
|
||||||
click_button 'Search'
|
click_button 'Search'
|
||||||
|
expect(page).to have_content(booth.name)
|
||||||
|
|
||||||
within('#search-booths-results') do
|
within('#search-booths-results') do
|
||||||
click_link 'Assign booth'
|
click_link 'Assign booth'
|
||||||
@@ -167,4 +168,4 @@ feature 'Admin booths assignments' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ feature 'Polls' do
|
|||||||
|
|
||||||
polls.each do |poll|
|
polls.each do |poll|
|
||||||
expect(page).to have_content(poll.name)
|
expect(page).to have_content(poll.name)
|
||||||
expect(page).to have_link("Participate in this poll")
|
expect(page).to have_link("View details about this poll")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -57,9 +57,6 @@ describe "Abilities::Administrator" do
|
|||||||
it { should be_able_to(:valuate, SpendingProposal) }
|
it { should be_able_to(:valuate, SpendingProposal) }
|
||||||
it { should be_able_to(:destroy, SpendingProposal) }
|
it { should be_able_to(:destroy, SpendingProposal) }
|
||||||
|
|
||||||
it { should be_able_to(:manage, Poll) }
|
|
||||||
it { should be_able_to(:manage, Poll::Booth) }
|
|
||||||
|
|
||||||
it { should be_able_to(:create, Budget) }
|
it { should be_able_to(:create, Budget) }
|
||||||
it { should be_able_to(:update, Budget) }
|
it { should be_able_to(:update, Budget) }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user