Merge branch 'master' into budget-emails
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
11
app/views/budgets/investments/_feasibility_link.html.erb
Normal file
11
app/views/budgets/investments/_feasibility_link.html.erb
Normal file
@@ -0,0 +1,11 @@
|
||||
<div class="sidebar-divider"></div>
|
||||
<h2 class="sidebar-title"><%= t("budgets.investments.index.sidebar.by_feasibility") %></h2>
|
||||
<br>
|
||||
|
||||
<% 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 %>
|
||||
@@ -46,7 +46,6 @@
|
||||
<% unless investment.unfeasible? %>
|
||||
|
||||
<% if investment.should_show_votes? %>
|
||||
|
||||
<div id="<%= dom_id(investment) %>_votes"
|
||||
class="small-12 medium-3 column text-center">
|
||||
<%= render partial: '/budgets/investments/votes', locals: {
|
||||
@@ -55,9 +54,17 @@
|
||||
vote_url: namespaced_budget_investment_vote_path(investment, value: 'yes')
|
||||
} %>
|
||||
</div>
|
||||
|
||||
<% elsif investment.should_show_vote_count? %>
|
||||
<div id="<%= dom_id(investment) %>_votes"
|
||||
class="small-12 medium-3 column text-center">
|
||||
<div class="supports js-participation">
|
||||
<span class="total-supports no-button">
|
||||
<%= t("budgets.investments.investment.supports",
|
||||
count: investment.total_votes) %>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<% elsif investment.should_show_ballots? %>
|
||||
|
||||
<div id="<%= dom_id(investment) %>_ballot"
|
||||
class="small-12 medium-3 column text-center">
|
||||
<%= render partial: '/budgets/investments/ballot', locals: {
|
||||
@@ -66,7 +73,6 @@
|
||||
ballot: ballot
|
||||
} %>
|
||||
</div>
|
||||
|
||||
<% end %>
|
||||
|
||||
<% end %>
|
||||
|
||||
@@ -55,11 +55,10 @@
|
||||
|
||||
<% if investment.should_show_aside? %>
|
||||
<aside class="small-12 medium-3 column">
|
||||
<div class="sidebar-divider"></div>
|
||||
<h2><%= t("votes.supports") %></h2>
|
||||
<div class="text-center">
|
||||
|
||||
<% if investment.should_show_votes? %>
|
||||
<div class="sidebar-divider"></div>
|
||||
<h2><%= t("budgets.investments.show.supports") %></h2>
|
||||
<div class="text-center">
|
||||
<div id="<%= dom_id(investment) %>_votes">
|
||||
<%= render partial: '/budgets/investments/votes', locals: {
|
||||
investment: investment,
|
||||
@@ -67,7 +66,20 @@
|
||||
vote_url: vote_budget_investment_path(investment.budget, investment, value: 'yes')
|
||||
} %>
|
||||
</div>
|
||||
<% elsif investment.should_show_ballots? %>
|
||||
</div>
|
||||
<% elsif investment.should_show_vote_count? %>
|
||||
<div class="sidebar-divider"></div>
|
||||
<h2><%= t("budgets.investments.show.supports") %></h2>
|
||||
<div class="text-center">
|
||||
<span class="total-supports">
|
||||
<%= t("budgets.investments.investment.supports",
|
||||
count: investment.total_votes) %>
|
||||
</span>
|
||||
</div>
|
||||
<% elsif investment.should_show_ballots? %>
|
||||
<div class="sidebar-divider"></div>
|
||||
<h2><%= t("budgets.investments.show.votes") %></h2>
|
||||
<div class="text-center">
|
||||
<div id="<%= dom_id(investment) %>_ballot">
|
||||
<%= render partial: 'ballot', locals: {
|
||||
investment: investment,
|
||||
@@ -75,8 +87,8 @@
|
||||
ballot: ballot,
|
||||
} %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="sidebar-divider"></div>
|
||||
<h2><%= t("budgets.investments.show.share") %></h2>
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
<% if @budget.accepting? %>
|
||||
<%= render "shared/tag_cloud", taggable: 'budget/investment' %>
|
||||
<%= render 'categories' %>
|
||||
<%= render 'feasibility_link' %>
|
||||
<% end %>
|
||||
|
||||
|
||||
|
||||
@@ -14,12 +14,12 @@
|
||||
<%= t("budgets.investments.investment.already_supported") %>
|
||||
</div>
|
||||
<% elsif investment.should_show_votes? %>
|
||||
|
||||
<%= link_to vote_url,
|
||||
class: "button button-support small expanded",
|
||||
title: t('budgets.investments.investment.support_title'),
|
||||
method: "post",
|
||||
remote: true,
|
||||
remote: (current_user && current_user.voted_in_group?(investment.group) ? true : false),
|
||||
data: (current_user && current_user.voted_in_group?(investment.group) ? nil : { confirm: t('budgets.investments.investment.confirm_group')} ),
|
||||
"aria-hidden" => css_for_aria_hidden(reason) do %>
|
||||
<%= t("budgets.investments.investment.give_support") %>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user