2 module ApplicationHelper
4 def gravatar_icon(user_email = '', size = 40)
5 if Gitlab.config.disable_gravatar? || user_email.blank?
8 gravatar_prefix = request.ssl? ? "https://secure" : "http://www"
10 "#{gravatar_prefix}.gravatar.com/avatar/#{Digest::MD5.hexdigest(user_email.downcase)}?s=#{size}&d=identicon"
15 request.ssl? ? "https" : "http"
19 "#{request_protocol}://#{Gitlab.config.web_host}/"
22 def last_commit(project)
23 if project.repo_exists?
24 time_ago_in_words(project.commit.committed_date) + " ago"
32 def grouped_options_refs(destination = :tree)
34 ["Branch", @project.repo.heads.map(&:name) ],
35 [ "Tag", @project.tags ]
38 # If reference is commit id -
39 # we should add it to branch/tag selectbox
40 if(@ref && !options.flatten.include?(@ref) &&
41 @ref =~ /^[0-9a-zA-Z]{6,52}$/)
42 options << ["Commit", [@ref]]
45 grouped_options_for_select(options, @ref || @project.default_branch)
48 def search_autocomplete_source
49 projects = current_user.projects.map{ |p| { label: p.name, url: project_path(p) } }
51 { label: "Profile", url: profile_path },
52 { label: "Keys", url: keys_path },
53 { label: "Dashboard", url: root_path },
54 { label: "Admin", url: admin_root_path }
59 if @project && !@project.new_record?
61 { label: "#{@project.name} / Issues", url: project_issues_path(@project) },
62 { label: "#{@project.name} / Wall", url: wall_project_path(@project) },
63 { label: "#{@project.name} / Tree", url: tree_project_ref_path(@project, @project.root_ref) },
64 { label: "#{@project.name} / Commits", url: project_commits_path(@project) },
65 { label: "#{@project.name} / Team", url: project_team_index_path(@project) }
69 [projects, default_nav, project_nav].flatten.to_json
73 Devise.omniauth_providers.include?(:ldap)
77 Gitlab::Theme.css_class_by_id(current_user.try(:theme_id))
80 def show_last_push_widget?(event)
82 event.last_push_to_non_root? &&
85 event.project.merge_requests_enabled
88 def tab_class(tab_key)
93 when :wiki; controller.controller_name == "wikis"
94 when :issues; issues_tab?
95 when :network; current_page?(controller: "projects", action: "graph", id: @project)
96 when :merge_requests; controller.controller_name == "merge_requests"
99 when :help; controller.controller_name == "help"
100 when :search; current_page?(search_path)
101 when :dash_issues; current_page?(dashboard_issues_path)
102 when :dash_mr; current_page?(dashboard_merge_requests_path)
103 when :root; current_page?(dashboard_path) || current_page?(root_path)
106 when :profile; current_page?(controller: "profile", action: :show)
107 when :history; current_page?(controller: "profile", action: :history)
108 when :account; current_page?(controller: "profile", action: :account)
109 when :token; current_page?(controller: "profile", action: :token)
110 when :design; current_page?(controller: "profile", action: :design)
111 when :ssh_keys; controller.controller_name == "keys"
114 when :admin_root; controller.controller_name == "dashboard"
115 when :admin_users; controller.controller_name == 'users'
116 when :admin_projects; controller.controller_name == "projects"
117 when :admin_hooks; controller.controller_name == 'hooks'
118 when :admin_resque; controller.controller_name == 'resque'
119 when :admin_logs; controller.controller_name == 'logs'
124 active ? "current" : nil
127 def hexdigest(string)
128 Digest::SHA1.hexdigest string
131 def project_last_activity project
132 activity = project.last_activity
133 if activity && activity.created_at
134 time_ago_in_words(activity.created_at) + " ago"
140 def authbutton(provider, size = 64)
141 file_name = "#{provider.to_s.split('_').first}_#{size}.png"
142 image_tag("authbuttons/#{file_name}",
143 alt: "Sign in with #{provider.to_s.titleize}")