From 5664ea2fdeadbd677dc20f0675f6566cffdfc0a4 Mon Sep 17 00:00:00 2001 From: Mark Fletcher Date: Wed, 20 Dec 2017 12:08:45 +0000 Subject: [PATCH 1/3] Accept options hash for Groups dropdown --- app/views/shared/groups/_dropdown.html.haml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/shared/groups/_dropdown.html.haml b/app/views/shared/groups/_dropdown.html.haml index 8e6747ca740..1a259b679c7 100644 --- a/app/views/shared/groups/_dropdown.html.haml +++ b/app/views/shared/groups/_dropdown.html.haml @@ -1,3 +1,4 @@ +- options_hash = local_assigns.fetch(:options_hash, groups_sort_options_hash) - show_archive_options = local_assigns.fetch(:show_archive_options, false) - if @sort.present? - default_sort_by = @sort @@ -10,12 +11,12 @@ .dropdown.inline.js-group-filter-dropdown-wrap.append-right-10 %button.dropdown-toggle{ type: 'button', 'data-toggle' => 'dropdown' } %span.dropdown-label - = sort_options_hash[default_sort_by] + = options_hash[default_sort_by] = icon('chevron-down') %ul.dropdown-menu.dropdown-menu-align-right.dropdown-menu-selectable %li.dropdown-header = _("Sort by") - - groups_sort_options_hash.each do |value, title| + - options_hash.each do |value, title| %li.js-filter-sort-order = link_to filter_groups_path(sort: value), class: ("is-active" if default_sort_by == value) do = title From 225980db35cc468b892aa71d26aa622e5fe08b96 Mon Sep 17 00:00:00 2001 From: Mark Fletcher Date: Wed, 20 Dec 2017 12:09:35 +0000 Subject: [PATCH 2/3] Employ Groups dropdown in admin view --- app/helpers/sorting_helper.rb | 8 ++++++-- app/views/admin/groups/index.html.haml | 18 +----------------- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/app/helpers/sorting_helper.rb b/app/helpers/sorting_helper.rb index b05eb93b465..52805334680 100644 --- a/app/helpers/sorting_helper.rb +++ b/app/helpers/sorting_helper.rb @@ -43,14 +43,18 @@ module SortingHelper end def groups_sort_options_hash - options = { + { sort_value_recently_created => sort_title_recently_created, sort_value_oldest_created => sort_title_oldest_created, sort_value_recently_updated => sort_title_recently_updated, sort_value_oldest_updated => sort_title_oldest_updated } + end - options + def admin_groups_sort_options_hash + groups_sort_options_hash.merge( + sort_value_largest_group => sort_title_largest_group + ) end def member_sort_options_hash diff --git a/app/views/admin/groups/index.html.haml b/app/views/admin/groups/index.html.haml index 535251fef5e..25946ba6eaf 100644 --- a/app/views/admin/groups/index.html.haml +++ b/app/views/admin/groups/index.html.haml @@ -11,23 +11,7 @@ .search-field-holder = search_field_tag :name, project_name, class: "form-control search-text-input js-search-input", autofocus: true, spellcheck: false, placeholder: 'Search by name' = icon("search", class: "search-icon") - .dropdown - - toggle_text = @sort.present? ? sort_options_hash[@sort] : sort_title_recently_created - = dropdown_toggle(toggle_text, { toggle: 'dropdown' }) - %ul.dropdown-menu.dropdown-menu-align-right - %li.dropdown-header - Sort by - %li - = link_to admin_groups_path(sort: sort_value_recently_created, name: project_name) do - = sort_title_recently_created - = link_to admin_groups_path(sort: sort_value_oldest_created, name: project_name) do - = sort_title_oldest_created - = link_to admin_groups_path(sort: sort_value_recently_updated, name: project_name) do - = sort_title_recently_updated - = link_to admin_groups_path(sort: sort_value_oldest_updated, name: project_name) do - = sort_title_oldest_updated - = link_to admin_groups_path(sort: sort_value_largest_group, name: project_name) do - = sort_title_largest_group + = render "shared/groups/dropdown", options_hash: admin_groups_sort_options_hash = link_to new_admin_group_path, class: "btn btn-new" do New group %ul.content-list From e7deeddc1b88a2809bd03dbcb876c5d460c297e5 Mon Sep 17 00:00:00 2001 From: Mark Fletcher Date: Wed, 20 Dec 2017 12:17:39 +0000 Subject: [PATCH 3/3] Enable sorting by name in the Groups dropdown --- app/helpers/sorting_helper.rb | 2 ++ ...le-ordering-projects-subgroups-by-name.yml | 5 +++ spec/finders/group_descendants_finder_spec.rb | 35 +++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 changelogs/unreleased/36958-enable-ordering-projects-subgroups-by-name.yml diff --git a/app/helpers/sorting_helper.rb b/app/helpers/sorting_helper.rb index 52805334680..36a311dfa8a 100644 --- a/app/helpers/sorting_helper.rb +++ b/app/helpers/sorting_helper.rb @@ -44,6 +44,8 @@ module SortingHelper def groups_sort_options_hash { + sort_value_name => sort_title_name, + sort_value_name_desc => sort_title_name_desc, sort_value_recently_created => sort_title_recently_created, sort_value_oldest_created => sort_title_oldest_created, sort_value_recently_updated => sort_title_recently_updated, diff --git a/changelogs/unreleased/36958-enable-ordering-projects-subgroups-by-name.yml b/changelogs/unreleased/36958-enable-ordering-projects-subgroups-by-name.yml new file mode 100644 index 00000000000..8348e3e8ceb --- /dev/null +++ b/changelogs/unreleased/36958-enable-ordering-projects-subgroups-by-name.yml @@ -0,0 +1,5 @@ +--- +title: Enable ordering of groups and their children by name +merge_request: +author: +type: added diff --git a/spec/finders/group_descendants_finder_spec.rb b/spec/finders/group_descendants_finder_spec.rb index 074914420a1..ae050f36b4a 100644 --- a/spec/finders/group_descendants_finder_spec.rb +++ b/spec/finders/group_descendants_finder_spec.rb @@ -73,6 +73,41 @@ describe GroupDescendantsFinder do expect(finder.execute).to contain_exactly(matching_project) end end + + context 'sorting by name' do + let!(:project1) { create(:project, namespace: group, name: 'a', path: 'project-a') } + let!(:project2) { create(:project, namespace: group, name: 'z', path: 'project-z') } + let(:params) do + { + sort: 'name_asc' + } + end + + it 'sorts elements by name' do + expect(subject.execute).to eq( + [ + project1, + project2 + ] + ) + end + + context 'with nested groups', :nested_groups do + let!(:subgroup1) { create(:group, parent: group, name: 'a', path: 'sub-a') } + let!(:subgroup2) { create(:group, parent: group, name: 'z', path: 'sub-z') } + + it 'sorts elements by name' do + expect(subject.execute).to eq( + [ + subgroup1, + subgroup2, + project1, + project2 + ] + ) + end + end + end end context 'with nested groups', :nested_groups do