From eb7dc3ef2d7f130af076b609c7af4bb834102213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 4 Jun 2019 11:48:14 +0200 Subject: [PATCH] Extract partial to render budget navigation links --- app/helpers/budgets_helper.rb | 14 ++++++++++++++ app/views/budgets/_subnav.html.erb | 17 +++++++++++++++++ app/views/budgets/executions/show.html.erb | 16 +--------------- app/views/budgets/results/show.html.erb | 17 +---------------- app/views/budgets/stats/show.html.erb | 17 +---------------- 5 files changed, 34 insertions(+), 47 deletions(-) create mode 100644 app/views/budgets/_subnav.html.erb diff --git a/app/helpers/budgets_helper.rb b/app/helpers/budgets_helper.rb index d8425c217..5ac9b12a1 100644 --- a/app/helpers/budgets_helper.rb +++ b/app/helpers/budgets_helper.rb @@ -105,4 +105,18 @@ module BudgetsHelper ends_at: balloting_phase.ends_at }), method: :post end + + def budget_subnav_items_for(budget) + { + results: t("budgets.results.link"), + stats: t("stats.budgets.link"), + executions: t("budgets.executions.link") + }.map do |section, text| + { + text: text, + url: send("budget_#{section}_path", budget), + active: controller_name == section.to_s + } + end + end end diff --git a/app/views/budgets/_subnav.html.erb b/app/views/budgets/_subnav.html.erb new file mode 100644 index 000000000..f5f960377 --- /dev/null +++ b/app/views/budgets/_subnav.html.erb @@ -0,0 +1,17 @@ +
+
+
    + <% budget_subnav_items_for(budget).each do |item| %> + <% if item[:active] %> +
  • + <%= t("shared.you_are_in") %> + + <%= link_to item[:text], item[:url], class: "is-active" %> +
  • + <% else %> +
  • <%= link_to item[:text], item[:url] %>
  • + <% end %> + <% end %> +
+
+
diff --git a/app/views/budgets/executions/show.html.erb b/app/views/budgets/executions/show.html.erb index a0e3324bc..acab50de4 100644 --- a/app/views/budgets/executions/show.html.erb +++ b/app/views/budgets/executions/show.html.erb @@ -25,21 +25,7 @@ -
-
-
    -
  • - <%= link_to t("budgets.results.link"), budget_results_path(@budget) %> -
  • -
  • - <%= link_to t("stats.budgets.link"), budget_stats_path(@budget) %> -
  • -
  • - <%= link_to t("budgets.executions.link"), budget_executions_path(@budget), class: "is-active" %> -
  • -
-
-
+<%= render "budgets/subnav", budget: @budget %>
diff --git a/app/views/budgets/results/show.html.erb b/app/views/budgets/results/show.html.erb index d77f50b77..6a8829437 100644 --- a/app/views/budgets/results/show.html.erb +++ b/app/views/budgets/results/show.html.erb @@ -24,22 +24,7 @@
-
-
-
    -
  • - <%= t("shared.you_are_in") %> - <%= link_to t("budgets.results.link"), budget_results_path(@budget), class: "is-active" %> -
  • -
  • - <%= link_to t("stats.budgets.link"), budget_stats_path(@budget) %> -
  • -
  • - <%= link_to t("budgets.executions.link"), budget_executions_path(@budget) %> -
  • -
-
-
+<%= render "budgets/subnav", budget: @budget %>
diff --git a/app/views/budgets/stats/show.html.erb b/app/views/budgets/stats/show.html.erb index bbbfda4bb..60697135d 100644 --- a/app/views/budgets/stats/show.html.erb +++ b/app/views/budgets/stats/show.html.erb @@ -21,22 +21,7 @@
-
-
-
    -
  • - <%= t("shared.you_are_in") %> - <%= link_to t("budgets.results.link"), budget_results_path(@budget) %> -
  • -
  • - <%= link_to t("stats.budgets.link"), budget_stats_path(@budget), class: "is-active" %> -
  • -
  • - <%= link_to t("budgets.executions.link"), budget_executions_path(@budget) %> -
  • -
-
-
+ <%= render "budgets/subnav", budget: @budget %>