diff --git a/app/views/admin/budget_investments/_investments.html.erb b/app/components/admin/budget_investments/investments_component.html.erb similarity index 91% rename from app/views/admin/budget_investments/_investments.html.erb rename to app/components/admin/budget_investments/investments_component.html.erb index 073abb90d..f5e0f4a59 100644 --- a/app/views/admin/budget_investments/_investments.html.erb +++ b/app/components/admin/budget_investments/investments_component.html.erb @@ -4,11 +4,11 @@ class: "float-right small clear" %> <% if params[:advanced_filters].include?("winners") %> - <%= render Admin::Budgets::CalculateWinnersButtonComponent.new(@budget, from_investments: true) %> + <%= render Admin::Budgets::CalculateWinnersButtonComponent.new(budget, from_investments: true) %> <% end %> - <% if @investments.any? %> -

<%= page_entries_info @investments %>

+ <% if investments.any? %> +

<%= page_entries_info investments %>

<%= render "admin/shared/columns_selector", cookie: "investments-columns", default: %w[id title supports admin valuator geozone feasibility price valuation_finished visible_to_valuators selected incompatible] %> @@ -32,7 +32,7 @@ <%= t("admin.budget_investments.index.list.geozone") %> <%= t("admin.budget_investments.index.list.feasibility") %> - <% if @budget.show_money? %> + <% if budget.show_money? %> <%= t("admin.budget_investments.index.list.price") %> <% end %> @@ -49,13 +49,13 @@ - <% @investments.each do |investment| %> + <% investments.each do |investment| %> <%= render Admin::BudgetInvestments::RowComponent.new(investment) %> <% end %> - <%= paginate @investments %> + <%= paginate investments %> <% else %>
<%= t("admin.budget_investments.index.no_budget_investments") %> diff --git a/app/components/admin/budget_investments/investments_component.rb b/app/components/admin/budget_investments/investments_component.rb new file mode 100644 index 000000000..74f7f439b --- /dev/null +++ b/app/components/admin/budget_investments/investments_component.rb @@ -0,0 +1,30 @@ +class Admin::BudgetInvestments::InvestmentsComponent < ApplicationComponent + attr_reader :budget, :investments + use_helpers :set_direction, :set_sorting_icon + + def initialize(budget, investments) + @budget = budget + @investments = investments + end + + private + + def csv_params + csv_params = params.clone.merge(format: :csv) + csv_params = csv_params.to_unsafe_h.transform_keys(&:to_sym) + csv_params.delete(:page) + csv_params + end + + def link_to_investments_sorted_by(column) + direction = set_direction(params[:direction]) + icon = set_sorting_icon(direction, column) + + translation = t("admin.budget_investments.index.list.#{column}") + + link_to( + safe_join([translation, tag.span(class: "icon-sortable #{icon}")]), + admin_budget_budget_investments_path(sort_by: column, direction: direction) + ) + end +end diff --git a/app/helpers/budget_investments_helper.rb b/app/helpers/budget_investments_helper.rb index dc0920630..f3a49cde6 100644 --- a/app/helpers/budget_investments_helper.rb +++ b/app/helpers/budget_investments_helper.rb @@ -3,18 +3,6 @@ module BudgetInvestmentsHelper params.map { |af| t("admin.budget_investments.index.filters.#{af}") }.join(", ") end - def link_to_investments_sorted_by(column) - direction = set_direction(params[:direction]) - icon = set_sorting_icon(direction, column) - - translation = t("admin.budget_investments.index.list.#{column}") - - link_to( - safe_join([translation, tag.span(class: "icon-sortable #{icon}")]), - admin_budget_budget_investments_path(sort_by: column, direction: direction) - ) - end - def set_sorting_icon(direction, sort_by) if sort_by.to_s == params[:sort_by] if direction == "desc" diff --git a/app/helpers/budgets_helper.rb b/app/helpers/budgets_helper.rb index ffcfc548c..7ad8d9a52 100644 --- a/app/helpers/budgets_helper.rb +++ b/app/helpers/budgets_helper.rb @@ -1,11 +1,4 @@ module BudgetsHelper - def csv_params - csv_params = params.clone.merge(format: :csv) - csv_params = csv_params.to_unsafe_h.transform_keys(&:to_sym) - csv_params.delete(:page) - csv_params - end - def namespaced_budget_investment_path(investment, options = {}) case namespace when "management" diff --git a/app/views/admin/budget_investments/index.html.erb b/app/views/admin/budget_investments/index.html.erb index bfd50f9e8..7a8e46741 100644 --- a/app/views/admin/budget_investments/index.html.erb +++ b/app/views/admin/budget_investments/index.html.erb @@ -12,4 +12,4 @@ <%= render "/shared/filter_subnav", i18n_namespace: "admin.budget_investments.index" %> -<%= render "investments" %> +<%= render Admin::BudgetInvestments::InvestmentsComponent.new(@budget, @investments) %>