From 39c6ac4a913e67588a6b445465e1775958e2ceaf Mon Sep 17 00:00:00 2001 From: rgarcia Date: Thu, 5 Apr 2018 02:21:09 +0200 Subject: [PATCH 1/2] Display message in budget's index when there are no budgets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- app/helpers/budgets_helper.rb | 1 + app/views/budgets/index.html.erb | 276 +++++++++++++------------- config/locales/en/budgets.yml | 1 + config/locales/es/budgets.yml | 1 + spec/features/budgets/budgets_spec.rb | 7 + 5 files changed, 150 insertions(+), 136 deletions(-) diff --git a/app/helpers/budgets_helper.rb b/app/helpers/budgets_helper.rb index fc20c36a9..8cff4b72b 100644 --- a/app/helpers/budgets_helper.rb +++ b/app/helpers/budgets_helper.rb @@ -65,6 +65,7 @@ module BudgetsHelper end def current_budget_map_locations + return unless current_budget.present? MapLocation.where(investment_id: current_budget.investments).map { |l| l.json_data } end end diff --git a/app/views/budgets/index.html.erb b/app/views/budgets/index.html.erb index ff0a7a505..360e79d72 100644 --- a/app/views/budgets/index.html.erb +++ b/app/views/budgets/index.html.erb @@ -3,168 +3,172 @@ <%= render "shared/canonical", href: budgets_url %> <% end %> -
-
-
+<% if current_budget.present? %> +
+
+
-

<%= current_budget.name %>

-
- <%= safe_html_with_links(current_budget.description) %> +

<%= current_budget.name %>

+
+ <%= safe_html_with_links(current_budget.description) %> +
+

+ <%= link_to t("budgets.index.section_header.help"), "#section_help" %> +

-

- <%= link_to t("budgets.index.section_header.help"), "#section_help" %> -

-
-
-

- <%= t("budgets.show.phase") %> -

-

<%= t("budgets.phase.#{current_budget.phase}") %>

+
+

+ <%= t("budgets.show.phase") %> +

+

<%= t("budgets.phase.#{current_budget.phase}") %>

- <%= 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_user %> - <% if current_user.level_two_or_three_verified? %> - <%= link_to t("budgets.investments.index.sidebar.create"), - new_budget_investment_guide, - class: "button margin-top expanded" %> + <% if current_budget.accepting? %> + <% if current_user %> + <% if current_user.level_two_or_three_verified? %> + <%= link_to t("budgets.investments.index.sidebar.create"), + new_budget_investment_guide, + class: "button margin-top expanded" %> + <% else %> +
+ <%= t("budgets.investments.index.sidebar.verified_only", + verify: link_to(t("budgets.investments.index.sidebar.verify_account"), + verification_path)).html_safe %> +
+ <% end %> <% else %> -
- <%= t("budgets.investments.index.sidebar.verified_only", - verify: link_to(t("budgets.investments.index.sidebar.verify_account"), - verification_path)).html_safe %> +
+ <%= 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 %>
<% end %> - <% else %> -
- <%= 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 %> -
<% end %> - <% end %> - <% if current_budget.finished? || (current_budget.balloting? && can?(:read_results, current_budget)) %> - <%= link_to t("budgets.show.see_results"), - budget_results_path(current_budget, heading_id: current_budget.headings.first), - class: "button margin-top expanded" %> - <% end %> -
-
-
- -
-
-
- -
- <% current_budget.groups.each do |group| %> -

<%= group.name %>

-
    - <% group.headings.order_by_group_name.each do |heading| %> -
  • - <% 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 %> -
    - <%= heading_name_and_price_html(heading, current_budget) %> -
    - <% end %> -
  • - <% end %> -
+ <% if current_budget.finished? || (current_budget.balloting? && can?(:read_results, current_budget)) %> + <%= link_to t("budgets.show.see_results"), + budget_results_path(current_budget, heading_id: current_budget.headings.first), + class: "button margin-top expanded" %> <% end %>
+
+
- <% unless current_budget.informing? %> -
-

<%= t("budgets.index.map") %>

- <%= render_map(nil, "budgets", false, nil, @budgets_coordinates) %> +
+
+
+ +
+ <% current_budget.groups.each do |group| %> +

<%= group.name %>

+
    + <% group.headings.order_by_group_name.each do |heading| %> +
  • + <% 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 %> +
    + <%= heading_name_and_price_html(heading, current_budget) %> +
    + <% end %> +
  • + <% end %> +
+ <% end %>
-

- <% show_links = show_links_to_budget_investments(current_budget) %> - <% if show_links %> - <%= link_to budget_investments_path(current_budget.id) do %> - <%= t("budgets.index.investment_proyects") %> - <% end %>
- <% end %> - <%= link_to budget_investments_path(budget_id: current_budget.id, filter: 'unfeasible') do %> - <%= t("budgets.index.unfeasible_investment_proyects") %> - <% end %>
- <% if show_links %> - <%= link_to budget_investments_path(budget_id: current_budget.id, filter: 'unselected') do %> - <%= t("budgets.index.not_selected_investment_proyects") %> - <% end %> - <% end %> -

- <% end %> + <% unless current_budget.informing? %> +
+

<%= t("budgets.index.map") %>

+ <%= render_map(nil, "budgets", false, nil, @budgets_coordinates) %> +
-
-

<%= t("budgets.index.all_phases") %>

- <%= render "phases", budget: current_budget %> +

+ <% show_links = show_links_to_budget_investments(current_budget) %> + <% if show_links %> + <%= link_to budget_investments_path(current_budget.id) do %> + <%= t("budgets.index.investment_proyects") %> + <% end %>
+ <% end %> + <%= link_to budget_investments_path(budget_id: current_budget.id, filter: 'unfeasible') do %> + <%= t("budgets.index.unfeasible_investment_proyects") %> + <% end %>
+ <% if show_links %> + <%= link_to budget_investments_path(budget_id: current_budget.id, filter: 'unselected') do %> + <%= t("budgets.index.not_selected_investment_proyects") %> + <% end %> + <% end %> +

+ <% end %> + +
+

<%= t("budgets.index.all_phases") %>

+ <%= render "phases", budget: current_budget %> +
-
- <% if @finished_budgets.present? %> -
-
- + <% if @finished_budgets.present? %> +
+
+ -
- <% @finished_budgets.each do |budget| %> -
-
-
-
-
-

<%= budget.name %>

+
+ <% @finished_budgets.each do |budget| %> +
+
+
+
+
+

<%= budget.name %>

+
-
-
-
- <%= link_to t("budgets.index.see_results"), - budget_results_path(budget.id), - class: "button expanded" %> +
+
+ <%= link_to t("budgets.index.see_results"), + budget_results_path(budget.id), + class: "button expanded" %> +
-
- <% end %> + <% end %> +
+
+
+ <% end %> + +
+
+
+

+ <%= t("budgets.index.section_footer.title") %> +

+

<%= t("budgets.index.section_footer.description") %>

+

<%= t("budgets.index.section_footer.help_text_1") %>

+

<%= t("budgets.index.section_footer.help_text_2") %>

+

<%= t("budgets.index.section_footer.help_text_3", + org: link_to(setting['org_name'], new_user_registration_path)).html_safe %>

+

<%= t("budgets.index.section_footer.help_text_4") %>

- <% end %> - -
-
-
-

- <%= t("budgets.index.section_footer.title") %> -

-

<%= t("budgets.index.section_footer.description") %>

-

<%= t("budgets.index.section_footer.help_text_1") %>

-

<%= t("budgets.index.section_footer.help_text_2") %>

-

<%= t("budgets.index.section_footer.help_text_3", - org: link_to(setting['org_name'], new_user_registration_path)).html_safe %>

-

<%= t("budgets.index.section_footer.help_text_4") %>

-
-
-
+<% else %> + <%= t("budgets.index.empty_budgets") %> +<% end %> \ No newline at end of file diff --git a/config/locales/en/budgets.yml b/config/locales/en/budgets.yml index 48d3b3462..eeed3b2fb 100644 --- a/config/locales/en/budgets.yml +++ b/config/locales/en/budgets.yml @@ -41,6 +41,7 @@ en: finished: Finished budget index: title: Participatory budgets + empty_budgets: There are no budgets section_header: icon_alt: Participatory budgets icon title: Participatory budgets diff --git a/config/locales/es/budgets.yml b/config/locales/es/budgets.yml index 67ad55d5f..70ed9c454 100644 --- a/config/locales/es/budgets.yml +++ b/config/locales/es/budgets.yml @@ -41,6 +41,7 @@ es: finished: Resultados index: title: Presupuestos participativos + empty_budgets: No hay presupuestos participativos section_header: icon_alt: Icono de Presupuestos participativos title: Presupuestos participativos diff --git a/spec/features/budgets/budgets_spec.rb b/spec/features/budgets/budgets_spec.rb index d391dc9be..cd1ee6cd5 100644 --- a/spec/features/budgets/budgets_spec.rb +++ b/spec/features/budgets/budgets_spec.rb @@ -117,6 +117,13 @@ feature 'Budgets' do end end + scenario "No budgets" do + Budget.destroy_all + + visit budgets_path + + expect(page).to have_content "There are no budgets" + end end scenario 'Index shows only published phases' do From 563c1ebc931d73ced624d2daddb654ea66e0f2a6 Mon Sep 17 00:00:00 2001 From: decabeza Date: Thu, 5 Apr 2018 12:47:58 +0200 Subject: [PATCH 2/2] Adds styles to no budgets message --- app/views/budgets/index.html.erb | 48 +++++++++++++++++++++----------- config/locales/en/budgets.yml | 4 +-- config/locales/es/budgets.yml | 4 +-- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/app/views/budgets/index.html.erb b/app/views/budgets/index.html.erb index 360e79d72..2856dee3b 100644 --- a/app/views/budgets/index.html.erb +++ b/app/views/budgets/index.html.erb @@ -1,4 +1,4 @@ -<% provide :title do %><%= t('budgets.index.title') %><% end %> +<% provide :title do %><%= t("budgets.index.title") %><% end %> <% content_for :canonical do %> <%= render "shared/canonical", href: budgets_url %> <% end %> @@ -152,23 +152,37 @@
<% end %> - +
+<% else %> +
-
-
-

- <%= t("budgets.index.section_footer.title") %> -

-

<%= t("budgets.index.section_footer.description") %>

-

<%= t("budgets.index.section_footer.help_text_1") %>

-

<%= t("budgets.index.section_footer.help_text_2") %>

-

<%= t("budgets.index.section_footer.help_text_3", - org: link_to(setting['org_name'], new_user_registration_path)).html_safe %>

-

<%= t("budgets.index.section_footer.help_text_4") %>

-
+
+

<%= t("budgets.index.title") %>

-<% else %> - <%= t("budgets.index.empty_budgets") %> -<% end %> \ No newline at end of file + +
+
+
+ <%= t("budgets.index.empty_budgets") %> +
+
+
+<% end %> + +
+
+
+

+ <%= t("budgets.index.section_footer.title") %> +

+

<%= t("budgets.index.section_footer.description") %>

+

<%= t("budgets.index.section_footer.help_text_1") %>

+

<%= t("budgets.index.section_footer.help_text_2") %>

+

<%= t("budgets.index.section_footer.help_text_3", + org: link_to(setting['org_name'], new_user_registration_path)).html_safe %>

+

<%= t("budgets.index.section_footer.help_text_4") %>

+
+
+
diff --git a/config/locales/en/budgets.yml b/config/locales/en/budgets.yml index eeed3b2fb..b50e122a8 100644 --- a/config/locales/en/budgets.yml +++ b/config/locales/en/budgets.yml @@ -41,7 +41,7 @@ en: finished: Finished budget index: title: Participatory budgets - empty_budgets: There are no budgets + empty_budgets: There are no budgets. section_header: icon_alt: Participatory budgets icon title: Participatory budgets @@ -131,7 +131,7 @@ en: already_added: You have already added this investment project already_supported: You have already supported this investment project. Share it! support_title: Support this project - confirm_group: + confirm_group: one: "You can only support investments in %{count} district. If you continue you cannot change the election of your district. Are you sure?" other: "You can only support investments in %{count} district. If you continue you cannot change the election of your district. Are you sure?" supports: diff --git a/config/locales/es/budgets.yml b/config/locales/es/budgets.yml index 70ed9c454..2bf7cf85a 100644 --- a/config/locales/es/budgets.yml +++ b/config/locales/es/budgets.yml @@ -41,7 +41,7 @@ es: finished: Resultados index: title: Presupuestos participativos - empty_budgets: No hay presupuestos participativos + empty_budgets: No hay presupuestos participativos. section_header: icon_alt: Icono de Presupuestos participativos title: Presupuestos participativos @@ -131,7 +131,7 @@ es: already_added: Ya has añadido este proyecto de gasto already_supported: Ya has apoyado este proyecto de gasto. ¡Compártelo! support_title: Apoyar este proyecto - confirm_group: + confirm_group: one: "Sólo puedes apoyar proyectos en %{count} distritos. Si sigues adelante no podrás cambiar la elección de este distrito. ¿Estás seguro?" other: "Sólo puedes apoyar proyectos en %{count} distritos. Si sigues adelante no podrás cambiar la elección de este distrito. ¿Estás seguro?" supports: