-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from jmkoni/add-filteriffic-to-users
add filteriffic to user model
- Loading branch information
Showing
7 changed files
with
181 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<% if users.load.empty? %> | ||
No users at this time! | ||
<% else %> | ||
<div id="filterrific_results"> | ||
<div class="card card-body bg-light d-block p-3 my-3"> | ||
<div class="row"> | ||
<div class="col-md-10"> | ||
<%= page_entries_info users, model: 'user', class: 'align-middle' %> | ||
</div> | ||
<div class="col-md-2"> | ||
<%= link_to "Reset filters", reset_filterrific_url, class: 'btn btn-secondary align-middle' %> | ||
</div> | ||
</div> | ||
<%= render_filterrific_spinner %> | ||
</div> | ||
<table class="table table-hover table-sm table-responsive"> | ||
<thead class="thead-light"> | ||
<tr> | ||
<th scope="col"><%= filterrific_sorting_link(@filterrific, :email) %></th> | ||
<th scope="col"><%= filterrific_sorting_link(@filterrific, :years_experience) %></th> | ||
<th scope="col"><%= filterrific_sorting_link(@filterrific, :admin) %></th> | ||
<th scope="col" colspan="3"></th> | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
<% @users.each do |user| %> | ||
<tr> | ||
<td><%= user.email %></td> | ||
<td><%= user.years_experience %></td> | ||
<td><%= user.is_admin %></td> | ||
<% if user.admin? %> | ||
<td><%= link_to 'Demote', user_demote_path(user), method: :put %></td> | ||
<% else %> | ||
<td><%= link_to 'Promote', user_promote_path(user), method: :put %></td> | ||
<% end %> | ||
<td><%= link_to 'Edit', edit_user_path(user) %></td> | ||
<td><%= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } %></td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
</div> | ||
<%= will_paginate users, renderer: WillPaginate::ActionView::BootstrapLinkRenderer %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
<% if can? :manage, User %> | ||
<h1>Users</h1><!-- | ||
<%= link_to 'New User', new_user_path %> --> | ||
<table class="table table-hover table-sm table-responsive"> | ||
<thead class="thead-light"> | ||
<tr> | ||
<th scope="col">Email</th> | ||
<th scope="col">Years experience</th> | ||
<th scope="col">Is admin</th> | ||
<th scope="col" colspan="3"></th> | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
<% @users.each do |user| %> | ||
<tr> | ||
<td><%= user.email %></td> | ||
<td><%= user.years_experience %></td> | ||
<td><%= user.is_admin %></td> | ||
<% if user.admin? %> | ||
<td><%= link_to 'Demote', user_demote_path(user), method: :put %></td> | ||
<% else %> | ||
<td><%= link_to 'Promote', user_promote_path(user), method: :put %></td> | ||
<% end %> | ||
<td><%= link_to 'Edit', edit_user_path(user) %></td> | ||
<td><%= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } %></td> | ||
</tr> | ||
<h1>Users</h1> | ||
<%= link_to 'New User', new_user_path %> | ||
<br/> | ||
<div class="card card-body bg-light"> | ||
<%= form_for_filterrific @filterrific do |f| %> | ||
<div class="row"> | ||
<div class="col-md-3"> | ||
<div class="form-group"> | ||
<label class="font-weight-bold">Search</label> | ||
<%= f.text_field( | ||
:search_query, | ||
class: 'filterrific-periodically-observed' | ||
) %> | ||
</div> | ||
</div> | ||
<div class="col-md-3"> | ||
<div class="form-group"> | ||
<label class="font-weight-bold">Sorted by</label> | ||
<%= f.select(:sorted_by, @filterrific.select_options[:sorted_by], | ||
{}, | ||
{ class: 'form-control' } | ||
) %> | ||
</div> | ||
</div> | ||
</div> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
<% end %> | ||
</div> | ||
<% end %> | ||
|
||
<%= render 'list', users: @users %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<% js = escape_javascript( | ||
render( | ||
partial: 'users/list', | ||
locals: { users: @users } | ||
) | ||
) %> | ||
$("#filterrific_results").html("<%= js %>"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,36 @@ | |
end | ||
end | ||
end | ||
|
||
describe 'search_query' do | ||
it 'gets all users with query' do | ||
user1 = create(:user, email: '[email protected]') | ||
user2 = create(:user, email: '[email protected]') | ||
user3 = create(:user, email: '[email protected]') | ||
aggregate_failures do | ||
expect(User.search_query('unicorns').length).to eq 1 | ||
expect(User.search_query('unicorns')).to include user1 | ||
expect(User.search_query('unicorns')).not_to include user2 | ||
expect(User.search_query('unicorns')).not_to include user3 | ||
end | ||
end | ||
end | ||
|
||
describe 'sorted_by' do | ||
it 'gets all users sorted' do | ||
user1 = create(:user, email: '[email protected]', is_admin: true, years_experience: 3) | ||
user2 = create(:user, email: '[email protected]', is_admin: false, years_experience: 4) | ||
user3 = create(:user, email: '[email protected]', is_admin: false, years_experience: 5) | ||
aggregate_failures do | ||
expect(User.sorted_by('email_asc').first).to eq user1 | ||
expect(User.sorted_by('email_desc').first).to eq user2 | ||
expect(User.sorted_by('years_experience_asc').first).to eq user1 | ||
expect(User.sorted_by('years_experience_desc').first).to eq user3 | ||
expect(User.sorted_by('admin_desc').first).to eq user1 | ||
expect { User.sorted_by('oh_no') }.to raise_error(ArgumentError, 'Invalid sort option: "oh_no"') | ||
end | ||
end | ||
end | ||
end | ||
|
||
context 'methods' do | ||
|