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
7e1686d8
Commit
7e1686d8
authored
Mar 15, 2021
by
Athar Hameed
Committed by
Bob Van Landuyt
Mar 15, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Show number of files in snippets list
parent
8ccc6836
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
83 additions
and
0 deletions
+83
-0
app/controllers/dashboard/snippets_controller.rb
app/controllers/dashboard/snippets_controller.rb
+1
-0
app/controllers/explore/snippets_controller.rb
app/controllers/explore/snippets_controller.rb
+1
-0
app/controllers/projects/snippets_controller.rb
app/controllers/projects/snippets_controller.rb
+1
-0
app/controllers/snippets_controller.rb
app/controllers/snippets_controller.rb
+1
-0
app/helpers/snippets_helper.rb
app/helpers/snippets_helper.rb
+14
-0
app/models/snippet.rb
app/models/snippet.rb
+1
-0
app/views/shared/snippets/_snippet.html.haml
app/views/shared/snippets/_snippet.html.haml
+2
-0
changelogs/unreleased/215043-include-number-of-files-in-snippet-lists.yml
...eased/215043-include-number-of-files-in-snippet-lists.yml
+5
-0
locale/gitlab.pot
locale/gitlab.pot
+5
-0
spec/views/shared/snippets/_snippet.html.haml_spec.rb
spec/views/shared/snippets/_snippet.html.haml_spec.rb
+52
-0
No files found.
app/controllers/dashboard/snippets_controller.rb
View file @
7e1686d8
...
...
@@ -19,6 +19,7 @@ class Dashboard::SnippetsController < Dashboard::ApplicationController
.
page
(
params
[
:page
])
.
inc_author
.
inc_projects_namespace_route
.
inc_statistics
return
if
redirect_out_of_range
(
@snippets
)
...
...
app/controllers/explore/snippets_controller.rb
View file @
7e1686d8
...
...
@@ -11,6 +11,7 @@ class Explore::SnippetsController < Explore::ApplicationController
.
page
(
params
[
:page
])
.
without_count
.
inc_author
.
inc_statistics
@noteable_meta_data
=
noteable_meta_data
(
@snippets
,
'Snippet'
)
end
...
...
app/controllers/projects/snippets_controller.rb
View file @
7e1686d8
...
...
@@ -22,6 +22,7 @@ class Projects::SnippetsController < Projects::Snippets::ApplicationController
.
execute
.
page
(
params
[
:page
])
.
inc_author
.
inc_statistics
return
if
redirect_out_of_range
(
@snippets
)
...
...
app/controllers/snippets_controller.rb
View file @
7e1686d8
...
...
@@ -24,6 +24,7 @@ class SnippetsController < Snippets::ApplicationController
.
execute
.
page
(
params
[
:page
])
.
inc_author
.
inc_statistics
return
if
redirect_out_of_range
(
@snippets
)
...
...
app/helpers/snippets_helper.rb
View file @
7e1686d8
...
...
@@ -68,4 +68,18 @@ module SnippetsHelper
title:
'Download'
,
rel:
'noopener noreferrer'
)
end
def
snippet_file_count
(
snippet
)
file_count
=
snippet
.
statistics
&
.
file_count
return
unless
file_count
&
.
nonzero?
tooltip
=
n_
(
'%d file'
,
'%d files'
,
file_count
)
%
file_count
tag
.
span
(
class:
'file_count'
,
title:
tooltip
,
data:
{
toggle:
'tooltip'
,
container:
'body'
})
do
concat
(
sprite_icon
(
'documents'
,
css_class:
'gl-vertical-align-middle'
))
concat
(
' '
)
concat
(
file_count
)
end
end
end
app/models/snippet.rb
View file @
7e1686d8
...
...
@@ -82,6 +82,7 @@ class Snippet < ApplicationRecord
scope
:fresh
,
->
{
order
(
"created_at DESC"
)
}
scope
:inc_author
,
->
{
includes
(
:author
)
}
scope
:inc_relations_for_view
,
->
{
includes
(
author: :status
)
}
scope
:inc_statistics
,
->
{
includes
(
:statistics
)
}
scope
:with_statistics
,
->
{
joins
(
:statistics
)
}
scope
:inc_projects_namespace_route
,
->
{
includes
(
project:
[
:route
,
:namespace
])
}
...
...
app/views/shared/snippets/_snippet.html.haml
View file @
7e1686d8
...
...
@@ -9,6 +9,8 @@
=
snippet
.
title
%ul
.controls
%li
=
snippet_file_count
(
snippet
)
%li
=
link_to
gitlab_snippet_path
(
snippet
,
anchor:
'notes'
),
class:
(
'no-comments'
if
notes_count
==
0
)
do
=
sprite_icon
(
'comments'
,
css_class:
'gl-vertical-align-text-bottom'
)
...
...
changelogs/unreleased/215043-include-number-of-files-in-snippet-lists.yml
0 → 100644
View file @
7e1686d8
---
title
:
Show number of files in snippet lists
merge_request
:
55452
author
:
type
:
changed
locale/gitlab.pot
View file @
7e1686d8
...
...
@@ -203,6 +203,11 @@ msgid_plural "%d failed security jobs"
msgstr[0] ""
msgstr[1] ""
msgid "%d file"
msgid_plural "%d files"
msgstr[0] ""
msgstr[1] ""
msgid "%d fixed test result"
msgid_plural "%d fixed test results"
msgstr[0] ""
...
...
spec/views/shared/snippets/_snippet.html.haml_spec.rb
0 → 100644
View file @
7e1686d8
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
'shared/snippets/_snippet.html.haml'
do
let_it_be
(
:snippet
)
{
create
(
:snippet
)
}
before
do
allow
(
view
).
to
receive
(
:current_application_settings
).
and_return
(
Gitlab
::
CurrentSettings
.
current_application_settings
)
allow
(
view
).
to
receive
(
:can?
)
{
true
}
@noteable_meta_data
=
Class
.
new
{
include
Gitlab
::
NoteableMetadata
}.
new
.
noteable_meta_data
([
snippet
],
'Snippet'
)
end
context
'snippet with statistics'
do
it
'renders correct file count and tooltip'
do
snippet
.
statistics
.
file_count
=
3
render
'shared/snippets/snippet'
,
snippet:
snippet
expect
(
rendered
).
to
have_selector
(
"span.file_count"
,
text:
'3'
)
expect
(
rendered
).
to
have_selector
(
"span.file_count[title=
\"
3 files
\"
]"
)
end
it
'renders correct file count and tooltip when file_count is 1'
do
snippet
.
statistics
.
file_count
=
1
render
'shared/snippets/snippet'
,
snippet:
snippet
expect
(
rendered
).
to
have_selector
(
"span.file_count"
,
text:
'1'
)
expect
(
rendered
).
to
have_selector
(
"span.file_count[title=
\"
1 file
\"
]"
)
end
it
'does not render file count when file count is 0'
do
snippet
.
statistics
.
file_count
=
0
render
'shared/snippets/snippet'
,
snippet:
snippet
expect
(
rendered
).
not_to
have_selector
(
'span.file_count'
)
end
end
context
'snippet without statistics'
do
it
'does not render file count if statistics are not present'
do
snippet
.
statistics
=
nil
render
'shared/snippets/snippet'
,
snippet:
snippet
expect
(
rendered
).
not_to
have_selector
(
'span.file_count'
)
end
end
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