diff options
Diffstat (limited to 'app/models/ci/catalog/listing.rb')
-rw-r--r-- | app/models/ci/catalog/listing.rb | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/app/models/ci/catalog/listing.rb b/app/models/ci/catalog/listing.rb index b9e777f27a0..1cb030c67c3 100644 --- a/app/models/ci/catalog/listing.rb +++ b/app/models/ci/catalog/listing.rb @@ -14,16 +14,25 @@ module Ci @current_user = current_user end - def resources - Ci::Catalog::Resource - .joins(:project).includes(:project) - .merge(projects_in_namespace_visible_to_user) + def resources(sort: nil) + case sort.to_s + when 'name_desc' then all_resources.order_by_name_desc + when 'name_asc' then all_resources.order_by_name_asc + else + all_resources.order_by_created_at_desc + end end private attr_reader :namespace, :current_user + def all_resources + Ci::Catalog::Resource + .joins(:project).includes(:project) + .merge(projects_in_namespace_visible_to_user) + end + def projects_in_namespace_visible_to_user Project .in_namespace(namespace.self_and_descendant_ids) |