Commit 4d345bc4 authored by Rubén Dávila's avatar Rubén Dávila

Remember last sort option used.

parent 1553c560
...@@ -297,7 +297,8 @@ class ApplicationController < ActionController::Base ...@@ -297,7 +297,8 @@ class ApplicationController < ActionController::Base
end end
def set_filters_params def set_filters_params
params[:sort] ||= 'id_desc' set_default_sort
params[:scope] = 'all' if params[:scope].blank? params[:scope] = 'all' if params[:scope].blank?
params[:state] = 'opened' if params[:state].blank? params[:state] = 'opened' if params[:state].blank?
...@@ -404,4 +405,23 @@ class ApplicationController < ActionController::Base ...@@ -404,4 +405,23 @@ class ApplicationController < ActionController::Base
current_user.nil? && root_path == request.path current_user.nil? && root_path == request.path
end end
private
def set_default_sort
controller_name = params[:controller].sub(/Controller\Z/, '').underscore
cookie_suffix = "_sort_#{controller_name}"
key = if @project
"#{@project.cookie_key}#{cookie_suffix}"
elsif @group
"#{@group.cookie_key}#{cookie_suffix}"
else
"#{current_user.cookie_key}#{cookie_suffix}"
end
cookies[key] ||= 'id_desc'
cookies[key] = params[:sort] if params[:sort].present?
params[:sort] = cookies[key]
end
end end
module CookieHelpers
def cookie_key
"#{model_name.singular}_#{id}"
end
end
...@@ -19,6 +19,7 @@ require 'file_size_validator' ...@@ -19,6 +19,7 @@ require 'file_size_validator'
class Group < Namespace class Group < Namespace
include Gitlab::ConfigHelper include Gitlab::ConfigHelper
include Referable include Referable
include CookieHelpers
has_many :group_members, dependent: :destroy, as: :source, class_name: 'GroupMember' has_many :group_members, dependent: :destroy, as: :source, class_name: 'GroupMember'
alias_method :members, :group_members alias_method :members, :group_members
......
...@@ -51,6 +51,7 @@ class Project < ActiveRecord::Base ...@@ -51,6 +51,7 @@ class Project < ActiveRecord::Base
include AfterCommitQueue include AfterCommitQueue
include CaseSensitivity include CaseSensitivity
include TokenAuthenticatable include TokenAuthenticatable
include CookieHelpers
extend Gitlab::ConfigHelper extend Gitlab::ConfigHelper
......
...@@ -73,6 +73,7 @@ class User < ActiveRecord::Base ...@@ -73,6 +73,7 @@ class User < ActiveRecord::Base
include Sortable include Sortable
include CaseSensitivity include CaseSensitivity
include TokenAuthenticatable include TokenAuthenticatable
include CookieHelpers
add_authentication_token_field :authentication_token add_authentication_token_field :authentication_token
......
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