Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
c68f6de8
Commit
c68f6de8
authored
Nov 23, 2020
by
Lee Tickett
Committed by
Sean McGivern
Nov 23, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remember project ordering when inside groups
parent
6b976e32
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
141 additions
and
24 deletions
+141
-24
app/controllers/concerns/sorting_preference.rb
app/controllers/concerns/sorting_preference.rb
+15
-12
app/controllers/groups/application_controller.rb
app/controllers/groups/application_controller.rb
+13
-0
app/controllers/groups/children_controller.rb
app/controllers/groups/children_controller.rb
+10
-0
app/controllers/groups_controller.rb
app/controllers/groups_controller.rb
+5
-0
app/helpers/groups_helper.rb
app/helpers/groups_helper.rb
+4
-0
app/helpers/sorting_helper.rb
app/helpers/sorting_helper.rb
+3
-2
app/views/shared/groups/_dropdown.html.haml
app/views/shared/groups/_dropdown.html.haml
+2
-9
changelogs/unreleased/remember_project_ordering.yml
changelogs/unreleased/remember_project_ordering.yml
+5
-0
ee/app/controllers/groups/roadmap_controller.rb
ee/app/controllers/groups/roadmap_controller.rb
+1
-1
spec/features/projects/user_sorts_projects_spec.rb
spec/features/projects/user_sorts_projects_spec.rb
+82
-0
spec/helpers/sorting_helper_spec.rb
spec/helpers/sorting_helper_spec.rb
+1
-0
No files found.
app/controllers/concerns/sorting_preference.rb
View file @
c68f6de8
...
...
@@ -4,8 +4,11 @@ module SortingPreference
include
SortingHelper
include
CookiesHelper
def
set_sort_order
set_sort_order_from_user_preference
||
set_sort_order_from_cookie
||
params
[
:sort
]
||
default_sort_order
def
set_sort_order
(
field
=
sorting_field
,
default_order
=
default_sort_order
)
set_sort_order_from_user_preference
(
field
)
||
set_sort_order_from_cookie
(
field
)
||
params
[
:sort
]
||
default_order
end
# Implement sorting_field method on controllers
...
...
@@ -29,42 +32,42 @@ module SortingPreference
private
def
set_sort_order_from_user_preference
def
set_sort_order_from_user_preference
(
field
=
sorting_field
)
return
unless
current_user
return
unless
sorting_
field
return
unless
field
user_preference
=
current_user
.
user_preference
sort_param
=
params
[
:sort
]
sort_param
||=
user_preference
[
sorting_
field
]
sort_param
||=
user_preference
[
field
]
return
sort_param
if
Gitlab
::
Database
.
read_only?
if
user_preference
[
sorting_
field
]
!=
sort_param
user_preference
.
update
(
sorting_
field
=>
sort_param
)
if
user_preference
[
field
]
!=
sort_param
user_preference
.
update
(
field
=>
sort_param
)
end
sort_param
end
def
set_sort_order_from_cookie
def
set_sort_order_from_cookie
(
field
=
sorting_field
)
return
unless
legacy_sort_cookie_name
sort_param
=
params
[
:sort
]
if
params
[
:sort
].
present?
# fallback to legacy cookie value for backward compatibility
sort_param
||=
cookies
[
legacy_sort_cookie_name
]
sort_param
||=
cookies
[
remember_sorting_key
]
sort_param
||=
cookies
[
remember_sorting_key
(
field
)
]
sort_value
=
update_cookie_value
(
sort_param
)
set_secure_cookie
(
remember_sorting_key
,
sort_value
)
set_secure_cookie
(
remember_sorting_key
(
field
)
,
sort_value
)
sort_value
end
# Convert sorting_field to legacy cookie name for backwards compatibility
# :merge_requests_sort => 'mergerequest_sort'
# :issues_sort => 'issue_sort'
def
remember_sorting_key
@remember_sorting_key
||=
sorting_
field
def
remember_sorting_key
(
field
=
sorting_field
)
@remember_sorting_key
||=
field
.
to_s
.
split
(
'_'
)[
0
..-
2
]
.
map
(
&
:singularize
)
...
...
app/controllers/groups/application_controller.rb
View file @
c68f6de8
...
...
@@ -3,11 +3,14 @@
class
Groups::ApplicationController
<
ApplicationController
include
RoutableActions
include
ControllerWithCrossProjectAccessCheck
include
SortingHelper
include
SortingPreference
layout
'group'
skip_before_action
:authenticate_user!
before_action
:group
before_action
:set_sorting
requires_cross_project_access
private
...
...
@@ -57,6 +60,16 @@ class Groups::ApplicationController < ApplicationController
url_for
(
safe_params
)
end
def
set_sorting
if
has_project_list?
@group_projects_sort
=
set_sort_order
(
Project
::
SORTING_PREFERENCE_FIELD
,
sort_value_name
)
end
end
def
has_project_list?
false
end
end
Groups
::
ApplicationController
.
prepend_if_ee
(
'EE::Groups::ApplicationController'
)
app/controllers/groups/children_controller.rb
View file @
c68f6de8
...
...
@@ -2,12 +2,15 @@
module
Groups
class
ChildrenController
<
Groups
::
ApplicationController
extend
::
Gitlab
::
Utils
::
Override
before_action
:group
skip_cross_project_access_check
:index
feature_category
:subgroups
def
index
params
[
:sort
]
||=
@group_projects_sort
parent
=
if
params
[
:parent_id
].
present?
GroupFinder
.
new
(
current_user
).
execute
(
id:
params
[
:parent_id
])
else
...
...
@@ -40,5 +43,12 @@ module Groups
params:
params
.
to_unsafe_h
).
execute
@children
=
@children
.
page
(
params
[
:page
])
end
private
override
:has_project_list?
def
has_project_list?
true
end
end
end
app/controllers/groups_controller.rb
View file @
c68f6de8
...
...
@@ -329,6 +329,11 @@ class GroupsController < Groups::ApplicationController
def
markdown_service_params
params
.
merge
(
group:
group
)
end
override
:has_project_list?
def
has_project_list?
%w(details show index)
.
include?
(
action_name
)
end
end
GroupsController
.
prepend_if_ee
(
'EE::GroupsController'
)
app/helpers/groups_helper.rb
View file @
c68f6de8
...
...
@@ -189,6 +189,10 @@ module GroupsHelper
params
.
key?
(
:purchased_quantity
)
&&
params
[
:purchased_quantity
].
to_i
>
0
end
def
project_list_sort_by
@group_projects_sort
||
@sort
||
params
[
:sort
]
||
sort_value_recently_created
end
private
def
just_created?
...
...
app/helpers/sorting_helper.rb
View file @
c68f6de8
...
...
@@ -40,6 +40,7 @@ module SortingHelper
sort_value_latest_activity
=>
sort_title_latest_activity
,
sort_value_recently_created
=>
sort_title_created_date
,
sort_value_name
=>
sort_title_name
,
sort_value_name_desc
=>
sort_title_name_desc
,
sort_value_stars_desc
=>
sort_title_stars
}
...
...
@@ -95,8 +96,8 @@ module SortingHelper
sort_value_name_desc
=>
sort_title_name_desc
,
sort_value_recently_created
=>
sort_title_recently_created
,
sort_value_oldest_created
=>
sort_title_oldest_created
,
sort_value_
recently_updated
=>
sort_title_recently_updated
,
sort_value_oldest_
updated
=>
sort_title_oldest_updated
sort_value_
latest_activity
=>
sort_title_recently_updated
,
sort_value_oldest_
activity
=>
sort_title_oldest_updated
}
end
...
...
app/views/shared/groups/_dropdown.html.haml
View file @
c68f6de8
-
options_hash
=
local_assigns
.
fetch
(
:options_hash
,
groups_sort_options_hash
)
-
show_archive_options
=
local_assigns
.
fetch
(
:show_archive_options
,
false
)
-
if
@sort
.
present?
-
default_sort_by
=
@sort
-
else
-
if
params
[
:sort
]
-
default_sort_by
=
params
[
:sort
]
-
else
-
default_sort_by
=
sort_value_recently_created
.dropdown.inline.js-group-filter-dropdown-wrap.gl-mr-3
%button
.dropdown-menu-toggle
{
type:
'button'
,
'data-toggle'
=>
'dropdown'
}
%span
.dropdown-label
=
options_hash
[
defaul
t_sort_by
]
=
options_hash
[
project_lis
t_sort_by
]
=
sprite_icon
(
'chevron-down'
,
css_class:
'dropdown-menu-toggle-icon gl-top-3'
)
%ul
.dropdown-menu.dropdown-menu-right.dropdown-menu-selectable
%li
.dropdown-header
=
_
(
"Sort by"
)
-
options_hash
.
each
do
|
value
,
title
|
%li
.js-filter-sort-order
=
link_to
filter_groups_path
(
sort:
value
),
class:
(
"is-active"
if
defaul
t_sort_by
==
value
)
do
=
link_to
filter_groups_path
(
sort:
value
),
class:
(
"is-active"
if
project_lis
t_sort_by
==
value
)
do
=
title
-
if
show_archive_options
%li
.divider
...
...
changelogs/unreleased/remember_project_ordering.yml
0 → 100644
View file @
c68f6de8
---
title
:
Remember last used project ordering option across groups
merge_request
:
47850
author
:
Lee Tickett
type
:
changed
ee/app/controllers/groups/roadmap_controller.rb
View file @
c68f6de8
...
...
@@ -34,7 +34,7 @@ module Groups
sort_value_start_date_soon
end
def
remember_sorting_key
def
remember_sorting_key
(
field
=
nil
)
@remember_sorting_key
||=
"roadmap_sort"
end
...
...
spec/features/projects/user_sorts_projects_spec.rb
0 → 100644
View file @
c68f6de8
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
'User sorts projects and order persists'
do
include
CookieHelper
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:group
)
{
create
(
:group
)
}
let_it_be
(
:group_member
)
{
create
(
:group_member
,
:maintainer
,
user:
user
,
group:
group
)
}
let_it_be
(
:project
)
{
create
(
:project
,
:public
,
group:
group
)
}
shared_examples_for
"sort order persists across all views"
do
|
project_paths_label
,
group_paths_label
|
it
"is set on the dashboard_projects_path"
do
visit
(
dashboard_projects_path
)
expect
(
find
(
'.dropdown-menu a.is-active'
,
text:
project_paths_label
)).
to
have_content
(
project_paths_label
)
end
it
"is set on the explore_projects_path"
do
visit
(
explore_projects_path
)
expect
(
find
(
'.dropdown-menu a.is-active'
,
text:
project_paths_label
)).
to
have_content
(
project_paths_label
)
end
it
"is set on the group_canonical_path"
do
visit
(
group_canonical_path
(
group
))
expect
(
find
(
'.dropdown-menu a.is-active'
,
text:
group_paths_label
)).
to
have_content
(
group_paths_label
)
end
it
"is set on the details_group_path"
do
visit
(
details_group_path
(
group
))
expect
(
find
(
'.dropdown-menu a.is-active'
,
text:
group_paths_label
)).
to
have_content
(
group_paths_label
)
end
end
context
"from explore projects"
do
before
do
sign_in
(
user
)
visit
(
explore_projects_path
)
find
(
'#sort-projects-dropdown'
).
click
first
(
:link
,
'Last updated'
).
click
end
it_behaves_like
"sort order persists across all views"
,
"Last updated"
,
"Last updated"
end
context
'from dashboard projects'
do
before
do
sign_in
(
user
)
visit
(
dashboard_projects_path
)
find
(
'#sort-projects-dropdown'
).
click
first
(
:link
,
'Name'
).
click
end
it_behaves_like
"sort order persists across all views"
,
"Name"
,
"Name"
end
context
'from group homepage'
do
before
do
sign_in
(
user
)
visit
(
group_canonical_path
(
group
))
find
(
'button.dropdown-menu-toggle'
).
click
first
(
:link
,
'Last created'
).
click
end
it_behaves_like
"sort order persists across all views"
,
"Created date"
,
"Last created"
end
context
'from group details'
do
before
do
sign_in
(
user
)
visit
(
details_group_path
(
group
))
find
(
'button.dropdown-menu-toggle'
).
click
first
(
:link
,
'Most stars'
).
click
end
it_behaves_like
"sort order persists across all views"
,
"Stars"
,
"Most stars"
end
end
spec/helpers/sorting_helper_spec.rb
View file @
c68f6de8
...
...
@@ -77,6 +77,7 @@ RSpec.describe SortingHelper do
sort_value_latest_activity
=>
sort_title_latest_activity
,
sort_value_recently_created
=>
sort_title_created_date
,
sort_value_name
=>
sort_title_name
,
sort_value_name_desc
=>
sort_title_name_desc
,
sort_value_stars_desc
=>
sort_title_stars
}
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment