Commit 68787297 authored by Mike Greiling's avatar Mike Greiling

implement snippets_scope_menu partial to reduce code duplication

parent adbc3780
...@@ -8,6 +8,17 @@ module SnippetsHelper ...@@ -8,6 +8,17 @@ module SnippetsHelper
end end
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 # Get an array of line numbers surrounding a matching
# line, bounded by min/max. # line, bounded by min/max.
# #
......
...@@ -2,31 +2,7 @@ ...@@ -2,31 +2,7 @@
- header_title "Snippets", dashboard_snippets_path - header_title "Snippets", dashboard_snippets_path
= render 'dashboard/snippets_head' = render 'dashboard/snippets_head'
= render partial: 'snippets/snippets_scope_menu', locals: { include_private: true }
.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
.visible-xs .visible-xs
   
......
...@@ -2,34 +2,8 @@ ...@@ -2,34 +2,8 @@
- if current_user - if current_user
.top-area .top-area
.nav-links.snippet-scope-menu - include_private = @project.team.member?(current_user) || current_user.admin?
%li{ class: ("active" unless params[:scope]) } = render partial: 'snippets/snippets_scope_menu', locals: { subject: @project, include_private: include_private }
= 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
.nav-controls.hidden-xs .nav-controls.hidden-xs
- if can?(current_user, :create_project_snippet, @project) - if can?(current_user, :create_project_snippet, @project)
......
- 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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment