From 75db6c9d9b1c02b9ea7e30191ee886b672f966db Mon Sep 17 00:00:00 2001 From: Sukhbir Singh Date: Thu, 8 Mar 2018 05:33:06 +0530 Subject: [PATCH] users page sorting with headers completed with backend (#2355) --- app/controllers/users_controller.rb | 20 ++++++++++++++++++-- app/views/users/list.html.erb | 8 +++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index eea801c63f..f1d3db2277 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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]) @@ -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") diff --git a/app/views/users/list.html.erb b/app/views/users/list.html.erb index 3122d3d6cb..dac1a5dc6d 100644 --- a/app/views/users/list.html.erb +++ b/app/views/users/list.html.erb @@ -16,10 +16,12 @@ - - + + + - + + <% if current_user && (current_user.role == "admin" || current_user.role == "moderator") %> <% end %>
<%= t('users.list.username') %><%= t('users.list.last_activity') %> <%= t('users.list.username') %> <%= t('users.list.last_activity') %> <%= t('users.list.history') %><%= t('users.list.joined') %> <%= t('users.list.joined') %> <%= t('users.list.moderation') %>