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/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 2a531e04817..bd8a6d2d3d0 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -122,7 +122,9 @@ 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("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? @@ -137,12 +139,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..301845a8b19 100644 --- a/app/views/admin/budget_investments/_search_form.html.erb +++ b/app/views/admin/budget_investments/_search_form.html.erb @@ -11,14 +11,22 @@