Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/finders/crm/organizations_finder.rb')
-rw-r--r--app/finders/crm/organizations_finder.rb16
1 files changed, 15 insertions, 1 deletions
diff --git a/app/finders/crm/organizations_finder.rb b/app/finders/crm/organizations_finder.rb
index 5a8ab148ef3..69f72235c71 100644
--- a/app/finders/crm/organizations_finder.rb
+++ b/app/finders/crm/organizations_finder.rb
@@ -16,6 +16,11 @@ module Crm
attr_reader :params, :current_user
+ def self.counts_by_state(current_user, params = {})
+ params = params.merge(sort: nil)
+ new(current_user, params).execute.counts_by_state
+ end
+
def initialize(current_user, params = {})
@current_user = current_user
@params = params
@@ -28,11 +33,20 @@ module Crm
organizations = by_ids(organizations)
organizations = by_search(organizations)
organizations = by_state(organizations)
- organizations.sort_by_name
+ sort_organizations(organizations)
end
private
+ def sort_organizations(organizations)
+ return organizations.sort_by_name unless @params.key?(:sort)
+ return organizations if @params[:sort].nil?
+
+ field = @params[:sort][:field]
+ direction = @params[:sort][:direction]
+ organizations.sort_by_field(field, direction)
+ end
+
def root_group
strong_memoize(:root_group) do
group = params[:group]&.root_ancestor