Move admin investments partial to a component
This way it'll be easier to organize the code related to it.
This commit is contained in:
@@ -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? %>
|
||||
<h3 class="inline-block"><%= page_entries_info @investments %></h3>
|
||||
<% if investments.any? %>
|
||||
<h3 class="inline-block"><%= page_entries_info investments %></h3>
|
||||
<%= 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 @@
|
||||
</th>
|
||||
<th data-field="geozone"><%= t("admin.budget_investments.index.list.geozone") %></th>
|
||||
<th data-field="feasibility"><%= t("admin.budget_investments.index.list.feasibility") %></th>
|
||||
<% if @budget.show_money? %>
|
||||
<% if budget.show_money? %>
|
||||
<th data-field="price"><%= t("admin.budget_investments.index.list.price") %></th>
|
||||
<% end %>
|
||||
<th data-field="valuation_finished">
|
||||
@@ -49,13 +49,13 @@
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @investments.each do |investment| %>
|
||||
<% investments.each do |investment| %>
|
||||
<%= render Admin::BudgetInvestments::RowComponent.new(investment) %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%= paginate @investments %>
|
||||
<%= paginate investments %>
|
||||
<% else %>
|
||||
<div class="callout primary clear">
|
||||
<%= t("admin.budget_investments.index.no_budget_investments") %>
|
||||
@@ -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
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -12,4 +12,4 @@
|
||||
|
||||
<%= render "/shared/filter_subnav", i18n_namespace: "admin.budget_investments.index" %>
|
||||
|
||||
<%= render "investments" %>
|
||||
<%= render Admin::BudgetInvestments::InvestmentsComponent.new(@budget, @investments) %>
|
||||
|
||||
Reference in New Issue
Block a user