diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 4dce3bc81..aa93581cc 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -3,6 +3,8 @@ class PollsController < ApplicationController load_and_authorize_resource + before_filter :set_poll, only: [:stats, :results] + has_filters %w{current expired incoming} has_orders %w{most_voted newest oldest}, only: :show @@ -25,11 +27,18 @@ class PollsController < ApplicationController @commentable = @poll @comment_tree = CommentTree.new(@commentable, params[:page], @current_order) - + end + + def stats @stats = Poll::Stats.new(@poll).generate end def results + end + + private + + def set_poll @poll = Poll.find(params[:poll_id]) end diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index e2529f72a..4d2fe4434 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -6,7 +6,7 @@ module Abilities can [:read, :map], Debate can [:read, :map, :summary, :share], Proposal can :read, Comment - can [:read, :results], Poll + can [:read, :results, :stats], Poll can :read, Poll::Question can [:read, :welcome], Budget can :read, SpendingProposal @@ -23,7 +23,6 @@ module Abilities can [:read], Legislation::Question can [:create], Legislation::Answer can [:search, :comments, :read, :create, :new_comment], Legislation::Annotation - can :read_stats, Poll end end end diff --git a/app/views/polls/_poll_header.html.erb b/app/views/polls/_poll_header.html.erb new file mode 100644 index 000000000..db4918ab4 --- /dev/null +++ b/app/views/polls/_poll_header.html.erb @@ -0,0 +1,27 @@ +
+
+
+ <%= back_link_to polls_path, t("polls.show.back") %> + +

<%= @poll.name %>

+ + <%= safe_html_with_links simple_format(@poll.summary) %> + + <% if @poll.geozones.any? %> +
    + <% @poll.geozones.each do |g| %> +
  • <%= g.name %>
  • + <% end %> +
+ <% end %> +
+ + +
+
diff --git a/app/views/polls/_poll_subnav.html.erb b/app/views/polls/_poll_subnav.html.erb new file mode 100644 index 000000000..9b37e1867 --- /dev/null +++ b/app/views/polls/_poll_subnav.html.erb @@ -0,0 +1,21 @@ +
+
+ +
+
diff --git a/app/views/polls/_results_subnavigation.html.erb b/app/views/polls/_results_subnavigation.html.erb deleted file mode 100644 index 9c2a7e8b0..000000000 --- a/app/views/polls/_results_subnavigation.html.erb +++ /dev/null @@ -1,20 +0,0 @@ -
-
- -
-
\ No newline at end of file diff --git a/app/views/polls/_show.html.erb b/app/views/polls/_show.html.erb deleted file mode 100644 index ee75ea5e3..000000000 --- a/app/views/polls/_show.html.erb +++ /dev/null @@ -1,126 +0,0 @@ -
-
- <%= render "callout" %> - - <% if @poll.voted_in_booth?(current_user) %> -
- <%= t("polls.show.already_voted_in_booth") %> -
- <% else %> - - <% if current_user && @poll.voted_in_web?(current_user) %> -
- <%= t("polls.show.already_voted_in_web") %> -
- <% end %> - <% end %> - - <% @questions.each do |question| %> - <%= render 'polls/questions/question', question: question, token: @token %> - <% end %> - - <% if poll_voter_token(@poll, current_user).empty? %> - - <% end %> - - <%= link_to t("polls.show.participate_in_other_polls"), polls_path, class: "button hollow" %> -
-
- -
-
-
-

<%= t("polls.show.more_info_title") %>

- <%= safe_html_with_links simple_format(@poll.description) %> -
- - <% if false %> - - <% end %> -
-
- -
-
- - <% @poll_questions_answers.each do |answer| %> -
- - <% if answer.description.present? %> -

<%= answer.title %>

- <% end %> - - <% if answer.images.any? %> - <%= render "gallery", answer: answer %> - <% end %> - - <% if answer.description.present? %> - - <% end %> - - <% if answer.documents.present? %> - - <% end %> - - <% if answer.videos.present? %> - - <% end %> -
- <% end %> -
- -
- -
- <%= render "filter_subnav" %> - -
- <%= render "comments" %> -
-
\ No newline at end of file diff --git a/app/views/polls/results.html.erb b/app/views/polls/results.html.erb index 353f92fa1..f0c9e4a38 100644 --- a/app/views/polls/results.html.erb +++ b/app/views/polls/results.html.erb @@ -1,36 +1,44 @@ -
- - -
- <%- @poll.questions.each do |question| %> - -

<%= question.title %>

- - - <%- question.question_answers.each do |answer| %> - - <% end %> - - - - - <%- question.question_answers.each do |answer| %> - - <% end %> - - -
><%= answer.title %>
> - <%= answer.total_votes %> - (<%= answer.total_votes_percentage %>%) -
- <% end %> +
diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index 880d0d421..4eabd240b 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -1,44 +1,134 @@ <% provide :title do %><%= @poll.name %><% end %>
-
-
-
- <%= back_link_to polls_path, t("polls.show.back") %> + <%= render "poll_header" %> -

<%= @poll.name %>

+ <%= render "poll_subnav" %> - <%= safe_html_with_links simple_format(@poll.summary) %> +
+
+ <%= render "callout" %> - <% if @poll.geozones.any? %> -
    - <% @poll.geozones.each do |g| %> -
  • <%= g.name %>
  • - <% end %> -
+ <% if @poll.voted_in_booth?(current_user) %> +
+ <%= t("polls.show.already_voted_in_booth") %> +
+ <% else %> + + <% if current_user && @poll.voted_in_web?(current_user) %> +
+ <%= t("polls.show.already_voted_in_web") %> +
<% end %> + <% end %> + + <% @questions.each do |question| %> + <%= render 'polls/questions/question', question: question, token: @token %> + <% end %> + + <% if poll_voter_token(@poll, current_user).empty? %> + + <% end %> + + <%= link_to t("polls.show.participate_in_other_polls"), polls_path, class: "button hollow" %> +
+
+ +
+
+
+

<%= t("polls.show.more_info_title") %>

+ <%= safe_html_with_links simple_format(@poll.description) %>
- + <% if false %> + + <% end %>
- -
- <%= render "results_subnavigation" %> -
- <%= render "polls/stats/show" %> +
+
+ + <% @poll_questions_answers.each do |answer| %> +
+ + <% if answer.description.present? %> +

<%= answer.title %>

+ <% end %> + + <% if answer.images.any? %> + <%= render "gallery", answer: answer %> + <% end %> + + <% if answer.description.present? %> + + <% end %> + + <% if answer.documents.present? %> + + <% end %> + + <% if answer.videos.present? %> + + <% end %> +
+ <% end %> +
+ +
+ +
+ <%= render "filter_subnav" %> + +
+ <%= render "comments" %>
- -
- <%= render "show" %> -
- diff --git a/app/views/polls/stats.html.erb b/app/views/polls/stats.html.erb new file mode 100644 index 000000000..20e5411ab --- /dev/null +++ b/app/views/polls/stats.html.erb @@ -0,0 +1,94 @@ +<% provide :title do %><%= @poll.name %><% end %> + +
+ <%= render "poll_header" %> + + <%= render "poll_subnav" %> + +
+ +
+

<%= t("polls.show.stats.total_participation") %>

+ +

+ <%= t("polls.show.stats.total_votes") %>
+ <%= @stats[:total_participants] %> +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
<%= t("polls.show.stats.votes") %><%= t("polls.show.stats.web") %><%= t("polls.show.stats.booth") %><%= t("polls.show.stats.total") %>
<%= t("polls.show.stats.valid") %><%= @stats[:total_web_valid] %> + (<%= number_to_percentage(@stats[:valid_percentage_web], + strip_insignificant_zeros: true, + precision: 2) %>)<%= @stats[:total_booth_valid] %> + (<%= number_to_percentage(@stats[:valid_percentage_booth], + strip_insignificant_zeros: true, + precision: 2) %>)<%= @stats[:total_valid_votes] %> + (<%= number_to_percentage(@stats[:total_valid_percentage], + strip_insignificant_zeros: true, + precision: 2) %>)
<%= t("polls.show.stats.white") %><%= @stats[:total_web_white] %> + (<%= number_to_percentage(@stats[:white_percentage_web], + strip_insignificant_zeros: true, + precision: 2) %>)<%= @stats[:total_booth_white] %> + (<%= number_to_percentage(@stats[:white_percentage_booth], + strip_insignificant_zeros: true, + precision: 2) %>)<%= @stats[:total_white_votes] %> + (<%= number_to_percentage(@stats[:total_white_percentage], + strip_insignificant_zeros: true, + precision: 2) %>)
<%= t("polls.show.stats.null_votes") %><%= @stats[:total_web_null] %> + (<%= number_to_percentage(@stats[:null_percentage_web], + strip_insignificant_zeros: true, + precision: 2) %>)<%= @stats[:total_booth_null] %> + (<%= number_to_percentage(@stats[:null_percentage_booth], + strip_insignificant_zeros: true, + precision: 2) %>)<%= @stats[:total_null_votes] %> + (<%= number_to_percentage(@stats[:total_null_percentage], + strip_insignificant_zeros: true, + precision: 2) %>)
<%= t("polls.show.stats.total") %><%= @stats[:total_participants_web] %> + (<%= number_to_percentage(@stats[:total_participants_web_percentage], + strip_insignificant_zeros: true, + precision: 2) %>)<%= @stats[:total_participants_booth] %> + (<%= number_to_percentage(@stats[:total_participants_booth_percentage], + strip_insignificant_zeros: true, + precision: 2) %>)<%= @stats[:total_participants_web] + @stats[:total_participants_booth] %>
+
+
+ +
diff --git a/app/views/polls/stats/_show.html.erb b/app/views/polls/stats/_show.html.erb deleted file mode 100644 index 1aeb7cf69..000000000 --- a/app/views/polls/stats/_show.html.erb +++ /dev/null @@ -1,85 +0,0 @@ -
- -
-

<%= t("polls.show.stats.total_participation") %>

- -

- <%= t("polls.show.stats.total_votes") %>
- <%= @stats[:total_participants] %> -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
<%= t("polls.show.stats.votes") %><%= t("polls.show.stats.web") %><%= t("polls.show.stats.booth") %><%= t("polls.show.stats.total") %>
<%= t("polls.show.stats.valid") %><%= @stats[:total_web_valid] %> - (<%= number_to_percentage(@stats[:valid_percentage_web], - strip_insignificant_zeros: true, - precision: 2) %>)<%= @stats[:total_booth_valid] %> - (<%= number_to_percentage(@stats[:valid_percentage_booth], - strip_insignificant_zeros: true, - precision: 2) %>)<%= @stats[:total_valid_votes] %> - (<%= number_to_percentage(@stats[:total_valid_percentage], - strip_insignificant_zeros: true, - precision: 2) %>)
<%= t("polls.show.stats.white") %><%= @stats[:total_web_white] %> - (<%= number_to_percentage(@stats[:white_percentage_web], - strip_insignificant_zeros: true, - precision: 2) %>)<%= @stats[:total_booth_white] %> - (<%= number_to_percentage(@stats[:white_percentage_booth], - strip_insignificant_zeros: true, - precision: 2) %>)<%= @stats[:total_white_votes] %> - (<%= number_to_percentage(@stats[:total_white_percentage], - strip_insignificant_zeros: true, - precision: 2) %>)
<%= t("polls.show.stats.null_votes") %><%= @stats[:total_web_null] %> - (<%= number_to_percentage(@stats[:null_percentage_web], - strip_insignificant_zeros: true, - precision: 2) %>)<%= @stats[:total_booth_null] %> - (<%= number_to_percentage(@stats[:null_percentage_booth], - strip_insignificant_zeros: true, - precision: 2) %>)<%= @stats[:total_null_votes] %> - (<%= number_to_percentage(@stats[:total_null_percentage], - strip_insignificant_zeros: true, - precision: 2) %>)
<%= t("polls.show.stats.total") %><%= @stats[:total_participants_web] %> - (<%= number_to_percentage(@stats[:total_participants_web_percentage], - strip_insignificant_zeros: true, - precision: 2) %>)<%= @stats[:total_participants_booth] %> - (<%= number_to_percentage(@stats[:total_participants_booth_percentage], - strip_insignificant_zeros: true, - precision: 2) %>)<%= @stats[:total_participants_web] + @stats[:total_participants_booth] %>
-
-
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 5ab529a87..38858b813 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -111,8 +111,9 @@ Rails.application.routes.draw do resources :annotations do get :search, on: :collection end - + resources :polls, only: [:show, :index] do + get :stats get :results resources :questions, controller: 'polls/questions', shallow: true do post :answer, on: :member