diff options
author | Rémy Coutable <remy@rymai.me> | 2017-12-21 09:10:20 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-12-21 09:10:20 +0000 |
commit | 0a8fa500f06707ec14a044bdc652aaf0920bf55b (patch) | |
tree | 23a8cad8281f7d3bf4933f2cd1720be50086632e | |
parent | 1e5083511197b8a2d01cc5556a13de27964f7941 (diff) | |
parent | e7deeddc1b88a2809bd03dbcb876c5d460c297e5 (diff) | |
download | gitlab-ce-0a8fa500f06707ec14a044bdc652aaf0920bf55b.tar.gz |
Merge branch '36958-enable-ordering-projects-subgroups-by-name' into 'master'
Enables ordering groups and their children by name in the web interface
Closes #24962 et #36958
See merge request gitlab-org/gitlab-ce!16045
-rw-r--r-- | app/helpers/sorting_helper.rb | 10 | ||||
-rw-r--r-- | app/views/admin/groups/index.html.haml | 18 | ||||
-rw-r--r-- | app/views/shared/groups/_dropdown.html.haml | 5 | ||||
-rw-r--r-- | changelogs/unreleased/36958-enable-ordering-projects-subgroups-by-name.yml | 5 | ||||
-rw-r--r-- | spec/finders/group_descendants_finder_spec.rb | 35 |
5 files changed, 52 insertions, 21 deletions
diff --git a/app/helpers/sorting_helper.rb b/app/helpers/sorting_helper.rb index b05eb93b465..36a311dfa8a 100644 --- a/app/helpers/sorting_helper.rb +++ b/app/helpers/sorting_helper.rb @@ -43,14 +43,20 @@ module SortingHelper end def groups_sort_options_hash - options = { + { + 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, 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 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 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 |