Fixed html, now it reflects the current search also added serach by name or id to the Budget::Invesment search function
This commit is contained in:
@@ -84,12 +84,8 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
|
||||
end
|
||||
|
||||
def load_investments
|
||||
@investments = if params[:title_or_id].present?
|
||||
Budget::Investment.search_by_title_or_id(params)
|
||||
else
|
||||
Budget::Investment.scoped_filter(params, @current_filter)
|
||||
.order(sort_by(params[:sort_by]))
|
||||
end
|
||||
@investments = Budget::Investment.scoped_filter(params, @current_filter)
|
||||
.order(sort_by(params[:sort_by]))
|
||||
@investments = @investments.page(params[:page]) unless request.format.csv?
|
||||
end
|
||||
|
||||
|
||||
11
app/helpers/admin_budget_investments_helper.rb
Normal file
11
app/helpers/admin_budget_investments_helper.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
module AdminBudgetInvestmentsHelper
|
||||
|
||||
def advanced_menu_visibility
|
||||
(params[:advanced_filters].empty? && params["max_per_heading"].blank?) ? 'hide' : ''
|
||||
end
|
||||
|
||||
def init_advanced_menu
|
||||
params[:advanced_filters] = [] unless params[:advanced_filters]
|
||||
end
|
||||
|
||||
end
|
||||
@@ -109,14 +109,15 @@ 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(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?
|
||||
results = results.by_valuator(params[:valuator_id]) if params[:valuator_id].present?
|
||||
results = results.by_valuator_group(params[:valuator_group_id]) if params[:valuator_group_id].present?
|
||||
results = results.by_admin(params[:administrator_id]) if params[:administrator_id].present?
|
||||
results = advanced_filters(params, results) if params[:advanced_filters].present?
|
||||
results = limit_results(budget, params, results) if params[:max_per_heading].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?
|
||||
results = results.by_valuator(params[:valuator_id]) if params[:valuator_id].present?
|
||||
results = results.by_valuator_group(params[:valuator_group_id]) if params[:valuator_group_id].present?
|
||||
results = results.by_admin(params[:administrator_id]) if params[:administrator_id].present?
|
||||
results = advanced_filters(params, results) if params[:advanced_filters].present?
|
||||
results = search_by_title_or_id(params[:title_or_id].strip, results) if params[:title_or_id]
|
||||
|
||||
results = results.send(current_filter) if current_filter.present?
|
||||
results.includes(:heading, :group, :budget, administrator: :user, valuators: :user)
|
||||
@@ -143,11 +144,12 @@ class Budget
|
||||
results.where("budget_investments.id IN (?)", ids)
|
||||
end
|
||||
|
||||
def self.search_by_title_or_id(params)
|
||||
results = Investment.where(budget_id: params[:budget_id])
|
||||
|
||||
return results.where(id: params[:title_or_id]) if params[:title_or_id] =~ /\A[0-9]+\z/
|
||||
results.where("title ILIKE ?", "%#{params[:title_or_id].strip}%")
|
||||
def self.search_by_title_or_id(title_or_id, results)
|
||||
if title_or_id =~ /^[0-9]+$/
|
||||
results.where(id: title_or_id)
|
||||
else
|
||||
results.where("title ILIKE ?", "%#{title_or_id}%")
|
||||
end
|
||||
end
|
||||
|
||||
def searchable_values
|
||||
|
||||
@@ -1,27 +1,24 @@
|
||||
<% i18n_namespace = "admin.budget_investments.index" %>
|
||||
|
||||
<% init_advanced_menu %>
|
||||
<%= form_tag(admin_budget_budget_investments_path(budget: @budget), method: :get, enforce_utf8: false) do %>
|
||||
<div class="row">
|
||||
<div class="small-12 medium-8 large-12 column">
|
||||
<%= link_to "#advanced_filters_content",
|
||||
data: {toggle: "advanced_filters"},
|
||||
class: "advanced-filters float-right clear" do %>
|
||||
<%= t("#{i18n_namespace}.advanced_filters") %>
|
||||
<%= t("admin.budget_investments.index.advanced_filters") %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<div id="advanced_filters" class="row advanced-filters-content hide" data-toggler=".hide">
|
||||
<% ["feasible", "selected", "undecided", "unfeasible"].each do |option| %>
|
||||
<div class="small-2 medium-2 large-2 column">
|
||||
<div class="input-group">
|
||||
<%= check_box_tag "advanced_filters[]", option, false, id: "advanced_filters_#{option}" %>
|
||||
<%= t("#{i18n_namespace}.filters.#{option}") %>
|
||||
<div id="advanced_filters" class="row advanced-filters-content <%= advanced_menu_visibility %>" data-toggler=".hide">
|
||||
<div class="small-12 medium-8 large-12 column">
|
||||
<% ["feasible", "selected", "undecided", "unfeasible"].each do |option| %>
|
||||
<div class="filter">
|
||||
<%= check_box_tag "advanced_filters[]", option, params[:advanced_filters].index(option), id: "advanced_filters_#{option}" %>
|
||||
<%= t("admin.budget_investments.index.filters.#{option}") %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="small-4 medium-4 large-4 column">
|
||||
<div class="input-group">
|
||||
<%= text_field_tag :max_per_heading, "", placeholder: t("#{i18n_namespace}.filters.max_per_heading") %>
|
||||
<% end %>
|
||||
<div class="filter">
|
||||
<%= text_field_tag :max_per_heading, params["max_per_heading"], placeholder: t("admin.budget_investments.index.filters.max_per_heading") %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -29,36 +26,36 @@
|
||||
<div class="small-12 medium-3 column">
|
||||
<%= select_tag :administrator_id,
|
||||
options_for_select(admin_select_options, params[:administrator_id]),
|
||||
{ prompt: t("#{i18n_namespace}.administrator_filter_all"),
|
||||
{ prompt: t("admin.budget_investments.index.administrator_filter_all"),
|
||||
label: false} %>
|
||||
</div>
|
||||
<div class="small-12 medium-3 column">
|
||||
<%= select_tag :valuator_or_group_id,
|
||||
options_for_select(valuator_or_group_select_options, params[:valuator_or_group_id]),
|
||||
{ prompt: t("#{i18n_namespace}.valuator_filter_all"),
|
||||
{ prompt: t("admin.budget_investments.index.valuator_filter_all"),
|
||||
label: false} %>
|
||||
</div>
|
||||
<div class="small-12 medium-3 column">
|
||||
<%= select_tag :heading_id,
|
||||
options_for_select(budget_heading_select_options(@budget), params[:heading_id]),
|
||||
{ prompt: t("#{i18n_namespace}.heading_filter_all"),
|
||||
{ prompt: t("admin.budget_investments.index.heading_filter_all"),
|
||||
label: false} %>
|
||||
</div>
|
||||
<div class="small-12 medium-3 column">
|
||||
<%= select_tag :tag_name,
|
||||
options_for_select(investment_tags_select_options(@budget), params[:tag_name]),
|
||||
{ prompt: t("#{i18n_namespace}.tags_filter_all"),
|
||||
{ prompt: t("admin.budget_investments.index.tags_filter_all"),
|
||||
label: false} %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row" >
|
||||
<div class="small-12 medium-6 column">
|
||||
<div class="input-group">
|
||||
<%= text_field_tag :title_or_id, "", placeholder: t("#{i18n_namespace}.placeholder") %>
|
||||
<%= text_field_tag :title_or_id, params["title_or_id"], placeholder: t("admin.budget_investments.index.placeholder") %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= submit_tag t("#{i18n_namespace}.buttons.filter"), class: "button expanded" %>
|
||||
<%= submit_tag t("admin.budget_investments.index.buttons.filter"), class: "button expanded" %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@@ -482,13 +482,8 @@ feature 'Admin budget investments' do
|
||||
expect(page).to have_content('Some investment')
|
||||
expect(page).to have_content('Some other investment')
|
||||
|
||||
<<<<<<< HEAD
|
||||
fill_in 'title_or_id', with: first_investment.id
|
||||
click_button 'Search'
|
||||
=======
|
||||
fill_in 'title_or_id', with: 999999
|
||||
click_button I18n.t("admin.budget_investments.index.buttons.filter")
|
||||
>>>>>>> 901dbf6... Fixed test for the refactored form
|
||||
|
||||
expect(page).to have_content('Some other investment')
|
||||
expect(page).not_to have_content('Some investment')
|
||||
|
||||
Reference in New Issue
Block a user