From 687872978100c168ce381448c0a9536fb53542ce Mon Sep 17 00:00:00 2001 From: Mike Greiling Date: Fri, 9 Dec 2016 15:38:10 -0600 Subject: implement snippets_scope_menu partial to reduce code duplication --- app/views/dashboard/snippets/index.html.haml | 26 +------------------ app/views/projects/snippets/index.html.haml | 30 ++-------------------- app/views/snippets/_snippets_scope_menu.html.haml | 31 +++++++++++++++++++++++ 3 files changed, 34 insertions(+), 53 deletions(-) create mode 100644 app/views/snippets/_snippets_scope_menu.html.haml (limited to 'app/views') 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   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 -- cgit v1.2.1