Add public changes to create and vote Poll:Questions with votation type

This commit is contained in:
lalo
2019-05-29 18:32:04 +02:00
committed by Javi Martín
parent 23d36835d7
commit c6e4b2480f
22 changed files with 711 additions and 135 deletions

View File

@@ -7,3 +7,11 @@ App.Sortable =
url: $(".sortable").data("js-url"),
data: { ordered_list: new_order },
type: "POST"
$(".sortable-priotirized-votation").sortable
update: (event, ui) ->
new_order = $(this).sortable("toArray", { attribute: "data-answer-id" })
$.ajax
url: $(this).data("js-url"),
data: { ordered_list: new_order },
type: "POST"

View File

@@ -1745,8 +1745,12 @@
background: #fafafa;
border-bottom: 1px solid #eee;
.column:nth-child(odd) {
border-right: 2px solid $text;
.margin-bottom {
margin-bottom: 0;
}
.orbit-bullets {
margin-bottom: 0;
}
.answer-divider {
@@ -1756,14 +1760,35 @@
padding-bottom: $line-height;
}
.answer-left-divider {
border-left: solid 1px $text;
padding-left: rem-calc(10);
}
.margin-top {
margin-top: rem-calc(10);
}
.margin-bottom {
margin-bottom: rem-calc(20);
}
.answer-description {
height: 100%;
max-height: rem-calc(1000);
&.short {
height: rem-calc(300);
max-height: rem-calc(70);
overflow: hidden;
max-width: rem-calc(700);
}
}
.question-divider {
border-bottom: rgba(219, 219, 219, 0.62) solid 1px;
margin-bottom: 1rem;
padding: rem-calc(24);
}
}
.orbit-bullets button {
@@ -1991,6 +2016,69 @@
}
}
.icon-like,
.icon-unlike {
background: #fff;
border: 2px solid $text-light;
border-radius: rem-calc(3);
color: $text-light;
display: inline-block;
font-size: rem-calc(30);
line-height: rem-calc(30);
padding: rem-calc(3) rem-calc(6);
position: relative;
&:hover,
&:active {
color: #fff;
cursor: pointer;
opacity: 1 !important;
}
}
.active-like {
color: #fff;
cursor: pointer;
opacity: 1 !important;
background: $like;
border: 2px solid $like;
}
.active-unlike {
color: #fff;
cursor: pointer;
opacity: 1 !important;
background: $unlike;
border: 2px solid $unlike;
}
.icon-like {
&:hover,
&:active,
.picked {
background: $like;
border: 2px solid $like;
}
}
.icon-unlike {
&:hover,
&:active {
background: $unlike;
border: 2px solid $unlike;
}
}
.vote-align {
float: right;
}
.vote-divider {
border-bottom: 1px solid $text-light;
}
// 09. Polls results and stats
// ---------------------------

View File

@@ -0,0 +1,70 @@
class Polls::AnswersController < ApplicationController
load_and_authorize_resource :poll
load_and_authorize_resource :question, class: "Poll::Question"
authorize_resource :answer, class: "Poll::Answer"
def create
@question = Poll::Question.find_by(id: params[:id])
if @question.votation_type.open? && !check_question_answer_exist
@question.question_answers.create(
title: params[:answer],
given_order: @question.question_answers.count + 1,
hidden: false
)
flash.now[:notice] = t("dashboard.polls.index.succesfull")
else
flash.now[:alert] = "Unfortunately failed to sent"
end
load_for_answers
if @question.enum_type&.include?("answer_couples")
last_pair ||= generate_and_store_new_pair(@question)
@last_pair_question_answers = {@question.id => last_pair}
end
render "polls/questions/answer", format: :js
end
def delete
@question = Poll::Question.find_by(id: params[:id])
!@question.answers.find_by(author: current_user, answer: params[:answer]).destroy
@question.question_answers.each do |question_answer|
question_answer.set_most_voted
end
question_answers
load_for_answers
if @question.enum_type&.include?("answer_couples")
last_pair ||= generate_and_store_new_pair(@question)
@last_pair_question_answers = {@question.id => last_pair}
end
render "polls/questions/answer", format: :js
end
private
def check_question_answer_exist
exist = false
@question.question_answers.each do |question_answer|
break if exist
exist = true if question_answer.title == params[:answer]
end
exist
end
def load_for_answers
@page = params[:page].present? ? params[:page] : 1
question_answers
@answers_by_question_id = {@question.id => @question.answers
.by_author(current_user)
.order(:order)
.pluck(:answer)}
end
def question_answers
if @question.is_positive_negative?
@answers = @question.question_answers.visibles.page(params[:page])
else
@answers = @question.question_answers.visibles
end
end
end

View File

@@ -3,18 +3,79 @@ class Polls::QuestionsController < ApplicationController
load_and_authorize_resource :poll
load_and_authorize_resource :question, class: "Poll::Question"
has_orders %w{most_voted newest oldest}, only: :show
has_orders %w[most_voted newest oldest], only: :show
def answer
answer = @question.answers.find_or_initialize_by(author: current_user)
token = params[:token]
answer.answer = params[:answer]
answer.touch if answer.persisted?
answer.save!
answer.record_voter_participation(token)
@answers_by_question_id = { @question.id => params[:answer] }
answer = store_answer
vote_stored(answer, params[:answer], params[:token]) if answer.present?
load_for_answers
if @question.enum_type&.include?("answer_couples")
last_pair ||= generate_and_store_new_pair(@question)
@last_pair_question_answers = {@question.id => last_pair}
end
end
def load_answers
load_for_answers
render action: "answer.js.erb"
end
def prioritized_answers
unless params[:ordered_list].empty?
params[:ordered_list].each_with_index do |answer, i|
answer_obj = @question.votation_type.answer(current_user,
answer,
order: i + 1)
vote_stored(answer_obj, answer, params[:tooken]) if answer_obj.present?
end
@question.votation_type.update_priorized_values(current_user.id)
end
load_for_answers
render action: "answer.js.erb"
end
private
def load_for_answers
@page = params[:page].present? ? params[:page] : 1
question_answers
@answers_by_question_id = {@question.id => @question.answers
.by_author(current_user)
.order(:order)
.pluck(:answer)}
end
def vote_stored(answer, new_answer, token)
answer.answer = new_answer
answer.touch if answer.persisted?
answer.save!
answer.record_voter_participation(token)
@question.question_answers.visibles.where(question_id: @question).each do |question_answer|
question_answer.set_most_voted
end
end
def store_answer
if @question.votation_type.nil?
answer = @question.answers.find_or_initialize_by(author: current_user)
else
answer = @question.votation_type.answer(current_user,
params[:answer],
positive: params[:positive])
end
answer
end
def generate_and_store_new_pair(question)
Poll::PairAnswer.generate_pair(question, current_user)
end
def question_answers
if @question.is_positive_negative?
@answers = @question.question_answers.visibles.page(@page)
else
@answers = @question.question_answers.visibles
end
end
end

View File

@@ -20,13 +20,27 @@ class PollsController < ApplicationController
def show
@questions = @poll.questions.for_render.sort_for_list
@token = poll_voter_token(@poll, current_user)
@poll_questions_answers = Poll::Question::Answer.where(question: @poll.questions)
@poll_questions_answers = Poll::Question::Answer.visibles
.where(question: @poll.questions)
.where.not(description: "").order(:given_order)
@answers_by_question_id = {}
poll_answers = ::Poll::Answer.by_question(@poll.question_ids).by_author(current_user.try(:id))
poll_answers.each do |answer|
@answers_by_question_id[answer.question_id] = answer.answer
@last_pair_question_answers = {}
@questions.each do |question|
@answers_by_question_id[question.id] = question.answers.by_author(current_user).pluck(:answer)
if question.enum_type&.include?("answer_couples")
last_pair = question.pair_answers.by_author(current_user).first
last_pair ||= generate_and_store_new_pair(question)
@last_pair_question_answers[question.id] = last_pair
end
if question.enum_type&.include?("answer_set_closed") ||
question.enum_type&.include?("answer_set_open")
votation_answer_sets(question)
end
end
@commentable = @poll
@@ -42,6 +56,18 @@ class PollsController < ApplicationController
private
def votation_answer_sets(question)
if question.votation_type.votation_set_answers.by_author(current_user).empty?
question.question_answers&.sample(question.max_groups_answers).each do |question_answer|
answer = VotationSetAnswer.new(answer: question_answer.title,
votation_type: question.votation_type,
author: current_user)
question.votation_type.votation_set_answers << answer
end
!question.save
end
end
def load_poll
@poll = Poll.where(slug: params[:id]).first || Poll.where(id: params[:id]).first
end
@@ -50,4 +76,8 @@ class PollsController < ApplicationController
@active_poll = ActivePoll.first
end
def generate_and_store_new_pair(question)
Poll::PairAnswer.generate_pair(question, current_user)
end
end

View File

@@ -78,4 +78,8 @@ module PollsHelper
def show_polls_description?
@active_poll.present? && @current_filter == "current"
end
def stored_positive_negative_value(question, answer)
question.answers.find_by(author_id: current_user.id, answer: answer.title).positive
end
end

View File

@@ -104,12 +104,18 @@ module Abilities
can :create, DirectMessage
can :show, DirectMessage, sender_id: user.id
can :answer, Poll do |poll|
can [:load_answers], Poll::Question
can [:answer], Poll do |poll|
poll.answerable_by?(user)
end
can :answer, Poll::Question do |question|
can [:answer, :prioritized_answers], Poll::Question do |question|
question.answerable_by?(user)
end
can [:create, :delete], Poll::Answer do |answer|
answer.question.answerable_by?(user)
end
end
can [:create, :show], ProposalNotification, proposal: { author_id: user.id }

View File

@@ -1,33 +1,22 @@
<div class="poll-question-answers">
<% if can?(:answer, question) && !question.poll.voted_in_booth?(current_user) %>
<% question.question_answers.each do |answer| %>
<% if @answers_by_question_id[question.id] == answer.title &&
(!voted_before_sign_in(question) ||
question.poll.voted_in_booth?(current_user)) %>
<span class="button answered"
title="<%= t("poll_questions.show.voted", answer: answer.title)%>">
<%= answer.title %>
</span>
<% else %>
<%= link_to answer.title,
answer_question_path(question, answer: answer.title, token: token),
method: :post,
remote: true,
title: t("poll_questions.show.vote_answer", answer: answer.title),
class: "button secondary hollow js-question-answer" %>
<% end %>
<% end %>
<% elsif !user_signed_in? %>
<% question.question_answers.order(id: :desc).each do |answer| %>
<%= link_to answer.title, new_user_session_path, class: "button secondary hollow" %>
<% end %>
<% elsif !current_user.level_two_or_three_verified? %>
<% question.question_answers.order(id: :desc).each do |answer| %>
<%= link_to answer.title, verification_path, class: "button secondary hollow" %>
<% end %>
<% if question.votation_type.nil? %>
<%= render "polls/questions/answers_unique", question: question, answers: answers, token: token %>
<% else %>
<% case question.votation_type.enum_type %>
<% when "unique" %>
<%= render "polls/questions/answers_unique", question: question, answers: answers, token: token %>
<% when "multiple", "positive_open" %>
<%= render "polls/questions/answers_multiple", question: question, answers: answers, token: token %>
<% when "positive_negative_open" %>
<%= render "polls/questions/answers_positive_negative", question: question, answers: answers, token: token, page: page %>
<% when "answer_couples_closed" %>
<%= render "polls/questions/answers_couples", answers_open: false, question: question, token: token %>
<% when "answer_couples_open" %>
<%= render "polls/questions/answers_couples", answers_open: true, question: question, token: token %>
<% when "answer_set_closed", "answer_set_open" %>
<%= render "polls/questions/answers_set", question: question, token: token, answers: question.votation_type.votation_set_answers.by_author(current_user) %>
<% when "prioritized" %>
<%= render "polls/questions/answers_prioritized", answers_open: false, question: question, answers: answers, token: token %>
<% else %>
<% question.question_answers.order(id: :desc).each do |answer| %>
<span class="button secondary hollow disabled"><%= answer.title %></span>
<% end %>
<%= render "polls/questions/answers_unique", question: question, answers: answers, token: token %>
<% end %>
</div>
<% end %>

View File

@@ -0,0 +1,39 @@
<div class="poll-question-answers">
<% if can?(:answer, question) && question.user_can_vote(current_user) %>
<div class="small-12 medium-12 text-center">
<% @last_pair_question_answers.dig(question.id)&.answers&.each do |answer| %>
<div class="small-12 medium-5 inline-block">
<%= link_to answer.title,
answer_question_path(question, answer: answer.title, token: token),
method: :post,
remote: true,
title: t("poll_questions.show.vote_answer", answer: answer.title),
class: "button secondary hollow js-question-answer" %>
</div>
<% end %>
</div>
<div class="small-12 medium-12 text-center">
<%= link_to "I can't decide",
answer_question_path(question, answer: "I can't decided", token: token),
method: :post,
remote: true,
title: "I can't decide",
class: "button secondary hollow js-question-answer" %>
</div>
<% if answers_open %>
<%= render "/polls/questions/new_answer", question: question, token: token %>
<% end %>
<% elsif !user_signed_in? %>
<% question.question_answers.visibles.order(id: :desc).each do |answer| %>
<%= link_to answer.title, new_user_session_path, class: "button secondary hollow" %>
<% end %>
<% elsif !current_user.level_two_or_three_verified? %>
<% question.question_answers.visibles.order(id: :desc).each do |answer| %>
<%= link_to answer.title, verification_path, class: "button secondary hollow" %>
<% end %>
<% else %>
<%= t('polls.index.max_votes_reached') %>
<% end %>
</div>

View File

@@ -0,0 +1,36 @@
<div class="poll-question-answers">
<% if can?(:answer, question) && !question.poll.voted_in_booth?(current_user) %>
<% answers&.each do |answer| %>
<% if @answers_by_question_id[question.id].include?(answer.title) %>
<%= link_to answer.title,
answer_question_path(question, answer: answer.title, token: token),
method: :delete,
remote: true,
title: t("poll_questions.show.voted", answer: answer.title),
class: "button answered expand" %>
<% else %>
<%= link_to answer.title,
answer_question_path(question, answer: answer.title, token: token),
method: :post,
remote: true,
title: t("poll_questions.show.vote_answer", answer: answer.title),
class: "button secondary hollow js-question-answer" %>
<% end %>
<% end %>
<% if question.enum_type == "positive_open" %>
<%= render "/polls/questions/new_answer", question: question, token: token %>
<% end %>
<% elsif !user_signed_in? %>
<% answers.order(id: :desc).each do |answer| %>
<%= link_to answer.title, new_user_session_path, class: "button secondary hollow" %>
<% end %>
<% elsif !current_user.level_two_or_three_verified? %>
<% answers.order(id: :desc).each do |answer| %>
<%= link_to answer.title, verification_path, class: "button secondary hollow" %>
<% end %>
<% else %>
<% answers.order(id: :desc).each do |answer| %>
<span class="button secondary hollow disabled"><%= answer.title %></span>
<% end %>
<% end %>
</div>

View File

@@ -0,0 +1,55 @@
<div class="poll-question-answers">
<% if can?(:answer, question) && !question.poll.voted_in_booth?(current_user) %>
<table class="voting-list">
<% answers&.each do |answer| %>
<tr class="answer medium-12 inline-block" style="border-bottom: 1px solid lightslategrey;">
<td class="title-answer medium-9 inline-block">
<span class="inline-block"><%= answer.title %></span>
</td>
<td class="votes inline-block vote-align">
<div class="in-favor inline-block">
<% if @answers_by_question_id[question.id].include?(answer.title) &&
stored_positive_negative_value(question, answer) %>
<%= render "polls/questions/like_dislike", question: question,
answer: answer, method: "delete", positive: true,
token: token, active: true, page: page %>
<% else %>
<%= render "polls/questions/like_dislike", question: question,
answer: answer, method: "post", positive: true,
token: token, active: false, page: page %>
<% end %>
</div>
<div class="against inline-block">
<% if @answers_by_question_id[question.id].include?(answer.title) &&
!stored_positive_negative_value(question, answer) %>
<%= render "polls/questions/like_dislike", question: question,
answer: answer, method: "delete", positive: false,
token: token, active: true, page: page %>
<% else %>
<%= render "polls/questions/like_dislike", question: question,
answer: answer, method: "post", positive: false,
token: token, active: false, page: page %>
<% end %>
</div>
</td>
</tr>
<% end %>
</table>
<%= paginate answers, params: {controller: "polls/questions", action: :load_answers, id: question}, remote: true %>
<%= render "/polls/questions/new_answer", question: question, token: token %>
<% elsif !user_signed_in? %>
<% answers.order(id: :desc).each do |answer| %>
<%= link_to answer.title, new_user_session_path, class: "button secondary hollow" %>
<% end %>
<% elsif !current_user.level_two_or_three_verified? %>
<% answers.visibles.order(id: :desc).each do |answer| %>
<%= link_to answer.title, verification_path, class: "button secondary hollow" %>
<% end %>
<% else %>
<% answers.order(id: :desc).each do |answer| %>
<span class="button secondary hollow disabled"><%= answer.title %></span>
<% end %>
<% end %>
</div>

View File

@@ -0,0 +1,44 @@
<div class="poll-question-answers">
<% if can?(:answer, question) && !question.poll.voted_in_booth?(current_user) %>
<ol type="1" class="sortable-priotirized-votation" data-js-url="<%= prioritized_answers_question_path(question, token: token) %>">
<% @answers_by_question_id[question.id].each do |answer| %>
<li data-answer-id="<%= answer %>">
<span class="button answered expanded"
title="<%= t("poll_questions.show.voted", answer: answer) %>">
<%= answer %>
</span>
</li>
<% end %>
</ol>
<% answers&.each do |answer| %>
<% if @answers_by_question_id[question.id].include?(answer.title) %>
<%= link_to answer.title,
answer_question_path(question, answer: answer.title, token: token),
method: :delete,
remote: true,
title: t("poll_questions.show.voted", answer: answer.title),
class: "button answered expand" %>
<% else %>
<%= link_to answer.title,
answer_question_path(question, answer: answer.title, token: token),
method: :post,
remote: true,
title: t("poll_questions.show.vote_answer", answer: answer.title),
class: "button secondary hollow js-question-answer" %>
<% end %>
<% end %>
<% elsif !user_signed_in? %>
<% answers.order(id: :desc).each do |answer| %>
<%= link_to answer.title, new_user_session_path, class: "button secondary hollow" %>
<% end %>
<% elsif !current_user.level_two_or_three_verified? %>
<% answers.order(id: :desc).each do |answer| %>
<%= link_to answer.title, verification_path, class: "button secondary hollow" %>
<% end %>
<% else %>
<% answers.order(id: :desc).each do |answer| %>
<span class="button secondary hollow disabled"><%= answer.title %></span>
<% end %>
<% end %>
</div>

View File

@@ -0,0 +1,37 @@
<div class="poll-question-answers">
<% if can?(:answer, question) %>
<% answers.each do |answer| %>
<% if @answers_by_question_id[question.id].include?(answer.answer) %>
<%= link_to answer.answer,
answer_question_path(question, answer: answer.answer, token: token),
method: :delete,
remote: true,
title: t("poll_questions.show.voted", answer: answer.answer),
class: "button answered" %>
<% else %>
<%= link_to answer.answer,
answer_question_path(question, answer: answer.answer, token: token),
method: :post,
remote: true,
title: t("poll_questions.show.vote_answer", answer: answer.answer),
class: "button secondary hollow js-question-answer" %>
<% end %>
<% end %>
<% if question.enum_type == "answer_set_open" %>
<%= render "/polls/questions/new_answer", question: question, token: token %>
<%= flash[:notice] %>
<% end %>
<% elsif !user_signed_in? %>
<% answers.order(id: :desc).each do |answer| %>
<%= link_to answer.answer, new_user_session_path, class: "button secondary hollow" %>
<% end %>
<% elsif !current_user.level_two_or_three_verified? %>
<% answers.order(id: :desc).each do |answer| %>
<%= link_to answer.answer, verification_path, class: "button secondary hollow" %>
<% end %>
<% else %>
<% answers.order(id: :desc).each do |answer| %>
<span class="button secondary hollow disabled"><%= answer.answer %></span>
<% end %>
<% end %>
</div>

View File

@@ -0,0 +1,33 @@
<div class="poll-question-answers">
<% if can?(:answer, question) && !question.poll.voted_in_booth?(current_user) %>
<% answers&.each do |answer| %>
<% if @answers_by_question_id[question.id].include?(answer.title) &&
(!voted_before_sign_in(question) ||
question.poll.voted_in_booth?(current_user)) %>
<span class="button answered"
title="<%= t("poll_questions.show.voted", answer: answer.title) %>">
<%= answer.title %>
</span>
<% else %>
<%= link_to answer.title,
answer_question_path(question, answer: answer.title, token: token),
method: :post,
remote: true,
title: t("poll_questions.show.vote_answer", answer: answer.title),
class: "button secondary hollow js-question-answer" %>
<% end %>
<% end %>
<% elsif !user_signed_in? %>
<% answers.order(id: :desc).each do |answer| %>
<%= link_to answer.title, new_user_session_path, class: "button secondary hollow" %>
<% end %>
<% elsif !current_user.level_two_or_three_verified? %>
<% answers.order(id: :desc).each do |answer| %>
<%= link_to answer.title, verification_path, class: "button secondary hollow" %>
<% end %>
<% else %>
<% answers.order(id: :desc).each do |answer| %>
<span class="button secondary hollow disabled"><%= answer.title %></span>
<% end %>
<% end %>
</div>

View File

@@ -0,0 +1,19 @@
<%= link_to answer_question_path(question, answer: answer.title, positive: positive, token: token, page: page),
method: method.to_sym,
remote: true,
title: t("poll_questions.show.vote_answer", answer: answer.title),
class: "expand js-question-answer" do %>
<% if positive %>
<% if active %>
<span class="icon-like active-like"></span>
<% else %>
<span class="icon-like"></span>
<% end %>
<% else %>
<% if active %>
<span class="icon-unlike active-unlike"></span>
<% else %>
<span class="icon-unlike"></span>
<% end %>
<% end %>
<% end %>

View File

@@ -0,0 +1,5 @@
<%= form_tag(create_answer_question_path(question, token: token), method: :post, remote: true) do %>
<label> You can add your own answer</label>
<input type="text" class="medium-10" name="answer">
<input class="button success" type="submit" value="<%= t("poll_questions.show.add_answer") %>">
<% end %>

View File

@@ -3,7 +3,35 @@
<%= question.title %>
</h3>
<% unless question.votation_type.nil? %>
<strong>
<%= t("poll_questions.description.#{question.enum_type}",
maximum: question.votation_type.max_votes,
system: question.votation_type.prioritization_type) %>
</strong>
<% end %>
<div id="<%= dom_id(question) %>_answers" class="padding">
<%= render "polls/questions/answers", question: question, token: token %>
<% answers = question.is_positive_negative? ? question.question_answers.visibles.page(1) : question.question_answers.visibles %>
<%= render "polls/questions/answers", question: question, token: token, answers: answers, page: 1 %>
</div>
<% if question.answers_with_read_more? %>
<div class="poll_question_read_more">
<p><%= t("poll_questions.read_more_about") %></p>
<p>
<% first = true %>
<% question.question_answers&.visibles&.each do |answer| %>
<% if answer.description.present? || answer.images.any? ||
answer.documents.present? || answer.videos.present? %>
<% unless first %>
<span>,&nbsp;</span>
<% end %>
<% first = false if first %>
<%= link_to answer.title, "#answer_description_#{answer.id}" %>
<% end %>
<% end %>
</p>
</div>
<% end %>
</div>

View File

@@ -1,2 +1,3 @@
<% token = poll_voter_token(@question.poll, current_user) %>
$("#<%= dom_id(@question) %>_answers").html("<%= j render("polls/questions/answers", question: @question, token: token) %>");
$("#<%= dom_id(@question) %>_answers").html("<%= j render("polls/questions/answers", question: @question, answers: @answers, token: token, page: @page) %>");
App.Sortable.initialize();

View File

@@ -1,4 +1,5 @@
<% provide :title do %><%= @poll.name %><% end %>
<% provide :title do %><%= @poll.name %>
<% end %>
<div class="polls-results-stats">
<%= render "poll_header" %>
@@ -10,37 +11,32 @@
<p><strong><%= t("polls.show.results.title") %></strong></p>
<ul class="menu vertical">
<%- @poll.questions.each do |question| %>
<li><%=link_to question.title, "##{question.title.parameterize}" %></li>
<li><%= link_to question.title, "##{question.title.parameterize}" %></li>
<% end %>
</ul>
</div>
<div class="small-12 medium-9 column" data-equalizer-watch>
<%- @poll.questions.each do |question| %>
<% most_voted_answer_id = question.most_voted_answer_id %>
<h3 id="<%= question.title.parameterize %>"><%= question.title %></h3>
<table id="question_<%= question.id %>_results_table">
<thead>
<tr>
<%- question.question_answers.each do |answer| %>
<th scope="col" <%= answer.id == most_voted_answer_id ? "class=win" : "" %>>
<% if answer.id == most_voted_answer_id %>
<span class="show-for-sr"><%= t("polls.show.results.most_voted_answer") %></span>
<% end %>
<%= answer.title %>
</th>
<% end %>
</tr>
</thead>
<tbody>
<tr>
<%- question.question_answers.each do |answer| %>
<td id="answer_<%= answer.id %>_result" <%= answer.id == most_voted_answer_id ? "class=win" : "" %>>
<%= answer.total_votes %>
<%- question.question_answers.visibles.each do |answer| %>
<tr scope="col" <%= answer.most_voted? ? "class=win" : "" %>>
<td>
<% if answer.most_voted %>
<span class="show-for-sr"><%= t("polls.show.results.most_voted_answer") %></span>
<% end %>
<%= answer.title %>
</td>
<td id="answer_<%= answer.id %>_result" <%= answer.most_voted? ? "class=win" : "" %>>
<%= answer.total_votes %>
<% unless question.enum_type == "positive_negative_open" || question.enum_type == "prioritized" %>
(<%= answer.total_votes_percentage.round(2) %>%)
</td>
<% end %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>

View File

@@ -1,4 +1,4 @@
<%= provide :title, t("social_share.polls_show.title_#{@poll.id}", default: @poll.title) %>
<%= provide :title, t("social_share.polls_show.title_#{@poll.id}", default: @poll.title) %>
<%= provide :meta_description, t("social_share.polls_show.description_#{@poll.id}", default: @poll.title) %>
<%= provide :social_media_meta_tags do %>
<%= render "shared/social_media_meta_tags",
@@ -55,71 +55,80 @@
<div id="poll_more_info_answers" class="expanded poll-more-info-answers">
<div class="row padding">
<% @questions.each do |question| %>
<% if question.answers_with_read_more? %>
<div class="row question-divider">
<h2><%= question.title %></h2>
<% question.question_answers.visibles.each do |answer| %>
<% if answer.description.present? || answer.images.any? || answer.documents.present? || answer.videos.present? %>
<div class="small-12 medium-6 column margin-top margin-bottom" id="answer_<%= answer.id %>">
<h3><%= answer.title %></h3>
<div class="margin-top">
<div id="answer_description_<%= answer.id %>"
class="answer-description short answer-left-divider" data-toggler="short">
<% if answer.description.present? %>
<%= answer.description %>
<% end %>
<% @poll_questions_answers.each do |answer| %>
<div class="small-12 medium-6 column end answer <%= cycle("first", "") %>" id="answer_<%= answer.id %>">
<% if answer.images.any? %>
<div class="margin-top">
<%= render "gallery", answer: answer %>
</div>
<% end %>
<% if answer.description.present? %>
<h3><%= answer.title %></h3>
<% end %>
<% if answer.documents.present? %>
<div class="document-link">
<p>
<span class="icon-document"></span>&nbsp;
<strong><%= t("polls.show.documents") %></strong>
</p>
<% answer.documents.each do |document| %>
<%= link_to document.title,
document.attachment.url,
target: "_blank",
rel: "nofollow" %>
<br>
<% end %>
</div>
<% end %>
<% if answer.images.any? %>
<%= render "gallery", answer: answer %>
<% end %>
<% if answer.videos.present? %>
<div class="video-link">
<p>
<span class="icon-video"></span>&nbsp;
<strong><%= t("polls.show.videos") %></strong>
</p>
<% if answer.description.present? %>
<div class="margin-top">
<div id="answer_description_<%= answer.id %>" class="answer-description short" data-toggler="short">
<%= safe_html_with_links simple_format(answer.description) %>
</div>
<div class="margin">
<a id="read_more_<%= answer.id %>"
data-toggle="answer_description_<%= answer.id %> read_more_<%= answer.id %> read_less_<%= answer.id %>"
data-toggler="hide">
<%= t("polls.show.read_more", answer: answer.title) %>
</a>
<a id="read_less_<%= answer.id %>"
data-toggle="answer_description_<%= answer.id %> read_more_<%= answer.id %> read_less_<%= answer.id %>"
data-toggler="hide"
class="hide">
<%= t("polls.show.read_less", answer: answer.title) %>
</a>
</div>
</div>
<% end %>
<% if answer.documents.present? %>
<div class="document-link">
<p>
<span class="icon-document"></span>&nbsp;
<strong><%= t("polls.show.documents") %></strong>
</p>
<% answer.documents.each do |document| %>
<%= link_to document.title,
document.attachment.url,
target: "_blank",
rel: "nofollow" %><br>
<% answer.videos.each do |video| %>
<%= link_to video.title,
video.url,
target: "_blank",
rel: "nofollow" %>
<br>
<% end %>
</div>
<% end %>
</div>
<div class="margin-top margin-bottom">
<a id="read_more_<%= answer.id %>"
data-toggle="answer_description_<%= answer.id %>
read_more_<%= answer.id %> read_less_<%= answer.id %>"
data-toggler="hide">
<%= t("polls.show.read_more", answer: answer.title) %>
</a>
<a id="read_less_<%= answer.id %>"
data-toggle="answer_description_<%= answer.id %>
read_more_<%= answer.id %> read_less_<%= answer.id %>"
data-toggler="hide" class="hide">
<%= t("polls.show.read_less", answer: answer.title) %>
</a>
</div>
</div>
</div>
<% end %>
</div>
<% end %>
<% if answer.videos.present? %>
<div class="video-link">
<p>
<span class="icon-video"></span>&nbsp;
<strong><%= t("polls.show.videos") %></strong>
</p>
<% answer.videos.each do |video| %>
<%= link_to video.title,
video.url,
target: "_blank",
rel: "nofollow" %><br>
<% end %>
</div>
<% end %>
</div>
<% end %>
</div>
<% end %>
<% end %>
</div>

View File

@@ -5,6 +5,12 @@ resources :polls, only: [:show, :index] do
end
resources :questions, controller: "polls/questions", shallow: true do
post :answer, on: :member
member do
post :answer
post :prioritized_answers
delete :answer, to: "polls/answers#delete"
post :create_answer, to: "polls/answers#create"
get :load_answers
end
end
end

View File

@@ -213,6 +213,18 @@ describe Abilities::Common do
it { should_not be_able_to(:answer, expired_poll_question_from_all_geozones) }
it { should_not be_able_to(:answer, expired_poll_question_from_other_geozone) }
it { should be_able_to(:prioritized_answers, poll_question_from_own_geozone) }
it { should be_able_to(:prioritized_answers, poll_question_from_all_geozones) }
it { should_not be_able_to(:prioritized_answers, poll_question_from_other_geozone) }
it { should_not be_able_to(:prioritized_answers, expired_poll_question_from_own_geozone) }
it { should_not be_able_to(:prioritized_answers, expired_poll_question_from_all_geozones) }
it { should_not be_able_to(:prioritized_answers, expired_poll_question_from_other_geozone) }
context "Poll::Question" do
it { should be_able_to(:load_answers, Poll::Question) }
end
context "without geozone" do
before { user.geozone = nil }