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
54a1193d
Commit
54a1193d
authored
Dec 07, 2016
by
Mike Greiling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add scope filters to project snippets page
parent
b65d3e11
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
7 deletions
+52
-7
app/controllers/projects/snippets_controller.rb
app/controllers/projects/snippets_controller.rb
+5
-3
app/finders/snippets_finder.rb
app/finders/snippets_finder.rb
+20
-4
app/views/projects/snippets/index.html.haml
app/views/projects/snippets/index.html.haml
+27
-0
No files found.
app/controllers/projects/snippets_controller.rb
View file @
54a1193d
...
@@ -19,10 +19,12 @@ class Projects::SnippetsController < Projects::ApplicationController
...
@@ -19,10 +19,12 @@ class Projects::SnippetsController < Projects::ApplicationController
respond_to
:html
respond_to
:html
def
index
def
index
@snippets
=
SnippetsFinder
.
new
.
execute
(
current_user
,
{
@snippets
=
SnippetsFinder
.
new
.
execute
(
current_user
,
filter: :by_project
,
filter: :by_project
,
project:
@project
project:
@project
,
})
scope:
params
[
:scope
]
)
@snippets
=
@snippets
.
page
(
params
[
:page
])
@snippets
=
@snippets
.
page
(
params
[
:page
])
end
end
...
...
app/finders/snippets_finder.rb
View file @
54a1193d
...
@@ -8,7 +8,7 @@ class SnippetsFinder
...
@@ -8,7 +8,7 @@ class SnippetsFinder
when
:by_user
then
when
:by_user
then
by_user
(
current_user
,
params
[
:user
],
params
[
:scope
])
by_user
(
current_user
,
params
[
:user
],
params
[
:scope
])
when
:by_project
when
:by_project
by_project
(
current_user
,
params
[
:project
])
by_project
(
current_user
,
params
[
:project
]
,
params
[
:scope
]
)
end
end
end
end
...
@@ -47,15 +47,31 @@ class SnippetsFinder
...
@@ -47,15 +47,31 @@ class SnippetsFinder
end
end
end
end
def
by_project
(
current_user
,
project
)
def
by_project
(
current_user
,
project
,
scope
)
snippets
=
project
.
snippets
.
fresh
snippets
=
project
.
snippets
.
fresh
if
current_user
if
current_user
if
project
.
team
.
member?
(
current_user
)
||
current_user
.
admin?
if
project
.
team
.
member?
(
current_user
)
||
current_user
.
admin?
case
scope
when
'are_internal'
then
snippets
.
are_internal
when
'are_private'
then
snippets
.
are_private
when
'are_public'
then
snippets
.
are_public
else
snippets
snippets
end
else
case
scope
when
'are_internal'
then
snippets
.
are_internal
when
'are_public'
then
snippets
.
are_public
else
else
snippets
.
public_and_internal
snippets
.
public_and_internal
end
end
end
else
else
snippets
.
are_public
snippets
.
are_public
end
end
...
...
app/views/projects/snippets/index.html.haml
View file @
54a1193d
-
page_title
"Snippets"
-
page_title
"Snippets"
-
if
current_user
.nav-links.snippet-scope-menu
%li
{
class:
(
"active"
unless
params
[
:scope
])
}
=
link_to
namespace_project_snippets_path
(
@project
.
namespace
,
@project
)
do
All
%span
.badge
=
@project
.
snippets
.
count
-
if
@project
.
team
.
member?
(
current_user
)
||
current_user
.
admin?
%li
{
class:
(
"active"
if
params
[
:scope
]
==
"are_private"
)
}
=
link_to
namespace_project_snippets_path
(
@project
.
namespace
,
@project
,
scope:
'are_private'
)
do
Private
%span
.badge
=
@project
.
snippets
.
are_private
.
count
%li
{
class:
(
"active"
if
params
[
:scope
]
==
"are_internal"
)
}
=
link_to
namespace_project_snippets_path
(
@project
.
namespace
,
@project
,
scope:
'are_internal'
)
do
Internal
%span
.badge
=
@project
.
snippets
.
are_internal
.
count
%li
{
class:
(
"active"
if
params
[
:scope
]
==
"are_public"
)
}
=
link_to
namespace_project_snippets_path
(
@project
.
namespace
,
@project
,
scope:
'are_public'
)
do
Public
%span
.badge
=
@project
.
snippets
.
are_public
.
count
.sub-header-block
.sub-header-block
-
if
can?
(
current_user
,
:create_project_snippet
,
@project
)
-
if
can?
(
current_user
,
:create_project_snippet
,
@project
)
=
link_to
new_namespace_project_snippet_path
(
@project
.
namespace
,
@project
),
class:
"btn btn-new btn-wide-on-sm pull-right"
,
title:
"New snippet"
do
=
link_to
new_namespace_project_snippet_path
(
@project
.
namespace
,
@project
),
class:
"btn btn-new btn-wide-on-sm pull-right"
,
title:
"New snippet"
do
...
...
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