diff options
author | Ruben Davila <rdavila84@gmail.com> | 2017-05-02 13:20:41 -0500 |
---|---|---|
committer | Ruben Davila <rdavila84@gmail.com> | 2017-05-02 13:20:41 -0500 |
commit | bbfbcebdf69261bac6aa142f430719955e8e86b9 (patch) | |
tree | 25916a1a761cb6c8fcdac4b20b76017a7f4506d3 /lib/gitlab/issuable_sorter.rb | |
parent | 3b82444eb7791e58e3e0ba2f08b8ccde48e3d4c6 (diff) | |
parent | 920d55b9f8afd35e16351fb57d671acf66092e89 (diff) | |
download | gitlab-ce-bbfbcebdf69261bac6aa142f430719955e8e86b9.tar.gz |
Merge branch 'master' into 28433-internationalise-cycle-analytics-page
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 |