Commit d8e204f6
Changed files (4)
app
controllers
models
user
views
admin
users
app/controllers/admin/users_controller.rb
@@ -6,7 +6,7 @@ module Admin
end
def index
- @users = repository.search_by(params[:q])
+ @users = repository.search_with(params)
end
def show
app/controllers/profiles_controller.rb
@@ -5,7 +5,7 @@ class ProfilesController < ApplicationController
end
def index
- @profiles = repository.search_with(params).page(page).per(per_page)
+ @profiles = repository.artists.search_with(params).page(page).per(per_page)
end
def show
app/models/user/repository.rb
@@ -23,9 +23,13 @@ class User
def search_filters_for(params)
[
- ->(users){ users.artists },
->(users){ params[:q].blank? ? users.all : users.search_by(params[:q]) },
+ ->(users) { users.order(created_at: sort(params)) },
]
end
+
+ def sort(params)
+ params[:sort] == "oldest" ? :asc : :desc
+ end
end
end
app/views/admin/users/_index.html.erb
@@ -1,19 +1,35 @@
<table class="table table-striped table-condensed">
<thead>
<tr>
- <td>cakes</td>
+ <td></td>
<td>name</td>
<td>email</td>
- <td>created at</td>
+ <td>urls</td>
+ <td>
+ created at
+ <%= link_to url_for(params.merge(sort: "newest")), remote: true do %>
+ <i class="fa fa-sort-up"></i>
+ <% end %>
+ <%= link_to url_for(params.merge(sort: "oldest")), remote: true do %>
+ <i class="fa fa-sort-down"></i>
+ <% end %>
+ </td>
</tr>
</thead>
<tbody>
<%- @users.each do |user| %>
<tr>
- <td><%= user.creations_count %></td>
- <td><%= link_to user.name, admin_user_path(user) %></td>
+ <td>edit</td>
+ <td><%= link_to "#{user.name} (#{user.creations_count})", admin_user_path(user) %></td>
<td><%= mail_to user.email %></td>
- <td><%= time_ago_in_words(user.created_at) %></td>
+ <td>
+ <ul>
+ <%= "<li>#{user.website}</li>".html_safe unless user.website.blank? %>
+ <%= "<li>#{user.twitter}</li>".html_safe unless user.twitter.blank? %>
+ <%= "<li>#{user.facebook}</li>".html_safe unless user.facebook.blank? %>
+ </ul>
+ </td>
+ <td><%= user.created_at.strftime("%Y-%m-%d") %></td>
</tr>
<% end %>
</tbody>