Fix max_per_heading filter in Admin budget investments list
Also changed the name of the param to `min_total_supports`, which is more descriptive on what it actually does. Backport of 75f20d5 and 07f0806 from AyuntamientoMadrid/consul fork
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
module AdminBudgetInvestmentsHelper
|
||||
|
||||
def advanced_menu_visibility
|
||||
(params[:advanced_filters].empty? && params["max_per_heading"].blank?) ? 'hide' : ''
|
||||
(params[:advanced_filters].empty? && params["min_total_supports"].blank?) ? 'hide' : ''
|
||||
end
|
||||
|
||||
def init_advanced_menu
|
||||
|
||||
@@ -109,7 +109,8 @@ class Budget
|
||||
budget = Budget.find_by(slug: params[:budget_id]) || Budget.find_by(id: params[:budget_id])
|
||||
results = Investment.by_budget(budget)
|
||||
|
||||
results = limit_results(budget, params, results) if params[:max_per_heading].present?
|
||||
results = results.where("cached_votes_up + physical_votes >= ?",
|
||||
params[:min_total_supports]) if params[:min_total_supports].present?
|
||||
results = results.where(group_id: params[:group_id]) if params[:group_id].present?
|
||||
results = results.by_tag(params[:tag_name]) if params[:tag_name].present?
|
||||
results = results.by_heading(params[:heading_id]) if params[:heading_id].present?
|
||||
@@ -132,18 +133,6 @@ class Budget
|
||||
results.where("budget_investments.id IN (?)", ids)
|
||||
end
|
||||
|
||||
def self.limit_results(budget, params, results)
|
||||
max_per_heading = params[:max_per_heading].to_i
|
||||
return results if max_per_heading <= 0
|
||||
|
||||
ids = []
|
||||
budget.headings.pluck(:id).each do |hid|
|
||||
ids += Investment.where(heading_id: hid).order(confidence_score: :desc).limit(max_per_heading).pluck(:id)
|
||||
end
|
||||
|
||||
results.where("budget_investments.id IN (?)", ids)
|
||||
end
|
||||
|
||||
def self.search_by_title_or_id(title_or_id, results)
|
||||
if title_or_id =~ /^[0-9]+$/
|
||||
results.where(id: title_or_id)
|
||||
|
||||
@@ -112,7 +112,7 @@
|
||||
investment,
|
||||
filter: params[:filter],
|
||||
sort_by: params[:sort_by],
|
||||
max_per_heading: params[:max_per_heading],
|
||||
min_total_supports: params[:min_total_supports],
|
||||
advanced_filters: params[:advanced_filters],
|
||||
page: params[:page]),
|
||||
method: :patch,
|
||||
@@ -125,7 +125,7 @@
|
||||
investment,
|
||||
filter: params[:filter],
|
||||
sort_by: params[:sort_by],
|
||||
max_per_heading: params[:max_per_heading],
|
||||
min_total_supports: params[:min_total_supports],
|
||||
advanced_filters: params[:advanced_filters],
|
||||
page: params[:page]),
|
||||
method: :patch,
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="filter">
|
||||
<%= text_field_tag :max_per_heading, params["max_per_heading"], placeholder: t("admin.budget_investments.index.filters.max_per_heading") %>
|
||||
<%= text_field_tag :min_total_supports, params["min_total_supports"], placeholder: t("admin.budget_investments.index.filters.min_total_supports") %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user