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
6baff650
Commit
6baff650
authored
Jan 28, 2019
by
Camil Staps
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change sorting options for starrers: name (asc/desc), most/least recent star
parent
91f574b8
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
87 additions
and
20 deletions
+87
-20
app/controllers/projects/starrers_controller.rb
app/controllers/projects/starrers_controller.rb
+2
-5
app/finders/users_finder.rb
app/finders/users_finder.rb
+0
-5
app/finders/users_star_projects_finder.rb
app/finders/users_star_projects_finder.rb
+31
-0
app/helpers/sorting_helper.rb
app/helpers/sorting_helper.rb
+17
-0
app/models/user.rb
app/models/user.rb
+0
-1
app/models/users_star_project.rb
app/models/users_star_project.rb
+25
-0
app/views/projects/starrers/_starrer.html.haml
app/views/projects/starrers/_starrer.html.haml
+6
-6
app/views/projects/starrers/index.html.haml
app/views/projects/starrers/index.html.haml
+3
-3
locale/gitlab.pot
locale/gitlab.pot
+3
-0
No files found.
app/controllers/projects/starrers_controller.rb
View file @
6baff650
...
@@ -10,12 +10,9 @@ class Projects::StarrersController < Projects::ApplicationController
...
@@ -10,12 +10,9 @@ class Projects::StarrersController < Projects::ApplicationController
def
index
def
index
@sort
=
params
[
:sort
].
presence
||
sort_value_name
@sort
=
params
[
:sort
].
presence
||
sort_value_name
params
[
:
has_starred
]
=
@project
params
[
:
project
]
=
@project
@starrers
=
UsersFinder
.
new
(
current_user
,
params
).
execute
@starrers
=
UsersStarProjectsFinder
.
new
(
params
).
execute
@starrers
=
@starrers
.
joins
(
:users_star_projects
)
.
select
(
'"users".*, "users_star_projects"."created_at" as "starred_since"'
)
.
where
(
users_star_projects:
{
project_id:
@project
.
project_id
})
@starrers
=
@starrers
.
sort_by_attribute
(
@sort
)
@starrers
=
@starrers
.
sort_by_attribute
(
@sort
)
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: enable CodeReuse/ActiveRecord
...
...
app/finders/users_finder.rb
View file @
6baff650
...
@@ -37,7 +37,6 @@ class UsersFinder
...
@@ -37,7 +37,6 @@ class UsersFinder
users
=
by_2fa
(
users
)
users
=
by_2fa
(
users
)
users
=
by_created_at
(
users
)
users
=
by_created_at
(
users
)
users
=
by_custom_attributes
(
users
)
users
=
by_custom_attributes
(
users
)
users
=
by_has_starred
(
users
)
users
users
end
end
...
@@ -95,8 +94,4 @@ class UsersFinder
...
@@ -95,8 +94,4 @@ class UsersFinder
users
users
end
end
end
end
def
by_has_starred
(
items
)
params
[
:has_starred
].
present?
?
items
.
has_starred
(
params
[
:has_starred
])
:
items
end
end
end
app/finders/users_star_projects_finder.rb
0 → 100644
View file @
6baff650
# frozen_string_literal: true
class
UsersStarProjectsFinder
include
CustomAttributesFilter
attr_accessor
:params
def
initialize
(
params
=
{})
@params
=
params
end
def
execute
stars
=
UsersStarProject
.
all
.
order_id_desc
stars
=
by_search
(
stars
)
stars
=
by_project
(
stars
)
stars
end
private
def
by_search
(
items
)
return
items
unless
params
[
:search
].
present?
items
.
search
(
params
[
:search
])
end
def
by_project
(
items
)
params
[
:project
].
present?
?
items
.
by_project
(
params
[
:project
])
:
items
end
end
app/helpers/sorting_helper.rb
View file @
6baff650
...
@@ -167,6 +167,15 @@ module SortingHelper
...
@@ -167,6 +167,15 @@ module SortingHelper
}
}
end
end
def
starrers_sort_options_hash
{
sort_value_name
=>
sort_title_name
,
sort_value_name_desc
=>
sort_title_name_desc
,
sort_value_recently_created
=>
sort_title_recently_starred
,
sort_value_oldest_created
=>
sort_title_oldest_starred
}
end
def
sortable_item
(
item
,
path
,
sorted_by
)
def
sortable_item
(
item
,
path
,
sorted_by
)
link_to
item
,
path
,
class:
sorted_by
==
item
?
'is-active'
:
''
link_to
item
,
path
,
class:
sorted_by
==
item
?
'is-active'
:
''
end
end
...
@@ -327,6 +336,10 @@ module SortingHelper
...
@@ -327,6 +336,10 @@ module SortingHelper
s_
(
'SortOptions|Oldest sign in'
)
s_
(
'SortOptions|Oldest sign in'
)
end
end
def
sort_title_oldest_starred
s_
(
'SortOptions|Oldest starred'
)
end
def
sort_title_oldest_updated
def
sort_title_oldest_updated
s_
(
'SortOptions|Oldest updated'
)
s_
(
'SortOptions|Oldest updated'
)
end
end
...
@@ -347,6 +360,10 @@ module SortingHelper
...
@@ -347,6 +360,10 @@ module SortingHelper
s_
(
'SortOptions|Recent sign in'
)
s_
(
'SortOptions|Recent sign in'
)
end
end
def
sort_title_recently_starred
s_
(
'SortOptions|Recently starred'
)
end
def
sort_title_recently_updated
def
sort_title_recently_updated
s_
(
'SortOptions|Last updated'
)
s_
(
'SortOptions|Last updated'
)
end
end
...
...
app/models/user.rb
View file @
6baff650
...
@@ -282,7 +282,6 @@ class User < ApplicationRecord
...
@@ -282,7 +282,6 @@ class User < ApplicationRecord
scope
:for_todos
,
->
(
todos
)
{
where
(
id:
todos
.
select
(
:user_id
))
}
scope
:for_todos
,
->
(
todos
)
{
where
(
id:
todos
.
select
(
:user_id
))
}
scope
:with_emails
,
->
{
preload
(
:emails
)
}
scope
:with_emails
,
->
{
preload
(
:emails
)
}
scope
:with_dashboard
,
->
(
dashboard
)
{
where
(
dashboard:
dashboard
)
}
scope
:with_dashboard
,
->
(
dashboard
)
{
where
(
dashboard:
dashboard
)
}
scope
:has_starred
,
->
(
project
)
{
joins
(
:users_star_projects
).
where
(
'users_star_projects.project_id'
:
project
.
id
)
}
# Limits the users to those that have TODOs, optionally in the given state.
# Limits the users to those that have TODOs, optionally in the given state.
#
#
...
...
app/models/users_star_project.rb
View file @
6baff650
# frozen_string_literal: true
# frozen_string_literal: true
class
UsersStarProject
<
ApplicationRecord
class
UsersStarProject
<
ApplicationRecord
include
Sortable
belongs_to
:project
,
counter_cache: :star_count
,
touch:
true
belongs_to
:project
,
counter_cache: :star_count
,
touch:
true
belongs_to
:user
belongs_to
:user
validates
:user
,
presence:
true
validates
:user
,
presence:
true
validates
:user_id
,
uniqueness:
{
scope:
[
:project_id
]
}
validates
:user_id
,
uniqueness:
{
scope:
[
:project_id
]
}
validates
:project
,
presence:
true
validates
:project
,
presence:
true
alias_attribute
:starred_since
,
:created_at
scope
:order_user_name_asc
,
->
{
joins
(
:user
).
reorder
(
'"users"."name" ASC'
)
}
scope
:order_user_name_desc
,
->
{
joins
(
:user
).
reorder
(
'"users"."name" DESC'
)
}
scope
:by_project
,
->
(
project
)
{
where
(
project_id:
project
.
id
)
}
class
<<
self
def
sort_by_attribute
(
method
)
order_method
=
method
||
'id_desc'
case
order_method
.
to_s
when
'name_asc'
then
order_user_name_asc
when
'name_desc'
then
order_user_name_desc
else
order_by
(
order_method
)
end
end
def
search
(
query
)
joins
(
:user
).
merge
(
User
.
search
(
query
))
end
end
end
end
app/views/projects/starrers/_starrer.html.haml
View file @
6baff650
-
user
=
local_assigns
.
fetch
(
:us
er
)
-
starrer
=
local_assigns
.
fetch
(
:starr
er
)
.col-lg-3.col-md-4.col-sm-12
.col-lg-3.col-md-4.col-sm-12
.card
.card
.card-body
.card-body
=
image_tag
avatar_icon_for_user
(
user
,
40
),
class:
"avatar s40"
,
alt:
''
=
image_tag
avatar_icon_for_user
(
starrer
.
user
,
40
),
class:
"avatar s40"
,
alt:
''
.user-info
.user-info
.block-truncated
.block-truncated
=
link_to
user
.
name
,
user_path
(
user
),
class:
'user js-user-link'
,
data:
{
user_id:
user
.
id
}
=
link_to
starrer
.
user
.
name
,
user_path
(
starrer
.
user
),
class:
'user js-user-link'
,
data:
{
user_id:
starrer
.
user
.
id
}
.block-truncated
.block-truncated
%span
.cgray
=
user
.
to_reference
%span
.cgray
=
starrer
.
user
.
to_reference
-
if
user
==
current_user
-
if
starrer
.
user
==
current_user
%span
.badge.badge-success.prepend-left-5
=
_
(
"It's you"
)
%span
.badge.badge-success.prepend-left-5
=
_
(
"It's you"
)
.block-truncated
.block-truncated
=
time_ago_with_tooltip
(
us
er
.
starred_since
)
=
time_ago_with_tooltip
(
starr
er
.
starred_since
)
app/views/projects/starrers/index.html.haml
View file @
6baff650
...
@@ -14,16 +14,16 @@
...
@@ -14,16 +14,16 @@
%button
.user-search-btn
{
type:
"submit"
,
"aria-label"
=>
_
(
"Submit search"
)
}
%button
.user-search-btn
{
type:
"submit"
,
"aria-label"
=>
_
(
"Submit search"
)
}
=
icon
(
"search"
)
=
icon
(
"search"
)
.dropdown.inline.user-sort-dropdown
.dropdown.inline.user-sort-dropdown
=
dropdown_toggle
(
us
ers_sort_options_hash
[
@sort
],
{
toggle:
'dropdown'
})
=
dropdown_toggle
(
starr
ers_sort_options_hash
[
@sort
],
{
toggle:
'dropdown'
})
%ul
.dropdown-menu.dropdown-menu-right.dropdown-menu-selectable
%ul
.dropdown-menu.dropdown-menu-right.dropdown-menu-selectable
%li
.dropdown-header
%li
.dropdown-header
=
_
(
"Sort by"
)
=
_
(
"Sort by"
)
-
us
ers_sort_options_hash
.
each
do
|
value
,
title
|
-
starr
ers_sort_options_hash
.
each
do
|
value
,
title
|
%li
%li
=
link_to
filter_user_path
(
sort:
value
),
class:
(
"is-active"
if
@sort
==
value
)
do
=
link_to
filter_user_path
(
sort:
value
),
class:
(
"is-active"
if
@sort
==
value
)
do
=
title
=
title
-
if
@starrers
.
size
>
0
-
if
@starrers
.
size
>
0
.row.prepend-top-10
.row.prepend-top-10
=
render
partial:
'starrer'
,
collection:
@starrers
,
as: :
us
er
=
render
partial:
'starrer'
,
collection:
@starrers
,
as: :
starr
er
-
else
-
else
.nothing-here-block
Nobody has starred this repository yet
.nothing-here-block
Nobody has starred this repository yet
locale/gitlab.pot
View file @
6baff650
...
@@ -10268,6 +10268,9 @@ msgstr ""
...
@@ -10268,6 +10268,9 @@ msgstr ""
msgid "SortOptions|Oldest sign in"
msgid "SortOptions|Oldest sign in"
msgstr ""
msgstr ""
msgid "SortOptions|Oldest starred"
msgstr ""
msgid "SortOptions|Oldest updated"
msgid "SortOptions|Oldest updated"
msgstr ""
msgstr ""
...
...
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