diff options
author | Jeff Stubler <brunsa2@gmail.com> | 2016-10-26 03:03:42 +0300 |
---|---|---|
committer | Jeff Stubler <brunsa2@gmail.com> | 2017-04-26 02:57:08 +0300 |
commit | a78eeefd6e76c956751a2a7f03efeaee28f83b46 (patch) | |
tree | 1216d2d6f63dafa0313c65156a45b2a0b192acc3 /lib/gitlab/issuable_sorter.rb | |
parent | 1af9dfb8a8b163d70a8631a6cbb564709d5a3730 (diff) |
Change issues sentence to use natural sorting
Diffstat (limited to 'lib/gitlab/issuable_sorter.rb')
-rw-r--r-- | lib/gitlab/issuable_sorter.rb | 29 |
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 |