Commit 74c8a635ce27336cd385d438291b22e921f88e1c
1 parent
313ac555
Exists in
master
and in
4 other branches
Move project nav checks to helper
Showing
2 changed files
with
54 additions
and
17 deletions
Show diff stats
app/helpers/projects_helper.rb
... | ... | @@ -48,4 +48,36 @@ module ProjectsHelper |
48 | 48 | def remove_project_message(project) |
49 | 49 | "You are going to remove #{project.name_with_namespace}.\n Removed project CANNOT be restored!\n Are you ABSOLUTELY sure?" |
50 | 50 | end |
51 | + | |
52 | + def project_nav_tabs | |
53 | + @nav_tabs ||= get_project_nav_tabs(@project, current_user) | |
54 | + end | |
55 | + | |
56 | + def project_nav_tab?(name) | |
57 | + project_nav_tabs.include? name | |
58 | + end | |
59 | + | |
60 | + private | |
61 | + | |
62 | + def get_project_nav_tabs(project, current_user) | |
63 | + nav_tabs = [:home] | |
64 | + | |
65 | + if project.repo_exists? && can?(current_user, :download_code, project) | |
66 | + nav_tabs << [:files, :commits, :network, :graphs] | |
67 | + end | |
68 | + | |
69 | + if project.repo_exists? && project.merge_requests_enabled | |
70 | + nav_tabs << :merge_requests | |
71 | + end | |
72 | + | |
73 | + if can?(current_user, :admin_project, project) | |
74 | + nav_tabs << :settings | |
75 | + end | |
76 | + | |
77 | + [:issues, :wiki, :wall, :snippets].each do |feature| | |
78 | + nav_tabs << feature if project.send :"#{feature}_enabled" | |
79 | + end | |
80 | + | |
81 | + nav_tabs.flatten | |
82 | + end | |
51 | 83 | end | ... | ... |
app/views/layouts/nav/_project.html.haml
... | ... | @@ -3,43 +3,48 @@ |
3 | 3 | = link_to project_path(@project), title: "Project" do |
4 | 4 | %i.icon-home |
5 | 5 | |
6 | - - unless @project.empty_repo? | |
7 | - - if can? current_user, :download_code, @project | |
8 | - = nav_link(controller: %w(tree blob blame)) do | |
9 | - = link_to 'Files', project_tree_path(@project, @ref || @repository.root_ref) | |
10 | - = nav_link(controller: %w(commit commits compare repositories protected_branches)) do | |
11 | - = link_to "Commits", project_commits_path(@project, @ref || @repository.root_ref) | |
12 | - = nav_link(controller: %w(network)) do | |
13 | - = link_to "Network", project_network_path(@project, @ref || @repository.root_ref) | |
14 | - = nav_link(controller: %w(graphs)) do | |
15 | - = link_to "Graphs", project_graph_path(@project, @ref || @repository.root_ref) | |
16 | - | |
17 | - - if @project.issues_enabled | |
6 | + - if project_nav_tab? :files | |
7 | + = nav_link(controller: %w(tree blob blame)) do | |
8 | + = link_to 'Files', project_tree_path(@project, @ref || @repository.root_ref) | |
9 | + | |
10 | + - if project_nav_tab? :commits | |
11 | + = nav_link(controller: %w(commit commits compare repositories protected_branches)) do | |
12 | + = link_to "Commits", project_commits_path(@project, @ref || @repository.root_ref) | |
13 | + | |
14 | + - if project_nav_tab? :network | |
15 | + = nav_link(controller: %w(network)) do | |
16 | + = link_to "Network", project_network_path(@project, @ref || @repository.root_ref) | |
17 | + | |
18 | + - if project_nav_tab? :graphs | |
19 | + = nav_link(controller: %w(graphs)) do | |
20 | + = link_to "Graphs", project_graph_path(@project, @ref || @repository.root_ref) | |
21 | + | |
22 | + - if project_nav_tab? :issues | |
18 | 23 | = nav_link(controller: %w(issues milestones labels)) do |
19 | 24 | = link_to url_for_project_issues do |
20 | 25 | Issues |
21 | 26 | - if @project.used_default_issues_tracker? |
22 | 27 | %span.count.issue_counter= @project.issues.opened.count |
23 | 28 | |
24 | - - if @project.repo_exists? && @project.merge_requests_enabled | |
29 | + - if project_nav_tab? :merge_requests | |
25 | 30 | = nav_link(controller: :merge_requests) do |
26 | 31 | = link_to project_merge_requests_path(@project) do |
27 | 32 | Merge Requests |
28 | 33 | %span.count.merge_counter= @project.merge_requests.opened.count |
29 | 34 | |
30 | - - if @project.wiki_enabled | |
35 | + - if project_nav_tab? :wiki | |
31 | 36 | = nav_link(controller: :wikis) do |
32 | 37 | = link_to 'Wiki', project_wiki_path(@project, :home) |
33 | 38 | |
34 | - - if @project.wall_enabled | |
39 | + - if project_nav_tab? :wall | |
35 | 40 | = nav_link(controller: :walls) do |
36 | 41 | = link_to 'Wall', project_wall_path(@project) |
37 | 42 | |
38 | - - if @project.snippets_enabled | |
43 | + - if project_nav_tab? :snippets | |
39 | 44 | = nav_link(controller: :snippets) do |
40 | 45 | = link_to 'Snippets', project_snippets_path(@project) |
41 | 46 | |
42 | - - if can? current_user, :admin_project, @project | |
47 | + - if project_nav_tab? :settings | |
43 | 48 | = nav_link(html_options: {class: "#{project_tab_class}"}) do |
44 | 49 | = link_to edit_project_path(@project), class: "stat-tab tab " do |
45 | 50 | Settings | ... | ... |