diff --git a/app/controllers/budgets/investments_controller.rb b/app/controllers/budgets/investments_controller.rb index 704ff8d83..ebf14d94b 100644 --- a/app/controllers/budgets/investments_controller.rb +++ b/app/controllers/budgets/investments_controller.rb @@ -62,6 +62,10 @@ module Budgets def vote @investment.register_selection(current_user) load_investment_votes(@investment) + respond_to do |format| + format.html { redirect_to budget_investments_path(heading_id: @investment.heading.id) } + format.js + end end private diff --git a/app/controllers/management/budgets/investments_controller.rb b/app/controllers/management/budgets/investments_controller.rb index e790312d6..025b6301d 100644 --- a/app/controllers/management/budgets/investments_controller.rb +++ b/app/controllers/management/budgets/investments_controller.rb @@ -34,6 +34,10 @@ class Management::Budgets::InvestmentsController < Management::BaseController def vote @investment.register_selection(managed_user) load_investment_votes(@investment) + respond_to do |format| + format.html { redirect_to management_budget_investments_path(heading_id: @investment.heading.id) } + format.js + end end def print diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 4c8816abc..100433707 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -155,6 +155,7 @@ class Budget def reason_for_not_being_selectable_by(user) return permission_problem(user) if permission_problem?(user) + return :different_heading_assigned unless valid_heading?(user) return :no_selecting_allowed unless budget.selecting? end @@ -182,6 +183,24 @@ class Budget reason_for_not_being_selectable_by(user).blank? end + def valid_heading?(user) + !different_heading_assigned?(user) + end + + def different_heading_assigned?(user) + other_heading_ids = group.heading_ids - [heading.id] + voted_in?(other_heading_ids, user) + end + + def voted_in?(heading_ids, user) + heading_ids.include? heading_voted_by_user?(user) + end + + def heading_voted_by_user?(user) + user.votes.for_budget_investments(budget.investments.where(group: group)). + votables.map(&:heading_id).first + end + def ballotable_by?(user) reason_for_not_being_ballotable_by(user).blank? end @@ -204,13 +223,19 @@ class Budget end def should_show_aside? - (budget.selecting? && !unfeasible?) || (budget.balloting? && feasible?) || budget.on_hold? + (budget.selecting? && !unfeasible?) || + (budget.balloting? && feasible?) || + (budget.valuating? && feasible?) end def should_show_votes? budget.selecting? end + def should_show_vote_count? + budget.valuating? + end + def should_show_ballots? budget.balloting? end diff --git a/app/models/user.rb b/app/models/user.rb index 881f5700d..f8991d676 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -103,6 +103,10 @@ class User < ActiveRecord::Base comment_flags.each_with_object({}){ |f, h| h[f.flaggable_id] = true } end + def voted_in_group?(group) + votes.for_budget_investments(Budget::Investment.where(group: group)).exists? + end + def administrator? administrator.present? end diff --git a/app/views/budgets/investments/_feasibility_link.html.erb b/app/views/budgets/investments/_feasibility_link.html.erb new file mode 100644 index 000000000..118a02e7f --- /dev/null +++ b/app/views/budgets/investments/_feasibility_link.html.erb @@ -0,0 +1,11 @@ + + +
+ +<% if params[:unfeasible].present? %> + <%= link_to t("budgets.investments.index.sidebar.feasible"), + budget_investments_path(@budget, heading_id: @heading, unfeasible: nil) %> +<% else %> + <%= link_to t("budgets.investments.index.sidebar.unfeasible"), + budget_investments_path(@budget, heading_id: @heading, unfeasible: 1) %> +<% end %> \ No newline at end of file diff --git a/app/views/budgets/investments/_investment.html.erb b/app/views/budgets/investments/_investment.html.erb index c9c247784..c9391cbe5 100644 --- a/app/views/budgets/investments/_investment.html.erb +++ b/app/views/budgets/investments/_investment.html.erb @@ -46,7 +46,6 @@ <% unless investment.unfeasible? %> <% if investment.should_show_votes? %> -
<%= render partial: '/budgets/investments/votes', locals: { @@ -55,9 +54,17 @@ vote_url: namespaced_budget_investment_vote_path(investment, value: 'yes') } %>
- + <% elsif investment.should_show_vote_count? %> +
+
+ + <%= t("budgets.investments.investment.supports", + count: investment.total_votes) %> + +
+
<% elsif investment.should_show_ballots? %> -
<%= render partial: '/budgets/investments/ballot', locals: { @@ -66,7 +73,6 @@ ballot: ballot } %>
- <% end %> <% end %> diff --git a/app/views/budgets/investments/_investment_show.html.erb b/app/views/budgets/investments/_investment_show.html.erb index 12f23fe87..af3c6b194 100644 --- a/app/views/budgets/investments/_investment_show.html.erb +++ b/app/views/budgets/investments/_investment_show.html.erb @@ -55,11 +55,10 @@ <% if investment.should_show_aside? %>