Merge pull request #2799 from wairbut-m2c/backport-2588-fix_supports_filter

Fix `max_per_heading` filter in Admin budget investments list
This commit is contained in:
Alberto
2018-07-26 14:11:03 +02:00
committed by GitHub
7 changed files with 29 additions and 47 deletions

View File

@@ -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

View File

@@ -113,7 +113,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?

View File

@@ -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,

View File

@@ -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>

View File

@@ -167,7 +167,7 @@ en:
selected: Selected
undecided: Undecided
unfeasible: Unfeasible
max_per_heading: Max. supports per heading
min_total_supports: Minimum supports
winners: Winners
one_filter_html: "Current applied filters: <b><em>%{filter}</em></b>"
two_filters_html: "Current applied filters: <b><em>%{filter}, %{advanced_filters}</em></b>"

View File

@@ -167,7 +167,7 @@ es:
selected: Seleccionados
undecided: Sin decidir
unfeasible: Inviables
max_per_heading: Corte por partida
min_total_supports: Apoyos mínimos
winners: Ganadores
one_filter_html: "Filtros en uso: <b><em>%{filter}</em></b>"
two_filters_html: "Filtros en uso: <b><em>%{filter}, %{advanced_filters}</em></b>"

View File

@@ -371,59 +371,40 @@ feature 'Admin budget investments' do
expect(page).to have_content 'The budget has to stay on phase "Balloting projects", "Reviewing Ballots" or "Finished budget" in order to calculate winners projects'
end
scenario "Limiting by max number of investments per heading", :js do
scenario "Filtering by minimum number of votes", :js do
group_1 = create(:budget_group, budget: budget)
group_2 = create(:budget_group, budget: budget)
parks = create(:budget_heading, group: group_1)
roads = create(:budget_heading, group: group_2)
streets = create(:budget_heading, group: group_2)
[2, 4, 90, 100, 200, 300].each do |n|
create(:budget_investment, heading: parks, cached_votes_up: n, title: "Park with #{n} supports")
end
[21, 31, 51, 81, 91, 101].each do |n|
create(:budget_investment, heading: roads, cached_votes_up: n, title: "Road with #{n} supports")
end
[3, 10, 30, 33, 44, 55].each do |n|
create(:budget_investment, heading: streets, cached_votes_up: n, title: "Street with #{n} supports")
end
create(:budget_investment, heading: parks, cached_votes_up: 40, title: "Park with 40 supports")
create(:budget_investment, heading: parks, cached_votes_up: 99, title: "Park with 99 supports")
create(:budget_investment, heading: roads, cached_votes_up: 100, title: "Road with 100 supports")
create(:budget_investment, heading: roads, cached_votes_up: 199, title: "Road with 199 supports")
create(:budget_investment, heading: streets, cached_votes_up: 200, title: "Street with 200 supports")
create(:budget_investment, heading: streets, cached_votes_up: 300, title: "Street with 300 supports")
visit admin_budget_budget_investments_path(budget)
[2, 4, 90, 100, 200, 300].each do |n|
expect(page).to have_link("Park with #{n} supports")
end
[21, 31, 51, 81, 91, 101].each do |n|
expect(page).to have_link("Road with #{n} supports")
end
[3, 10, 30, 33, 44, 55].each do |n|
expect(page).to have_link("Street with #{n} supports")
end
expect(page).to have_link("Park with 40 supports")
expect(page).to have_link("Park with 99 supports")
expect(page).to have_link("Road with 100 supports")
expect(page).to have_link("Road with 199 supports")
expect(page).to have_link("Street with 200 supports")
expect(page).to have_link("Street with 300 supports")
click_link 'Advanced filters'
fill_in "max_per_heading", with: 5
fill_in "min_total_supports", with: 180
click_button 'Filter'
expect(page).to have_content('There are 15 investments')
expect(page).not_to have_link("Park with 2 supports")
expect(page).not_to have_link("Road with 21 supports")
expect(page).not_to have_link("Street with 3 supports")
[4, 90, 100, 200, 300].each do |n|
expect(page).to have_link("Park with #{n} supports")
end
[31, 51, 81, 91, 101].each do |n|
expect(page).to have_link("Road with #{n} supports")
end
[10, 30, 33, 44, 55].each do |n|
expect(page).to have_link("Street with #{n} supports")
end
expect(page).to have_content('There are 3 investments')
expect(page).to have_link("Road with 199 supports")
expect(page).to have_link("Street with 200 supports")
expect(page).to have_link("Street with 300 supports")
expect(page).not_to have_link("Park with 40 supports")
expect(page).not_to have_link("Park with 99 supports")
expect(page).not_to have_link("Road with 100 supports")
end
scenario "Combination of checkbox with text search", :js do