Commit 757bea8e authored by 🙈  jacopo beschi 🙉's avatar 🙈 jacopo beschi 🙉 Committed by Douglas Barbosa Alexandre
Browse files

Allows to sort projects by most stars

parent f079f2838ba8
......@@ -35,7 +35,8 @@ def projects_sort_options_hash
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 @@ def sort_title_contacted_date
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 @@ def sort_value_upvotes
def sort_value_contacted_date
'contacted_asc'
end
def sort_value_most_stars
'stars_desc'
end
end
......@@ -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 @@ def sort_by_attribute(method)
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
......
---
title: Allows to sort projects by most stars
merge_request: 21762
author: Jacopo Beschi @jacopo-beschi
type: added
......@@ -5551,6 +5551,9 @@ msgstr ""
msgid "SortOptions|Most popular"
msgstr ""
msgid "SortOptions|Most stars"
msgstr ""
msgid "SortOptions|Name"
msgstr ""
......
......@@ -103,6 +103,14 @@
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
......
......@@ -1072,6 +1072,18 @@ def create_pipeline
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 }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment