Display message in budget's index when there are no budgets
When there are no budgets we were seeing an exception in the budgets’ index There are two parts to take into account here: 1) Making sure there is a current_budget present, otherwise we display the “no budgets” message 2) The map helper is called from the controller, so we need to make sure current_budget is present there too Note: We could have added a bunch of `try` statements in the budgets’s index, instead of using a conditional, however there are quite a few `current_budget` calls so it seems more appropriate to use a conditional
This commit is contained in:
@@ -65,6 +65,7 @@ module BudgetsHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
def current_budget_map_locations
|
def current_budget_map_locations
|
||||||
|
return unless current_budget.present?
|
||||||
MapLocation.where(investment_id: current_budget.investments).map { |l| l.json_data }
|
MapLocation.where(investment_id: current_budget.investments).map { |l| l.json_data }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,168 +3,172 @@
|
|||||||
<%= render "shared/canonical", href: budgets_url %>
|
<%= render "shared/canonical", href: budgets_url %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<div id="budget_heading" class="expanded budget no-margin-top">
|
<% if current_budget.present? %>
|
||||||
<div class="row" data-equalizer data-equalizer-on="medium">
|
<div id="budget_heading" class="expanded budget no-margin-top">
|
||||||
<div class="small-12 medium-9 column padding" data-equalizer-watch>
|
<div class="row" data-equalizer data-equalizer-on="medium">
|
||||||
|
<div class="small-12 medium-9 column padding" data-equalizer-watch>
|
||||||
|
|
||||||
<h1><%= current_budget.name %></h1>
|
<h1><%= current_budget.name %></h1>
|
||||||
<div class="description">
|
<div class="description">
|
||||||
<%= safe_html_with_links(current_budget.description) %>
|
<%= safe_html_with_links(current_budget.description) %>
|
||||||
|
</div>
|
||||||
|
<p>
|
||||||
|
<%= link_to t("budgets.index.section_header.help"), "#section_help" %>
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<p>
|
<div class="small-12 medium-3 column info padding" data-equalizer-watch>
|
||||||
<%= link_to t("budgets.index.section_header.help"), "#section_help" %>
|
<p>
|
||||||
</p>
|
<strong><%= t("budgets.show.phase") %></strong>
|
||||||
</div>
|
</p>
|
||||||
<div class="small-12 medium-3 column info padding" data-equalizer-watch>
|
<h2><%= t("budgets.phase.#{current_budget.phase}") %></h2>
|
||||||
<p>
|
|
||||||
<strong><%= t("budgets.show.phase") %></strong>
|
|
||||||
</p>
|
|
||||||
<h2><%= t("budgets.phase.#{current_budget.phase}") %></h2>
|
|
||||||
|
|
||||||
<%= link_to t("budgets.index.section_header.all_phases"), "#all_phases" %>
|
<%= link_to t("budgets.index.section_header.all_phases"), "#all_phases" %>
|
||||||
|
|
||||||
<% if current_budget.accepting? %>
|
<% if current_budget.accepting? %>
|
||||||
<% if current_user %>
|
<% if current_user %>
|
||||||
<% if current_user.level_two_or_three_verified? %>
|
<% if current_user.level_two_or_three_verified? %>
|
||||||
<%= link_to t("budgets.investments.index.sidebar.create"),
|
<%= link_to t("budgets.investments.index.sidebar.create"),
|
||||||
new_budget_investment_guide,
|
new_budget_investment_guide,
|
||||||
class: "button margin-top expanded" %>
|
class: "button margin-top expanded" %>
|
||||||
|
<% else %>
|
||||||
|
<div class="callout warning margin-top">
|
||||||
|
<%= t("budgets.investments.index.sidebar.verified_only",
|
||||||
|
verify: link_to(t("budgets.investments.index.sidebar.verify_account"),
|
||||||
|
verification_path)).html_safe %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<div class="callout warning margin-top">
|
<div class="callout primary margin-top">
|
||||||
<%= t("budgets.investments.index.sidebar.verified_only",
|
<%= t("budgets.investments.index.sidebar.not_logged_in",
|
||||||
verify: link_to(t("budgets.investments.index.sidebar.verify_account"),
|
sign_in: link_to(t("budgets.investments.index.sidebar.sign_in"),
|
||||||
verification_path)).html_safe %>
|
new_user_session_path),
|
||||||
|
sign_up: link_to(t("budgets.investments.index.sidebar.sign_up"),
|
||||||
|
new_user_registration_path)).html_safe %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% else %>
|
|
||||||
<div class="callout primary margin-top">
|
|
||||||
<%= t("budgets.investments.index.sidebar.not_logged_in",
|
|
||||||
sign_in: link_to(t("budgets.investments.index.sidebar.sign_in"),
|
|
||||||
new_user_session_path),
|
|
||||||
sign_up: link_to(t("budgets.investments.index.sidebar.sign_up"),
|
|
||||||
new_user_registration_path)).html_safe %>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
|
||||||
|
|
||||||
|
|
||||||
<% if current_budget.finished? || (current_budget.balloting? && can?(:read_results, current_budget)) %>
|
<% if current_budget.finished? || (current_budget.balloting? && can?(:read_results, current_budget)) %>
|
||||||
<%= link_to t("budgets.show.see_results"),
|
<%= link_to t("budgets.show.see_results"),
|
||||||
budget_results_path(current_budget, heading_id: current_budget.headings.first),
|
budget_results_path(current_budget, heading_id: current_budget.headings.first),
|
||||||
class: "button margin-top expanded" %>
|
class: "button margin-top expanded" %>
|
||||||
<% end %>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="budget_info" class="budget-info">
|
|
||||||
<div class="row margin-top">
|
|
||||||
<div class="small-12 column">
|
|
||||||
|
|
||||||
<div id="groups_and_headings" class="groups-and-headings">
|
|
||||||
<% current_budget.groups.each do |group| %>
|
|
||||||
<h2 id="<%= group.name.parameterize %>"><%= group.name %></h2>
|
|
||||||
<ul class="no-bullet">
|
|
||||||
<% group.headings.order_by_group_name.each do |heading| %>
|
|
||||||
<li class="heading small-12 medium-4 large-2">
|
|
||||||
<% unless current_budget.informing? %>
|
|
||||||
<%= link_to budget_investments_path(current_budget.id, heading_id: heading.id) do %>
|
|
||||||
<%= heading_name_and_price_html(heading, current_budget) %>
|
|
||||||
<% end %>
|
|
||||||
<% else %>
|
|
||||||
<div>
|
|
||||||
<%= heading_name_and_price_html(heading, current_budget) %>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
</li>
|
|
||||||
<% end %>
|
|
||||||
</ul>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<% unless current_budget.informing? %>
|
<div id="budget_info" class="budget-info">
|
||||||
<div id="map">
|
<div class="row margin-top">
|
||||||
<h3><%= t("budgets.index.map") %></h3>
|
<div class="small-12 column">
|
||||||
<%= render_map(nil, "budgets", false, nil, @budgets_coordinates) %>
|
|
||||||
|
<div id="groups_and_headings" class="groups-and-headings">
|
||||||
|
<% current_budget.groups.each do |group| %>
|
||||||
|
<h2 id="<%= group.name.parameterize %>"><%= group.name %></h2>
|
||||||
|
<ul class="no-bullet">
|
||||||
|
<% group.headings.order_by_group_name.each do |heading| %>
|
||||||
|
<li class="heading small-12 medium-4 large-2">
|
||||||
|
<% unless current_budget.informing? %>
|
||||||
|
<%= link_to budget_investments_path(current_budget.id, heading_id: heading.id) do %>
|
||||||
|
<%= heading_name_and_price_html(heading, current_budget) %>
|
||||||
|
<% end %>
|
||||||
|
<% else %>
|
||||||
|
<div>
|
||||||
|
<%= heading_name_and_price_html(heading, current_budget) %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p>
|
<% unless current_budget.informing? %>
|
||||||
<% show_links = show_links_to_budget_investments(current_budget) %>
|
<div id="map">
|
||||||
<% if show_links %>
|
<h3><%= t("budgets.index.map") %></h3>
|
||||||
<%= link_to budget_investments_path(current_budget.id) do %>
|
<%= render_map(nil, "budgets", false, nil, @budgets_coordinates) %>
|
||||||
<small><%= t("budgets.index.investment_proyects") %></small>
|
</div>
|
||||||
<% end %><br>
|
|
||||||
<% end %>
|
|
||||||
<%= link_to budget_investments_path(budget_id: current_budget.id, filter: 'unfeasible') do %>
|
|
||||||
<small><%= t("budgets.index.unfeasible_investment_proyects") %></small>
|
|
||||||
<% end %><br>
|
|
||||||
<% if show_links %>
|
|
||||||
<%= link_to budget_investments_path(budget_id: current_budget.id, filter: 'unselected') do %>
|
|
||||||
<small><%= t("budgets.index.not_selected_investment_proyects") %></small>
|
|
||||||
<% end %>
|
|
||||||
<% end %>
|
|
||||||
</p>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<div id="all_phases">
|
<p>
|
||||||
<h2><%= t("budgets.index.all_phases") %></h2>
|
<% show_links = show_links_to_budget_investments(current_budget) %>
|
||||||
<%= render "phases", budget: current_budget %>
|
<% if show_links %>
|
||||||
|
<%= link_to budget_investments_path(current_budget.id) do %>
|
||||||
|
<small><%= t("budgets.index.investment_proyects") %></small>
|
||||||
|
<% end %><br>
|
||||||
|
<% end %>
|
||||||
|
<%= link_to budget_investments_path(budget_id: current_budget.id, filter: 'unfeasible') do %>
|
||||||
|
<small><%= t("budgets.index.unfeasible_investment_proyects") %></small>
|
||||||
|
<% end %><br>
|
||||||
|
<% if show_links %>
|
||||||
|
<%= link_to budget_investments_path(budget_id: current_budget.id, filter: 'unselected') do %>
|
||||||
|
<small><%= t("budgets.index.not_selected_investment_proyects") %></small>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
</p>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<div id="all_phases">
|
||||||
|
<h2><%= t("budgets.index.all_phases") %></h2>
|
||||||
|
<%= render "phases", budget: current_budget %>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<% if @finished_budgets.present? %>
|
<% if @finished_budgets.present? %>
|
||||||
<div class="row margin-top">
|
<div class="row margin-top">
|
||||||
<div class="small-12 medium-9 column">
|
<div class="small-12 medium-9 column">
|
||||||
<ul class="no-bullet submenu">
|
<ul class="no-bullet submenu">
|
||||||
<li class="inline-block">
|
<li class="inline-block">
|
||||||
<%= link_to "#other_budgets", class: "active" do %>
|
<%= link_to "#other_budgets", class: "active" do %>
|
||||||
<h2>
|
<h2>
|
||||||
<%= t("budgets.index.finished_budgets") %>
|
<%= t("budgets.index.finished_budgets") %>
|
||||||
</h2>
|
</h2>
|
||||||
<% end %>
|
<% end %>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<div id="finished_budgets" class="budget-investments-list">
|
<div id="finished_budgets" class="budget-investments-list">
|
||||||
<% @finished_budgets.each do |budget| %>
|
<% @finished_budgets.each do |budget| %>
|
||||||
<div class="budget-investment clear">
|
<div class="budget-investment clear">
|
||||||
<div class="panel past-budgets">
|
<div class="panel past-budgets">
|
||||||
<div class="row" data-equalizer data-equalizer-on="medium">
|
<div class="row" data-equalizer data-equalizer-on="medium">
|
||||||
<div class="small-12 medium-9 column table" data-equalizer-watch>
|
<div class="small-12 medium-9 column table" data-equalizer-watch>
|
||||||
<div class="table-cell align-middle">
|
<div class="table-cell align-middle">
|
||||||
<h3><%= budget.name %></h3>
|
<h3><%= budget.name %></h3>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="small-12 medium-3 column table" data-equalizer-watch>
|
||||||
<div class="small-12 medium-3 column table" data-equalizer-watch>
|
<div id="budget_<%= budget.id %>_results" class="table-cell align-middle">
|
||||||
<div id="budget_<%= budget.id %>_results" class="table-cell align-middle">
|
<%= link_to t("budgets.index.see_results"),
|
||||||
<%= link_to t("budgets.index.see_results"),
|
budget_results_path(budget.id),
|
||||||
budget_results_path(budget.id),
|
class: "button expanded" %>
|
||||||
class: "button expanded" %>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<% end %>
|
||||||
<% end %>
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="small-12 column">
|
||||||
|
<div id="section_help" class="margin" data-magellan-target="section_help">
|
||||||
|
<p class="lead">
|
||||||
|
<strong><%= t("budgets.index.section_footer.title") %></strong>
|
||||||
|
</p>
|
||||||
|
<p><%= t("budgets.index.section_footer.description") %></p>
|
||||||
|
<p><%= t("budgets.index.section_footer.help_text_1") %></p>
|
||||||
|
<p><%= t("budgets.index.section_footer.help_text_2") %></p>
|
||||||
|
<p><%= t("budgets.index.section_footer.help_text_3",
|
||||||
|
org: link_to(setting['org_name'], new_user_registration_path)).html_safe %></p>
|
||||||
|
<p><%= t("budgets.index.section_footer.help_text_4") %></p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="small-12 column">
|
|
||||||
<div id="section_help" class="margin" data-magellan-target="section_help">
|
|
||||||
<p class="lead">
|
|
||||||
<strong><%= t("budgets.index.section_footer.title") %></strong>
|
|
||||||
</p>
|
|
||||||
<p><%= t("budgets.index.section_footer.description") %></p>
|
|
||||||
<p><%= t("budgets.index.section_footer.help_text_1") %></p>
|
|
||||||
<p><%= t("budgets.index.section_footer.help_text_2") %></p>
|
|
||||||
<p><%= t("budgets.index.section_footer.help_text_3",
|
|
||||||
org: link_to(setting['org_name'], new_user_registration_path)).html_safe %></p>
|
|
||||||
<p><%= t("budgets.index.section_footer.help_text_4") %></p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<% else %>
|
||||||
|
<%= t("budgets.index.empty_budgets") %>
|
||||||
|
<% end %>
|
||||||
@@ -41,6 +41,7 @@ en:
|
|||||||
finished: Finished budget
|
finished: Finished budget
|
||||||
index:
|
index:
|
||||||
title: Participatory budgets
|
title: Participatory budgets
|
||||||
|
empty_budgets: There are no budgets
|
||||||
section_header:
|
section_header:
|
||||||
icon_alt: Participatory budgets icon
|
icon_alt: Participatory budgets icon
|
||||||
title: Participatory budgets
|
title: Participatory budgets
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ es:
|
|||||||
finished: Resultados
|
finished: Resultados
|
||||||
index:
|
index:
|
||||||
title: Presupuestos participativos
|
title: Presupuestos participativos
|
||||||
|
empty_budgets: No hay presupuestos participativos
|
||||||
section_header:
|
section_header:
|
||||||
icon_alt: Icono de Presupuestos participativos
|
icon_alt: Icono de Presupuestos participativos
|
||||||
title: Presupuestos participativos
|
title: Presupuestos participativos
|
||||||
|
|||||||
@@ -117,6 +117,13 @@ feature 'Budgets' do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario "No budgets" do
|
||||||
|
Budget.destroy_all
|
||||||
|
|
||||||
|
visit budgets_path
|
||||||
|
|
||||||
|
expect(page).to have_content "There are no budgets"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'Index shows only published phases' do
|
scenario 'Index shows only published phases' do
|
||||||
|
|||||||
Reference in New Issue
Block a user