summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorMike Greiling <mike@pixelcog.com>2016-12-09 15:38:10 -0600
committerMike Greiling <mike@pixelcog.com>2016-12-10 00:57:23 -0600
commit687872978100c168ce381448c0a9536fb53542ce (patch)
tree0703562ca713ca84098512a8ba166e2bfe023b8b /app
parentadbc37804e49e1d3ba02bf61122696e135666ff3 (diff)
downloadgitlab-ce-687872978100c168ce381448c0a9536fb53542ce.tar.gz
implement snippets_scope_menu partial to reduce code duplication
Diffstat (limited to 'app')
-rw-r--r--app/helpers/snippets_helper.rb11
-rw-r--r--app/views/dashboard/snippets/index.html.haml26
-rw-r--r--app/views/projects/snippets/index.html.haml30
-rw-r--r--app/views/snippets/_snippets_scope_menu.html.haml31
4 files changed, 45 insertions, 53 deletions
diff --git a/app/helpers/snippets_helper.rb b/app/helpers/snippets_helper.rb
index 7e33a562077..fc7febd3385 100644
--- a/app/helpers/snippets_helper.rb
+++ b/app/helpers/snippets_helper.rb
@@ -8,6 +8,17 @@ module SnippetsHelper
end
end
+ # Return the path of a snippets index for a user or for a project
+ #
+ # @returns String, path to snippet index
+ def snippets_path(subject = nil, opts = nil)
+ if subject.is_a?(Project)
+ namespace_project_snippets_path(subject.namespace, subject, opts)
+ else # assume subject === User
+ dashboard_snippets_path(opts)
+ end
+ end
+
# Get an array of line numbers surrounding a matching
# line, bounded by min/max.
#
diff --git a/app/views/dashboard/snippets/index.html.haml b/app/views/dashboard/snippets/index.html.haml
index 81bfa44a665..85cbe0bf0e6 100644
--- a/app/views/dashboard/snippets/index.html.haml
+++ b/app/views/dashboard/snippets/index.html.haml
@@ -2,31 +2,7 @@
- header_title "Snippets", dashboard_snippets_path
= render 'dashboard/snippets_head'
-
-.nav-links.snippet-scope-menu
- %li{ class: ("active" unless params[:scope]) }
- = link_to dashboard_snippets_path do
- All
- %span.badge
- = current_user.snippets.count
-
- %li{ class: ("active" if params[:scope] == "are_private") }
- = link_to dashboard_snippets_path(scope: 'are_private') do
- Private
- %span.badge
- = current_user.snippets.are_private.count
-
- %li{ class: ("active" if params[:scope] == "are_internal") }
- = link_to dashboard_snippets_path(scope: 'are_internal') do
- Internal
- %span.badge
- = current_user.snippets.are_internal.count
-
- %li{ class: ("active" if params[:scope] == "are_public") }
- = link_to dashboard_snippets_path(scope: 'are_public') do
- Public
- %span.badge
- = current_user.snippets.are_public.count
+= render partial: 'snippets/snippets_scope_menu', locals: { include_private: true }
.visible-xs
&nbsp;
diff --git a/app/views/projects/snippets/index.html.haml b/app/views/projects/snippets/index.html.haml
index 978f4b87564..84e05cd6d88 100644
--- a/app/views/projects/snippets/index.html.haml
+++ b/app/views/projects/snippets/index.html.haml
@@ -2,34 +2,8 @@
- if current_user
.top-area
- .nav-links.snippet-scope-menu
- %li{ class: ("active" unless params[:scope]) }
- = link_to namespace_project_snippets_path(@project.namespace, @project) do
- All
- %span.badge
- - if @project.team.member?(current_user) || current_user.admin?
- = @project.snippets.count
- - else
- = @project.snippets.public_and_internal.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
+ - include_private = @project.team.member?(current_user) || current_user.admin?
+ = render partial: 'snippets/snippets_scope_menu', locals: { subject: @project, include_private: include_private }
.nav-controls.hidden-xs
- if can?(current_user, :create_project_snippet, @project)
diff --git a/app/views/snippets/_snippets_scope_menu.html.haml b/app/views/snippets/_snippets_scope_menu.html.haml
new file mode 100644
index 00000000000..cb837f1fac1
--- /dev/null
+++ b/app/views/snippets/_snippets_scope_menu.html.haml
@@ -0,0 +1,31 @@
+- subject = local_assigns.fetch(:subject, current_user)
+- include_private = local_assigns.fetch(:include_private, false)
+
+.nav-links.snippet-scope-menu
+ %li{ class: ("active" unless params[:scope]) }
+ = link_to snippets_path(subject) do
+ All
+ %span.badge
+ - if include_private
+ = subject.snippets.count
+ - else
+ = subject.snippets.public_and_internal.count
+
+ - if include_private
+ %li{ class: ("active" if params[:scope] == "are_private") }
+ = link_to snippets_path(subject, scope: 'are_private') do
+ Private
+ %span.badge
+ = subject.snippets.are_private.count
+
+ %li{ class: ("active" if params[:scope] == "are_internal") }
+ = link_to snippets_path(subject, scope: 'are_internal') do
+ Internal
+ %span.badge
+ = subject.snippets.are_internal.count
+
+ %li{ class: ("active" if params[:scope] == "are_public") }
+ = link_to snippets_path(subject, scope: 'are_public') do
+ Public
+ %span.badge
+ = subject.snippets.are_public.count