Skip to content

Commit

Permalink
Add max support advanced filter for admin budget investments
Browse files Browse the repository at this point in the history
  • Loading branch information
abelardogilm authored and microweb10 committed May 29, 2019
1 parent 11170ee commit 3e8ae68
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 16 deletions.
8 changes: 7 additions & 1 deletion app/helpers/admin_budget_investments_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
module AdminBudgetInvestmentsHelper

def advanced_menu_visibility
(params[:advanced_filters].empty? && params["min_total_supports"].blank?) ? "hide" : ""
if params[:advanced_filters].empty? &&
params["min_total_supports"].blank? &&
params["max_total_supports"].blank?
"hide"
else
""
end
end

def init_advanced_menu
Expand Down
2 changes: 2 additions & 0 deletions app/models/budget/investment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ def self.scoped_filter(params, current_filter)

results = results.where("cached_votes_up + physical_votes >= ?",
params[:min_total_supports]) if params[:min_total_supports].present?
results = results.where("cached_votes_up + physical_votes <= ?",
params[:max_total_supports]) if params[:max_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?
Expand Down
11 changes: 9 additions & 2 deletions app/views/admin/budget_investments/_search_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@
<%= label_tag "advanced_filters[#{filter}]", t("admin.budget_investments.index.filters.#{filter}") %>
</div>
<% end %>
<div class="filter">
<%= text_field_tag :min_total_supports, params["min_total_supports"], placeholder: t("admin.budget_investments.index.filters.min_total_supports") %>
<div>
<div class="filter">
<%= label_tag :min_total_supports, t("admin.budget_investments.index.filters.min_total_supports") %>
<%= text_field_tag :min_total_supports, params["min_total_supports"] %>
</div>
<div class="filter">
<%= label_tag :max_total_supports, t("admin.budget_investments.index.filters.max_total_supports") %>
<%= text_field_tag :max_total_supports, params["max_total_supports"] %>
</div>
</div>
</div>
</div>
Expand Down
27 changes: 14 additions & 13 deletions app/views/admin/budget_investments/_select_investment.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,26 @@
filter: params[:filter],
sort_by: params[:sort_by],
min_total_supports: params[:min_total_supports],
max_total_supports: params[:max_total_supports],
advanced_filters: params[:advanced_filters],
page: params[:page]),
method: :patch,
remote: true,
class: "button small expanded" %>
<% elsif investment.feasible? && investment.valuation_finished? %>
<% unless investment.budget.finished? %>
<%= link_to t("admin.budget_investments.index.select"),
toggle_selection_admin_budget_budget_investment_path(@budget,
investment,
filter: params[:filter],
sort_by: params[:sort_by],
min_total_supports: params[:min_total_supports],
advanced_filters: params[:advanced_filters],
page: params[:page]),
method: :patch,
remote: true,
class: "button small hollow expanded" %>
<% end %>
<%= link_to_unless investment.budget.finished?,
t("admin.budget_investments.index.select"),
toggle_selection_admin_budget_budget_investment_path(@budget,
investment,
filter: params[:filter],
sort_by: params[:sort_by],
min_total_supports: params[:min_total_supports],
max_total_supports: params[:max_total_supports],
advanced_filters: params[:advanced_filters],
page: params[:page]),
method: :patch,
remote: true,
class: "button small hollow expanded" %>
<% end %>
</td>
<% if params[:filter] == "selected" %>
Expand Down
1 change: 1 addition & 0 deletions config/locales/en/admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ en:
undecided: Undecided
unfeasible: Unfeasible
min_total_supports: Minimum supports
max_total_supports: Maximum supports
winners: Winners
valuation_open: Open
one_filter_html: "Current applied filters: <b><em>%{filter}</em></b>"
Expand Down
1 change: 1 addition & 0 deletions config/locales/es/admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ es:
undecided: Sin decidir
unfeasible: Inviables
min_total_supports: Apoyos mínimos
max_total_supports: Apoyos máximos
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>"
Expand Down
36 changes: 36 additions & 0 deletions spec/features/admin/budget_investments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,42 @@
expect(page).not_to have_link("Road 100 supports")
end

scenario "Filtering by maximum 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)

create(:budget_investment, heading: parks, cached_votes_up: 40, title: "Park 40 supports")
create(:budget_investment, heading: parks, cached_votes_up: 99, title: "Park 99 supports")
create(:budget_investment, heading: roads, cached_votes_up: 100, title: "Road 100 supports")
create(:budget_investment, heading: roads, cached_votes_up: 199, title: "Road 199 supports")
create(:budget_investment, heading: streets, cached_votes_up: 200, title: "St. 200 supports")
create(:budget_investment, heading: streets, cached_votes_up: 300, title: "St. 300 supports")

visit admin_budget_budget_investments_path(budget)

expect(page).to have_link("Park 40 supports")
expect(page).to have_link("Park 99 supports")
expect(page).to have_link("Road 100 supports")
expect(page).to have_link("Road 199 supports")
expect(page).to have_link("St. 200 supports")
expect(page).to have_link("St. 300 supports")

click_link "Advanced filters"
fill_in "max_total_supports", with: 180
click_button "Filter"

expect(page).to have_content("There are 3 investments")
expect(page).not_to have_link("Road 199 supports")
expect(page).not_to have_link("St. 200 supports")
expect(page).not_to have_link("St. 300 supports")
expect(page).to have_link("Park 40 supports")
expect(page).to have_link("Park 99 supports")
expect(page).to have_link("Road 100 supports")
end

scenario "Combination of checkbox with text search", :js do
user = create(:user, username: "Admin 1")
administrator = create(:administrator, user: user)
Expand Down

0 comments on commit 3e8ae68

Please sign in to comment.