Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
05fca6bf
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
05fca6bf
编写于
10月 13, 2014
作者:
D
Dmitriy Zaporozhets
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'sorting-users-in-admin' into 'master'
Sorting users in admin See merge request !1170
上级
b2b71ffa
4e0da232
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
70 addition
and
11 deletion
+70
-11
app/controllers/admin/users_controller.rb
app/controllers/admin/users_controller.rb
+1
-0
app/finders/snippets_finder.rb
app/finders/snippets_finder.rb
+11
-11
app/models/user.rb
app/models/user.rb
+10
-0
app/views/admin/users/index.html.haml
app/views/admin/users/index.html.haml
+20
-0
spec/models/user_spec.rb
spec/models/user_spec.rb
+28
-0
未找到文件。
app/controllers/admin/users_controller.rb
浏览文件 @
05fca6bf
...
...
@@ -4,6 +4,7 @@ class Admin::UsersController < Admin::ApplicationController
def
index
@users
=
User
.
filter
(
params
[
:filter
])
@users
=
@users
.
search
(
params
[
:name
])
if
params
[
:name
].
present?
@users
=
@users
.
sort
(
@sort
=
params
[
:sort
])
@users
=
@users
.
alphabetically
.
page
(
params
[
:page
])
end
...
...
app/finders/snippets_finder.rb
浏览文件 @
05fca6bf
...
...
@@ -30,18 +30,18 @@ class SnippetsFinder
snippets
=
user
.
snippets
.
fresh
.
non_expired
if
user
==
current_user
snippets
=
case
scope
when
'are_internal'
then
snippets
.
are_internal
when
'are_private'
then
snippets
.
are_private
when
'are_public'
then
snippets
.
are_public
else
snippets
end
case
scope
when
'are_internal'
then
snippets
.
are_internal
when
'are_private'
then
snippets
.
are_private
when
'are_public'
then
snippets
.
are_public
else
snippets
end
else
snippets
=
snippets
.
public_and_internal
snippets
.
public_and_internal
end
end
...
...
app/models/user.rb
浏览文件 @
05fca6bf
...
...
@@ -196,6 +196,16 @@ class User < ActiveRecord::Base
end
end
def
sort
(
method
)
case
method
.
to_s
when
'recent_sign_in'
then
reorder
(
'users.last_sign_in_at DESC'
)
when
'oldest_sign_in'
then
reorder
(
'users.last_sign_in_at ASC'
)
when
'recently_created'
then
reorder
(
'users.created_at DESC'
)
when
'late_created'
then
reorder
(
'users.created_at ASC'
)
else
reorder
(
"users.name ASC"
)
end
end
def
find_for_commit
(
email
,
name
)
# Prefer email match over name match
User
.
where
(
email:
email
).
first
||
...
...
app/views/admin/users/index.html.haml
浏览文件 @
05fca6bf
...
...
@@ -32,6 +32,26 @@
.panel-heading
Users (
#{
@users
.
total_count
}
)
.panel-head-actions
.dropdown.inline
%a
.dropdown-toggle.btn
{
href:
'#'
,
"data-toggle"
=>
"dropdown"
}
%span
.light
sort:
-
if
@sort
.
present?
=
@sort
.
humanize
-
else
Name
%b
.caret
%ul
.dropdown-menu
%li
=
link_to
admin_users_path
(
sort:
nil
)
do
Name
=
link_to
admin_users_path
(
sort:
'recent_sign_in'
)
do
Recent sign in
=
link_to
admin_users_path
(
sort:
'oldest_sign_in'
)
do
Oldest sign in
=
link_to
admin_users_path
(
sort:
'recently_created'
)
do
Recently created
=
link_to
admin_users_path
(
sort:
'late_created'
)
do
Late created
=
link_to
'New User'
,
new_admin_user_path
,
class:
"btn btn-new"
%ul
.well-list
-
@users
.
each
do
|
user
|
...
...
spec/models/user_spec.rb
浏览文件 @
05fca6bf
...
...
@@ -429,4 +429,32 @@ describe User do
expect
(
user
.
starred?
(
project
)).
to
be_false
end
end
describe
"#sort"
do
before
do
User
.
delete_all
@user
=
create
:user
,
created_at:
Date
.
today
,
last_sign_in_at:
Date
.
today
,
name:
'Alpha'
@user1
=
create
:user
,
created_at:
Date
.
today
-
1
,
last_sign_in_at:
Date
.
today
-
1
,
name:
'Omega'
end
it
"sorts users as recently_signed_in"
do
User
.
sort
(
'recent_sign_in'
).
first
.
should
==
@user
end
it
"sorts users as late_signed_in"
do
User
.
sort
(
'oldest_sign_in'
).
first
.
should
==
@user1
end
it
"sorts users as recently_created"
do
User
.
sort
(
'recently_created'
).
first
.
should
==
@user
end
it
"sorts users as late_created"
do
User
.
sort
(
'late_created'
).
first
.
should
==
@user1
end
it
"sorts users by name when nil is passed"
do
User
.
sort
(
nil
).
first
.
should
==
@user
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录