Commit 8f36de52 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'ce-7210-add-sort-direction-button-sort-dropdown' into 'master'

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

See merge request gitlab-org/gitlab-ce!23506
parents bba23151 1dbebd54
......@@ -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
......
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment