From 79a02df92e18137787371468be5c8897ad2f97b0 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Mon, 17 Sep 2012 12:39:57 -0400 Subject: Update usages of tree_file_project_ref_path to project_tree_path --- app/helpers/application_helper.rb | 10 +++++----- app/helpers/tree_helper.rb | 5 +++++ 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'app/helpers') diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0938dc2322a..d90fb32f30f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -58,11 +58,11 @@ module ApplicationHelper if @project && !@project.new_record? project_nav = [ - { label: "#{@project.name} / Issues", url: project_issues_path(@project) }, - { label: "#{@project.name} / Wall", url: wall_project_path(@project) }, - { label: "#{@project.name} / Tree", url: tree_project_ref_path(@project, @project.root_ref) }, - { label: "#{@project.name} / Commits", url: project_commits_path(@project) }, - { label: "#{@project.name} / Team", url: project_team_index_path(@project) } + { label: "#{@project.name} / Issues", url: project_issues_path(@project) }, + { label: "#{@project.name} / Wall", url: wall_project_path(@project) }, + { label: "#{@project.name} / Tree", url: project_tree_path(@project, @ref || @project.root_ref) }, + { label: "#{@project.name} / Commits", url: project_commits_path(@project, @ref || @project.root_ref) }, + { label: "#{@project.name} / Team", url: project_team_index_path(@project) } ] end diff --git a/app/helpers/tree_helper.rb b/app/helpers/tree_helper.rb index 2b7265ca19e..81a16989405 100644 --- a/app/helpers/tree_helper.rb +++ b/app/helpers/tree_helper.rb @@ -39,4 +39,9 @@ module TreeHelper def gitlab_markdown?(filename) filename.end_with?(*%w(.mdown .md .markdown)) end + + # Simple shortcut to File.join + def tree_join(*args) + File.join(*args) + end end -- cgit v1.2.1 From 3ad931ca9211d2ca0f345f97db00193ee5533dfd Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Tue, 25 Sep 2012 19:22:44 -0400 Subject: Add current_controller? helper method Simplifies some of the "active tab" checks we're doing --- app/helpers/application_helper.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'app/helpers') diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d90fb32f30f..505f6067c59 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,6 +1,17 @@ require 'digest/md5' module ApplicationHelper + # Check if a particular controller is the current one + # + # Examples + # + # # On TreeController + # current_controller?(:tree) # => true + # current_controller?(:commits) # => false + def current_controller?(name) + controller.controller_name == name.to_s.downcase + end + def gravatar_icon(user_email = '', size = 40) if Gitlab.config.disable_gravatar? || user_email.blank? 'no_avatar.png' -- cgit v1.2.1 From 60ac6a28a2f198427c2d1ad68421aee484e14028 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Tue, 25 Sep 2012 21:18:00 -0400 Subject: Allow current_controller? helper to take an Array of options --- app/helpers/application_helper.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'app/helpers') diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 505f6067c59..d916d8874a7 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -3,13 +3,16 @@ module ApplicationHelper # Check if a particular controller is the current one # + # args - One or more controller names to check + # # Examples # # # On TreeController - # current_controller?(:tree) # => true - # current_controller?(:commits) # => false - def current_controller?(name) - controller.controller_name == name.to_s.downcase + # current_controller?(:tree) # => true + # current_controller?(:commits) # => false + # current_controller?(:commits, :tree) # => true + def current_controller?(*args) + args.any? { |v| v.to_s.downcase == controller.controller_name } end def gravatar_icon(user_email = '', size = 40) -- cgit v1.2.1 From adcc6a0b0e08158353627a8a900971aca07429bd Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Tue, 25 Sep 2012 21:18:39 -0400 Subject: Move tab_class helper to TabHelper --- app/helpers/application_helper.rb | 39 --------------------------------------- app/helpers/tab_helper.rb | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 39 deletions(-) (limited to 'app/helpers') diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d916d8874a7..f874851aee1 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -99,45 +99,6 @@ module ApplicationHelper event.project.merge_requests_enabled end - def tab_class(tab_key) - active = case tab_key - - # Project Area - when :wall; wall_tab? - when :wiki; controller.controller_name == "wikis" - when :issues; issues_tab? - when :network; current_page?(controller: "projects", action: "graph", id: @project) - when :merge_requests; controller.controller_name == "merge_requests" - - # Dashboard Area - when :help; controller.controller_name == "help" - when :search; current_page?(search_path) - when :dash_issues; current_page?(dashboard_issues_path) - when :dash_mr; current_page?(dashboard_merge_requests_path) - when :root; current_page?(dashboard_path) || current_page?(root_path) - - # Profile Area - when :profile; current_page?(controller: "profile", action: :show) - when :history; current_page?(controller: "profile", action: :history) - when :account; current_page?(controller: "profile", action: :account) - when :token; current_page?(controller: "profile", action: :token) - when :design; current_page?(controller: "profile", action: :design) - when :ssh_keys; controller.controller_name == "keys" - - # Admin Area - when :admin_root; controller.controller_name == "dashboard" - when :admin_users; controller.controller_name == 'users' - when :admin_projects; controller.controller_name == "projects" - when :admin_hooks; controller.controller_name == 'hooks' - when :admin_resque; controller.controller_name == 'resque' - when :admin_logs; controller.controller_name == 'logs' - - else - false - end - active ? "current" : nil - end - def hexdigest(string) Digest::SHA1.hexdigest string end diff --git a/app/helpers/tab_helper.rb b/app/helpers/tab_helper.rb index b5d7ccb7d3c..4cc97b1119d 100644 --- a/app/helpers/tab_helper.rb +++ b/app/helpers/tab_helper.rb @@ -1,4 +1,43 @@ module TabHelper + def tab_class(tab_key) + active = case tab_key + + # Project Area + when :wall; wall_tab? + when :wiki; controller.controller_name == "wikis" + when :issues; issues_tab? + when :network; current_page?(controller: "projects", action: "graph", id: @project) + when :merge_requests; controller.controller_name == "merge_requests" + + # Dashboard Area + when :help; controller.controller_name == "help" + when :search; current_page?(search_path) + when :dash_issues; current_page?(dashboard_issues_path) + when :dash_mr; current_page?(dashboard_merge_requests_path) + when :root; current_page?(dashboard_path) || current_page?(root_path) + + # Profile Area + when :profile; current_page?(controller: "profile", action: :show) + when :history; current_page?(controller: "profile", action: :history) + when :account; current_page?(controller: "profile", action: :account) + when :token; current_page?(controller: "profile", action: :token) + when :design; current_page?(controller: "profile", action: :design) + when :ssh_keys; controller.controller_name == "keys" + + # Admin Area + when :admin_root; controller.controller_name == "dashboard" + when :admin_users; controller.controller_name == 'users' + when :admin_projects; controller.controller_name == "projects" + when :admin_hooks; controller.controller_name == 'hooks' + when :admin_resque; controller.controller_name == 'resque' + when :admin_logs; controller.controller_name == 'logs' + + else + false + end + active ? "current" : nil + end + def issues_tab? controller.controller_name == "issues" || controller.controller_name == "milestones" end -- cgit v1.2.1 From 51c1e499006df02ff3dfc2a781457a01cc77550f Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Tue, 25 Sep 2012 22:07:41 -0400 Subject: Change active tab and nav class to "active" The main nav used active, the sub nav used current. This normalizes it. --- app/helpers/tab_helper.rb | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'app/helpers') diff --git a/app/helpers/tab_helper.rb b/app/helpers/tab_helper.rb index 4cc97b1119d..9491e277a02 100644 --- a/app/helpers/tab_helper.rb +++ b/app/helpers/tab_helper.rb @@ -5,7 +5,6 @@ module TabHelper # Project Area when :wall; wall_tab? when :wiki; controller.controller_name == "wikis" - when :issues; issues_tab? when :network; current_page?(controller: "projects", action: "graph", id: @project) when :merge_requests; controller.controller_name == "merge_requests" @@ -35,11 +34,7 @@ module TabHelper else false end - active ? "current" : nil - end - - def issues_tab? - controller.controller_name == "issues" || controller.controller_name == "milestones" + active ? "active" : nil end def wall_tab? @@ -48,21 +43,17 @@ module TabHelper def project_tab_class [:show, :files, :edit, :update].each do |action| - return "current" if current_page?(controller: "projects", action: action, id: @project) + return "active" if current_page?(controller: "projects", action: action, id: @project) end if ['snippets', 'hooks', 'deploy_keys', 'team_members'].include? controller.controller_name - "current" + "active" end end - def tree_tab_class - controller.controller_name == "refs" ? "current" : nil - end - def commit_tab_class if ['commits', 'repositories', 'protected_branches'].include? controller.controller_name - "current" + "active" end end -- cgit v1.2.1 From b62d6a1fe28ad040e96fd88604131f357e5e6e9e Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Tue, 25 Sep 2012 23:34:26 -0400 Subject: Remove commit_tab_class helper --- app/helpers/tab_helper.rb | 6 ------ 1 file changed, 6 deletions(-) (limited to 'app/helpers') diff --git a/app/helpers/tab_helper.rb b/app/helpers/tab_helper.rb index 9491e277a02..c26e3467511 100644 --- a/app/helpers/tab_helper.rb +++ b/app/helpers/tab_helper.rb @@ -51,12 +51,6 @@ module TabHelper end end - def commit_tab_class - if ['commits', 'repositories', 'protected_branches'].include? controller.controller_name - "active" - end - end - def branches_tab_class if current_page?(branches_project_repository_path(@project)) || controller.controller_name == "protected_branches" || -- cgit v1.2.1 From aa0c4b77b60acfc85d99e9eacaff25e34b136529 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Wed, 26 Sep 2012 15:06:07 -0400 Subject: Add current_action? helper --- app/helpers/application_helper.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'app/helpers') diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f874851aee1..185e7d84149 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,4 +1,5 @@ require 'digest/md5' + module ApplicationHelper # Check if a particular controller is the current one @@ -15,6 +16,20 @@ module ApplicationHelper args.any? { |v| v.to_s.downcase == controller.controller_name } end + # Check if a partcular action is the current one + # + # args - One or more action names to check + # + # Examples + # + # # On Projects#new + # current_action?(:new) # => true + # current_action?(:create) # => false + # current_action?(:new, :create) # => true + def current_action?(*args) + args.any? { |v| v.to_s.downcase == action_name } + end + def gravatar_icon(user_email = '', size = 40) if Gitlab.config.disable_gravatar? || user_email.blank? 'no_avatar.png' -- cgit v1.2.1 From f064c84019f7414cb9cfa9e49fb735dba7f495df Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Wed, 26 Sep 2012 16:13:23 -0400 Subject: Add nav_link helper to TabHelper --- app/helpers/tab_helper.rb | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'app/helpers') diff --git a/app/helpers/tab_helper.rb b/app/helpers/tab_helper.rb index c26e3467511..abd724b9212 100644 --- a/app/helpers/tab_helper.rb +++ b/app/helpers/tab_helper.rb @@ -1,4 +1,72 @@ module TabHelper + # Navigation link helper + # + # Returns an `li` element with an 'active' class if the supplied + # controller(s) and/or action(s) currently active. The contents of the + # element is the value passed to the block. + # + # options - The options hash used to determine if the element is "active" (default: {}) + # :controller - One or more controller names to check (optional). + # :action - One or more action names to check (optional). + # :path - A shorthand path, such as 'dashboard#index', to check (optional). + # :html_options - Extra options to be passed to the list element (optional). + # block - An optional block that will become the contents of the returned + # `li` element. + # + # When both :controller and :action are specified, BOTH must match in order + # to be marked as active. When only one is given, either can match. + # + # Examples + # + # # Assuming we're on TreeController#show + # + # # Controller matches, but action doesn't + # nav_link(controller: [:tree, :refs], action: :edit) { "Hello" } + # # => '
  • Hello
  • ' + # + # # Controller matches + # nav_link(controller: [:tree, :refs]) { "Hello" } + # # => '
  • Hello
  • ' + # + # # Shorthand path + # nav_link(path: 'tree#show') { "Hello" } + # # => '
  • Hello
  • ' + # + # # Supplying custom options for the list element + # nav_link(controller: :tree, html_options: {class: 'home'}) { "Hello" } + # # => '
  • Hello
  • ' + # + # Returns a list item element String + def nav_link(options = {}, &block) + if path = options.delete(:path) + c, a, _ = path.split('#') + else + c = options.delete(:controller) + a = options.delete(:action) + end + + if c && a + # When given both options, make sure BOTH are active + klass = current_controller?(*c) && current_action?(*a) ? 'active' : '' + else + # Otherwise check EITHER option + klass = current_controller?(*c) || current_action?(*a) ? 'active' : '' + end + + # Add our custom class into the html_options, which may or may not exist + # and which may or may not already have a :class key + o = options.delete(:html_options) || {} + o[:class] ||= '' + o[:class] += ' ' + klass + o[:class].strip! + + if block_given? + content_tag(:li, capture(&block), o) + else + content_tag(:li, nil, o) + end + end + def tab_class(tab_key) active = case tab_key -- cgit v1.2.1 From 36f68140d1fcd89ed6bd92ac69cf13c566db63d5 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Wed, 26 Sep 2012 16:14:17 -0400 Subject: Replace various "active tab" checks with nav_link Also remove now-unused tab_class helper --- app/helpers/tab_helper.rb | 44 +------------------------------------------- 1 file changed, 1 insertion(+), 43 deletions(-) (limited to 'app/helpers') diff --git a/app/helpers/tab_helper.rb b/app/helpers/tab_helper.rb index abd724b9212..c76c1b6f83d 100644 --- a/app/helpers/tab_helper.rb +++ b/app/helpers/tab_helper.rb @@ -67,48 +67,6 @@ module TabHelper end end - def tab_class(tab_key) - active = case tab_key - - # Project Area - when :wall; wall_tab? - when :wiki; controller.controller_name == "wikis" - when :network; current_page?(controller: "projects", action: "graph", id: @project) - when :merge_requests; controller.controller_name == "merge_requests" - - # Dashboard Area - when :help; controller.controller_name == "help" - when :search; current_page?(search_path) - when :dash_issues; current_page?(dashboard_issues_path) - when :dash_mr; current_page?(dashboard_merge_requests_path) - when :root; current_page?(dashboard_path) || current_page?(root_path) - - # Profile Area - when :profile; current_page?(controller: "profile", action: :show) - when :history; current_page?(controller: "profile", action: :history) - when :account; current_page?(controller: "profile", action: :account) - when :token; current_page?(controller: "profile", action: :token) - when :design; current_page?(controller: "profile", action: :design) - when :ssh_keys; controller.controller_name == "keys" - - # Admin Area - when :admin_root; controller.controller_name == "dashboard" - when :admin_users; controller.controller_name == 'users' - when :admin_projects; controller.controller_name == "projects" - when :admin_hooks; controller.controller_name == 'hooks' - when :admin_resque; controller.controller_name == 'resque' - when :admin_logs; controller.controller_name == 'logs' - - else - false - end - active ? "active" : nil - end - - def wall_tab? - current_page?(controller: "projects", action: "wall", id: @project) - end - def project_tab_class [:show, :files, :edit, :update].each do |action| return "active" if current_page?(controller: "projects", action: action, id: @project) @@ -121,7 +79,7 @@ module TabHelper def branches_tab_class if current_page?(branches_project_repository_path(@project)) || - controller.controller_name == "protected_branches" || + current_controller?(:protected_branches) || current_page?(project_repository_path(@project)) 'active' end -- cgit v1.2.1 From 2c8d3c33ff64ac6af5daf125a2f9ef917e55bcfc Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 27 Sep 2012 09:53:42 +0300 Subject: Fixed ref switcher --- app/helpers/application_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/helpers') diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 185e7d84149..911b46c9a30 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -60,8 +60,8 @@ module ApplicationHelper def grouped_options_refs(destination = :tree) options = [ - ["Branch", @project.repo.heads.map(&:name) ], - [ "Tag", @project.tags ] + ["Branch", @project.branch_names ], + [ "Tag", @project.tag_names ] ] # If reference is commit id - -- cgit v1.2.1