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
end
def set_filters_params
params[:sort] ||= 'id_desc'
set_default_sort
params[:scope] = 'all' if params[:scope].blank?
params[:state] = 'opened' if params[:state].blank?
......@@ -404,4 +405,23 @@ class ApplicationController < ActionController::Base
current_user.nil? && root_path == request.path
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
module CookieHelpers
def cookie_key
"#{model_name.singular}_#{id}"
end
end
......@@ -19,7 +19,8 @@ require 'file_size_validator'
class Group < Namespace
include Gitlab::ConfigHelper
include Referable
include CookieHelpers
has_many :group_members, dependent: :destroy, as: :source, class_name: 'GroupMember'
alias_method :members, :group_members
has_many :users, through: :group_members
......
......@@ -51,6 +51,7 @@ class Project < ActiveRecord::Base
include AfterCommitQueue
include CaseSensitivity
include TokenAuthenticatable
include CookieHelpers
extend Gitlab::ConfigHelper
......
......@@ -73,6 +73,7 @@ class User < ActiveRecord::Base
include Sortable
include CaseSensitivity
include TokenAuthenticatable
include CookieHelpers
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