Commit 36f68140d1fcd89ed6bd92ac69cf13c566db63d5

Authored by Robert Speicher
1 parent f064c840

Replace various "active tab" checks with nav_link

Also remove now-unused tab_class helper
app/helpers/tab_helper.rb
@@ -67,48 +67,6 @@ module TabHelper @@ -67,48 +67,6 @@ module TabHelper
67 end 67 end
68 end 68 end
69 69
70 - def tab_class(tab_key)  
71 - active = case tab_key  
72 -  
73 - # Project Area  
74 - when :wall; wall_tab?  
75 - when :wiki; controller.controller_name == "wikis"  
76 - when :network; current_page?(controller: "projects", action: "graph", id: @project)  
77 - when :merge_requests; controller.controller_name == "merge_requests"  
78 -  
79 - # Dashboard Area  
80 - when :help; controller.controller_name == "help"  
81 - when :search; current_page?(search_path)  
82 - when :dash_issues; current_page?(dashboard_issues_path)  
83 - when :dash_mr; current_page?(dashboard_merge_requests_path)  
84 - when :root; current_page?(dashboard_path) || current_page?(root_path)  
85 -  
86 - # Profile Area  
87 - when :profile; current_page?(controller: "profile", action: :show)  
88 - when :history; current_page?(controller: "profile", action: :history)  
89 - when :account; current_page?(controller: "profile", action: :account)  
90 - when :token; current_page?(controller: "profile", action: :token)  
91 - when :design; current_page?(controller: "profile", action: :design)  
92 - when :ssh_keys; controller.controller_name == "keys"  
93 -  
94 - # Admin Area  
95 - when :admin_root; controller.controller_name == "dashboard"  
96 - when :admin_users; controller.controller_name == 'users'  
97 - when :admin_projects; controller.controller_name == "projects"  
98 - when :admin_hooks; controller.controller_name == 'hooks'  
99 - when :admin_resque; controller.controller_name == 'resque'  
100 - when :admin_logs; controller.controller_name == 'logs'  
101 -  
102 - else  
103 - false  
104 - end  
105 - active ? "active" : nil  
106 - end  
107 -  
108 - def wall_tab?  
109 - current_page?(controller: "projects", action: "wall", id: @project)  
110 - end  
111 -  
112 def project_tab_class 70 def project_tab_class
113 [:show, :files, :edit, :update].each do |action| 71 [:show, :files, :edit, :update].each do |action|
114 return "active" if current_page?(controller: "projects", action: action, id: @project) 72 return "active" if current_page?(controller: "projects", action: action, id: @project)
@@ -121,7 +79,7 @@ module TabHelper @@ -121,7 +79,7 @@ module TabHelper
121 79
122 def branches_tab_class 80 def branches_tab_class
123 if current_page?(branches_project_repository_path(@project)) || 81 if current_page?(branches_project_repository_path(@project)) ||
124 - controller.controller_name == "protected_branches" || 82 + current_controller?(:protected_branches) ||
125 current_page?(project_repository_path(@project)) 83 current_page?(project_repository_path(@project))
126 'active' 84 'active'
127 end 85 end
app/views/blame/_head.html.haml
1 %ul.nav.nav-tabs 1 %ul.nav.nav-tabs
2 %li 2 %li
3 = render partial: 'shared/ref_switcher', locals: {destination: 'tree', path: params[:path]} 3 = render partial: 'shared/ref_switcher', locals: {destination: 'tree', path: params[:path]}
4 - %li{class: "#{'active' if (controller.controller_name == "refs") }"}  
5 - = link_to project_tree_path(@project, @ref) do  
6 - Source 4 + = nav_link(controller: :refs) do
  5 + = link_to 'Source', project_tree_path(@project, @ref)
7 %li.right 6 %li.right
8 .input-prepend.project_clone_holder 7 .input-prepend.project_clone_holder
9 %button{class: "btn small active", :"data-clone" => @project.ssh_url_to_repo} SSH 8 %button{class: "btn small active", :"data-clone" => @project.ssh_url_to_repo} SSH
app/views/commits/_head.html.haml
1 %ul.nav.nav-tabs 1 %ul.nav.nav-tabs
2 %li= render partial: 'shared/ref_switcher', locals: {destination: 'commits'} 2 %li= render partial: 'shared/ref_switcher', locals: {destination: 'commits'}
3 - %li{class: "#{'active' if current_controller?(:commit, :commits)}"}  
4 - = link_to project_commits_path(@project, @project.root_ref) do  
5 - Commits  
6 - %li{class: "#{'active' if current_controller?(:compare)}"}  
7 - = link_to project_compare_index_path(@project) do  
8 - Compare  
9 - %li{class: "#{branches_tab_class}"} 3 +
  4 + = nav_link(controller: [:commit, :commits]) do
  5 + = link_to 'Commits', project_commits_path(@project, @project.root_ref)
  6 + = nav_link(controller: :compare) do
  7 + = link_to 'Compare', project_compare_index_path(@project)
  8 +
  9 + = nav_link(html_options: {class: branches_tab_class}) do
10 = link_to project_repository_path(@project) do 10 = link_to project_repository_path(@project) do
11 Branches 11 Branches
12 %span.badge= @project.repo.branch_count 12 %span.badge= @project.repo.branch_count
13 13
14 - %li{class: "#{'active' if current_page?(tags_project_repository_path(@project)) }"} 14 + = nav_link(controller: :repositories, action: :tags) do
15 = link_to tags_project_repository_path(@project) do 15 = link_to tags_project_repository_path(@project) do
16 Tags 16 Tags
17 %span.badge= @project.repo.tag_count 17 %span.badge= @project.repo.tag_count
app/views/issues/_head.html.haml
1 %ul.nav.nav-tabs 1 %ul.nav.nav-tabs
2 - %li{class: "#{'active' if current_page?(project_issues_path(@project))}"}  
3 - = link_to project_issues_path(@project), class: "tab" do  
4 - Browse Issues  
5 - %li{class: "#{'active' if current_page?(project_milestones_path(@project))}"}  
6 - = link_to project_milestones_path(@project), class: "tab" do  
7 - Milestones  
8 - %li{class: "#{'active' if current_page?(project_labels_path(@project))}"}  
9 - = link_to project_labels_path(@project), class: "tab" do  
10 - Labels 2 + = nav_link(controller: :issues) do
  3 + = link_to 'Browse Issues', project_issues_path(@project), class: "tab"
  4 + = nav_link(controller: :milestones) do
  5 + = link_to 'Milestones', project_milestones_path(@project), class: "tab"
  6 + = nav_link(controller: :labels) do
  7 + = link_to 'Labels', project_labels_path(@project), class: "tab"
11 %li.right 8 %li.right
12 %span.rss-icon 9 %span.rss-icon
13 = link_to project_issues_path(@project, :atom, { private_token: current_user.private_token }) do 10 = link_to project_issues_path(@project, :atom, { private_token: current_user.private_token }) do
app/views/layouts/_app_menu.html.haml
1 %ul.main_menu 1 %ul.main_menu
2 - %li.home{class: tab_class(:root)} 2 + = nav_link(path: 'dashboard#index', html_options: {class: 'home'}) do
3 = link_to "Home", root_path, title: "Home" 3 = link_to "Home", root_path, title: "Home"
4 4
5 - %li{class: tab_class(:dash_issues)} 5 + = nav_link(path: 'dashboard#issues') do
6 = link_to dashboard_issues_path do 6 = link_to dashboard_issues_path do
7 Issues 7 Issues
8 %span.count= current_user.assigned_issues.opened.count 8 %span.count= current_user.assigned_issues.opened.count
9 9
10 - %li{class: tab_class(:dash_mr)} 10 + = nav_link(path: 'dashboard#merge_requests') do
11 = link_to dashboard_merge_requests_path do 11 = link_to dashboard_merge_requests_path do
12 Merge Requests 12 Merge Requests
13 %span.count= current_user.cared_merge_requests.count 13 %span.count= current_user.cared_merge_requests.count
14 14
15 - %li{class: tab_class(:search)} 15 + = nav_link(path: 'search#show') do
16 = link_to "Search", search_path 16 = link_to "Search", search_path
17 17
18 - %li{class: tab_class(:help)} 18 + = nav_link(path: 'help#index') do
19 = link_to "Help", help_path 19 = link_to "Help", help_path
app/views/layouts/_project_menu.html.haml
1 %ul.main_menu 1 %ul.main_menu
2 - %li.home{class: project_tab_class} 2 + = nav_link(html_options: {class: "home #{project_tab_class}"}) do
3 = link_to @project.code, project_path(@project), title: "Project" 3 = link_to @project.code, project_path(@project), title: "Project"
4 4
5 - if @project.repo_exists? 5 - if @project.repo_exists?
6 - if can? current_user, :download_code, @project 6 - if can? current_user, :download_code, @project
7 - %li{class: current_controller?(:tree, :blob, :blame) ? 'active' : ''} 7 + = nav_link(controller: %w(tree blob blame)) do
8 = link_to 'Files', project_tree_path(@project, @ref || @project.root_ref) 8 = link_to 'Files', project_tree_path(@project, @ref || @project.root_ref)
9 - %li{class: current_controller?(:commit, :commits, :compare, :repositories, :protected_branches) ? 'active' : ''} 9 + = nav_link(controller: %w(commit commits compare repositories protected_branches)) do
10 = link_to "Commits", project_commits_path(@project, @ref || @project.root_ref) 10 = link_to "Commits", project_commits_path(@project, @ref || @project.root_ref)
11 - %li{class: tab_class(:network)} 11 + = nav_link(path: 'projects#graph') do
12 = link_to "Network", graph_project_path(@project) 12 = link_to "Network", graph_project_path(@project)
13 13
14 - if @project.issues_enabled 14 - if @project.issues_enabled
15 - %li{class: current_controller?(:issues, :milestones, :labels) ? 'active' : ''} 15 + = nav_link(controller: %w(issues milestones labels)) do
16 = link_to project_issues_filter_path(@project) do 16 = link_to project_issues_filter_path(@project) do
17 Issues 17 Issues
18 %span.count.issue_counter= @project.issues.opened.count 18 %span.count.issue_counter= @project.issues.opened.count
19 19
20 - if @project.repo_exists? 20 - if @project.repo_exists?
21 - if @project.merge_requests_enabled 21 - if @project.merge_requests_enabled
22 - %li{class: tab_class(:merge_requests)} 22 + = nav_link(controller: :merge_requests) do
23 = link_to project_merge_requests_path(@project) do 23 = link_to project_merge_requests_path(@project) do
24 Merge Requests 24 Merge Requests
25 %span.count.merge_counter= @project.merge_requests.opened.count 25 %span.count.merge_counter= @project.merge_requests.opened.count
26 26
27 - if @project.wall_enabled 27 - if @project.wall_enabled
28 - %li{class: tab_class(:wall)}  
29 - = link_to wall_project_path(@project) do  
30 - Wall 28 + = nav_link(path: 'projects#wall') do
  29 + = link_to 'Wall', wall_project_path(@project)
31 30
32 - if @project.wiki_enabled 31 - if @project.wiki_enabled
33 - %li{class: tab_class(:wiki)}  
34 - = link_to project_wiki_path(@project, :index) do  
35 - Wiki 32 + = nav_link(controller: :wikis) do
  33 + = link_to 'Wiki', project_wiki_path(@project, :index)
app/views/layouts/admin.html.haml
@@ -6,17 +6,17 @@ @@ -6,17 +6,17 @@
6 = render "layouts/head_panel", title: "Admin area" 6 = render "layouts/head_panel", title: "Admin area"
7 .container 7 .container
8 %ul.main_menu 8 %ul.main_menu
9 - %li.home{class: tab_class(:admin_root)} 9 + = nav_link(controller: :dashboard, html_options: {class: 'home'}) do
10 = link_to "Stats", admin_root_path 10 = link_to "Stats", admin_root_path
11 - %li{class: tab_class(:admin_projects)} 11 + = nav_link(controller: :projects) do
12 = link_to "Projects", admin_projects_path 12 = link_to "Projects", admin_projects_path
13 - %li{class: tab_class(:admin_users)} 13 + = nav_link(controller: :users) do
14 = link_to "Users", admin_users_path 14 = link_to "Users", admin_users_path
15 - %li{class: tab_class(:admin_logs)} 15 + = nav_link(controller: :logs) do
16 = link_to "Logs", admin_logs_path 16 = link_to "Logs", admin_logs_path
17 - %li{class: tab_class(:admin_hooks)} 17 + = nav_link(controller: :hooks) do
18 = link_to "Hooks", admin_hooks_path 18 = link_to "Hooks", admin_hooks_path
19 - %li{class: tab_class(:admin_resque)} 19 + = nav_link(controller: :resque) do
20 = link_to "Resque", admin_resque_path 20 = link_to "Resque", admin_resque_path
21 21
22 .content= yield 22 .content= yield
app/views/layouts/profile.html.haml
@@ -6,23 +6,17 @@ @@ -6,23 +6,17 @@
6 = render "layouts/head_panel", title: "Profile" 6 = render "layouts/head_panel", title: "Profile"
7 .container 7 .container
8 %ul.main_menu 8 %ul.main_menu
9 - %li.home{class: tab_class(:profile)} 9 + = nav_link(path: 'profile#show', html_options: {class: 'home'}) do
10 = link_to "Profile", profile_path 10 = link_to "Profile", profile_path
11 -  
12 - %li{class: tab_class(:account)} 11 + = nav_link(path: 'profile#account') do
13 = link_to "Account", profile_account_path 12 = link_to "Account", profile_account_path
14 -  
15 - %li{class: tab_class(:ssh_keys)} 13 + = nav_link(controller: :keys) do
16 = link_to keys_path do 14 = link_to keys_path do
17 SSH Keys 15 SSH Keys
18 %span.count= current_user.keys.count 16 %span.count= current_user.keys.count
19 -  
20 - %li{class: tab_class(:design)} 17 + = nav_link(path: 'profile#design') do
21 = link_to "Design", profile_design_path 18 = link_to "Design", profile_design_path
22 -  
23 - %li{class: tab_class(:history)} 19 + = nav_link(path: 'profile#history') do
24 = link_to "History", profile_history_path 20 = link_to "History", profile_history_path
25 21
26 -  
27 - .content  
28 - = yield 22 + .content= yield
app/views/projects/_project_head.html.haml
1 %ul.nav.nav-tabs 1 %ul.nav.nav-tabs
2 - %li{ class: "#{'active' if current_page?(project_path(@project)) }" } 2 + = nav_link(path: 'projects#show') do
3 = link_to project_path(@project), class: "activities-tab tab" do 3 = link_to project_path(@project), class: "activities-tab tab" do
4 %i.icon-home 4 %i.icon-home
5 Show 5 Show
6 - %li{ class: " #{'active' if (controller.controller_name == "team_members") || current_page?(project_team_index_path(@project)) }" } 6 + = nav_link(controller: :team_members) do
7 = link_to project_team_index_path(@project), class: "team-tab tab" do 7 = link_to project_team_index_path(@project), class: "team-tab tab" do
8 %i.icon-user 8 %i.icon-user
9 Team 9 Team
10 - %li{ class: "#{'active' if current_page?(files_project_path(@project)) }" }  
11 - = link_to files_project_path(@project), class: "files-tab tab " do  
12 - Attachments  
13 - %li{ class: " #{'active' if (controller.controller_name == "snippets") }" }  
14 - = link_to project_snippets_path(@project), class: "snippets-tab tab" do  
15 - Snippets 10 + = nav_link(path: 'projects#files') do
  11 + = link_to 'Attachments', files_project_path(@project), class: "files-tab tab"
  12 + = nav_link(controller: :snippets) do
  13 + = link_to 'Snippets', project_snippets_path(@project), class: "snippets-tab tab"
16 14
17 - if can? current_user, :admin_project, @project 15 - if can? current_user, :admin_project, @project
18 - %li.right{class: "#{'active' if controller.controller_name == "deploy_keys"}"} 16 + = nav_link(controller: :deploy_keys, html_options: {class: 'right'}) do
19 = link_to project_deploy_keys_path(@project) do 17 = link_to project_deploy_keys_path(@project) do
20 %span 18 %span
21 Deploy Keys 19 Deploy Keys
22 - %li.right{class: "#{'active' if controller.controller_name == "hooks" }"} 20 + = nav_link(controller: :hooks, html_options: {class: 'right'}) do
23 = link_to project_hooks_path(@project) do 21 = link_to project_hooks_path(@project) do
24 %span 22 %span
25 Hooks 23 Hooks
26 - %li.right{ class: "#{'active' if current_page?(edit_project_path(@project)) }" } 24 + = nav_link(path: 'projects#edit', html_options: {class: 'right'}) do
27 = link_to edit_project_path(@project), class: "stat-tab tab " do 25 = link_to edit_project_path(@project), class: "stat-tab tab " do
28 %i.icon-edit 26 %i.icon-edit
29 Edit 27 Edit
app/views/repositories/_branches_head.html.haml
1 = render "commits/head" 1 = render "commits/head"
2 %ul.nav.nav-pills 2 %ul.nav.nav-pills
3 - %li{class: ("active" if current_page?(project_repository_path(@project)))}  
4 - = link_to project_repository_path(@project) do  
5 - Recent  
6 - %li{class: ("active" if current_page?(project_protected_branches_path(@project)))}  
7 - = link_to project_protected_branches_path(@project) do  
8 - Protected  
9 - %li{class: ("active" if current_page?(branches_project_repository_path(@project)))}  
10 - = link_to branches_project_repository_path(@project) do  
11 - All 3 + = nav_link(path: 'repositories#show') do
  4 + = link_to 'Recent', project_repository_path(@project)
  5 + = nav_link(path: 'protected_branches#index') do
  6 + = link_to 'Protected', project_protected_branches_path(@project)
  7 + = nav_link(path: 'repositories#branches') do
  8 + = link_to 'All', branches_project_repository_path(@project)
app/views/tree/_head.html.haml
1 %ul.nav.nav-tabs 1 %ul.nav.nav-tabs
2 %li 2 %li
3 = render partial: 'shared/ref_switcher', locals: {destination: 'tree', path: @path} 3 = render partial: 'shared/ref_switcher', locals: {destination: 'tree', path: @path}
4 - %li{class: "#{'active' if (controller.controller_name == "tree") }"}  
5 - = link_to project_tree_path(@project, @ref) do  
6 - Source 4 + = nav_link(controller: :tree) do
  5 + = link_to 'Source', project_tree_path(@project, @ref)
7 %li.right 6 %li.right
8 .input-prepend.project_clone_holder 7 .input-prepend.project_clone_holder
9 %button{class: "btn small active", :"data-clone" => @project.ssh_url_to_repo} SSH 8 %button{class: "btn small active", :"data-clone" => @project.ssh_url_to_repo} SSH