From 55c15bca86c0e7653ec0b8d151127d892d285f50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Tue, 17 Oct 2017 18:29:14 +0200 Subject: [PATCH 01/52] Added poll results route --- app/controllers/polls_controller.rb | 4 ++++ config/routes.rb | 1 + 2 files changed, 5 insertions(+) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 338f72cc4..834c9950d 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -27,4 +27,8 @@ class PollsController < ApplicationController @comment_tree = CommentTree.new(@commentable, params[:page], @current_order) end + def results + @poll = Poll.find(params[:poll_id]) + end + end diff --git a/config/routes.rb b/config/routes.rb index 1fb74aa53..3a7c1dcae 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -113,6 +113,7 @@ Rails.application.routes.draw do end resources :polls, only: [:show, :index] do + get :results resources :questions, controller: 'polls/questions', shallow: true do post :answer, on: :member end From 49118ea312c9f11306083ec58e1a6e9e8daac620 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Tue, 17 Oct 2017 18:29:32 +0200 Subject: [PATCH 02/52] Gave permission to everyone to access poll results --- app/models/abilities/everyone.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index 3004ca8ad..2a6eaf4aa 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, Poll + can [:read, :results], Poll can :read, Poll::Question can [:read, :welcome], Budget can :read, SpendingProposal From bfe0addf3b767858853b3d155053f7c3451e47d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Tue, 17 Oct 2017 18:29:53 +0200 Subject: [PATCH 03/52] Added poll results view --- app/views/polls/results.html.erb | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 app/views/polls/results.html.erb diff --git a/app/views/polls/results.html.erb b/app/views/polls/results.html.erb new file mode 100644 index 000000000..353f92fa1 --- /dev/null +++ b/app/views/polls/results.html.erb @@ -0,0 +1,36 @@ +
+ + +
+ <%- @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 %> + +
+
From 610aea2c72e5238bb9f6ad8b528ebaa986e96b08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Tue, 17 Oct 2017 18:30:20 +0200 Subject: [PATCH 04/52] Added new methods to Poll question and Poll answers --- app/models/poll/question.rb | 4 ++++ app/models/poll/question/answer.rb | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/app/models/poll/question.rb b/app/models/poll/question.rb index 90e528bd0..94a68b806 100644 --- a/app/models/poll/question.rb +++ b/app/models/poll/question.rb @@ -60,4 +60,8 @@ class Poll::Question < ActiveRecord::Base where(poll_id: Poll.answerable_by(user).pluck(:id)) end + def answers_total_votes + question_answers.map { |a| Poll::Answer.where(question_id: self, answer: a.title).count }.sum + end + end diff --git a/app/models/poll/question/answer.rb b/app/models/poll/question/answer.rb index ccbcf1abd..de6e35d1d 100644 --- a/app/models/poll/question/answer.rb +++ b/app/models/poll/question/answer.rb @@ -31,4 +31,18 @@ class Poll::Question::Answer < ActiveRecord::Base def self.last_position(question_id) where(question_id: question_id).maximum('given_order') || 0 end + + def total_votes + Poll::Answer.where(question_id: question, answer: title).count + end + + def is_winner? + answers = question.question_answers + .map { |a| Poll::Answer.where(question_id: a.question, answer: a.title).count } + !answers.any?{ |a| a > total_votes } + end + + def total_votes_percentage + ((total_votes*100) / question.answers_total_votes).round(2) + end end From 70a35fbe58221bf6bd7a04683f9a5a432b9b39dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 18 Oct 2017 18:35:53 +0200 Subject: [PATCH 05/52] Poll views improvements Reorganized poll `#show`, `#stats` and `#results` views. Gave stats section its own route. --- app/controllers/polls_controller.rb | 11 +- app/models/abilities/everyone.rb | 3 +- app/views/polls/_poll_header.html.erb | 27 ++++ app/views/polls/_poll_subnav.html.erb | 21 +++ .../polls/_results_subnavigation.html.erb | 20 --- app/views/polls/_show.html.erb | 126 --------------- app/views/polls/results.html.erb | 70 +++++---- app/views/polls/show.html.erb | 148 ++++++++++++++---- app/views/polls/stats.html.erb | 94 +++++++++++ app/views/polls/stats/_show.html.erb | 85 ---------- config/routes.rb | 3 +- 11 files changed, 313 insertions(+), 295 deletions(-) create mode 100644 app/views/polls/_poll_header.html.erb create mode 100644 app/views/polls/_poll_subnav.html.erb delete mode 100644 app/views/polls/_results_subnavigation.html.erb delete mode 100644 app/views/polls/_show.html.erb create mode 100644 app/views/polls/stats.html.erb delete mode 100644 app/views/polls/stats/_show.html.erb 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 @@ +
+
+
    +
  • + <%= link_to t("polls.show.results_menu"), + poll_results_path(@poll), + class: (controller_name == "polls" && action_name == "results" ? "is-active" : "") %> +
  • +
  • + <%= link_to t("polls.show.stats_menu"), + poll_stats_path(@poll), + class: (controller_name == "polls" && action_name == "stats" ? "is-active" : "") %> +
  • +
  • + <%= link_to t("polls.show.info_menu"), + poll_path(@poll), + class: (controller_name == "polls" && action_name == "show" ? "is-active" : "") %> +
  • +
+
+
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 @@ -
-
-
    -
  • - <%= link_to "#tab-stats" do %> -

    - <%= t("polls.show.stats_menu") %> -

    - <% end %> -
  • -
  • - <%= link_to "#tab-information" do %> -

    - <%= t("polls.show.info_menu") %> -

    - <% end %> -
  • -
-
-
\ 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 From 68341e5a7682c923c69c67be9ca0e76a57e35466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 18 Oct 2017 18:36:02 +0200 Subject: [PATCH 06/52] Added translations --- config/locales/en/general.yml | 1 + config/locales/es/general.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index 85bfbe699..93b2b8931 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -500,6 +500,7 @@ en: videos: "External video" info_menu: "Information" stats_menu: "Participation statistics" + results_menu: "Poll results" stats: title: "Participation data" total_participation: "Total participation" diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index a15952cc9..3da5c5593 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -500,6 +500,7 @@ es: videos: "Vídeo externo" info_menu: "Información" stats_menu: "Estadísticas de participación" + results_menu: "Resultados de la votación" stats: title: "Datos de participación" total_participation: "Participación total" From 6e680c187fb50bf560c93cdd4cd7b01bf8b2a1c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 19 Oct 2017 12:17:20 +0200 Subject: [PATCH 07/52] Added new column `most_voted` to Poll::Question::Answers --- app/models/poll/question/answer.rb | 9 ++-- ..._add_most_voted_to_poll_question_answer.rb | 5 ++ db/schema.rb | 54 ++++++++++++++++--- 3 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 db/migrate/20171019095042_add_most_voted_to_poll_question_answer.rb diff --git a/app/models/poll/question/answer.rb b/app/models/poll/question/answer.rb index de6e35d1d..eff45a57a 100644 --- a/app/models/poll/question/answer.rb +++ b/app/models/poll/question/answer.rb @@ -13,6 +13,7 @@ class Poll::Question::Answer < ActiveRecord::Base validates :given_order, presence: true, uniqueness: { scope: :question_id } before_validation :set_order, on: :create + before_save :most_voted def description super.try :html_safe @@ -36,13 +37,15 @@ class Poll::Question::Answer < ActiveRecord::Base Poll::Answer.where(question_id: question, answer: title).count end - def is_winner? + def most_voted answers = question.question_answers .map { |a| Poll::Answer.where(question_id: a.question, answer: a.title).count } - !answers.any?{ |a| a > total_votes } + most_voted = !answers.any?{ |a| a > total_votes } + + self.update_attributes(most_voted: most_voted) end def total_votes_percentage - ((total_votes*100) / question.answers_total_votes).round(2) + ((total_votes*100) / question.answers_total_votes).round(2) rescue 0 end end diff --git a/db/migrate/20171019095042_add_most_voted_to_poll_question_answer.rb b/db/migrate/20171019095042_add_most_voted_to_poll_question_answer.rb new file mode 100644 index 000000000..e32b7e325 --- /dev/null +++ b/db/migrate/20171019095042_add_most_voted_to_poll_question_answer.rb @@ -0,0 +1,5 @@ +class AddMostVotedToPollQuestionAnswer < ActiveRecord::Migration + def change + add_column :poll_question_answers, :most_voted, :boolean + end +end diff --git a/db/schema.rb b/db/schema.rb index 8a03412be..f83358423 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171010143623) do +ActiveRecord::Schema.define(version: 20171019095042) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -486,6 +486,10 @@ ActiveRecord::Schema.define(version: 20171010143623) do t.boolean "draft_publication_enabled", default: false t.boolean "result_publication_enabled", default: false t.boolean "published", default: true + t.date "proposals_phase_start_date" + t.date "proposals_phase_end_date" + t.boolean "proposals_phase_enabled" + t.text "proposals_description" end add_index "legislation_processes", ["allegations_end_date"], name: "index_legislation_processes_on_allegations_end_date", using: :btree @@ -498,6 +502,36 @@ ActiveRecord::Schema.define(version: 20171010143623) do add_index "legislation_processes", ["result_publication_date"], name: "index_legislation_processes_on_result_publication_date", using: :btree add_index "legislation_processes", ["start_date"], name: "index_legislation_processes_on_start_date", using: :btree + create_table "legislation_proposals", force: :cascade do |t| + t.integer "legislation_process_id" + t.string "title", limit: 80 + t.text "description" + t.string "question" + t.string "external_url" + t.integer "author_id" + t.datetime "hidden_at" + t.integer "flags_count", default: 0 + t.datetime "ignored_flag_at" + t.integer "cached_votes_up", default: 0 + t.integer "comments_count", default: 0 + t.datetime "confirmed_hide_at" + t.integer "hot_score", limit: 8, default: 0 + t.integer "confidence_score", default: 0 + t.string "responsible_name", limit: 60 + t.text "summary" + t.string "video_url" + t.tsvector "tsv" + t.integer "geozone_id" + t.datetime "retired_at" + t.string "retired_reason" + t.text "retired_explanation" + t.integer "community_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "legislation_proposals", ["legislation_process_id"], name: "index_legislation_proposals_on_legislation_process_id", using: :btree + create_table "legislation_question_options", force: :cascade do |t| t.integer "legislation_question_id" t.string "value" @@ -666,6 +700,7 @@ ActiveRecord::Schema.define(version: 20171010143623) do t.text "description" t.integer "question_id" t.integer "given_order", default: 1 + t.boolean "most_voted" end add_index "poll_question_answers", ["question_id"], name: "index_poll_question_answers_on_question_id", using: :btree @@ -919,16 +954,20 @@ ActiveRecord::Schema.define(version: 20171010143623) do add_index "taggings", ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context", using: :btree create_table "tags", force: :cascade do |t| - t.string "name", limit: 40 - t.integer "taggings_count", default: 0 - t.integer "debates_count", default: 0 - t.integer "proposals_count", default: 0 - t.integer "spending_proposals_count", default: 0 + t.string "name", limit: 40 + t.integer "taggings_count", default: 0 + t.integer "debates_count", default: 0 + t.integer "proposals_count", default: 0 + t.integer "spending_proposals_count", default: 0 t.string "kind" - t.integer "budget/investments_count", default: 0 + t.integer "budget/investments_count", default: 0 + t.integer "legislation/proposals_count", default: 0 + t.integer "legislation/processes_count", default: 0 end add_index "tags", ["debates_count"], name: "index_tags_on_debates_count", using: :btree + add_index "tags", ["legislation/processes_count"], name: "index_tags_on_legislation/processes_count", using: :btree + add_index "tags", ["legislation/proposals_count"], name: "index_tags_on_legislation/proposals_count", using: :btree add_index "tags", ["name"], name: "index_tags_on_name", unique: true, using: :btree add_index "tags", ["proposals_count"], name: "index_tags_on_proposals_count", using: :btree add_index "tags", ["spending_proposals_count"], name: "index_tags_on_spending_proposals_count", using: :btree @@ -1106,6 +1145,7 @@ ActiveRecord::Schema.define(version: 20171010143623) do add_foreign_key "identities", "users" add_foreign_key "images", "users" add_foreign_key "legislation_draft_versions", "legislation_processes" + add_foreign_key "legislation_proposals", "legislation_processes" add_foreign_key "locks", "users" add_foreign_key "managers", "users" add_foreign_key "moderators", "users" From f029cc20165840121d54ab0231fca7e33bd7a6e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 19 Oct 2017 12:17:33 +0200 Subject: [PATCH 08/52] Cached Poll stats methods --- app/models/poll/stats.rb | 118 ++++++++++++++++++++++----------------- 1 file changed, 68 insertions(+), 50 deletions(-) diff --git a/app/models/poll/stats.rb b/app/models/poll/stats.rb index 1df281434..ac45a2aae 100644 --- a/app/models/poll/stats.rb +++ b/app/models/poll/stats.rb @@ -16,110 +16,128 @@ class Poll end private - + def total_participants - total_participants_web + total_participants_booth + stats_cache('total_participants') { total_participants_web + total_participants_booth } end def total_participants_web - total_web_valid + total_web_white + total_web_null + stats_cache('total_participants_web') { total_web_valid + total_web_white + total_web_null } end - + def total_participants_web_percentage - (total_participants) == 0 ? 0 : total_participants_web * 100 / total_participants + stats_cache('total_participants_web_percentage') { + (total_participants) == 0 ? 0 : total_participants_web * 100 / total_participants + } end def total_participants_booth - voters.where(origin: 'booth').count + stats_cache('total_participants_booth') { voters.where(origin: 'booth').count } end - + def total_participants_booth_percentage - (total_participants) == 0 ? 0 : total_participants_booth * 100 / total_participants.to_f + stats_cache('total_participants_booth_percentage') { + (total_participants) == 0 ? 0 : total_participants_booth * 100 / total_participants.to_f + } end - + def total_web_valid - voters.where(origin: 'web').count + stats_cache('total_web_valid') { voters.where(origin: 'web').count } end - + def valid_percentage_web - (total_valid_votes) == 0 ? 0 : total_web_valid * 100 / total_valid_votes.to_f + stats_cache('valid_percentage_web') { + (total_valid_votes) == 0 ? 0 : total_web_valid * 100 / total_valid_votes.to_f + } end - + def total_web_white - 0 + stats_cache('total_web_white') { 0 } end - + def white_percentage_web - 0 + stats_cache('white_percentage_web') { 0 } end - + def total_web_null - 0 + stats_cache('total_web_null') { 0 } end - + def null_percentage_web - 0 + stats_cache('null_percentage_web') { 0 } end - + def total_booth_valid - recounts.sum(:total_amount) + stats_cache('total_booth_valid') { recounts.sum(:total_amount) } end - + def valid_percentage_booth - (total_valid_votes) == 0 ? 0 : total_booth_valid * 100 / total_valid_votes.to_f + stats_cache('valid_percentage_booth') { + (total_valid_votes) == 0 ? 0 : total_booth_valid * 100 / total_valid_votes.to_f + } end - - def total_booth_white - recounts.sum(:white_amount) + + def total_booth_white + stats_cache('total_booth_white') { recounts.sum(:white_amount) } end - + def white_percentage_booth - (total_white_votes) == 0 ? 0 : total_booth_white * 100 / total_white_votes.to_f + stats_cache('white_percentage_booth') { + (total_white_votes) == 0 ? 0 : total_booth_white * 100 / total_white_votes.to_f + } end - + def total_booth_null - recounts.sum(:null_amount) + stats_cache('total_booth_null') { recounts.sum(:null_amount) } end - + def null_percentage_booth - (total_null_votes == 0) ? 0 : total_booth_null * 100 / total_null_votes.to_f + stats_cache('null_percentage_booth') { + (total_null_votes == 0) ? 0 : total_booth_null * 100 / total_null_votes.to_f + } end - + def total_valid_votes - total_web_valid + total_booth_valid + stats_cache('total_valid_votes') { total_web_valid + total_booth_valid } end - + def total_valid_percentage - (total_participants) == 0 ? 0 : total_valid_votes * 100 / total_participants.to_f + stats_cache('total_valid_percentage'){ + (total_participants) == 0 ? 0 : total_valid_votes * 100 / total_participants.to_f + } end - + def total_white_votes - total_web_white + total_booth_white + stats_cache('total_white_votes') { total_web_white + total_booth_white } end - + def total_white_percentage - (total_participants) == 0 ? 0 : total_white_votes * 100 / total_participants.to_f + stats_cache('total_white_percentage') { + (total_participants) == 0 ? 0 : total_white_votes * 100 / total_participants.to_f + } end - + def total_null_votes - total_web_null + total_booth_null + stats_cache('total_null_votes') { total_web_null + total_booth_null } end - + def total_null_percentage - (total_participants) == 0 ? 0 : total_null_votes * 100 / total_participants.to_f + stats_cache('total_null_percentage') { + (total_participants) == 0 ? 0 : total_null_votes * 100 / total_participants.to_f + } end def voters - @poll.voters + stats_cache('voters') { @poll.voters } end - + def recounts - @poll.recounts + stats_cache('recounts') { @poll.recounts } end def stats_cache(key, &block) - Rails.cache.fetch("polls_stats/#{@poll.id}/#{key}/v7", &block) + Rails.cache.fetch("polls_stats/#{@poll.id}/#{key}", &block) end end -end \ No newline at end of file +end From 8be8bb07f9b681047154a90d0c808ef22ff56f14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 19 Oct 2017 12:17:49 +0200 Subject: [PATCH 09/52] Added first poll results tests --- spec/features/polls/results_spec.rb | 26 ++++++++++++++++++++++++++ spec/features/polls/voter_spec.rb | 4 ++-- spec/support/common_actions.rb | 6 +++--- 3 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 spec/features/polls/results_spec.rb diff --git a/spec/features/polls/results_spec.rb b/spec/features/polls/results_spec.rb new file mode 100644 index 000000000..c67ad3869 --- /dev/null +++ b/spec/features/polls/results_spec.rb @@ -0,0 +1,26 @@ +require 'rails_helper' + +feature 'Poll Results' do + scenario 'List each Poll question' do + user = create(:user, :level_two) + + poll = create(:poll) + question1 = create(:poll_question, poll: poll) + answer1 = create(:poll_question_answer, question: question1, title: 'Yes') + answer2 = create(:poll_question_answer, question: question1, title: 'No') + + question2 = create(:poll_question, poll: poll) + answer3 = create(:poll_question_answer, question: question2, title: 'Blue') + answer4 = create(:poll_question_answer, question: question2, title: 'Green') + answer5 = create(:poll_question_answer, question: question2, title: 'Yellow') + + login_as user + vote_for_poll_via_web(poll, question1, 'Yes') + vote_for_poll_via_web(poll, question1, 'Blue') + + visit poll_results_path(poll) + + expect(page).to have_content(question1.title) + expect(page).to have_content(question2.title) + end +end diff --git a/spec/features/polls/voter_spec.rb b/spec/features/polls/voter_spec.rb index ff9b71755..7e451be17 100644 --- a/spec/features/polls/voter_spec.rb +++ b/spec/features/polls/voter_spec.rb @@ -95,7 +95,7 @@ feature "Voter" do scenario "Trying to vote in web and then in booth", :js do login_as user - vote_for_poll_via_web(poll, question) + vote_for_poll_via_web(poll, question, 'Yes') click_link "Sign out" @@ -127,7 +127,7 @@ feature "Voter" do scenario "Trying to vote in web again", :js do login_as user - vote_for_poll_via_web(poll, question) + vote_for_poll_via_web(poll, question, 'Yes') visit poll_path(poll) diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index b87a54d8e..90deab1b5 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -299,12 +299,12 @@ module CommonActions end end - def vote_for_poll_via_web(poll, question) + def vote_for_poll_via_web(poll, question, answer) visit poll_path(poll) within("#poll_question_#{question.id}_answers") do - click_link 'Yes' - expect(page).to_not have_link('Yes') + click_link "#{answer}" + expect(page).to_not have_link("#{answer}") end expect(Poll::Voter.count).to eq(1) From 78fa77b28d8d6f7d334a54c4f4aec576e58084e0 Mon Sep 17 00:00:00 2001 From: decabeza Date: Thu, 19 Oct 2017 12:23:14 +0200 Subject: [PATCH 10/52] fixes styles for poll subnav --- app/assets/stylesheets/layout.scss | 2 ++ app/views/polls/_poll_subnav.html.erb | 42 ++++++++++++++++----------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index 06fdfd396..d79a2b37f 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -214,6 +214,8 @@ a { margin-bottom: $line-height / 2; li { + font-size: $base-font-size; + margin-bottom: 0; margin-right: $line-height / 2; @include breakpoint(medium) { diff --git a/app/views/polls/_poll_subnav.html.erb b/app/views/polls/_poll_subnav.html.erb index 9b37e1867..8155e2ef4 100644 --- a/app/views/polls/_poll_subnav.html.erb +++ b/app/views/polls/_poll_subnav.html.erb @@ -1,21 +1,29 @@ -
+
-
    -
  • - <%= link_to t("polls.show.results_menu"), - poll_results_path(@poll), - class: (controller_name == "polls" && action_name == "results" ? "is-active" : "") %> -
  • -
  • - <%= link_to t("polls.show.stats_menu"), - poll_stats_path(@poll), - class: (controller_name == "polls" && action_name == "stats" ? "is-active" : "") %> -
  • -
  • - <%= link_to t("polls.show.info_menu"), - poll_path(@poll), - class: (controller_name == "polls" && action_name == "show" ? "is-active" : "") %> -
  • +
From a0eb6e56a10da349ed3f8c22d84c7a7385c34db2 Mon Sep 17 00:00:00 2001 From: decabeza Date: Thu, 19 Oct 2017 12:23:57 +0200 Subject: [PATCH 11/52] fixes styles for polls tabs, uses underscore for ids --- app/assets/stylesheets/layout.scss | 13 ++++++++----- app/views/polls/_filter_subnav.html.erb | 6 +++--- app/views/polls/show.html.erb | 4 ++-- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index d79a2b37f..9e6d3bc08 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -318,13 +318,16 @@ a { } .tabs { - border: { - left: 0; - right: 0; - top: 0; - }; + border-left: 0; + border-right: 0; + border-top: 0; margin-bottom: $line-height; + .tabs-title { + font-size: $base-font-size; + margin-bottom: 0; + } + .tabs-title > a { color: $text-medium; margin-bottom: rem-calc(-1); diff --git a/app/views/polls/_filter_subnav.html.erb b/app/views/polls/_filter_subnav.html.erb index b096edaf2..fe43ddf5d 100644 --- a/app/views/polls/_filter_subnav.html.erb +++ b/app/views/polls/_filter_subnav.html.erb @@ -1,8 +1,8 @@ -
+
-
    +
    • - <%= link_to "#tab-comments" do %> + <%= link_to "#tab_comments" do %>

      <%= t("polls.show.comments_tab") %> (<%= @poll.comments_count %>) diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index 4eabd240b..01bdddc54 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -124,10 +124,10 @@

-
+
<%= render "filter_subnav" %> -
+
<%= render "comments" %>
From e13a48b57219eb2226a6ba65adf642b983965573 Mon Sep 17 00:00:00 2001 From: decabeza Date: Thu, 19 Oct 2017 12:27:22 +0200 Subject: [PATCH 12/52] adds styles to polls stats --- app/assets/stylesheets/layout.scss | 4 + app/assets/stylesheets/participation.scss | 50 ++++++++ app/views/polls/stats.html.erb | 136 +++++++++++++--------- 3 files changed, 134 insertions(+), 56 deletions(-) diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index 9e6d3bc08..9428c1982 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -381,6 +381,10 @@ a { box-shadow: none; } +.uppercase { + text-transform: uppercase; +} + // 02. Header // ---------- diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index a887d83de..382615739 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -8,6 +8,7 @@ // 06. Budget // 07. Proposals successful // 08. Polls +// 09. Polls results and stats // // 01. Votes and supports @@ -1803,3 +1804,52 @@ } } } + +// 09. Polls results and stats +// --------------------------- + +.polls-results-stats { + + .sidebar { + border-right: 1px solid $border; + + .menu { + padding: 0; + + li a { + color: $link; + } + } + } + + table { + table-layout: fixed; + + caption { + padding: $line-height / 2 0; + text-align: left; + } + + th { + text-align: left; + + &.win { + background: #009fde; + } + } + + td { + + &.win { + background: #ccedf8; + font-weight: bold; + } + } + } + + .number { + font-size: rem-calc(60); + font-weight: bold; + line-height: rem-calc(60); + } +} diff --git a/app/views/polls/stats.html.erb b/app/views/polls/stats.html.erb index 20e5411ab..5daaf433a 100644 --- a/app/views/polls/stats.html.erb +++ b/app/views/polls/stats.html.erb @@ -1,25 +1,28 @@ <% provide :title do %><%= @poll.name %><% end %> -
+
<%= render "poll_header" %> <%= render "poll_subnav" %> -
-