Add search form for Admin::BudgetInvestments (#2336)

This commit is contained in:
Angel Perez
2018-01-24 08:58:32 -04:00
parent c08edf044d
commit 680ca46ef1
6 changed files with 47 additions and 2 deletions

View File

@@ -53,8 +53,12 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
private
def load_investments
if params[:project_title].present?
@investments = Budget::Investment.where("title ILIKE ?", "%#{params[:project_title].strip}%")
else
@investments = Budget::Investment.scoped_filter(params, @current_filter)
.order(cached_votes_up: :desc, created_at: :desc)
end
@investments = @investments.page(params[:page]) unless request.format.csv?
end

View File

@@ -0,0 +1,12 @@
<div class="small-12 medium-6">
<%= form_for(Budget::Investment.new, url: admin_budget_budget_investments_path(budget: @budget),
method: :get,
remote: true) do |f| %>
<div class="input-group">
<%= text_field_tag :project_title, "", placeholder: t("#{i18n_namespace}.placeholder") %>
<div class="input-group-button">
<%= f.submit t("#{i18n_namespace}.buttons.search"), class: "button" %>
</div>
</div>
<% end %>
</div>

View File

@@ -1,5 +1,7 @@
<h2 class="inline-block"><%= @budget.name %> - <%= t("admin.budget_investments.index.title") %></h2>
<%= render 'search_form', i18n_namespace: "admin.budget_investments.index" %>
<%= form_tag(admin_budget_budget_investments_path(budget: @budget), method: :get, enforce_utf8: false) do %>
<div class="small-12 medium-3 column">
<%= select_tag :administrator_id,

View File

@@ -138,6 +138,7 @@ en:
valuator_filter_all: All valuators
tags_filter_all: All tags
advanced_filters: Advanced filters
placeholder: Search projects
filters:
all: All
without_admin: Without assigned admin
@@ -153,6 +154,8 @@ en:
button: Filter
one_filter_html: "Current applied filter: <b><em>%{filter}</em></b>"
two_filters_html: "Current applied filters: <b><em>%{filter}, %{second_filter}</em></b>"
buttons:
search: Search
download_current_selection: "Download current selection"
no_budget_investments: "There are no investment projects."
title: Investment projects

View File

@@ -138,6 +138,7 @@ es:
valuator_filter_all: Todos los evaluadores
tags_filter_all: Todas las etiquetas
advanced_filters: Filtros avanzados
placeholder: Buscar proyectos
filters:
all: Todos
without_admin: Sin administrador
@@ -153,6 +154,8 @@ es:
button: Filtrar
one_filter_html: "Filtro en uso: <b><em>%{filter}</em></b>"
two_filters_html: "Filtros en uso: <b><em>%{filter}, %{second_filter}</em></b>"
buttons:
search: Buscar
download_current_selection: "Descargar selección actual"
no_budget_investments: "No hay proyectos de gasto."
title: Proyectos de gasto

View File

@@ -338,6 +338,27 @@ feature 'Admin budget investments' do
end
context 'Search' do
background do
@budget = create(:budget)
@investment_1 = create(:budget_investment, title: "Some investment", budget: @budget)
@investment_2 = create(:budget_investment, title: "Some other investment", budget: @budget)
end
scenario "Search investments by title" do
visit admin_budget_budget_investments_path(@budget)
expect(page).to have_content(@investment_1.title)
expect(page).to have_content(@investment_2.title)
fill_in 'project_title', with: 'Some investment'
click_button 'Search'
expect(page).to have_content(@investment_1.title)
expect(page).to_not have_content(@investment_2.title)
end
end
context 'Show' do
background do
@administrator = create(:administrator, user: create(:user, username: 'Ana', email: 'ana@admins.org'))