Merge pull request #4769 from consul/assigned_heading
Show assigned heading on investment show
This commit is contained in:
@@ -1,12 +1,11 @@
|
|||||||
class Budgets::Investments::BallotComponent < ApplicationComponent
|
class Budgets::Investments::BallotComponent < ApplicationComponent
|
||||||
attr_reader :investment, :investment_ids, :ballot, :assigned_heading
|
attr_reader :investment, :investment_ids, :ballot
|
||||||
delegate :current_user, :heading_link, :link_to_verify_account, to: :helpers
|
delegate :current_user, :heading_link, :link_to_verify_account, to: :helpers
|
||||||
|
|
||||||
def initialize(investment:, investment_ids:, ballot:, assigned_heading:)
|
def initialize(investment:, investment_ids:, ballot:)
|
||||||
@investment = investment
|
@investment = investment
|
||||||
@investment_ids = investment_ids
|
@investment_ids = investment_ids
|
||||||
@ballot = ballot
|
@ballot = ballot
|
||||||
@assigned_heading = assigned_heading
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@@ -42,6 +41,10 @@ class Budgets::Investments::BallotComponent < ApplicationComponent
|
|||||||
budget_ballot_path(budget))
|
budget_ballot_path(budget))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def assigned_heading
|
||||||
|
ballot.heading_for_group(investment.group)
|
||||||
|
end
|
||||||
|
|
||||||
def cannot_vote_text
|
def cannot_vote_text
|
||||||
if reason.present? && !voted?
|
if reason.present? && !voted?
|
||||||
t("budgets.ballots.reasons_for_not_balloting.#{reason}",
|
t("budgets.ballots.reasons_for_not_balloting.#{reason}",
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ module Budgets
|
|||||||
|
|
||||||
before_action :load_ballot, only: [:index, :show]
|
before_action :load_ballot, only: [:index, :show]
|
||||||
before_action :load_heading, only: [:index, :show]
|
before_action :load_heading, only: [:index, :show]
|
||||||
|
before_action :load_map, only: [:index]
|
||||||
before_action :set_random_seed, only: :index
|
before_action :set_random_seed, only: :index
|
||||||
before_action :load_categories, only: :index
|
before_action :load_categories, only: :index
|
||||||
before_action :set_default_investment_filter, only: :index
|
before_action :set_default_investment_filter, only: :index
|
||||||
@@ -134,10 +135,8 @@ module Budgets
|
|||||||
if params[:heading_id].present?
|
if params[:heading_id].present?
|
||||||
@heading = @budget.headings.find_by_slug_or_id! params[:heading_id]
|
@heading = @budget.headings.find_by_slug_or_id! params[:heading_id]
|
||||||
@assigned_heading = @ballot&.heading_for_group(@heading.group)
|
@assigned_heading = @ballot&.heading_for_group(@heading.group)
|
||||||
load_map
|
|
||||||
elsif @budget.single_heading?
|
elsif @budget.single_heading?
|
||||||
@heading = @budget.headings.first
|
@heading = @budget.headings.first
|
||||||
load_map
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -161,13 +160,15 @@ module Budgets
|
|||||||
@view = (params[:view] == "minimal") ? "minimal" : "default"
|
@view = (params[:view] == "minimal") ? "minimal" : "default"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def investments_with_filters
|
||||||
|
@budget.investments.apply_filters_and_search(@budget, params, @current_filter)
|
||||||
|
end
|
||||||
|
|
||||||
def investments
|
def investments
|
||||||
if @current_order == "random"
|
if @current_order == "random"
|
||||||
@budget.investments.apply_filters_and_search(@budget, params, @current_filter)
|
investments_with_filters.sort_by_random(session[:random_seed])
|
||||||
.sort_by_random(session[:random_seed])
|
|
||||||
else
|
else
|
||||||
@budget.investments.apply_filters_and_search(@budget, params, @current_filter)
|
investments_with_filters.send("sort_by_#{@current_order}")
|
||||||
.send("sort_by_#{@current_order}")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -180,7 +181,7 @@ module Budgets
|
|||||||
end
|
end
|
||||||
|
|
||||||
def load_map
|
def load_map
|
||||||
@map_location = MapLocation.load_from_heading(@heading)
|
@map_location = MapLocation.load_from_heading(@heading) if @heading.present?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
<%= render Budgets::Investments::BallotComponent.new(
|
<%= render Budgets::Investments::BallotComponent.new(
|
||||||
investment: investment,
|
investment: investment,
|
||||||
investment_ids: investment_ids,
|
investment_ids: investment_ids,
|
||||||
ballot: ballot,
|
ballot: ballot
|
||||||
assigned_heading: @assigned_heading
|
|
||||||
) %>
|
) %>
|
||||||
|
|||||||
@@ -8,8 +8,7 @@ describe Budgets::Investments::BallotComponent do
|
|||||||
Budgets::Investments::BallotComponent.new(
|
Budgets::Investments::BallotComponent.new(
|
||||||
investment: investment,
|
investment: investment,
|
||||||
investment_ids: [],
|
investment_ids: [],
|
||||||
ballot: Budget::Ballot.where(budget: budget, user: controller.current_user).first_or_create!,
|
ballot: Budget::Ballot.where(budget: budget, user: controller.current_user).first_or_create!
|
||||||
assigned_heading: nil
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1389,6 +1389,22 @@ describe "Budget Investments" do
|
|||||||
expect(page).to have_content "€10,000"
|
expect(page).to have_content "€10,000"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario "Show message if user already voted in other heading" do
|
||||||
|
group = create(:budget_group, budget: budget, name: "Global Group")
|
||||||
|
heading = create(:budget_heading, group: group, name: "Heading 1")
|
||||||
|
investment = create(:budget_investment, :selected, heading: heading)
|
||||||
|
heading2 = create(:budget_heading, group: group, name: "Heading 2")
|
||||||
|
investment2 = create(:budget_investment, :selected, heading: heading2)
|
||||||
|
user = create(:user, :level_two, ballot_lines: [investment])
|
||||||
|
|
||||||
|
login_as(user)
|
||||||
|
visit budget_investment_path(budget, investment2)
|
||||||
|
|
||||||
|
expect(page).to have_selector(".participation-not-allowed",
|
||||||
|
text: "You have already voted a different heading: Heading 1",
|
||||||
|
visible: :hidden)
|
||||||
|
end
|
||||||
|
|
||||||
scenario "Sidebar in show should display vote text" do
|
scenario "Sidebar in show should display vote text" do
|
||||||
investment = create(:budget_investment, :selected, budget: budget)
|
investment = create(:budget_investment, :selected, budget: budget)
|
||||||
visit budget_investment_path(budget, investment)
|
visit budget_investment_path(budget, investment)
|
||||||
|
|||||||
Reference in New Issue
Block a user