Extract methods in investment row component

This way we simplify the code a little bit.
This commit is contained in:
Javi Martín
2024-10-07 13:23:14 +02:00
parent bb42809168
commit 9330cdb304
2 changed files with 28 additions and 15 deletions

View File

@@ -4,11 +4,7 @@
</td>
<td data-field="title">
<%= link_to investment.title,
admin_budget_budget_investment_path(budget_id: budget.id,
id: investment.id,
params: Budget::Investment.filter_params(params).to_h),
target: "_blank" %>
<%= link_to investment.title, investment_path, target: "_blank" %>
</td>
<td class="text-center" data-field="supports">
@@ -16,13 +12,7 @@
</td>
<td class="small" data-field="admin">
<% if investment.administrator.present? %>
<span title="<%= t("admin.budget_investments.index.assigned_admin") %>">
<%= investment.administrator.description_or_name %>
</span>
<% else %>
<%= t("admin.budget_investments.index.no_admin_assigned") %>
<% end %>
<%= administrator_info %>
</td>
<td class="small" data-field="author">
@@ -30,9 +20,7 @@
</td>
<td class="small" data-field="valuator">
<% valuators = [investment.assigned_valuation_groups, investment.assigned_valuators].compact %>
<% no_valuators_assigned = t("admin.budget_investments.index.no_valuators_assigned") %>
<%= valuators.present? ? valuators.join(", ") : no_valuators_assigned %>
<%= valuators_info %>
</td>
<td class="small" data-field="geozone">

View File

@@ -11,4 +11,29 @@ class Admin::BudgetInvestments::RowComponent < ApplicationComponent
def budget
investment.budget
end
def investment_path
admin_budget_budget_investment_path(budget_id: budget.id,
id: investment.id,
params: Budget::Investment.filter_params(params).to_h)
end
def administrator_info
if investment.administrator.present?
tag.span(investment.administrator.description_or_name,
title: t("admin.budget_investments.index.assigned_admin"))
else
t("admin.budget_investments.index.no_admin_assigned")
end
end
def valuators_info
valuators = [investment.assigned_valuation_groups, investment.assigned_valuators].compact
if valuators.present?
valuators.join(", ")
else
t("admin.budget_investments.index.no_valuators_assigned")
end
end
end