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
c49c596d
Commit
c49c596d
authored
Sep 21, 2018
by
🙈 jacopo beschi 🙉
Committed by
Douglas Barbosa Alexandre
Sep 21, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allows to sort projects by most stars
parent
8f191590
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
41 additions
and
2 deletions
+41
-2
app/helpers/sorting_helper.rb
app/helpers/sorting_helper.rb
+10
-1
app/models/project.rb
app/models/project.rb
+3
-1
changelogs/unreleased/add-most-stars-for-filter-option.yml
changelogs/unreleased/add-most-stars-for-filter-option.yml
+5
-0
locale/gitlab.pot
locale/gitlab.pot
+3
-0
spec/features/dashboard/projects_spec.rb
spec/features/dashboard/projects_spec.rb
+8
-0
spec/models/project_spec.rb
spec/models/project_spec.rb
+12
-0
No files found.
app/helpers/sorting_helper.rb
View file @
c49c596d
...
...
@@ -35,7 +35,8 @@ module SortingHelper
sort_value_name
=>
sort_title_name
,
sort_value_oldest_activity
=>
sort_title_oldest_activity
,
sort_value_oldest_created
=>
sort_title_oldest_created
,
sort_value_recently_created
=>
sort_title_recently_created
sort_value_recently_created
=>
sort_title_recently_created
,
sort_value_most_stars
=>
sort_title_most_stars
}
if
current_controller?
(
'admin/projects'
)
...
...
@@ -246,6 +247,10 @@ module SortingHelper
s_
(
'SortOptions|Last Contact'
)
end
def
sort_title_most_stars
s_
(
'SortOptions|Most stars'
)
end
# Values.
def
sort_value_access_level_asc
'access_level_asc'
...
...
@@ -370,4 +375,8 @@ module SortingHelper
def
sort_value_contacted_date
'contacted_asc'
end
def
sort_value_most_stars
'stars_desc'
end
end
app/models/project.rb
View file @
c49c596d
...
...
@@ -331,7 +331,7 @@ class Project < ActiveRecord::Base
# last_activity_at is throttled every minute, but last_repository_updated_at is updated with every push
scope
:sorted_by_activity
,
->
{
reorder
(
"GREATEST(COALESCE(last_activity_at, '1970-01-01'), COALESCE(last_repository_updated_at, '1970-01-01')) DESC"
)
}
scope
:sorted_by_stars
,
->
{
reorder
(
'projects.star_count DESC'
)
}
scope
:sorted_by_stars
,
->
{
reorder
(
star_count: :desc
)
}
scope
:in_namespace
,
->
(
namespace_ids
)
{
where
(
namespace_id:
namespace_ids
)
}
scope
:personal
,
->
(
user
)
{
where
(
namespace_id:
user
.
namespace_id
)
}
...
...
@@ -481,6 +481,8 @@ class Project < ActiveRecord::Base
reorder
(
last_activity_at: :desc
)
when
'latest_activity_asc'
reorder
(
last_activity_at: :asc
)
when
'stars_desc'
sorted_by_stars
else
order_by
(
method
)
end
...
...
changelogs/unreleased/add-most-stars-for-filter-option.yml
0 → 100644
View file @
c49c596d
---
title
:
Allows to sort projects by most stars
merge_request
:
21762
author
:
Jacopo Beschi @jacopo-beschi
type
:
added
locale/gitlab.pot
View file @
c49c596d
...
...
@@ -5551,6 +5551,9 @@ msgstr ""
msgid "SortOptions|Most popular"
msgstr ""
msgid "SortOptions|Most stars"
msgstr ""
msgid "SortOptions|Name"
msgstr ""
...
...
spec/features/dashboard/projects_spec.rb
View file @
c49c596d
...
...
@@ -103,6 +103,14 @@ describe 'Dashboard Projects' do
expect
(
page
).
not_to
have_content
(
project
.
name
)
expect
(
page
).
to
have_content
(
project3
.
name
)
end
it
'sorts projects by most stars when sorting by most stars'
do
project_with_most_stars
=
create
(
:project
,
namespace:
user
.
namespace
,
star_count:
10
)
visit
dashboard_projects_path
(
sort: :stars_desc
)
expect
(
first
(
'.project-row'
)).
to
have_content
(
project_with_most_stars
.
title
)
end
end
context
'when on Starred projects tab'
do
...
...
spec/models/project_spec.rb
View file @
c49c596d
...
...
@@ -1072,6 +1072,18 @@ describe Project do
it
{
expect
(
project
.
builds_enabled?
).
to
be_truthy
}
end
describe
'.sort_by_attribute'
do
it
'reorders the input relation by start count desc'
do
project1
=
create
(
:project
,
star_count:
2
)
project2
=
create
(
:project
,
star_count:
1
)
project3
=
create
(
:project
)
projects
=
described_class
.
sort_by_attribute
(
:stars_desc
)
expect
(
projects
).
to
eq
([
project1
,
project2
,
project3
])
end
end
describe
'.with_shared_runners'
do
subject
{
described_class
.
with_shared_runners
}
...
...
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