diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-12 21:08:31 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-12 21:08:31 +0300 |
commit | 884a65481f9e5365329f4ba371ac5b813c45a2f9 (patch) | |
tree | cc4030d36a739eaf91543d270db9a33093f51446 /app/models/release.rb | |
parent | b17f0b91a66f2101a54dd1efed0c4973f04b1daf (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/release.rb')
-rw-r--r-- | app/models/release.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/app/models/release.rb b/app/models/release.rb index 4c9d89105d7..f2162a0f674 100644 --- a/app/models/release.rb +++ b/app/models/release.rb @@ -30,6 +30,12 @@ class Release < ApplicationRecord scope :with_project_and_namespace, -> { includes(project: :namespace) } scope :recent, -> { sorted.limit(MAX_NUMBER_TO_DISPLAY) } + # Sorting + scope :order_created, -> { reorder('created_at ASC') } + scope :order_created_desc, -> { reorder('created_at DESC') } + scope :order_released, -> { reorder('released_at ASC') } + scope :order_released_desc, -> { reorder('released_at DESC') } + delegate :repository, to: :project MAX_NUMBER_TO_DISPLAY = 3 @@ -92,6 +98,17 @@ class Release < ApplicationRecord def set_released_at self.released_at ||= created_at end + + def self.sort_by_attribute(method) + case method.to_s + when 'created_at_asc' then order_created + when 'created_at_desc' then order_created_desc + when 'released_at_asc' then order_released + when 'released_at_desc' then order_released_desc + else + order_created_desc + end + end end Release.prepend_if_ee('EE::Release') |