From 11170ee2caea58b429f6ba35ea34fcc37e5594e3 Mon Sep 17 00:00:00 2001 From: lalo Date: Wed, 3 Apr 2019 22:27:48 +0200 Subject: [PATCH 1/2] Move admin budget investments tabs filters to advanced filters component --- app/assets/stylesheets/admin.scss | 5 + .../admin/budget_investments_controller.rb | 6 +- app/controllers/admin/budgets_controller.rb | 4 +- app/models/budget/investment.rb | 11 +- .../budget_investments/_investments.html.erb | 2 +- .../budget_investments/_search_form.html.erb | 7 +- spec/factories/budgets.rb | 16 +- .../features/admin/budget_investments_spec.rb | 240 +++++++++++++++--- spec/features/admin/budgets_spec.rb | 4 +- spec/models/budget/investment_spec.rb | 87 +++++++ 10 files changed, 331 insertions(+), 51 deletions(-) diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index fe8ccbe3cdb..988cf6d9806 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -1199,6 +1199,11 @@ code { .filter { display: inline-block; margin: 0 $line-height / 2; + + label { + font-weight: normal; + margin: 0; + } } .button { diff --git a/app/controllers/admin/budget_investments_controller.rb b/app/controllers/admin/budget_investments_controller.rb index 3e6b19d68f4..93e84a5bc7a 100644 --- a/app/controllers/admin/budget_investments_controller.rb +++ b/app/controllers/admin/budget_investments_controller.rb @@ -4,10 +4,8 @@ class Admin::BudgetInvestmentsController < Admin::BaseController feature_flag :budgets - has_orders %w{oldest}, only: [:show, :edit] - has_filters(%w{all without_admin without_valuator under_valuation - valuation_finished winners}, - only: [:index, :toggle_selection]) + has_orders %w[oldest], only: [:show, :edit] + has_filters %w[all], only: [:index, :toggle_selection] before_action :load_budget before_action :load_investment, only: [:show, :edit, :update, :toggle_selection] diff --git a/app/controllers/admin/budgets_controller.rb b/app/controllers/admin/budgets_controller.rb index f840ad0905a..fa9ad67520d 100644 --- a/app/controllers/admin/budgets_controller.rb +++ b/app/controllers/admin/budgets_controller.rb @@ -25,7 +25,9 @@ def edit def calculate_winners return unless @budget.balloting_process? @budget.headings.each { |heading| Budget::Result.new(@budget, heading).delay.calculate_winners } - redirect_to admin_budget_budget_investments_path(budget_id: @budget.id, filter: "winners"), + redirect_to admin_budget_budget_investments_path( + budget_id: @budget.id, + advanced_filters: ["winners"]), notice: I18n.t("admin.budgets.winners.calculated") end diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 2a531e04817..0c6eda38351 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -122,7 +122,7 @@ def self.scoped_filter(params, current_filter) results = Investment.by_budget(budget) results = results.where("cached_votes_up + physical_votes >= ?", - params[:min_total_supports]) if params[:min_total_supports].present? + 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? @@ -137,12 +137,19 @@ def self.scoped_filter(params, current_filter) end def self.advanced_filters(params, results) + results = results.without_admin if params[:advanced_filters].include?("without_admin") + results = results.without_valuator if params[:advanced_filters].include?("without_valuator") + results = results.under_valuation if params[:advanced_filters].include?("under_valuation") + results = results.valuation_finished if params[:advanced_filters].include?("valuation_finished") + results = results.winners if params[:advanced_filters].include?("winners") + ids = [] ids += results.valuation_finished_feasible.pluck(:id) if params[:advanced_filters].include?("feasible") ids += results.where(selected: true).pluck(:id) if params[:advanced_filters].include?("selected") ids += results.undecided.pluck(:id) if params[:advanced_filters].include?("undecided") ids += results.unfeasible.pluck(:id) if params[:advanced_filters].include?("unfeasible") - results.where("budget_investments.id IN (?)", ids) + results = results.where("budget_investments.id IN (?)", ids) if ids.any? + results end def self.order_filter(params) diff --git a/app/views/admin/budget_investments/_investments.html.erb b/app/views/admin/budget_investments/_investments.html.erb index 0be6f5e1060..3813489293f 100644 --- a/app/views/admin/budget_investments/_investments.html.erb +++ b/app/views/admin/budget_investments/_investments.html.erb @@ -2,7 +2,7 @@ admin_budget_budget_investments_path(csv_params), class: "float-right small clear" %> -<% if params[:filter] == "winners" %> +<% if params[:advanced_filters].include?("winners") %> <% if display_calculate_winners_button?(@budget) %> <%= link_to calculate_winner_button_text(@budget), calculate_winners_admin_budget_path(@budget), diff --git a/app/views/admin/budget_investments/_search_form.html.erb b/app/views/admin/budget_investments/_search_form.html.erb index 94ae8fc0b9b..b7d44ad5a85 100644 --- a/app/views/admin/budget_investments/_search_form.html.erb +++ b/app/views/admin/budget_investments/_search_form.html.erb @@ -11,10 +11,11 @@
- <% ["feasible", "selected", "undecided", "unfeasible"].each do |option| %> + <% %w[feasible selected undecided unfeasible without_admin without_valuator under_valuation + valuation_finished winners].each do |filter| %>
- <%= check_box_tag "advanced_filters[]", option, params[:advanced_filters].index(option), id: "advanced_filters_#{option}" %> - <%= t("admin.budget_investments.index.filters.#{option}") %> + <%= check_box_tag "advanced_filters[]", filter, params[:advanced_filters].index(filter), id: "advanced_filters_#{filter}" %> + <%= label_tag "advanced_filters[#{filter}]", t("admin.budget_investments.index.filters.#{filter}") %>
<% end %>
diff --git a/spec/factories/budgets.rb b/spec/factories/budgets.rb index 30419093868..d7b0e066248 100644 --- a/spec/factories/budgets.rb +++ b/spec/factories/budgets.rb @@ -149,13 +149,17 @@ valuation_finished true end - trait :hidden do - hidden_at { Time.current } - end + trait :hidden do + hidden_at { Time.current } + end - trait :with_ignored_flag do - ignored_flag_at { Time.current } - end + trait :with_ignored_flag do + ignored_flag_at { Time.current } + end + + trait :with_administrator do + administrator + end trait :flagged do after :create do |investment| diff --git a/spec/features/admin/budget_investments_spec.rb b/spec/features/admin/budget_investments_spec.rb index 1378f70c47a..b6593a25d83 100644 --- a/spec/features/admin/budget_investments_spec.rb +++ b/spec/features/admin/budget_investments_spec.rb @@ -317,12 +317,161 @@ expect(page).not_to have_link("Build a hospital") end + scenario "Filtering by without assigned admin", :js do + create(:budget_investment, + title: "Investment without admin", + budget: budget) + create(:budget_investment, + :with_administrator, + title: "Investment with admin", + budget: budget) + + visit admin_budget_budget_investments_path(budget_id: budget) + expect(page).to have_link("Investment without admin") + expect(page).to have_link("Investment with admin") + + click_link "Advanced filters" + check("Without assigned admin") + click_button "Filter" + + expect(page).to have_content("There is 1 investment") + expect(page).to have_link("Investment without admin") + expect(page).not_to have_link("Investment with admin") + + uncheck("Without assigned admin") + click_button "Filter" + + expect(page).to have_content("There are 2 investments") + expect(page).to have_link("Investment without admin") + expect(page).to have_link("Investment with admin") + end + + scenario "Filtering by without assigned valuator", :js do + user = create(:user) + valuator = create(:valuator, user: user) + create(:budget_investment, + title: "Investment without valuator", + budget: budget) + create(:budget_investment, + title: "Investment with valuator", + budget: budget, + valuators: [valuator]) + + visit admin_budget_budget_investments_path(budget_id: budget) + expect(page).to have_link("Investment without valuator") + expect(page).to have_link("Investment with valuator") + + click_link "Advanced filters" + check "Without assigned valuator" + click_button "Filter" + + expect(page).to have_content("There is 1 investment") + expect(page).to have_link("Investment without valuator") + expect(page).not_to have_link("Investment with valuator") + + uncheck "Without assigned valuator" + click_button "Filter" + + expect(page).to have_content("There are 2 investments") + expect(page).to have_link("Investment without valuator") + expect(page).to have_link("Investment with valuator") + end + + scenario "Filtering by under valuation", :js do + user = create(:user) + valuator = create(:valuator, user: user) + create(:budget_investment, + :with_administrator, + valuation_finished: false, + title: "Investment without valuation", + budget: budget, + valuators: [valuator]) + create(:budget_investment, + :with_administrator, + title: "Investment with valuation", + budget: budget) + + visit admin_budget_budget_investments_path(budget_id: budget) + expect(page).to have_link("Investment without valuation") + expect(page).to have_link("Investment with valuation") + + click_link "Advanced filters" + check "Under valuation" + click_button "Filter" + + expect(page).to have_content("There is 1 investment") + expect(page).to have_link("Investment without valuation") + expect(page).not_to have_link("Investment with valuation") + + uncheck "Under valuation" + click_button "Filter" + + expect(page).to have_content("There are 2 investments") + expect(page).to have_link("Investment without valuation") + expect(page).to have_link("Investment with valuation") + end + + scenario "Filtering by valuation finished", :js do + create(:budget_investment, + title: "Investment valuation open", + budget: budget) + create(:budget_investment, + :finished, + title: "Investment valuation finished", + budget: budget) + + visit admin_budget_budget_investments_path(budget_id: budget) + expect(page).to have_link("Investment valuation open") + expect(page).to have_link("Investment valuation finished") + + click_link "Advanced filters" + check "Valuation finished" + click_button "Filter" + + expect(page).to have_content("There is 1 investment") + expect(page).not_to have_link("Investment valuation open") + expect(page).to have_link("Investment valuation finished") + + uncheck "Valuation finished" + click_button "Filter" + + expect(page).to have_content("There are 2 investments") + expect(page).to have_link("Investment valuation open") + expect(page).to have_link("Investment valuation finished") + end + + scenario "Filtering by winners", :js do + create(:budget_investment, + :winner, + valuation_finished: true, + title: "Investment winner", + budget: budget) + create(:budget_investment, + title: "Investment without winner", + budget: budget) + + visit admin_budget_budget_investments_path(budget_id: budget) + expect(page).to have_link("Investment winner") + expect(page).to have_link("Investment without winner") + + click_link "Advanced filters" + check "Winners" + click_button "Filter" + + expect(page).to have_content("There is 1 investment") + expect(page).to have_link("Investment winner") + expect(page).not_to have_link("Investment without winner") + + uncheck "Winners" + click_button "Filter" + + expect(page).to have_content("There are 2 investments") + expect(page).to have_link("Investment winner") + expect(page).to have_link("Investment without winner") + end + scenario "Current filter is properly highlighted" do - filters_links = { "all" => "All", - "without_admin" => "Without assigned admin", - "without_valuator" => "Without assigned valuator", - "under_valuation" => "Under valuation", - "valuation_finished" => "Valuation finished" } + filters_links = { "all" => "All" } visit admin_budget_budget_investments_path(budget_id: budget.id) @@ -354,13 +503,15 @@ expect(page).to have_content("Evaluating...") expect(page).to have_content("With group") - visit admin_budget_budget_investments_path(budget_id: budget.id, filter: "without_admin") + visit admin_budget_budget_investments_path(budget_id: budget.id, + advanced_filters: ["without_admin"]) expect(page).to have_content("Evaluating...") expect(page).to have_content("With group") expect(page).not_to have_content("Assigned idea") - visit admin_budget_budget_investments_path(budget_id: budget.id, filter: "without_valuator") + visit admin_budget_budget_investments_path(budget_id: budget.id, + advanced_filters: ["without_valuator"]) expect(page).to have_content("Assigned idea") expect(page).not_to have_content("Evaluating...") @@ -375,17 +526,20 @@ valuating.valuators.push(create(:valuator)) valuated.valuators.push(create(:valuator)) - visit admin_budget_budget_investments_path(budget_id: budget.id, filter: "under_valuation") + query_params = {budget_id: budget.id, advanced_filters: ["under_valuation"]} + + visit admin_budget_budget_investments_path(query_params) expect(page).to have_content("Ongoing valuation") expect(page).not_to have_content("Old idea") - visit admin_budget_budget_investments_path(budget_id: budget.id, filter: "valuation_finished") + visit admin_budget_budget_investments_path(budget_id: budget.id, + advanced_filters: ["valuation_finished"]) expect(page).not_to have_content("Ongoing valuation") expect(page).to have_content("Old idea") - visit admin_budget_budget_investments_path(budget_id: budget.id, filter: "all") + visit admin_budget_budget_investments_path(budget_id: budget.id, advanced_filters: ["filter"]) expect(page).to have_content("Ongoing valuation") expect(page).to have_content("Old idea") end @@ -446,7 +600,10 @@ budget.update(phase: "reviewing_ballots") visit admin_budget_budget_investments_path(budget) - click_link "Winners" + + click_link "Advanced filters" + check "Winners" + click_button "Filter" expect(page).to have_link "Calculate Winner Investments" @@ -457,7 +614,9 @@ budget.update(phase: "accepting") visit admin_budget_budget_investments_path(budget) - click_link "Winners" + + check "Winners" + click_button "Filter" expect(page).not_to have_link "Calculate Winner Investments" expect(page).to have_content 'The budget has to stay on phase "Balloting projects", '\ @@ -561,7 +720,7 @@ click_link "Advanced filters" - page.check("advanced_filters_feasible") + check("Feasible") click_button "Filter" expect(page).to have_css(".budget_investment", count: 2) @@ -617,7 +776,7 @@ click_link "Advanced filters" - within("#advanced_filters") { check("advanced_filters_feasible") } + within("#advanced_filters") { check("Feasible") } click_button("Filter") expect(page).to have_css(".budget_investment", count: 2) @@ -1233,16 +1392,17 @@ scenario "Filtering by valuation and selection", :js do visit admin_budget_budget_investments_path(budget) - within("#filter-subnav") { click_link "Valuation finished" } + click_link "Advanced filters" + check "Valuation finished" + click_button "Filter" + expect(page).not_to have_content(unfeasible_bi.title) expect(page).not_to have_content(feasible_bi.title) expect(page).to have_content(feasible_vf_bi.title) expect(page).to have_content(selected_bi.title) expect(page).to have_content(winner_bi.title) - click_link "Advanced filters" - - within("#advanced_filters") { check("advanced_filters_feasible") } + within("#advanced_filters") { check("Feasible") } click_button("Filter") expect(page).not_to have_content(unfeasible_bi.title) @@ -1252,8 +1412,8 @@ expect(page).to have_content(winner_bi.title) within("#advanced_filters") do - check("advanced_filters_selected") - uncheck("advanced_filters_feasible") + check("Selected") + uncheck("Feasible") end click_button("Filter") @@ -1264,7 +1424,9 @@ expect(page).to have_content(selected_bi.title) expect(page).to have_content(winner_bi.title) - within("#filter-subnav") { click_link "Winners" } + check "Winners" + click_button "Filter" + expect(page).not_to have_content(unfeasible_bi.title) expect(page).not_to have_content(feasible_bi.title) expect(page).not_to have_content(feasible_vf_bi.title) @@ -1277,7 +1439,7 @@ click_link "Advanced filters" - within("#advanced_filters") { check("advanced_filters_undecided") } + within("#advanced_filters") { check("Undecided") } click_button("Filter") expect(page).to have_content(undecided_bi.title) @@ -1287,7 +1449,7 @@ expect(page).not_to have_content(unfeasible_bi.title) expect(page).not_to have_content(feasible_vf_bi.title) - within("#advanced_filters") { check("advanced_filters_unfeasible") } + within("#advanced_filters") { check("Unfeasible") } click_button("Filter") expect(page).to have_content(undecided_bi.title) @@ -1358,7 +1520,7 @@ click_link "Advanced filters" - within("#advanced_filters") { check("advanced_filters_selected") } + within("#advanced_filters") { check("Selected") } click_button("Filter") within("#budget_investment_#{feasible_vf_bi.id}") do @@ -1371,7 +1533,7 @@ visit admin_budget_budget_investments_path(budget) click_link "Advanced filters" - within("#advanced_filters") { check("advanced_filters_selected") } + within("#advanced_filters") { check("Selected") } click_button("Filter") expect(page).to have_content("There are 2 investments") @@ -1428,15 +1590,18 @@ investment2.update(administrator: admin) visit admin_budget_budget_investments_path(budget) - within("#filter-subnav") { click_link "Under valuation" } - expect(page).not_to have_link("Under valuation") + click_link "Advanced filters" + check "Under valuation" + click_button "Filter" within("#budget_investment_#{investment1.id}") do check "budget_investment_visible_to_valuators" end visit admin_budget_budget_investments_path(budget) - within("#filter-subnav") { click_link "Under valuation" } + click_link "Advanced filters" + check "Under valuation" + click_button "Filter" within("#budget_investment_#{investment1.id}") do expect(find("#budget_investment_visible_to_valuators")).to be_checked @@ -1474,15 +1639,20 @@ investment2.update(administrator: admin, visible_to_valuators: true) visit admin_budget_budget_investments_path(budget) - within("#filter-subnav") { click_link "Under valuation" } - expect(page).not_to have_link("Under valuation") + + click_link "Advanced filters" + check "Under valuation" + click_button "Filter" within("#budget_investment_#{investment1.id}") do uncheck "budget_investment_visible_to_valuators" end visit admin_budget_budget_investments_path(budget) - within("#filter-subnav") { click_link "Under valuation" } + + click_link "Advanced filters" + check "Under valuation" + click_button "Filter" within("#budget_investment_#{investment1.id}") do expect(find("#budget_investment_visible_to_valuators")).not_to be_checked @@ -1503,7 +1673,9 @@ expect(page).to have_css("#budget_investment_visible_to_valuators") - within("#filter-subnav") { click_link "Under valuation" } + click_link "Advanced filters" + check "Under valuation" + click_button "Filter" within("#budget_investment_#{investment1.id}") do valuating_checkbox = find("#budget_investment_visible_to_valuators") @@ -1581,7 +1753,9 @@ create(:budget_investment, :finished, budget: budget, title: "Finished Investment") visit admin_budget_budget_investments_path(budget) - within("#filter-subnav") { click_link "Valuation finished" } + click_link "Advanced filters" + check "Valuation finished" + click_button "Filter" click_link "Download current selection" diff --git a/spec/features/admin/budgets_spec.rb b/spec/features/admin/budgets_spec.rb index 39245e61770..0319646b72b 100644 --- a/spec/features/admin/budgets_spec.rb +++ b/spec/features/admin/budgets_spec.rb @@ -318,7 +318,9 @@ expect(page).not_to have_content "Calculate Winner Investments" visit admin_budget_budget_investments_path(budget) - click_link "Winners" + click_link "Advanced filters" + check "Winners" + click_button "Filter" expect(page).to have_content "Recalculate Winner Investments" expect(page).not_to have_content "Calculate Winner Investments" diff --git a/spec/models/budget/investment_spec.rb b/spec/models/budget/investment_spec.rb index 8cbd372d8bf..4de1cd9f0ff 100644 --- a/spec/models/budget/investment_spec.rb +++ b/spec/models/budget/investment_spec.rb @@ -1362,4 +1362,91 @@ end end + + describe "scoped_filter" do + let(:budget) { create(:budget, phase: "balloting") } + let(:investment) { create(:budget_investment, budget: budget) } + + describe "with without_admin filter" do + let(:params) { {advanced_filters: ["without_admin"], budget_id: budget.id} } + it "returns only investment without admin" do + create(:budget_investment, + :finished, + budget: budget) + create(:budget_investment, + :with_administrator, + budget: budget) + investment3 = create(:budget_investment, budget: budget) + expect(described_class.scoped_filter(params, "all")).to eq([investment3]) + expect(described_class.scoped_filter(params, "all").count).to eq(1) + end + end + + describe "with without_valuator filter" do + let(:params) { {advanced_filters: ["without_valuator"], budget_id: budget.id} } + it "returns only investment without valuator" do + create(:budget_investment, + :finished, + budget: budget) + investment2 = create(:budget_investment, + :with_administrator, + budget: budget) + investment3 = create(:budget_investment, + budget: budget) + expect(described_class.scoped_filter(params, "all")) + .to contain_exactly(investment2, investment3) + expect(described_class.scoped_filter(params, "all").count) + .to eq(2) + end + end + + describe "with under_valuation filter" do + let(:params) { {advanced_filters: ["under_valuation"], budget_id: budget.id} } + it "returns only investment under valuation" do + valuator1 = create(:valuator) + investment1 = create(:budget_investment, + :with_administrator, + valuation_finished: false, + budget: budget) + investment1.valuators << valuator1 + create(:budget_investment, :with_administrator, budget: budget) + create(:budget_investment, budget: budget) + + expect(described_class.scoped_filter(params, "all")).to eq([investment1]) + expect(described_class.scoped_filter(params, "all").count).to eq(1) + end + end + + describe "with valuation_finished filter" do + let(:params) { {advanced_filters: ["valuation_finished"], budget_id: budget.id} } + it "returns only investment with valuation finished" do + investment1 = create(:budget_investment, + :selected, + budget: budget) + create(:budget_investment, + :with_administrator, + budget: budget) + create(:budget_investment, + budget: budget) + expect(described_class.scoped_filter(params, "all")).to eq([investment1]) + expect(described_class.scoped_filter(params, "all").count).to eq(1) + end + end + + describe "with winners filter" do + let(:params) { {advanced_filters: ["winners"], budget_id: budget.id} } + it "returns only investment winners" do + investment1 = create(:budget_investment, + :winner, + valuation_finished: true, + budget: budget) + create(:budget_investment, + :with_administrator, + budget: budget) + create(:budget_investment, budget: budget) + expect(described_class.scoped_filter(params, "all")).to eq([investment1]) + expect(described_class.scoped_filter(params, "all").count).to eq(1) + end + end + end end From 3e8ae6863b16d40c70eb94a2be648eeb13a57496 Mon Sep 17 00:00:00 2001 From: lalo Date: Tue, 2 Apr 2019 19:46:16 +0200 Subject: [PATCH 2/2] Add max support advanced filter for admin budget investments --- .../admin_budget_investments_helper.rb | 8 ++++- app/models/budget/investment.rb | 2 ++ .../budget_investments/_search_form.html.erb | 11 ++++-- .../_select_investment.html.erb | 27 +++++++------- config/locales/en/admin.yml | 1 + config/locales/es/admin.yml | 1 + .../features/admin/budget_investments_spec.rb | 36 +++++++++++++++++++ 7 files changed, 70 insertions(+), 16 deletions(-) diff --git a/app/helpers/admin_budget_investments_helper.rb b/app/helpers/admin_budget_investments_helper.rb index 5c2dc479e20..6aa28943823 100644 --- a/app/helpers/admin_budget_investments_helper.rb +++ b/app/helpers/admin_budget_investments_helper.rb @@ -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 diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 0c6eda38351..bd8a6d2d3d0 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -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? diff --git a/app/views/admin/budget_investments/_search_form.html.erb b/app/views/admin/budget_investments/_search_form.html.erb index b7d44ad5a85..301845a8b19 100644 --- a/app/views/admin/budget_investments/_search_form.html.erb +++ b/app/views/admin/budget_investments/_search_form.html.erb @@ -18,8 +18,15 @@ <%= label_tag "advanced_filters[#{filter}]", t("admin.budget_investments.index.filters.#{filter}") %>
<% end %> -
- <%= text_field_tag :min_total_supports, params["min_total_supports"], placeholder: t("admin.budget_investments.index.filters.min_total_supports") %> +
+
+ <%= label_tag :min_total_supports, t("admin.budget_investments.index.filters.min_total_supports") %> + <%= text_field_tag :min_total_supports, params["min_total_supports"] %> +
+
+ <%= label_tag :max_total_supports, t("admin.budget_investments.index.filters.max_total_supports") %> + <%= text_field_tag :max_total_supports, params["max_total_supports"] %> +
diff --git a/app/views/admin/budget_investments/_select_investment.html.erb b/app/views/admin/budget_investments/_select_investment.html.erb index 9173709762e..d14e591d26b 100644 --- a/app/views/admin/budget_investments/_select_investment.html.erb +++ b/app/views/admin/budget_investments/_select_investment.html.erb @@ -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 %> <% if params[:filter] == "selected" %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 26f200283c8..8c0904d9f30 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -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: %{filter}" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index e945599d91b..4642ae122ea 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -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: %{filter}" two_filters_html: "Filtros en uso: %{filter}, %{advanced_filters}" diff --git a/spec/features/admin/budget_investments_spec.rb b/spec/features/admin/budget_investments_spec.rb index b6593a25d83..2c4d9723001 100644 --- a/spec/features/admin/budget_investments_spec.rb +++ b/spec/features/admin/budget_investments_spec.rb @@ -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)