summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2018-12-04 15:04:35 +0000
committerSean McGivern <sean@gitlab.com>2018-12-04 15:04:35 +0000
commit8f36de529a0ad04b432caf608dd9af63bf7c8702 (patch)
tree9f949bdec1f21166f2d33bc7f4f38210a11f7591 /app
parentbba23151a1c0b4dff8f2c31301c5d0589876251d (diff)
parent1dbebd543e057c935c6286f7148048efac3eb4e3 (diff)
downloadgitlab-ce-8f36de529a0ad04b432caf608dd9af63bf7c8702.tar.gz
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
Diffstat (limited to 'app')
-rw-r--r--app/controllers/concerns/issuable_collections.rb28
1 files changed, 27 insertions, 1 deletions
diff --git a/app/controllers/concerns/issuable_collections.rb b/app/controllers/concerns/issuable_collections.rb
index 34a8c50fcbd..0837599977f 100644
--- a/app/controllers/concerns/issuable_collections.rb
+++ b/app/controllers/concerns/issuable_collections.rb
@@ -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