[CE backport]Add sort direction button with sort dropdown for epics

This commit is contained in:
Felipe Artur 2018-12-03 10:46:47 -02:00
parent 8cd5004b35
commit 1dbebd543e
2 changed files with 28 additions and 1 deletions

View file

@ -91,7 +91,7 @@ module IssuableCollections
options = {
scope: params[:scope],
state: params[:state],
sort: set_sort_order_from_cookie || default_sort_order
sort: set_sort_order
}
# Used by view to highlight active option
@ -113,6 +113,32 @@ module IssuableCollections
'opened'
end
def set_sort_order
set_sort_order_from_user_preference || set_sort_order_from_cookie || default_sort_order
end
def set_sort_order_from_user_preference
return unless current_user
return unless issuable_sorting_field
user_preference = current_user.user_preference
sort_param = params[:sort]
sort_param ||= user_preference[issuable_sorting_field]
if user_preference[issuable_sorting_field] != sort_param
user_preference.update_attribute(issuable_sorting_field, sort_param)
end
sort_param
end
# Implement default_sorting_field method on controllers
# to choose which column to store the sorting parameter.
def issuable_sorting_field
nil
end
def set_sort_order_from_cookie
sort_param = params[:sort] if params[:sort].present?
# fallback to legacy cookie value for backward compatibility

View file

@ -86,6 +86,7 @@ describe IssuableCollections do
it 'only allows whitelisted params' do
allow(controller).to receive(:cookies).and_return({})
allow(controller).to receive(:current_user).and_return(nil)
finder_options = controller.send(:finder_options)