Merge pull request #4718 from consul/single_heading_links
Simplify navigation in single heading budgets
This commit is contained in:
59
app/components/budgets/ballot/ballot_component.html.erb
Normal file
59
app/components/budgets/ballot/ballot_component.html.erb
Normal file
@@ -0,0 +1,59 @@
|
||||
<header>
|
||||
<%= back_link_to session[:ballot_referer] %>
|
||||
|
||||
<h1 class="text-center"><%= t("budgets.ballots.show.title") %></h1>
|
||||
|
||||
<div class="small-12 medium-8 column small-centered text-center">
|
||||
<h2>
|
||||
<%= sanitize(t("budgets.ballots.show.voted", count: ballot.investments.count)) %>
|
||||
</h2>
|
||||
<p class="confirmed">
|
||||
<%= t("budgets.ballots.show.voted_info") %>
|
||||
<p>
|
||||
<p><%= t("budgets.ballots.show.voted_info_2") %></p>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="row ballot">
|
||||
<% ballot_groups.each do |group| %>
|
||||
<% heading = ballot.heading_for_group(group) %>
|
||||
<div id="<%= dom_id(group) %>" class="small-12 medium-6 column end">
|
||||
<div class="margin-top ballot-content">
|
||||
<div class="subtitle">
|
||||
<h3>
|
||||
<%= group.name %> - <%= heading.name %>
|
||||
</h3>
|
||||
<%= link_to sanitize(ballot.amount_available_info(heading)), group_path(group) %>
|
||||
</div>
|
||||
<% if ballot.has_lines_in_group?(group) %>
|
||||
<h4 class="amount-spent text-right">
|
||||
<%= sanitize(ballot.amount_spent_info(heading)) %>
|
||||
</h4>
|
||||
<% else %>
|
||||
<p>
|
||||
<%= t("budgets.ballots.show.zero") %><br>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<ul class="ballot-list">
|
||||
<%= render Budgets::Ballot::InvestmentComponent.with_collection(
|
||||
ballot.investments.by_group(group.id)
|
||||
) %>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% no_balloted_groups.each do |group| %>
|
||||
<div id="<%= dom_id(group) %>" class="small-12 medium-6 column end">
|
||||
<div class="margin-top ballot-content">
|
||||
<div class="subtitle">
|
||||
<h3>
|
||||
<%= group.name %>
|
||||
</h3>
|
||||
<%= link_to t("budgets.ballots.show.no_balloted_group_yet"), group_path(group) %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
29
app/components/budgets/ballot/ballot_component.rb
Normal file
29
app/components/budgets/ballot/ballot_component.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
class Budgets::Ballot::BallotComponent < ApplicationComponent
|
||||
attr_reader :ballot
|
||||
|
||||
def initialize(ballot)
|
||||
@ballot = ballot
|
||||
end
|
||||
|
||||
def budget
|
||||
ballot.budget
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def ballot_groups
|
||||
ballot.groups.sort_by_name
|
||||
end
|
||||
|
||||
def no_balloted_groups
|
||||
budget.groups.sort_by_name - ballot.groups
|
||||
end
|
||||
|
||||
def group_path(group)
|
||||
if group.multiple_headings?
|
||||
budget_group_path(budget, group)
|
||||
else
|
||||
budget_investments_path(budget, heading_id: group.headings.first)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -135,6 +135,9 @@ module Budgets
|
||||
@heading = @budget.headings.find_by_slug_or_id! params[:heading_id]
|
||||
@assigned_heading = @ballot&.heading_for_group(@heading.group)
|
||||
load_map
|
||||
elsif @budget.single_heading?
|
||||
@heading = @budget.headings.first
|
||||
load_map
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,63 +1 @@
|
||||
<header>
|
||||
<%= back_link_to session[:ballot_referer] %>
|
||||
|
||||
<h1 class="text-center"><%= t("budgets.ballots.show.title") %></h1>
|
||||
|
||||
<div class="small-12 medium-8 column small-centered text-center">
|
||||
<h2>
|
||||
<%= sanitize(t("budgets.ballots.show.voted", count: @ballot.investments.count)) %>
|
||||
</h2>
|
||||
<p class="confirmed">
|
||||
<%= t("budgets.ballots.show.voted_info") %>
|
||||
<p>
|
||||
<p><%= t("budgets.ballots.show.voted_info_2") %></p>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="row ballot">
|
||||
<% ballot_groups = @ballot.groups.sort_by_name %>
|
||||
<% ballot_groups.each do |group| %>
|
||||
<% heading = @ballot.heading_for_group(group) %>
|
||||
<div id="<%= dom_id(group) %>" class="small-12 medium-6 column end">
|
||||
<div class="margin-top ballot-content">
|
||||
<div class="subtitle">
|
||||
<h3>
|
||||
<%= group.name %> - <%= heading.name %>
|
||||
</h3>
|
||||
<%= link_to sanitize(@ballot.amount_available_info(heading)),
|
||||
budget_group_path(@budget, group) %>
|
||||
</div>
|
||||
<% if @ballot.has_lines_in_group?(group) %>
|
||||
<h4 class="amount-spent text-right">
|
||||
<%= sanitize(@ballot.amount_spent_info(heading)) %>
|
||||
</h4>
|
||||
<% else %>
|
||||
<p>
|
||||
<%= t("budgets.ballots.show.zero") %><br>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<ul class="ballot-list">
|
||||
<%= render Budgets::Ballot::InvestmentComponent.with_collection(
|
||||
@ballot.investments.by_group(group.id)
|
||||
) %>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% no_balloted_groups = @budget.groups.sort_by_name - ballot_groups %>
|
||||
<% no_balloted_groups.each do |group| %>
|
||||
<div id="<%= dom_id(group) %>" class="small-12 medium-6 column end">
|
||||
<div class="margin-top ballot-content">
|
||||
<div class="subtitle">
|
||||
<h3>
|
||||
<%= group.name %>
|
||||
</h3>
|
||||
<%= link_to t("budgets.ballots.show.no_balloted_group_yet"), budget_group_path(@budget, group) %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
<%= render Budgets::Ballot::BallotComponent.new(@ballot) %>
|
||||
|
||||
53
spec/components/budgets/ballot/ballot_component_spec.rb
Normal file
53
spec/components/budgets/ballot/ballot_component_spec.rb
Normal file
@@ -0,0 +1,53 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Budgets::Ballot::BallotComponent do
|
||||
include Rails.application.routes.url_helpers
|
||||
before { request.session[:ballot_referer] = "/" }
|
||||
|
||||
describe "link to group" do
|
||||
let(:budget) { create(:budget, :balloting) }
|
||||
let(:group) { create(:budget_group, budget: budget) }
|
||||
let(:ballot) { create(:budget_ballot, user: create(:user), budget: budget) }
|
||||
|
||||
context "group with a single heading" do
|
||||
let!(:heading) { create(:budget_heading, group: group, price: 1000) }
|
||||
|
||||
it "displays a link to vote investments when there aren't any investments in the ballot" do
|
||||
render_inline Budgets::Ballot::BallotComponent.new(ballot)
|
||||
|
||||
expect(page).to have_link "You have not voted on this group yet, go vote!",
|
||||
href: budget_investments_path(budget, heading_id: heading.id)
|
||||
end
|
||||
|
||||
it "displays a link to continue voting when there are investments in the ballot" do
|
||||
ballot.investments << create(:budget_investment, :selected, heading: heading, price: 200)
|
||||
|
||||
render_inline Budgets::Ballot::BallotComponent.new(ballot)
|
||||
|
||||
expect(page).to have_link "Still available to you €800",
|
||||
href: budget_investments_path(budget, heading_id: heading.id)
|
||||
end
|
||||
end
|
||||
|
||||
context "group with multiple headings" do
|
||||
let!(:heading) { create(:budget_heading, group: group, price: 1000) }
|
||||
before { create(:budget_heading, group: group) }
|
||||
|
||||
it "displays a link to vote on a heading when there aren't any investments in the ballot" do
|
||||
render_inline Budgets::Ballot::BallotComponent.new(ballot)
|
||||
|
||||
expect(page).to have_link "You have not voted on this group yet, go vote!",
|
||||
href: budget_group_path(budget, group)
|
||||
end
|
||||
|
||||
it "displays a link to change the heading when there are invesments in the ballot" do
|
||||
ballot.investments << create(:budget_investment, :selected, heading: heading, price: 200)
|
||||
|
||||
render_inline Budgets::Ballot::BallotComponent.new(ballot)
|
||||
|
||||
expect(page).to have_link "Still available to you €800",
|
||||
href: budget_group_path(budget, group)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -344,15 +344,6 @@ describe "Ballots" do
|
||||
expect(page).to have_content "Still available to you €35"
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Display links to vote on groups with no investments voted yet" do
|
||||
group = create(:budget_group, budget: budget)
|
||||
|
||||
login_as(user)
|
||||
visit budget_ballot_path(budget)
|
||||
|
||||
expect(page).to have_link "You have not voted on this group yet, go vote!", href: budget_group_path(budget, group)
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Removing investments from ballot" do
|
||||
|
||||
@@ -1356,6 +1356,9 @@ describe "Budget Investments" do
|
||||
expect(page).to have_content investment2.title
|
||||
expect(page).to have_content "€20,000"
|
||||
end
|
||||
|
||||
expect(page).to have_link "Submit my ballot"
|
||||
expect(page).to have_content "STILL AVAILABLE TO YOU €666,666"
|
||||
end
|
||||
|
||||
scenario "Order by cost (only when balloting)" do
|
||||
|
||||
Reference in New Issue
Block a user