Skip to content
Snippets Groups Projects
Commit 7c520c78 authored by Rubén Dávila's avatar Rubén Dávila
Browse files

Make sorting preference reusable for all projects.

parent eccaa099
No related branches found
No related tags found
1 merge request!2537Save list sort in a cookie
Pipeline #
Loading
@@ -409,13 +409,22 @@ class ApplicationController < ActionController::Base
Loading
@@ -409,13 +409,22 @@ class ApplicationController < ActionController::Base
private private
   
def set_default_sort def set_default_sort
# Use the controller name so we have a distinct cookie for Issues, MRs and Dashboard key = if is_a_listing_page_for?('issues')
cookie_suffix = "_sort_#{params[:controller].underscore}" 'issues_sort'
elsif is_a_listing_page_for?('merge_requests')
'merge_requests_sort'
end
cookies[key] = params[:sort] if key && params[:sort].present?
params[:sort] = cookies[key] if key
params[:sort] ||= 'id_desc'
end
   
key = "#{(@project || @group || current_user).cookie_key}#{cookie_suffix}" def is_a_listing_page_for?(page_type)
controller_name, action_name = params.values_at(:controller, :action)
   
cookies[key] ||= 'id_desc' (controller_name == "projects/#{page_type}" && action_name == 'index') ||
cookies[key] = params[:sort] if params[:sort].present? (controller_name == 'groups' && action_name == page_type) ||
params[:sort] = cookies[key] (controller_name == 'dashboard' && action_name == page_type)
end end
end end
module CookieHelpers
def cookie_key
"#{model_name.singular}_#{id}"
end
end
Loading
@@ -19,7 +19,6 @@ require 'file_size_validator'
Loading
@@ -19,7 +19,6 @@ 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
Loading
Loading
Loading
@@ -51,7 +51,6 @@ class Project < ActiveRecord::Base
Loading
@@ -51,7 +51,6 @@ class Project < ActiveRecord::Base
include AfterCommitQueue include AfterCommitQueue
include CaseSensitivity include CaseSensitivity
include TokenAuthenticatable include TokenAuthenticatable
include CookieHelpers
   
extend Gitlab::ConfigHelper extend Gitlab::ConfigHelper
   
Loading
Loading
Loading
@@ -73,7 +73,6 @@ class User < ActiveRecord::Base
Loading
@@ -73,7 +73,6 @@ 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
   
Loading
Loading
Loading
@@ -50,6 +50,13 @@ Feature: Dashboard
Loading
@@ -50,6 +50,13 @@ Feature: Dashboard
And I visit dashboard issues page And I visit dashboard issues page
Then The list should be sorted by "Oldest updated" Then The list should be sorted by "Oldest updated"
   
@javascript
Scenario: Visiting Project's issues after sorting
Given I visit dashboard issues page
And I sort the list by "Oldest updated"
And I visit project "Shop" issues page
Then The list should be sorted by "Oldest updated"
@javascript @javascript
Scenario: Sorting Merge Requests Scenario: Sorting Merge Requests
Given I visit dashboard merge requests page Given I visit dashboard merge requests page
Loading
@@ -57,3 +64,10 @@ Feature: Dashboard
Loading
@@ -57,3 +64,10 @@ Feature: Dashboard
And I visit dashboard activity page And I visit dashboard activity page
And I visit dashboard merge requests page And I visit dashboard merge requests page
Then The list should be sorted by "Oldest updated" Then The list should be sorted by "Oldest updated"
@javascript
Scenario: Visiting Project's merge requests after sorting
Given I visit dashboard merge requests page
And I sort the list by "Oldest updated"
And I visit project "Shop" merge requests page
Then The list should be sorted by "Oldest updated"
Loading
@@ -67,6 +67,13 @@ Feature: Project Issues
Loading
@@ -67,6 +67,13 @@ Feature: Project Issues
And I visit project "Shop" issues page And I visit project "Shop" issues page
Then The list should be sorted by "Oldest updated" Then The list should be sorted by "Oldest updated"
   
@javascript
Scenario: Visiting Merge Requests from a differente Project after sorting
Given I visit project "Shop" merge requests page
And I sort the list by "Oldest updated"
And I visit dashboard merge requests page
Then The list should be sorted by "Oldest updated"
@javascript @javascript
Scenario: I search issue Scenario: I search issue
Given I fill in issue search with "Re" Given I fill in issue search with "Re"
Loading
Loading
Loading
@@ -92,6 +92,13 @@ Feature: Project Merge Requests
Loading
@@ -92,6 +92,13 @@ Feature: Project Merge Requests
And I visit project "Shop" merge requests page And I visit project "Shop" merge requests page
Then The list should be sorted by "Oldest updated" Then The list should be sorted by "Oldest updated"
   
@javascript
Scenario: Visiting Merge Requests from a differente Project after sorting
Given I visit project "Shop" merge requests page
And I sort the list by "Oldest updated"
And I visit dashboard merge requests page
Then The list should be sorted by "Oldest updated"
@javascript @javascript
Scenario: Visiting Merge Requests after commenting on diffs Scenario: Visiting Merge Requests after commenting on diffs
Given project "Shop" have "Bug NS-05" open merge request with diffs inside Given project "Shop" have "Bug NS-05" open merge request with diffs inside
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment