Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
c5be267e
Commit
c5be267e
authored
Feb 05, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor issuable sorting a bit
parent
bbca6a0a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
19 additions
and
11 deletions
+19
-11
app/models/concerns/issuable.rb
app/models/concerns/issuable.rb
+8
-1
app/models/concerns/sortable.rb
app/models/concerns/sortable.rb
+6
-5
app/models/project.rb
app/models/project.rb
+1
-1
features/steps/admin/groups.rb
features/steps/admin/groups.rb
+1
-1
spec/models/user_spec.rb
spec/models/user_spec.rb
+3
-3
No files found.
app/models/concerns/issuable.rb
View file @
c5be267e
...
@@ -29,6 +29,8 @@ module Issuable
...
@@ -29,6 +29,8 @@ module Issuable
scope
:only_opened
,
->
{
with_state
(
:opened
)
}
scope
:only_opened
,
->
{
with_state
(
:opened
)
}
scope
:only_reopened
,
->
{
with_state
(
:reopened
)
}
scope
:only_reopened
,
->
{
with_state
(
:reopened
)
}
scope
:closed
,
->
{
with_state
(
:closed
)
}
scope
:closed
,
->
{
with_state
(
:closed
)
}
scope
:order_milestone_due_desc
,
->
{
joins
(
:milestone
).
reorder
(
'milestones.due_date DESC, milestones.id DESC'
)
}
scope
:order_milestone_due_asc
,
->
{
joins
(
:milestone
).
reorder
(
'milestones.due_date ASC, milestones.id ASC'
)
}
delegate
:name
,
delegate
:name
,
:email
,
:email
,
...
@@ -54,7 +56,12 @@ module Issuable
...
@@ -54,7 +56,12 @@ module Issuable
end
end
def
sort
(
method
)
def
sort
(
method
)
order_by
(
method
)
case
method
.
to_s
when
'milestone_due_asc'
then
order_milestone_due_asc
when
'milestone_due_desc'
then
order_milestone_due_desc
else
order_by
(
method
)
end
end
end
end
end
...
...
app/models/concerns/sortable.rb
View file @
c5be267e
...
@@ -10,25 +10,26 @@ module Sortable
...
@@ -10,25 +10,26 @@ module Sortable
# by created_at field starting from newest
# by created_at field starting from newest
default_scope
{
order
(
created_at: :desc
,
id: :desc
)
}
default_scope
{
order
(
created_at: :desc
,
id: :desc
)
}
scope
:order_name_asc
,
->
{
reorder
(
name: :asc
)
}
scope
:order_created_desc
,
->
{
reorder
(
created_at: :desc
,
id: :desc
)
}
scope
:order_created_desc
,
->
{
reorder
(
created_at: :desc
,
id: :desc
)
}
scope
:order_created_asc
,
->
{
reorder
(
created_at: :asc
,
id: :asc
)
}
scope
:order_created_asc
,
->
{
reorder
(
created_at: :asc
,
id: :asc
)
}
scope
:order_updated_desc
,
->
{
reorder
(
updated_at: :desc
,
id: :desc
)
}
scope
:order_updated_desc
,
->
{
reorder
(
updated_at: :desc
,
id: :desc
)
}
scope
:order_updated_asc
,
->
{
reorder
(
updated_at: :asc
,
id: :asc
)
}
scope
:order_updated_asc
,
->
{
reorder
(
updated_at: :asc
,
id: :asc
)
}
scope
:order_milestone_due_desc
,
->
{
joins
(
:milestone
).
reorder
(
'milestones.due_date DESC, milestones.id DESC'
)
}
scope
:order_milestone_due_asc
,
->
{
joins
(
:milestone
).
reorder
(
'milestones.due_date ASC, milestones.id ASC'
)
}
if
column_names
.
include?
(
'name'
)
scope
:order_name_asc
,
->
{
reorder
(
name: :asc
)
}
scope
:order_name_desc
,
->
{
reorder
(
name: :desc
)
}
end
end
end
module
ClassMethods
module
ClassMethods
def
order_by
(
method
)
def
order_by
(
method
)
case
method
.
to_s
case
method
.
to_s
when
'name_asc'
then
order_name_asc
when
'name_asc'
then
order_name_asc
when
'name_desc'
then
order_name_desc
when
'updated_asc'
then
order_updated_asc
when
'updated_asc'
then
order_updated_asc
when
'updated_desc'
then
order_updated_desc
when
'updated_desc'
then
order_updated_desc
when
'created_asc'
then
order_created_asc
when
'created_asc'
then
order_created_asc
when
'created_desc'
then
order_created_desc
when
'created_desc'
then
order_created_desc
when
'milestone_due_asc'
then
order_milestone_due_asc
when
'milestone_due_desc'
then
order_milestone_due_desc
else
else
all
all
end
end
...
...
app/models/project.rb
View file @
c5be267e
...
@@ -140,7 +140,7 @@ class Project < ActiveRecord::Base
...
@@ -140,7 +140,7 @@ class Project < ActiveRecord::Base
mount_uploader
:avatar
,
AttachmentUploader
mount_uploader
:avatar
,
AttachmentUploader
# Scopes
# Scopes
scope
:sorted_by_activity
,
->
{
reorder
(
'projects.last_activity_at DESC'
)
}
scope
:sorted_by_activity
,
->
{
reorder
(
last_activity_at: :desc
)
}
scope
:sorted_by_stars
,
->
{
reorder
(
'projects.star_count DESC'
)
}
scope
:sorted_by_stars
,
->
{
reorder
(
'projects.star_count DESC'
)
}
scope
:sorted_by_names
,
->
{
joins
(
:namespace
).
reorder
(
'namespaces.name ASC, projects.name ASC'
)
}
scope
:sorted_by_names
,
->
{
joins
(
:namespace
).
reorder
(
'namespaces.name ASC, projects.name ASC'
)
}
...
...
features/steps/admin/groups.rb
View file @
c5be267e
...
@@ -33,7 +33,7 @@ class Spinach::Features::AdminGroups < Spinach::FeatureSteps
...
@@ -33,7 +33,7 @@ class Spinach::Features::AdminGroups < Spinach::FeatureSteps
end
end
step
'I should be redirected to group page'
do
step
'I should be redirected to group page'
do
current_path
.
should
==
admin_group_path
(
Group
.
last
)
current_path
.
should
==
admin_group_path
(
Group
.
find_by
(
path:
'gitlab'
)
)
end
end
When
'I select user "John Doe" from user list as "Reporter"'
do
When
'I select user "John Doe" from user list as "Reporter"'
do
...
...
spec/models/user_spec.rb
View file @
c5be267e
...
@@ -474,7 +474,7 @@ describe User do
...
@@ -474,7 +474,7 @@ describe User do
@user
=
create
:user
,
created_at:
Date
.
today
,
last_sign_in_at:
Date
.
today
,
name:
'Alpha'
@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'
@user1
=
create
:user
,
created_at:
Date
.
today
-
1
,
last_sign_in_at:
Date
.
today
-
1
,
name:
'Omega'
end
end
it
"sorts users as recently_signed_in"
do
it
"sorts users as recently_signed_in"
do
User
.
sort
(
'recent_sign_in'
).
first
.
should
==
@user
User
.
sort
(
'recent_sign_in'
).
first
.
should
==
@user
end
end
...
@@ -484,11 +484,11 @@ describe User do
...
@@ -484,11 +484,11 @@ describe User do
end
end
it
"sorts users as recently_created"
do
it
"sorts users as recently_created"
do
User
.
sort
(
'
recently_created
'
).
first
.
should
==
@user
User
.
sort
(
'
created_desc
'
).
first
.
should
==
@user
end
end
it
"sorts users as late_created"
do
it
"sorts users as late_created"
do
User
.
sort
(
'
late_created
'
).
first
.
should
==
@user1
User
.
sort
(
'
created_asc
'
).
first
.
should
==
@user1
end
end
it
"sorts users by name when nil is passed"
do
it
"sorts users by name when nil is passed"
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment