Commit 74c8a635 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Move project nav checks to helper

parent 313ac555
...@@ -48,4 +48,36 @@ module ProjectsHelper ...@@ -48,4 +48,36 @@ module ProjectsHelper
def remove_project_message(project) def remove_project_message(project)
"You are going to remove #{project.name_with_namespace}.\n Removed project CANNOT be restored!\n Are you ABSOLUTELY sure?" "You are going to remove #{project.name_with_namespace}.\n Removed project CANNOT be restored!\n Are you ABSOLUTELY sure?"
end end
def project_nav_tabs
@nav_tabs ||= get_project_nav_tabs(@project, current_user)
end
def project_nav_tab?(name)
project_nav_tabs.include? name
end
private
def get_project_nav_tabs(project, current_user)
nav_tabs = [:home]
if project.repo_exists? && can?(current_user, :download_code, project)
nav_tabs << [:files, :commits, :network, :graphs]
end
if project.repo_exists? && project.merge_requests_enabled
nav_tabs << :merge_requests
end
if can?(current_user, :admin_project, project)
nav_tabs << :settings
end
[:issues, :wiki, :wall, :snippets].each do |feature|
nav_tabs << feature if project.send :"#{feature}_enabled"
end
nav_tabs.flatten
end
end end
...@@ -3,43 +3,48 @@ ...@@ -3,43 +3,48 @@
= link_to project_path(@project), title: "Project" do = link_to project_path(@project), title: "Project" do
%i.icon-home %i.icon-home
- unless @project.empty_repo? - if project_nav_tab? :files
- if can? current_user, :download_code, @project
= nav_link(controller: %w(tree blob blame)) do = nav_link(controller: %w(tree blob blame)) do
= link_to 'Files', project_tree_path(@project, @ref || @repository.root_ref) = link_to 'Files', project_tree_path(@project, @ref || @repository.root_ref)
- if project_nav_tab? :commits
= nav_link(controller: %w(commit commits compare repositories protected_branches)) do = nav_link(controller: %w(commit commits compare repositories protected_branches)) do
= link_to "Commits", project_commits_path(@project, @ref || @repository.root_ref) = link_to "Commits", project_commits_path(@project, @ref || @repository.root_ref)
- if project_nav_tab? :network
= nav_link(controller: %w(network)) do = nav_link(controller: %w(network)) do
= link_to "Network", project_network_path(@project, @ref || @repository.root_ref) = link_to "Network", project_network_path(@project, @ref || @repository.root_ref)
- if project_nav_tab? :graphs
= nav_link(controller: %w(graphs)) do = nav_link(controller: %w(graphs)) do
= link_to "Graphs", project_graph_path(@project, @ref || @repository.root_ref) = link_to "Graphs", project_graph_path(@project, @ref || @repository.root_ref)
- if @project.issues_enabled - if project_nav_tab? :issues
= nav_link(controller: %w(issues milestones labels)) do = nav_link(controller: %w(issues milestones labels)) do
= link_to url_for_project_issues do = link_to url_for_project_issues do
Issues Issues
- if @project.used_default_issues_tracker? - if @project.used_default_issues_tracker?
%span.count.issue_counter= @project.issues.opened.count %span.count.issue_counter= @project.issues.opened.count
- if @project.repo_exists? && @project.merge_requests_enabled - if project_nav_tab? :merge_requests
= nav_link(controller: :merge_requests) do = nav_link(controller: :merge_requests) do
= link_to project_merge_requests_path(@project) do = link_to project_merge_requests_path(@project) do
Merge Requests Merge Requests
%span.count.merge_counter= @project.merge_requests.opened.count %span.count.merge_counter= @project.merge_requests.opened.count
- if @project.wiki_enabled - if project_nav_tab? :wiki
= nav_link(controller: :wikis) do = nav_link(controller: :wikis) do
= link_to 'Wiki', project_wiki_path(@project, :home) = link_to 'Wiki', project_wiki_path(@project, :home)
- if @project.wall_enabled - if project_nav_tab? :wall
= nav_link(controller: :walls) do = nav_link(controller: :walls) do
= link_to 'Wall', project_wall_path(@project) = link_to 'Wall', project_wall_path(@project)
- if @project.snippets_enabled - if project_nav_tab? :snippets
= nav_link(controller: :snippets) do = nav_link(controller: :snippets) do
= link_to 'Snippets', project_snippets_path(@project) = link_to 'Snippets', project_snippets_path(@project)
- if can? current_user, :admin_project, @project - if project_nav_tab? :settings
= nav_link(html_options: {class: "#{project_tab_class}"}) do = nav_link(html_options: {class: "#{project_tab_class}"}) do
= link_to edit_project_path(@project), class: "stat-tab tab " do = link_to edit_project_path(@project), class: "stat-tab tab " do
Settings Settings
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