Skip to content

Commit

Permalink
users page sorting with headers completed with backend (publiclab#2355)
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhbir-singh authored and jywarren committed Mar 8, 2018
1 parent a04a351 commit 75db6c9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
20 changes: 18 additions & 2 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,26 @@ def edit
end

def list
sort_param = params[:sort]

if params[:id]
order_string = 'updated_at DESC'
else
order_string = 'last_updated DESC'
end

if sort_param == 'username'
order_string = 'name ASC'
elsif sort_param == 'last_activity'
order_string = 'last_updated DESC'
elsif sort_param == 'joined'
order_string = 'created DESC'
end

# allow admins to view recent users
if params[:id]
@users = DrupalUser.joins('INNER JOIN rusers ON rusers.username = users.name')
.order("updated_at DESC")
.order(order_string)
.where('rusers.role = ?', params[:id])
.where('rusers.status = 1')
.page(params[:page])
Expand All @@ -95,7 +111,7 @@ def list
.joins(:node)
.group('users.uid')
.where('node.status = 1')
.order("last_updated DESC")
.order(order_string)
.page(params[:page])
end
@users = @users.where('users.status = 1') unless current_user && (current_user.role == "admin" || current_user.role == "moderator")
Expand Down
8 changes: 5 additions & 3 deletions app/views/users/list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
<table class="table">
<tr>
<th class="visible-sm visible-xs"></th>
<th style="text-align: center;"><%= t('users.list.username') %></th>
<th><%= t('users.list.last_activity') %></th>

<th style="text-align: center;"><a href = "<%= people_path %>?sort=username"> <%= t('users.list.username') %></a> <i class="fa fa-arrows-v"></i></th>
<th><a href = "<%= people_path %>?sort=last_activity"> <%= t('users.list.last_activity') %></a> <i class="fa fa-arrows-v"></i></th>
<th><%= t('users.list.history') %></th>
<th><%= t('users.list.joined') %></th>
<th><a href = "<%= people_path %>?sort=joined"> <%= t('users.list.joined') %></a> <i class="fa fa-arrows-v"></i></th>

<% if current_user && (current_user.role == "admin" || current_user.role == "moderator") %>
<th><%= t('users.list.moderation') %></th>
<% end %>
Expand Down

0 comments on commit 75db6c9

Please sign in to comment.