Allow changing the ordering of the user list

This commit is contained in:
Jyri-Petteri Paloposki 2020-10-23 00:20:24 +03:00
parent 08791e0457
commit c4d7169cb8
4 changed files with 19 additions and 13 deletions

View file

@ -7,16 +7,20 @@ class UsersController < ApplicationController
# GET /users GET /users.xml # GET /users GET /users.xml
def index def index
respond_to do |format| respond_to do |format|
order_by = 'login'
if params[:order] && User.column_names.include?(params[:order])
order_by = params[:order]
end
format.html do format.html do
@page_title = "TRACKS::Manage Users" @page_title = t('users.manage_users_title')
@users = User.order('login ASC').paginate :page => params[:page] @users = User.order(order_by + ' ASC').paginate :page => params[:page]
@total_users = User.count @total_users = User.count
# When we call users/signup from the admin page we store the URL so that # When we call users/signup from the admin page we store the URL so that
# we get returned here when signup is successful # we get returned here when signup is successful
store_location store_location
end end
format.xml do format.xml do
@users = User.order('login') @users = User.order(order_by)
render :xml => @users.to_xml(:root => :users, :except => [:password]) render :xml => @users.to_xml(:root => :users, :except => [:password])
end end
end end

View file

@ -4,24 +4,24 @@
<table class="users_table"> <table class="users_table">
<tr> <tr>
<th><%= User.human_attribute_name('login') %></th> <th><%= link_to User.human_attribute_name('login'), url_for(:order => 'login') %></th>
<th><%= User.human_attribute_name('display_name') %></th> <th><%= h User.human_attribute_name('display_name') %></th>
<th><%= User.human_attribute_name('email') %></th> <th><%= link_to User.human_attribute_name('email'), url_for(:order => 'email') %></th>
<th><%= User.human_attribute_name('auth_type') %></th> <th><%= link_to User.human_attribute_name('auth_type'), url_for(:order => 'auth_type') %></th>
<th><%= User.human_attribute_name('open_id_url') %></th> <th><%= link_to User.human_attribute_name('open_id_url'), url_for(:order => 'open_id_url') %></th>
<th><%= t('users.total_actions') %></th> <th><%= t('users.total_actions') %></th>
<th><%= t('users.total_contexts') %></th> <th><%= t('users.total_contexts') %></th>
<th><%= t('users.total_projects') %></th> <th><%= t('users.total_projects') %></th>
<th><%= t('users.total_notes') %></th> <th><%= t('users.total_notes') %></th>
<th><%= User.human_attribute_name('created_at') %></th> <th><%= link_to User.human_attribute_name('created_at'), url_for(:order => 'created_at') %></th>
<th><%= User.human_attribute_name('last_login_at') %></th> <th><%= link_to User.human_attribute_name('last_login_at'), url_for(:order => 'last_login_at') %></th>
<th>&nbsp;</th> <th>&nbsp;</th>
</tr> </tr>
<% for user in @users %> <% for user in @users %>
<tr <%= "class=\"highlight\"" if user.is_admin? %> id="user-<%= user.id %>"> <tr <%= "class=\"highlight\"" if user.is_admin? %> id="user-<%= user.id %>">
<td><%=h user.login %></td> <td><%= h user.login %></td>
<td><%=h user.display_name %></td> <td><%= h user.display_name %></td>
<td><%=h user.email %></td> <td><%= h user.email %></td>
<td><%= h user.auth_type %></td> <td><%= h user.auth_type %></td>
<td><%= h user.open_id_url || '-' %></td> <td><%= h user.open_id_url || '-' %></td>
<td><%= h user.todos.size %></td> <td><%= h user.todos.size %></td>

View file

@ -1091,6 +1091,7 @@ en:
identity_url: Identity URL identity_url: Identity URL
label_auth_type: Authentication type label_auth_type: Authentication type
manage_users: Manage users manage_users: Manage users
manage_users_title: TRACKS::Manage Users
new_password_label: New password new_password_label: New password
new_token_generated: New token successfully generated new_token_generated: New token successfully generated
new_user_heading: 'Sign up a new user:' new_user_heading: 'Sign up a new user:'

View file

@ -1091,6 +1091,7 @@ fi:
identity_url: Identity URL identity_url: Identity URL
label_auth_type: Authentication type label_auth_type: Authentication type
manage_users: Manage users manage_users: Manage users
manage_users_title: TRACKS::Hallitse käyttäjiä
new_password_label: New password new_password_label: New password
new_token_generated: New token successfully generated new_token_generated: New token successfully generated
new_user_heading: 'Sign up a new user:' new_user_heading: 'Sign up a new user:'