diff --git a/CHANGELOG b/CHANGELOG index cf75bee4348..8f8439158df 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ Please view this file on the master branch, on stable branches it's out of date. v 8.11.0 (unreleased) + - Fix the title of the toggle dropdown button. !5515 (herminiotorres) - Remove magic comments (`# encoding: UTF-8`) from Ruby files. !5456 (winniehell) - Fix CI status icon link underline (ClemMakesApps) - Fix of 'Commits being passed to custom hooks are already reachable when using the UI' diff --git a/app/controllers/projects/branches_controller.rb b/app/controllers/projects/branches_controller.rb index 6126acccaab..e926043f3eb 100644 --- a/app/controllers/projects/branches_controller.rb +++ b/app/controllers/projects/branches_controller.rb @@ -6,6 +6,7 @@ class Projects::BranchesController < Projects::ApplicationController before_action :authorize_push_code!, only: [:new, :create, :destroy] def index + @sort = params[:sort].presence || 'name' @branches = BranchesFinder.new(@repository, params).execute @branches = Kaminari.paginate_array(@branches).page(params[:page]) diff --git a/app/models/repository.rb b/app/models/repository.rb index d8775ecbd6c..8a6f4086518 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -615,11 +615,11 @@ class Repository case value when 'name' branches.sort_by(&:name) - when 'recently_updated' + when 'updated_desc' branches.sort do |a, b| commit(b.target).committed_date <=> commit(a.target).committed_date end - when 'last_updated' + when 'updated_asc' branches.sort do |a, b| commit(a.target).committed_date <=> commit(b.target).committed_date end diff --git a/app/views/projects/branches/index.html.haml b/app/views/projects/branches/index.html.haml index cb190d121c2..e889f29c816 100644 --- a/app/views/projects/branches/index.html.haml +++ b/app/views/projects/branches/index.html.haml @@ -14,18 +14,15 @@ .dropdown.inline %button.dropdown-toggle.btn{type: 'button', 'data-toggle' => 'dropdown'} %span.light - - if params[:sort].present? - = params[:sort].humanize - - else - Name + = projects_sort_options_hash[@sort] %b.caret %ul.dropdown-menu.dropdown-menu-align-right %li - = link_to filter_branches_path(sort: nil) do + = link_to filter_branches_path(sort: sort_value_name) do = sort_title_name - = link_to filter_branches_path(sort: 'recently_updated') do + = link_to filter_branches_path(sort: sort_value_recently_updated) do = sort_title_recently_updated - = link_to filter_branches_path(sort: 'last_updated') do + = link_to filter_branches_path(sort: sort_value_oldest_updated) do = sort_title_oldest_updated - if can? current_user, :push_code, @project diff --git a/spec/finders/branches_finder_spec.rb b/spec/finders/branches_finder_spec.rb index dd85203a038..6ea9a3a3ec5 100644 --- a/spec/finders/branches_finder_spec.rb +++ b/spec/finders/branches_finder_spec.rb @@ -16,7 +16,7 @@ describe BranchesFinder do end it 'sorts by recently_updated' do - branches_finder = described_class.new(repository, { sort: 'recently_updated' }) + branches_finder = described_class.new(repository, { sort: 'updated_desc' }) result = branches_finder.execute @@ -24,7 +24,7 @@ describe BranchesFinder do end it 'sorts by last_updated' do - branches_finder = described_class.new(repository, { sort: 'last_updated' }) + branches_finder = described_class.new(repository, { sort: 'updated_asc' }) result = branches_finder.execute @@ -53,7 +53,7 @@ describe BranchesFinder do context 'filter and sort' do it 'filters branches by name and sorts by recently_updated' do - params = { sort: 'recently_updated', search: 'feature' } + params = { sort: 'updated_desc', search: 'feature' } branches_finder = described_class.new(repository, params) result = branches_finder.execute @@ -63,7 +63,7 @@ describe BranchesFinder do end it 'filters branches by name and sorts by last_updated' do - params = { sort: 'last_updated', search: 'feature' } + params = { sort: 'updated_asc', search: 'feature' } branches_finder = described_class.new(repository, params) result = branches_finder.execute