Remove duplication in investment tag methods

This commit is contained in:
Javi Martín
2019-10-31 21:43:56 +01:00
parent 20001824e5
commit fb2b821c28
2 changed files with 5 additions and 11 deletions

View File

@@ -53,15 +53,9 @@ module BudgetsHelper
Budget::Ballot.where(user: current_user, budget: @budget).first
end
def investment_tags_select_options(budget)
tags = budget.investments.tags_on(:valuation_tags).order(:name).pluck(:name)
tags = tags.concat budget.valuation_tag_list
tags.uniq
end
def investment_milestone_tags_select_options(budget)
tags = budget.investments.tags_on(:milestone_tags).order(:name).pluck(:name)
tags = tags.concat budget.milestone_tag_list
def investment_tags_select_options(budget, context)
tags = budget.investments.tags_on(context).order(:name).pluck(:name)
tags = tags.concat budget.tag_list_on(context)
tags.uniq
end

View File

@@ -49,13 +49,13 @@
</div>
<div class="small-12 medium-3 column">
<%= select_tag :tag_name,
options_for_select(investment_tags_select_options(@budget), params[:tag_name]),
options_for_select(investment_tags_select_options(@budget, "valuation_tags"), params[:tag_name]),
{ prompt: t("admin.budget_investments.index.tags_filter_all") } %>
</div>
<div class="small-12 medium-3 column">
<%= select_tag :milestone_tag_name,
options_for_select(investment_milestone_tags_select_options(@budget), params[:milestone_tag_name]),
options_for_select(investment_tags_select_options(@budget, "milestone_tags"), params[:milestone_tag_name]),
{ prompt: t("admin.budget_investments.index.milestone_tags_filter_all") } %>
</div>