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:
authorJeff Stubler <brunsa2@gmail.com>2016-10-26 03:03:42 +0300
committerJeff Stubler <brunsa2@gmail.com>2017-04-26 02:57:08 +0300
commita78eeefd6e76c956751a2a7f03efeaee28f83b46 (patch)
tree1216d2d6f63dafa0313c65156a45b2a0b192acc3 /lib/gitlab/issuable_sorter.rb
parent1af9dfb8a8b163d70a8631a6cbb564709d5a3730 (diff)
Change issues sentence to use natural sorting
Diffstat (limited to 'lib/gitlab/issuable_sorter.rb')
-rw-r--r--lib/gitlab/issuable_sorter.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/gitlab/issuable_sorter.rb b/lib/gitlab/issuable_sorter.rb
new file mode 100644
index 00000000000..d392214867a
--- /dev/null
+++ b/lib/gitlab/issuable_sorter.rb
@@ -0,0 +1,29 @@
+module Gitlab
+ module IssuableSorter
+ class << self
+ def sort(project, issuables, &sort_key)
+ grouped_items = issuables.group_by do |issuable|
+ if issuable.project.id == project.id
+ :project_ref
+ elsif issuable.project.namespace.id == project.namespace.id
+ :namespace_ref
+ else
+ :full_ref
+ end
+ end
+
+ natural_sort_issuables(grouped_items[:project_ref], project) +
+ natural_sort_issuables(grouped_items[:namespace_ref], project) +
+ natural_sort_issuables(grouped_items[:full_ref], project)
+ end
+
+ private
+
+ def natural_sort_issuables(issuables, project)
+ VersionSorter.sort(issuables || []) do |issuable|
+ issuable.to_reference(project)
+ end
+ end
+ end
+ end
+end