3 module ApplicationHelper
5 # Check if a particular controller is the current one
7 # args - One or more controller names to check
12 # current_controller?(:tree) # => true
13 # current_controller?(:commits) # => false
14 # current_controller?(:commits, :tree) # => true
15 def current_controller?(*args)
16 args.any? { |v| v.to_s.downcase == controller.controller_name }
19 # Check if a partcular action is the current one
21 # args - One or more action names to check
26 # current_action?(:new) # => true
27 # current_action?(:create) # => false
28 # current_action?(:new, :create) # => true
29 def current_action?(*args)
30 args.any? { |v| v.to_s.downcase == action_name }
33 def gravatar_icon(user_email = '', size = 40)
34 if Gitlab.config.disable_gravatar? || user_email.blank?
37 gravatar_prefix = request.ssl? ? "https://secure" : "http://www"
39 "#{gravatar_prefix}.gravatar.com/avatar/#{Digest::MD5.hexdigest(user_email.downcase)}?s=#{size}&d=identicon"
44 request.ssl? ? "https" : "http"
48 "#{request_protocol}://#{Gitlab.config.web_host}/"
51 def last_commit(project)
52 if project.repo_exists?
53 time_ago_in_words(project.commit.committed_date) + " ago"
61 def grouped_options_refs(destination = :tree)
63 ["Branch", @project.repo.heads.map(&:name) ],
64 [ "Tag", @project.tags ]
67 # If reference is commit id -
68 # we should add it to branch/tag selectbox
69 if(@ref && !options.flatten.include?(@ref) &&
70 @ref =~ /^[0-9a-zA-Z]{6,52}$/)
71 options << ["Commit", [@ref]]
74 grouped_options_for_select(options, @ref || @project.default_branch)
77 def search_autocomplete_source
78 projects = current_user.projects.map{ |p| { label: p.name, url: project_path(p) } }
80 { label: "Profile", url: profile_path },
81 { label: "Keys", url: keys_path },
82 { label: "Dashboard", url: root_path },
83 { label: "Admin", url: admin_root_path }
88 if @project && !@project.new_record?
90 { label: "#{@project.name} / Issues", url: project_issues_path(@project) },
91 { label: "#{@project.name} / Wall", url: wall_project_path(@project) },
92 { label: "#{@project.name} / Tree", url: project_tree_path(@project, @ref || @project.root_ref) },
93 { label: "#{@project.name} / Commits", url: project_commits_path(@project, @ref || @project.root_ref) },
94 { label: "#{@project.name} / Team", url: project_team_index_path(@project) }
98 [projects, default_nav, project_nav].flatten.to_json
102 Devise.omniauth_providers.include?(:ldap)
106 Gitlab::Theme.css_class_by_id(current_user.try(:theme_id))
109 def show_last_push_widget?(event)
111 event.last_push_to_non_root? &&
114 event.project.merge_requests_enabled
117 def hexdigest(string)
118 Digest::SHA1.hexdigest string
121 def project_last_activity project
122 activity = project.last_activity
123 if activity && activity.created_at
124 time_ago_in_words(activity.created_at) + " ago"
130 def authbutton(provider, size = 64)
131 file_name = "#{provider.to_s.split('_').first}_#{size}.png"
132 image_tag("authbuttons/#{file_name}",
133 alt: "Sign in with #{provider.to_s.titleize}")