Remember last sort option used.
This commit is contained in:
parent
1553c560e0
commit
4d345bc400
5 changed files with 30 additions and 2 deletions
|
@ -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
|
||||
|
|
5
app/models/concerns/cookie_helpers.rb
Normal file
5
app/models/concerns/cookie_helpers.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
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
|
||||
|
||||
|
|
Loading…
Reference in a new issue