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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
7022357c
Commit
7022357c
authored
Jun 16, 2016
by
Alejandro Rodríguez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add sorting dropdown to tag page
parent
d9812bae
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
78 additions
and
4 deletions
+78
-4
CHANGELOG
CHANGELOG
+1
-0
app/controllers/projects/tags_controller.rb
app/controllers/projects/tags_controller.rb
+4
-2
app/models/repository.rb
app/models/repository.rb
+19
-0
app/views/projects/tags/index.html.haml
app/views/projects/tags/index.html.haml
+13
-2
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+41
-0
No files found.
CHANGELOG
View file @
7022357c
...
@@ -84,6 +84,7 @@ v 8.9.0 (unreleased)
...
@@ -84,6 +84,7 @@ v 8.9.0 (unreleased)
- Show categorised search queries in the search autocomplete
- Show categorised search queries in the search autocomplete
- RepositoryCheck::SingleRepositoryWorker public and private methods are now instrumented
- RepositoryCheck::SingleRepositoryWorker public and private methods are now instrumented
- Improve issuables APIs performance when accessing notes !4471
- Improve issuables APIs performance when accessing notes !4471
- Add sorting dropdown to tags page !4423
- External links now open in a new tab
- External links now open in a new tab
- Prevent default actions of disabled buttons and links
- Prevent default actions of disabled buttons and links
- Markdown editor now correctly resets the input value on edit cancellation !4175
- Markdown editor now correctly resets the input value on edit cancellation !4175
...
...
app/controllers/projects/tags_controller.rb
View file @
7022357c
...
@@ -6,8 +6,10 @@ class Projects::TagsController < Projects::ApplicationController
...
@@ -6,8 +6,10 @@ class Projects::TagsController < Projects::ApplicationController
before_action
:authorize_admin_project!
,
only:
[
:destroy
]
before_action
:authorize_admin_project!
,
only:
[
:destroy
]
def
index
def
index
sorted
=
VersionSorter
.
rsort
(
@repository
.
tag_names
)
@sort
=
params
[
:sort
]
||
'name'
@tags
=
Kaminari
.
paginate_array
(
sorted
).
page
(
params
[
:page
])
@tags
=
@repository
.
tags_sorted_by
(
@sort
)
@tags
=
Kaminari
.
paginate_array
(
@tags
).
page
(
params
[
:page
])
@releases
=
project
.
releases
.
where
(
tag:
@tags
)
@releases
=
project
.
releases
.
where
(
tag:
@tags
)
end
end
...
...
app/models/repository.rb
View file @
7022357c
...
@@ -598,6 +598,21 @@ class Repository
...
@@ -598,6 +598,21 @@ class Repository
end
end
end
end
def
tags_sorted_by
(
value
)
case
value
when
'name'
# Would be better to use `sort_by` but `version_sorter` only exposes
# `sort` and `rsort`
VersionSorter
.
rsort
(
tag_names
).
map
{
|
tag_name
|
find_tag
(
tag_name
)
}
when
'updated_desc'
tags_sorted_by_committed_date
.
reverse
when
'updated_asc'
tags_sorted_by_committed_date
else
tags
end
end
def
contributors
def
contributors
commits
=
self
.
commits
(
nil
,
limit:
2000
,
offset:
0
,
skip_merges:
true
)
commits
=
self
.
commits
(
nil
,
limit:
2000
,
offset:
0
,
skip_merges:
true
)
...
@@ -995,4 +1010,8 @@ class Repository
...
@@ -995,4 +1010,8 @@ class Repository
def
file_on_head
(
regex
)
def
file_on_head
(
regex
)
tree
(
:head
).
blobs
.
find
{
|
file
|
file
.
name
=~
regex
}
tree
(
:head
).
blobs
.
find
{
|
file
|
file
.
name
=~
regex
}
end
end
def
tags_sorted_by_committed_date
tags
.
sort_by
{
|
tag
|
commit
(
tag
.
target
).
committed_date
}
end
end
end
app/views/projects/tags/index.html.haml
View file @
7022357c
...
@@ -11,12 +11,23 @@
...
@@ -11,12 +11,23 @@
.nav-controls
.nav-controls
=
link_to
new_namespace_project_tag_path
(
@project
.
namespace
,
@project
),
class:
'btn btn-create new-tag-btn'
do
=
link_to
new_namespace_project_tag_path
(
@project
.
namespace
,
@project
),
class:
'btn btn-create new-tag-btn'
do
New tag
New tag
.dropdown.inline
%button
.dropdown-toggle.btn
{
type:
'button'
,
data:
{
toggle:
'dropdown'
}
}
%span
.light
=
@sort
.
humanize
%b
.caret
%ul
.dropdown-menu.dropdown-menu-align-right
%li
=
link_to
namespace_project_tags_path
(
sort:
nil
)
do
Name
=
link_to
namespace_project_tags_path
(
sort:
sort_value_recently_updated
)
do
=
sort_title_recently_updated
=
link_to
namespace_project_tags_path
(
sort:
sort_value_oldest_updated
)
do
=
sort_title_oldest_updated
.tags
.tags
-
unless
@tags
.
empty?
-
unless
@tags
.
empty?
%ul
.content-list
%ul
.content-list
-
@tags
.
each
do
|
tag
|
=
render
partial:
'tag'
,
collection:
@tags
=
render
'tag'
,
tag:
@repository
.
find_tag
(
tag
)
=
paginate
@tags
,
theme:
'gitlab'
=
paginate
@tags
,
theme:
'gitlab'
...
...
spec/models/repository_spec.rb
View file @
7022357c
...
@@ -31,6 +31,47 @@ describe Repository, models: true do
...
@@ -31,6 +31,47 @@ describe Repository, models: true do
it
{
is_expected
.
not_to
include
(
'v1.0.0'
)
}
it
{
is_expected
.
not_to
include
(
'v1.0.0'
)
}
end
end
describe
'tags_sorted_by'
do
context
'name'
do
subject
{
repository
.
tags_sorted_by
(
'name'
).
map
(
&
:name
)
}
it
{
is_expected
.
to
eq
([
'v1.1.0'
,
'v1.0.0'
])
}
end
context
'updated'
do
let
(
:tag_a
)
{
repository
.
find_tag
(
'v1.0.0'
)
}
let
(
:tag_b
)
{
repository
.
find_tag
(
'v1.1.0'
)
}
context
'desc'
do
subject
{
repository
.
tags_sorted_by
(
'updated_desc'
).
map
(
&
:name
)
}
before
do
double_first
=
double
(
committed_date:
Time
.
now
)
double_last
=
double
(
committed_date:
Time
.
now
-
1
.
second
)
allow
(
repository
).
to
receive
(
:commit
).
with
(
tag_a
.
target
).
and_return
(
double_first
)
allow
(
repository
).
to
receive
(
:commit
).
with
(
tag_b
.
target
).
and_return
(
double_last
)
end
it
{
is_expected
.
to
eq
([
'v1.0.0'
,
'v1.1.0'
])
}
end
context
'asc'
do
subject
{
repository
.
tags_sorted_by
(
'updated_asc'
).
map
(
&
:name
)
}
before
do
double_first
=
double
(
committed_date:
Time
.
now
-
1
.
second
)
double_last
=
double
(
committed_date:
Time
.
now
)
allow
(
repository
).
to
receive
(
:commit
).
with
(
tag_a
.
target
).
and_return
(
double_last
)
allow
(
repository
).
to
receive
(
:commit
).
with
(
tag_b
.
target
).
and_return
(
double_first
)
end
it
{
is_expected
.
to
eq
([
'v1.1.0'
,
'v1.0.0'
])
}
end
end
end
describe
:last_commit_for_path
do
describe
:last_commit_for_path
do
subject
{
repository
.
last_commit_for_path
(
sample_commit
.
id
,
'.gitignore'
).
id
}
subject
{
repository
.
last_commit_for_path
(
sample_commit
.
id
,
'.gitignore'
).
id
}
...
...
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