Merge pull request #5107 from consul/fix_map_investments_after_voting
Fix wrong investments on the map after voting
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<div class="my-ballot">
|
||||
<h2 class="sidebar-title">
|
||||
<%= t("budgets.investments.index.sidebar.my_ballot") %>
|
||||
</h2>
|
||||
|
||||
<% if ballot.investments.by_heading(heading.id).count > 0 %>
|
||||
<p>
|
||||
<em><%= sanitize(ballot.voted_info(heading)) %></em>
|
||||
</p>
|
||||
<% elsif assigned_heading.present? %>
|
||||
<p>
|
||||
<%= sanitize(t("budgets.investments.index.sidebar.different_heading_assigned",
|
||||
heading_link: heading_link(assigned_heading, budget)
|
||||
)) %>
|
||||
<br>
|
||||
<small>
|
||||
<%= sanitize(t("budgets.investments.index.sidebar.change_ballot",
|
||||
check_ballot: link_to(t("budgets.investments.index.sidebar.check_ballot_link"),
|
||||
budget_ballot_path(budget)))) %>
|
||||
</small>
|
||||
</p>
|
||||
<% else %>
|
||||
<p><strong><%= t("budgets.investments.index.sidebar.zero") %></strong></p>
|
||||
<% end %>
|
||||
|
||||
<p>
|
||||
<%= sanitize(ballot.change_vote_info(
|
||||
link: link_to(t("budgets.investments.index.sidebar.change_vote_link"),
|
||||
budget_ballot_path(budget)))) %>
|
||||
</p>
|
||||
|
||||
<ul class="ballot-list">
|
||||
<% if heading %>
|
||||
<%= render Budgets::Ballot::InvestmentForSidebarComponent.with_collection(
|
||||
ballot.investments.by_heading(heading.id),
|
||||
investment_ids: investment_ids
|
||||
) %>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
<%= link_to t("budgets.investments.header.check_ballot"),
|
||||
budget_ballot_path(budget),
|
||||
class: "button hollow expanded" %>
|
||||
</div>
|
||||
21
app/components/budgets/investments/my_ballot_component.rb
Normal file
21
app/components/budgets/investments/my_ballot_component.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
class Budgets::Investments::MyBallotComponent < ApplicationComponent
|
||||
attr_reader :ballot, :heading, :investment_ids, :assigned_heading
|
||||
delegate :can?, :heading_link, to: :helpers
|
||||
|
||||
def initialize(ballot:, heading:, investment_ids:, assigned_heading: nil)
|
||||
@ballot = ballot
|
||||
@heading = heading
|
||||
@investment_ids = investment_ids
|
||||
@assigned_heading = assigned_heading
|
||||
end
|
||||
|
||||
def render?
|
||||
heading && can?(:show, ballot)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def budget
|
||||
ballot.budget
|
||||
end
|
||||
end
|
||||
@@ -15,7 +15,6 @@ module Budgets
|
||||
def create
|
||||
load_investment
|
||||
load_heading
|
||||
load_map
|
||||
|
||||
@ballot.add_investment(@investment)
|
||||
end
|
||||
@@ -23,7 +22,6 @@ module Budgets
|
||||
def destroy
|
||||
@investment = @line.investment
|
||||
load_heading
|
||||
load_map
|
||||
|
||||
@line.destroy!
|
||||
load_investments
|
||||
@@ -69,12 +67,6 @@ module Budgets
|
||||
def load_categories
|
||||
@categories = Tag.category.order(:name)
|
||||
end
|
||||
|
||||
def load_map
|
||||
@investments ||= []
|
||||
@investments_map_coordinates = MapLocation.where(investment: @investments).map(&:json_data)
|
||||
@map_location = MapLocation.load_from_heading(@heading)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
$("#progress_bar").html("<%= j render("/budgets/ballot/progress_bar", ballot: @ballot, heading: @heading) %>");
|
||||
$("#sidebar").html("<%= j render("/budgets/investments/sidebar") %>");
|
||||
$("#my_ballot").html("<%= j render(
|
||||
Budgets::Investments::MyBallotComponent.new(
|
||||
ballot: @ballot,
|
||||
heading: @heading,
|
||||
investment_ids: @investment_ids
|
||||
)
|
||||
) %>");
|
||||
|
||||
<%= render "refresh_ballots",
|
||||
investment_ids: @investment_ids,
|
||||
ballot: @ballot %>
|
||||
|
||||
App.Map.initialize();
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
$("#progress_bar").html("<%= j render("budgets/ballot/progress_bar", ballot: @ballot, heading: @heading) %>");
|
||||
$("#sidebar").html("<%= j render("budgets/investments/sidebar") %>");
|
||||
$("#my_ballot").html("<%= j render(
|
||||
Budgets::Investments::MyBallotComponent.new(
|
||||
ballot: @ballot,
|
||||
heading: @heading,
|
||||
investment_ids: @investment_ids
|
||||
)
|
||||
) %>");
|
||||
$("#ballot").html("<%= j render("budgets/ballot/ballot") %>")
|
||||
|
||||
<%= render "refresh_ballots",
|
||||
investment_ids: @investment_ids,
|
||||
ballot: @ballot %>
|
||||
|
||||
App.Map.initialize();
|
||||
|
||||
@@ -12,52 +12,14 @@
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if @heading && can?(:show, @ballot) %>
|
||||
<div class="my-ballot">
|
||||
<h2 class="sidebar-title">
|
||||
<%= t("budgets.investments.index.sidebar.my_ballot") %>
|
||||
</h2>
|
||||
|
||||
<% if @ballot.investments.by_heading(@heading.id).count > 0 %>
|
||||
<p>
|
||||
<em><%= sanitize(@ballot.voted_info(@heading)) %></em>
|
||||
</p>
|
||||
<% elsif @assigned_heading.present? %>
|
||||
<p>
|
||||
<%= sanitize(t("budgets.investments.index.sidebar.different_heading_assigned",
|
||||
heading_link: heading_link(@assigned_heading, @budget)
|
||||
)) %>
|
||||
<br>
|
||||
<small>
|
||||
<%= sanitize(t("budgets.investments.index.sidebar.change_ballot",
|
||||
check_ballot: link_to(t("budgets.investments.index.sidebar.check_ballot_link"),
|
||||
budget_ballot_path(@budget)))) %>
|
||||
</small>
|
||||
</p>
|
||||
<% else %>
|
||||
<p><strong><%= t("budgets.investments.index.sidebar.zero") %></strong></p>
|
||||
<% end %>
|
||||
|
||||
<p>
|
||||
<%= sanitize(@ballot.change_vote_info(
|
||||
link: link_to(t("budgets.investments.index.sidebar.change_vote_link"),
|
||||
budget_ballot_path(@budget)))) %>
|
||||
</p>
|
||||
|
||||
<ul class="ballot-list">
|
||||
<% if @heading %>
|
||||
<%= render Budgets::Ballot::InvestmentForSidebarComponent.with_collection(
|
||||
@ballot.investments.by_heading(@heading.id),
|
||||
investment_ids: @investment_ids
|
||||
) %>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
<%= link_to t("budgets.investments.header.check_ballot"),
|
||||
budget_ballot_path(@budget),
|
||||
class: "button hollow expanded" %>
|
||||
</div>
|
||||
<% end %>
|
||||
<div id="my_ballot">
|
||||
<%= render Budgets::Investments::MyBallotComponent.new(
|
||||
ballot: @ballot,
|
||||
heading: @heading,
|
||||
investment_ids: @investment_ids,
|
||||
assigned_heading: @assigned_heading
|
||||
) %>
|
||||
</div>
|
||||
|
||||
<%= render Budgets::Investments::ContentBlocksComponent.new(@heading) %>
|
||||
|
||||
|
||||
@@ -193,6 +193,10 @@ FactoryBot.define do
|
||||
valuators { [create(:valuator)] }
|
||||
end
|
||||
|
||||
trait :with_map_location do
|
||||
map_location
|
||||
end
|
||||
|
||||
trait :flagged do
|
||||
after :create do |investment|
|
||||
Flag.flag(create(:user), investment)
|
||||
|
||||
@@ -161,15 +161,28 @@ describe "Ballots" do
|
||||
end
|
||||
|
||||
scenario "map and content block shoud be visible before and after" do
|
||||
create(:budget_investment, :selected, heading: new_york, price: 10000, title: "More bridges")
|
||||
stub_const("#{Budgets::InvestmentsController}::PER_PAGE", 1)
|
||||
|
||||
create(:budget_investment, :selected, :with_map_location,
|
||||
heading: new_york,
|
||||
price: 10000,
|
||||
title: "More bridges",
|
||||
)
|
||||
create(:budget_investment, :selected, :with_map_location,
|
||||
heading: new_york,
|
||||
price: 5000,
|
||||
title: "Less bridges"
|
||||
)
|
||||
|
||||
create(:heading_content_block, heading: new_york, body: "<li>New Block</li>")
|
||||
new_york.update!(allow_custom_content: true)
|
||||
|
||||
visit budget_investments_path(budget, heading_id: new_york)
|
||||
visit budget_investments_path(budget, heading_id: new_york, order: :price)
|
||||
|
||||
within("#sidebar") do
|
||||
expect(page).to have_content "OpenStreetMap"
|
||||
expect(page).to have_content "New Block"
|
||||
expect(page).to have_css ".map-icon", visible: :all, count: 2
|
||||
end
|
||||
|
||||
add_to_ballot("More bridges")
|
||||
@@ -178,6 +191,7 @@ describe "Ballots" do
|
||||
expect(page).to have_content "More bridges"
|
||||
expect(page).to have_content "OpenStreetMap"
|
||||
expect(page).to have_content "New Block"
|
||||
expect(page).to have_css ".map-icon", visible: :all, count: 2
|
||||
end
|
||||
|
||||
within(".budget-investment", text: "More bridges") do
|
||||
@@ -188,6 +202,7 @@ describe "Ballots" do
|
||||
expect(page).not_to have_content "More bridges"
|
||||
expect(page).to have_content "OpenStreetMap"
|
||||
expect(page).to have_content "New Block"
|
||||
expect(page).to have_css ".map-icon", visible: :all, count: 2
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user