Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/projects/snippets_controller.rb8
-rw-r--r--app/finders/snippets_finder.rb24
-rw-r--r--app/views/projects/snippets/index.html.haml27
3 files changed, 52 insertions, 7 deletions
diff --git a/app/controllers/projects/snippets_controller.rb b/app/controllers/projects/snippets_controller.rb
index e290a0eadda..0720be2e55d 100644
--- a/app/controllers/projects/snippets_controller.rb
+++ b/app/controllers/projects/snippets_controller.rb
@@ -19,10 +19,12 @@ class Projects::SnippetsController < Projects::ApplicationController
respond_to :html
def index
- @snippets = SnippetsFinder.new.execute(current_user, {
+ @snippets = SnippetsFinder.new.execute(
+ current_user,
filter: :by_project,
- project: @project
- })
+ project: @project,
+ scope: params[:scope]
+ )
@snippets = @snippets.page(params[:page])
end
diff --git a/app/finders/snippets_finder.rb b/app/finders/snippets_finder.rb
index 00ff1611039..99f1e73c800 100644
--- a/app/finders/snippets_finder.rb
+++ b/app/finders/snippets_finder.rb
@@ -8,7 +8,7 @@ class SnippetsFinder
when :by_user then
by_user(current_user, params[:user], params[:scope])
when :by_project
- by_project(current_user, params[:project])
+ by_project(current_user, params[:project], params[:scope])
end
end
@@ -47,14 +47,30 @@ class SnippetsFinder
end
end
- def by_project(current_user, project)
+ def by_project(current_user, project, scope)
snippets = project.snippets.fresh
if current_user
if project.team.member?(current_user) || current_user.admin?
- snippets
+ 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
+ end
else
- snippets.public_and_internal
+ case scope
+ when 'are_internal' then
+ snippets.are_internal
+ when 'are_public' then
+ snippets.are_public
+ else
+ snippets.public_and_internal
+ end
end
else
snippets.are_public
diff --git a/app/views/projects/snippets/index.html.haml b/app/views/projects/snippets/index.html.haml
index e77e1b026f6..76792fb5326 100644
--- a/app/views/projects/snippets/index.html.haml
+++ b/app/views/projects/snippets/index.html.haml
@@ -1,5 +1,32 @@
- 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
- 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