Skip to content

Commit

Permalink
Add Admin changes to create Poll:Questions with votation type
Browse files Browse the repository at this point in the history
  • Loading branch information
abelardogilm authored and javierm committed Jun 12, 2019
1 parent 7c9c50f commit 23d3683
Show file tree
Hide file tree
Showing 16 changed files with 485 additions and 16 deletions.
3 changes: 3 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
//= require cookies
//= require columns_selector
//= require budget_edit_associations.js.coffee
//= require votations

var initialize_modules = function() {
App.Answers.initialize();
Expand Down Expand Up @@ -140,6 +141,8 @@ var initialize_modules = function() {
if ( $('#js-columns-selector').length )
App.ColumnsSelector.initialize();
App.BudgetEditAssociations.initialize();
if ( $("#votation_type_enum_type").length )
App.Votations.initialize();
};

$(function(){
Expand Down
45 changes: 45 additions & 0 deletions app/assets/javascripts/votations.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
App.Votations =

checkMaxVotes: ->
if $("#votation_type_enum_type").val() == "0"
$(".js-max_votes").hide()
$("#max_votes").attr(disabled: true)
else
$(".js-max_votes").show()
$("#max_votes").attr(disabled: false)

checkPrioritization: ->
if $("#votation_type_enum_type").val() == "2"
$(".js-prioritization_type").show()
$("#prioritization_type").attr(disabled: false)
else
$(".js-prioritization_type").hide()
$("#prioritization_type").attr(disabled: true)

checkMaxGroups: ->
if $("#votation_type_enum_type").val() == "7" || $("#votation_type_enum_type").val() == "8"
$(".js-max_group_votes").show()
$("#max_groups_answers").attr(disabled: false)
else
$(".js-max_group_votes").hide()
$("#max_groups_answers").attr(disabled: true)

setTraduction: (response) ->
console.log response
$(".js-description_text").text(response["traduction"])

updateChecks: () ->
App.Votations.checkMaxVotes()
App.Votations.checkPrioritization()
App.Votations.checkMaxGroups()

initialize: ->
App.Votations.updateChecks()
$("#votation_type_enum_type").on
change: ->
App.Votations.updateChecks()
url = "/admin/get_options_traductions.json"
params = { enum_type: $("#votation_type_enum_type").val() }
$.get(url, params, (response) -> App.Votations.setTraduction response, "json")

false
13 changes: 13 additions & 0 deletions app/assets/stylesheets/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,10 @@ code {
font-weight: bold;
}

.hidden {
display: none;
}

table {

.callout {
Expand All @@ -796,6 +800,15 @@ table {
}
}

.info-type {
background-color: #ccf5ff;
padding: 15px;
}

.margin-description {
margin-top: rem-calc(20);
}

// 07. Legislation
// --------------

Expand Down
1 change: 1 addition & 0 deletions app/controllers/admin/budget_investments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
before_action :load_change_log, only: [:show]

def index
load_tags
respond_to do |format|
format.html
format.js
Expand Down
10 changes: 9 additions & 1 deletion app/controllers/admin/poll/questions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def new

def create
@question.author = @question.proposal.try(:author) || current_user
@question.votation_type = VotationType.build_by_type(@question, params[:votation_type])

if @question.save
redirect_to admin_question_path(@question)
Expand Down Expand Up @@ -53,11 +54,18 @@ def destroy
redirect_to admin_questions_path, notice: notice
end

def get_options_traductions
render json: {
traduction: t("polls.index.descriptions.#{VotationType.enum_types.key params[:enum_type].to_i}")
}
end

private

def question_params
attributes = [:poll_id, :question, :proposal_id]
params.require(:poll_question).permit(*attributes, translation_params(Poll::Question))
params.require(:poll_question).permit(*attributes, translation_params(Poll::Question),
:votation_type, :max_votes, :prioritization_type, :max_groups_answers)
end

def search_params
Expand Down
4 changes: 2 additions & 2 deletions app/models/abilities/administrator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def initialize(user)
can [:search, :create, :index, :destroy], ::Poll::Officer
can [:create, :destroy, :manage], ::Poll::BoothAssignment
can [:create, :destroy], ::Poll::OfficerAssignment
can [:read, :create, :update], Poll::Question
can :destroy, Poll::Question # , comments_count: 0, votes_up: 0
can [:read, :create, :update, :get_options_traductions], Poll::Question
can :destroy, Poll::Question

can :manage, SiteCustomization::Page
can :manage, SiteCustomization::Image
Expand Down
32 changes: 32 additions & 0 deletions app/views/admin/poll/questions/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,38 @@
<%= translations_form.text_field :title %>
<% end %>
<% if !@question.persisted? %>
<%= fields_for :votation_type do |votation_f| %>
<div class="small-12 medium-6">
<%= votation_f.select :enum_type,
options_for_select(VotationType.enum_types.map {|k, v| [t(k, scope: :enum_type), v]},
params.dig(:votation_type, :enum_type)), default: 0,
disabled: @question.persisted?, label: t("enum_type.title") %>
</div>

<div class="info-type">
<span class="js-description_text">
<%= t("polls.index.descriptions.unique") %>
</span>
<div class="small-12 medium-6 margin-description js-max_votes hidden ">
<%= votation_f.number_field :max_votes, min: 1, max: 999,
value: params.dig(:votation_type, :max_votes),
label: t("question.max_votes") %>
</div>
<div class="small-12 medium-6 js-prioritization_type hidden">
<%= votation_f.select :prioritization_type,
options_for_select(VotationType.prioritization_types.map {|k, v| [t(k, scope: :prioritization_type), v]},
params.dig(:votation_type, :prioritization_type) ), default: 0,
disabled: @question.persisted?, label: t("prioritization_type.title") %>
</div>
<div class="small-12 medium-6 js-max_group_votes hidden">
<%= votation_f.number_field :max_groups_answers, min: 1, max: 999,
value: params.dig(:votation_type, :max_groups_answers), label: t("question.max_group_answers") %>
</div>
</div>
<% end %>
<% end %>

<div class="small-12 medium-4 large-2 margin-top">
<%= f.submit(class: "button success expanded", value: t("shared.save")) %>
</div>
Expand Down
29 changes: 29 additions & 0 deletions app/views/admin/poll/questions/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,35 @@
<%= link_to @question.proposal.title, proposal_path(@question.proposal) %>
</p>
<% end %>
<% unless @question.votation_type.nil? %>
<p>
<strong><%= t("question.votation_type") %></strong>
<br>
<%= t("enum_type.#{@question.votation_type.enum_type}") %>
</p>
<% if !@question.votation_type.max_votes.nil? %>
<p>
<strong><%= t("question.max_votes") %></strong>
<br>
<%= @question.votation_type.max_votes %>
</p>
<% end %>
<% if !@question.votation_type.prioritization_type.nil? %>
<p>
<strong><%= t("prioritization_type.title") %></strong>
<br>
<%= t("prioritization_type.#{@question.votation_type.prioritization_type}") %>
</p>
<% end %>
<% if !@question.votation_type.max_groups_answers.nil? %>
<p>
<strong><%= t("question.max_group_answers") %></strong>
<br>
<%= @question.votation_type.max_groups_answers %>
</p>
<% end %>
<% end %>
</div>
</div>

Expand Down
40 changes: 40 additions & 0 deletions app/views/admin/poll/results/_votation_types_results.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<div class="polls-results-stats">

<div class="row margin">
<div class="small-12 medium-3 column">
<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>
<% end %>
</ul>
</div>

<div class="small-12 medium-9 column">
<%- @poll.questions.each do |question| %>
<h3 id="<%= question.title.parameterize %>"><%= question.title %></h3>
<table id="question_<%= question.id %>_results_table">
<tbody>
<%- 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" %>
(<%= answer.total_votes_percentage.round(2) %>%)
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>

</div>
</div>
</div>
12 changes: 8 additions & 4 deletions app/views/admin/poll/results/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@
</div>
<% end %>
<% if @partial_results.present? %>
<%= render "recount", resource: @poll %>
<%= render "result" %>
<%= render "results_by_booth" %>
<% if @poll.questions.any? { |question| question.votation_type.present? } %>
<%= render "votation_types_results" %>
<% else %>
<% if @partial_results.present? %>
<%= render "recount", resource: @poll %>
<%= render "result" %>
<%= render "results_by_booth" %>
<% end %>
<% end %>
<% if @poll.voters.any? %>
Expand Down
43 changes: 43 additions & 0 deletions config/locales/en/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ en:
index:
title: Polls
create: Create poll
succesfull: Answer added succesfully
count:
one: You have created %{count} poll.
other: You have created %{count} polls.
Expand Down Expand Up @@ -648,6 +649,17 @@ en:
title: Help about voting
description: Citizens' polls are a participatory mechanism by which citizens with voting rights can make direct decisions
no_polls: "There are no open votings."
max_votes_reached: "You have already made the maximum number of votes. Thank you very much for participating"
descriptions:
unique: It's only possible to answer one time to the question.
multiple: Allows to choose multiple answers. It's possible to set the maximum number of answers.
prioritized: Allows to choose more than one answer and they will be prioritized. It's possible to set the maximum number of answers chosen and the answer count type.
positive_open: Allows to vote positively a maximum number of times to questions. It's possible to set the maximum number of answers and add other answers.
positive_negative_open: Allows to vote positively and negatively a maximum number of times to questions. It's possible to set the maximum number of answers and add other answers.
answer_couples_open: Allows to vote a maximum number of times to couples of possible answers. It's possible to set the maximum number of couples and add other answers.
answer_couples_closed: Allows to vote a maximum number of times to couples of possible answers. It's possible to set the maximum number of couples and it's not possible to add other answers.
answer_set_open: Allows to vote a maximum number of answers to a group of them. It's possible to set the maximum number of answers, the size of the group and add other answers.
answer_set_closed: Allows to vote a maximum number of answers to a group of them. It's possible to set the maximum number of answers and the size of the group.
show:
already_voted_in_booth: "You have already participated in a physical booth. You can not participate again."
already_voted_in_web: "You have already participated in this poll. If you vote again it will be overwritten."
Expand Down Expand Up @@ -689,6 +701,18 @@ en:
show:
vote_answer: "Vote %{answer}"
voted: "You have voted %{answer}"
add_answer: "Add answer"
description:
multiple: "You can select a maximum of %{maximum} answers."
positive_negative_open: "You can vote positive or negative a maximum of %{maximum} answers. And you can add your own answers."
answer_couples_open: "Choose an option from the following pair. You can choose a maximum of %{maximum} answers."
answer_couples_closed: "Choose an option from the following pair. You can choose a maximum of %{maximum} answers."
answer_set_open: "You can choose a maximum of %{maximum} answers."
answer_set_closed: "You can choose a maximum of %{maximum} answers."
prioritized: "You can select a maximum of %{maximum} answers. This question will use the %{system} system for count."
positive_open: "You can select a maximum of %{maximum} answers and add your own answers."
unique: ""
read_more_about: "Read more about:"
proposal_notifications:
new:
title: "Send message"
Expand Down Expand Up @@ -992,3 +1016,22 @@ en:
surveys: Surveys
poll:
take_part: Take part from %{from} to %{to}
question:
max_votes: Maximum number of votes
max_group_answers: Maximum number of answers in the set
votation_type: Votation type
enum_type:
title: Votation type
unique: Unique answer, closed
multiple: Multiple answers, closed
prioritized: Multiple prioritized answer, closed
positive_open: Votable positive, open
positive_negative_open: Votable positive and negative, open
answer_couples_open: Couples of answers, open
answer_couples_closed: Couples of answers, closed
answer_set_open: Set of answers, open
answer_set_closed: Set of answers, closed
prioritization_type:
title: Prioritization type
borda: Borda votation
dowdall: Dowdall votation
Loading

0 comments on commit 23d3683

Please sign in to comment.