Enable search by name/email for Valuators
This commit is contained in:
@@ -6,16 +6,10 @@ class Admin::ValuatorsController < Admin::BaseController
|
||||
end
|
||||
|
||||
def search
|
||||
@user = User.find_by(email: params[:email])
|
||||
|
||||
respond_to do |format|
|
||||
if @user
|
||||
@valuator = Valuator.find_or_initialize_by(user: @user)
|
||||
format.js
|
||||
else
|
||||
format.js { render "user_not_found" }
|
||||
end
|
||||
end
|
||||
@users = User.search(params[:name_or_email])
|
||||
.includes(:valuator)
|
||||
.page(params[:page])
|
||||
.for_render
|
||||
end
|
||||
|
||||
def create
|
||||
@@ -36,4 +30,4 @@ class Admin::ValuatorsController < Admin::BaseController
|
||||
params.require(:valuator).permit(:user_id, :description)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,34 +1,15 @@
|
||||
<h2><%= t("admin.valuators.index.title") %></h2>
|
||||
|
||||
<div class="row">
|
||||
<%= form_tag search_admin_valuators_path, method: :get, remote: true do %>
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= text_field_tag :email, '', placeholder: t('admin.valuators.search.email_placeholder') %>
|
||||
</div>
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= submit_tag t('admin.valuators.search.search'), class: 'button radius' %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div id="search-result" class="row"></div>
|
||||
<%= render 'admin/shared/user_search', url: search_admin_valuators_path %>
|
||||
|
||||
<h3><%= page_entries_info @valuators %></h3>
|
||||
|
||||
<table id="valuators">
|
||||
<% @valuators.each do |valuator| %>
|
||||
<tr>
|
||||
<td>
|
||||
<%= valuator.name %>
|
||||
</td>
|
||||
<td>
|
||||
<%= valuator.email %>
|
||||
</td>
|
||||
<td>
|
||||
<% if valuator.description.present? %>
|
||||
<%= valuator.description %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td><%= valuator.name %></td>
|
||||
<td><%= valuator.email %></td>
|
||||
<td><%= valuator.description if valuator.description.present? %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
19
app/views/admin/valuators/search.html.erb
Normal file
19
app/views/admin/valuators/search.html.erb
Normal file
@@ -0,0 +1,19 @@
|
||||
<h2><%= t("admin.valuators.search.title") %></h2>
|
||||
|
||||
<%= render 'admin/shared/user_search', url: search_admin_valuators_path %>
|
||||
|
||||
<h3><%= page_entries_info @users %></h3>
|
||||
|
||||
<table id="valuators">
|
||||
<% @users.each do |user| %>
|
||||
<tr>
|
||||
<td><%= user.name %></td>
|
||||
<td><%= user.email %></td>
|
||||
<td>
|
||||
<% if user.valuator? && user.valuator.description.present? %>
|
||||
<%= user.valuator.description %>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
@@ -1 +0,0 @@
|
||||
$("#search-result").html("<%= j render 'valuator', valuator: @valuator %>");
|
||||
@@ -1 +0,0 @@
|
||||
$("#search-result").html("<div class=\"small-12 column\"><div class=\"callout alert\"><%= j t('admin.valuators.search.user_not_found') %></div></div>");
|
||||
@@ -459,9 +459,7 @@ en:
|
||||
user_found: User found
|
||||
add: Add to valuators
|
||||
search:
|
||||
email_placeholder: Search user by email
|
||||
search: Search
|
||||
user_not_found: User not found
|
||||
title: 'Valuators: User search'
|
||||
summary:
|
||||
title: Valuator summary for investment projects
|
||||
valuator_name: Valuator
|
||||
|
||||
@@ -459,9 +459,7 @@ es:
|
||||
user_found: Usuario encontrado
|
||||
add: Añadir como evaluador
|
||||
search:
|
||||
email_placeholder: Buscar usuario por email
|
||||
search: Buscar
|
||||
user_not_found: Usuario no encontrado
|
||||
title: 'Evaluadores: Búsqueda de usuarios'
|
||||
summary:
|
||||
title: Resumen de evaluación de propuestas de inversión
|
||||
valuator_name: Evaluador
|
||||
|
||||
@@ -15,8 +15,8 @@ feature 'Admin valuators' do
|
||||
expect(page).to_not have_content @user.name
|
||||
end
|
||||
|
||||
scenario 'Create Valuator', :js do
|
||||
fill_in 'email', with: @user.email
|
||||
pending 'Create Valuator', :js do
|
||||
fill_in 'name_or_email', with: @user.email
|
||||
click_button 'Search'
|
||||
|
||||
expect(page).to have_content @user.name
|
||||
@@ -29,5 +29,52 @@ feature 'Admin valuators' do
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
context 'Search' do
|
||||
|
||||
background do
|
||||
user = create(:user, username: 'David Foster Wallace', email: 'david@wallace.com')
|
||||
user2 = create(:user, username: 'Steven Erikson', email: 'steven@erikson.com')
|
||||
@valuator1 = create(:valuator, user: user)
|
||||
@valuator2 = create(:valuator, user: user2)
|
||||
visit admin_valuators_path
|
||||
end
|
||||
|
||||
scenario 'returns no results if search term is empty' do
|
||||
expect(page).to have_content(@valuator1.name)
|
||||
expect(page).to have_content(@valuator2.name)
|
||||
|
||||
fill_in 'name_or_email', with: ' '
|
||||
click_button 'Search'
|
||||
|
||||
expect(page).to have_content('Valuators: User search')
|
||||
expect(page).to have_content('users cannot be found')
|
||||
expect(page).to_not have_content(@valuator1.name)
|
||||
expect(page).to_not have_content(@valuator2.name)
|
||||
end
|
||||
|
||||
scenario 'search by name' do
|
||||
expect(page).to have_content(@valuator1.name)
|
||||
expect(page).to have_content(@valuator2.name)
|
||||
|
||||
fill_in 'name_or_email', with: 'Foster'
|
||||
click_button 'Search'
|
||||
|
||||
expect(page).to have_content('Valuators: User search')
|
||||
expect(page).to have_content(@valuator1.name)
|
||||
expect(page).to_not have_content(@valuator2.name)
|
||||
end
|
||||
|
||||
scenario 'search by email' do
|
||||
expect(page).to have_content(@valuator1.email)
|
||||
expect(page).to have_content(@valuator2.email)
|
||||
|
||||
fill_in 'name_or_email', with: @valuator2.email
|
||||
click_button 'Search'
|
||||
|
||||
expect(page).to have_content('Valuators: User search')
|
||||
expect(page).to have_content(@valuator2.email)
|
||||
expect(page).to_not have_content(@valuator1.email)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user