summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRubén Dávila <rdavila84@gmail.com>2016-01-22 17:00:35 -0500
committerRubén Dávila <rdavila84@gmail.com>2016-01-22 17:00:35 -0500
commit7c520c7803524de0eefb8fbcc79d4c943a80c4de (patch)
treeb18a7248b61a45d8b9b3d807408716d409a2ff5a
parenteccaa099d185c351f9e8762661f0dc004f11f256 (diff)
downloadgitlab-ce-7c520c7803524de0eefb8fbcc79d4c943a80c4de.tar.gz
Make sorting preference reusable for all projects.
-rw-r--r--app/controllers/application_controller.rb21
-rw-r--r--app/models/concerns/cookie_helpers.rb5
-rw-r--r--app/models/group.rb1
-rw-r--r--app/models/project.rb1
-rw-r--r--app/models/user.rb1
-rw-r--r--features/dashboard/dashboard.feature14
-rw-r--r--features/project/issues/issues.feature7
-rw-r--r--features/project/merge_requests.feature7
8 files changed, 43 insertions, 14 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index fb5900054ce..5d047f09f64 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -409,13 +409,22 @@ class ApplicationController < ActionController::Base
private
def set_default_sort
- # Use the controller name so we have a distinct cookie for Issues, MRs and Dashboard
- cookie_suffix = "_sort_#{params[:controller].underscore}"
+ key = if is_a_listing_page_for?('issues')
+ 'issues_sort'
+ elsif is_a_listing_page_for?('merge_requests')
+ 'merge_requests_sort'
+ end
- key = "#{(@project || @group || current_user).cookie_key}#{cookie_suffix}"
+ cookies[key] = params[:sort] if key && params[:sort].present?
+ params[:sort] = cookies[key] if key
+ params[:sort] ||= 'id_desc'
+ end
+
+ def is_a_listing_page_for?(page_type)
+ controller_name, action_name = params.values_at(:controller, :action)
- cookies[key] ||= 'id_desc'
- cookies[key] = params[:sort] if params[:sort].present?
- params[:sort] = cookies[key]
+ (controller_name == "projects/#{page_type}" && action_name == 'index') ||
+ (controller_name == 'groups' && action_name == page_type) ||
+ (controller_name == 'dashboard' && action_name == page_type)
end
end
diff --git a/app/models/concerns/cookie_helpers.rb b/app/models/concerns/cookie_helpers.rb
deleted file mode 100644
index 1c8d43a4661..00000000000
--- a/app/models/concerns/cookie_helpers.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-module CookieHelpers
- def cookie_key
- "#{model_name.singular}_#{id}"
- end
-end
diff --git a/app/models/group.rb b/app/models/group.rb
index 3ba18b85193..76042b3e3fd 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -19,7 +19,6 @@ 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
diff --git a/app/models/project.rb b/app/models/project.rb
index 5ba7532c61a..5579710a476 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -51,7 +51,6 @@ class Project < ActiveRecord::Base
include AfterCommitQueue
include CaseSensitivity
include TokenAuthenticatable
- include CookieHelpers
extend Gitlab::ConfigHelper
diff --git a/app/models/user.rb b/app/models/user.rb
index c24f8a35380..4214f01f6a4 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -73,7 +73,6 @@ class User < ActiveRecord::Base
include Sortable
include CaseSensitivity
include TokenAuthenticatable
- include CookieHelpers
add_authentication_token_field :authentication_token
diff --git a/features/dashboard/dashboard.feature b/features/dashboard/dashboard.feature
index 9060e9d0ad2..c3b3577c449 100644
--- a/features/dashboard/dashboard.feature
+++ b/features/dashboard/dashboard.feature
@@ -51,9 +51,23 @@ Feature: Dashboard
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
Scenario: Sorting Merge Requests
Given I visit dashboard merge requests page
And I sort the list by "Oldest updated"
And I visit dashboard activity page
And I visit dashboard merge requests page
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"
diff --git a/features/project/issues/issues.feature b/features/project/issues/issues.feature
index c1ae10f89c9..a91c5e0095d 100644
--- a/features/project/issues/issues.feature
+++ b/features/project/issues/issues.feature
@@ -68,6 +68,13 @@ Feature: Project Issues
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
Scenario: I search issue
Given I fill in issue search with "Re"
Then I should see "Release 0.4" in issues
diff --git a/features/project/merge_requests.feature b/features/project/merge_requests.feature
index 55c17ad0c15..6b43e7ffedf 100644
--- a/features/project/merge_requests.feature
+++ b/features/project/merge_requests.feature
@@ -93,6 +93,13 @@ Feature: Project Merge Requests
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
Scenario: Visiting Merge Requests after commenting on diffs
Given project "Shop" have "Bug NS-05" open merge request with diffs inside
And I visit merge request page "Bug NS-05"