Enable search by name/email for Valuators
This commit is contained in:
@@ -6,16 +6,10 @@ class Admin::ValuatorsController < Admin::BaseController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def search
|
def search
|
||||||
@user = User.find_by(email: params[:email])
|
@users = User.search(params[:name_or_email])
|
||||||
|
.includes(:valuator)
|
||||||
respond_to do |format|
|
.page(params[:page])
|
||||||
if @user
|
.for_render
|
||||||
@valuator = Valuator.find_or_initialize_by(user: @user)
|
|
||||||
format.js
|
|
||||||
else
|
|
||||||
format.js { render "user_not_found" }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@@ -36,4 +30,4 @@ class Admin::ValuatorsController < Admin::BaseController
|
|||||||
params.require(:valuator).permit(:user_id, :description)
|
params.require(:valuator).permit(:user_id, :description)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,34 +1,15 @@
|
|||||||
<h2><%= t("admin.valuators.index.title") %></h2>
|
<h2><%= t("admin.valuators.index.title") %></h2>
|
||||||
|
|
||||||
<div class="row">
|
<%= render 'admin/shared/user_search', url: search_admin_valuators_path %>
|
||||||
<%= 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>
|
|
||||||
|
|
||||||
<h3><%= page_entries_info @valuators %></h3>
|
<h3><%= page_entries_info @valuators %></h3>
|
||||||
|
|
||||||
<table id="valuators">
|
<table id="valuators">
|
||||||
<% @valuators.each do |valuator| %>
|
<% @valuators.each do |valuator| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td><%= valuator.name %></td>
|
||||||
<%= valuator.name %>
|
<td><%= valuator.email %></td>
|
||||||
</td>
|
<td><%= valuator.description if valuator.description.present? %></td>
|
||||||
<td>
|
|
||||||
<%= valuator.email %>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<% if valuator.description.present? %>
|
|
||||||
<%= valuator.description %>
|
|
||||||
<% end %>
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</table>
|
</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
|
user_found: User found
|
||||||
add: Add to valuators
|
add: Add to valuators
|
||||||
search:
|
search:
|
||||||
email_placeholder: Search user by email
|
title: 'Valuators: User search'
|
||||||
search: Search
|
|
||||||
user_not_found: User not found
|
|
||||||
summary:
|
summary:
|
||||||
title: Valuator summary for investment projects
|
title: Valuator summary for investment projects
|
||||||
valuator_name: Valuator
|
valuator_name: Valuator
|
||||||
|
|||||||
@@ -459,9 +459,7 @@ es:
|
|||||||
user_found: Usuario encontrado
|
user_found: Usuario encontrado
|
||||||
add: Añadir como evaluador
|
add: Añadir como evaluador
|
||||||
search:
|
search:
|
||||||
email_placeholder: Buscar usuario por email
|
title: 'Evaluadores: Búsqueda de usuarios'
|
||||||
search: Buscar
|
|
||||||
user_not_found: Usuario no encontrado
|
|
||||||
summary:
|
summary:
|
||||||
title: Resumen de evaluación de propuestas de inversión
|
title: Resumen de evaluación de propuestas de inversión
|
||||||
valuator_name: Evaluador
|
valuator_name: Evaluador
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ feature 'Admin valuators' do
|
|||||||
expect(page).to_not have_content @user.name
|
expect(page).to_not have_content @user.name
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'Create Valuator', :js do
|
pending 'Create Valuator', :js do
|
||||||
fill_in 'email', with: @user.email
|
fill_in 'name_or_email', with: @user.email
|
||||||
click_button 'Search'
|
click_button 'Search'
|
||||||
|
|
||||||
expect(page).to have_content @user.name
|
expect(page).to have_content @user.name
|
||||||
@@ -29,5 +29,52 @@ feature 'Admin valuators' do
|
|||||||
end
|
end
|
||||||
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