OSDN Git Service

Include gitlab-shell in patch update doc
[wvm/gitlab.git] / app / helpers / projects_helper.rb
1 module ProjectsHelper
2   def remove_from_project_team_message(project, user)
3     "You are going to remove #{user.name} from #{project.name} project team. Are you sure?"
4   end
5
6   def link_to_project project
7     link_to project do
8       title = content_tag(:span, project.name, class: 'projet-name')
9
10       if project.namespace
11         namespace = content_tag(:span, "#{project.namespace.human_name} / ", class: 'namespace-name')
12         title = namespace + title
13       end
14
15       title
16     end
17   end
18
19   def link_to_member(project, author, opts = {})
20     default_opts = { avatar: true, name: true, size: 16 }
21     opts = default_opts.merge(opts)
22
23     return "(deleted)" unless author
24
25     author_html =  ""
26
27     # Build avatar image tag
28     author_html << image_tag(avatar_icon(author.try(:email), opts[:size]), width: opts[:size], class: "avatar avatar-inline #{"s#{opts[:size]}" if opts[:size]}", alt:'') if opts[:avatar]
29
30     # Build name span tag
31     author_html << content_tag(:span, sanitize(author.name), class: 'author') if opts[:name]
32
33     author_html = author_html.html_safe
34
35     if opts[:name]
36       link_to(author_html, user_path(author), class: "author_link").html_safe
37     else
38       link_to(author_html, user_path(author), class: "author_link has_tooltip", data: { :'original-title' => sanitize(author.name) } ).html_safe
39     end
40   end
41
42   def project_title project
43     if project.group
44       content_tag :span do
45         link_to(simple_sanitize(project.group.name), group_path(project.group)) + " / " + project.name
46       end
47     else
48       project.name
49     end
50   end
51
52   def remove_project_message(project)
53     "You are going to remove #{project.name_with_namespace}.\n Removed project CANNOT be restored!\n Are you ABSOLUTELY sure?"
54   end
55
56   def project_nav_tabs
57     @nav_tabs ||= get_project_nav_tabs(@project, current_user)
58   end
59
60   def project_nav_tab?(name)
61     project_nav_tabs.include? name
62   end
63
64   def project_filter_path(options={})
65     exist_opts = {
66       state: params[:state],
67       scope: params[:scope],
68       label_name: params[:label_name],
69       milestone_id: params[:milestone_id],
70     }
71
72     options = exist_opts.merge(options)
73
74     path = request.path
75     path << "?#{options.to_param}"
76     path
77   end
78
79   def project_active_milestones
80     @project.milestones.active.order("due_date, title ASC").all
81   end
82
83   def project_issues_trackers
84     values = Project.issues_tracker.values.map do |tracker_key|
85       if tracker_key.to_sym == :gitlab
86         ['GitLab', tracker_key]
87       else
88         [Gitlab.config.issues_tracker[tracker_key]['title'] || tracker_key, tracker_key]
89       end
90     end
91
92     options_for_select(values)
93   end
94
95   private
96
97   def get_project_nav_tabs(project, current_user)
98     nav_tabs = [:home]
99
100     if !project.empty_repo? && can?(current_user, :download_code, project)
101       nav_tabs << [:files, :commits, :network, :graphs]
102     end
103
104     if project.repo_exists? && project.merge_requests_enabled
105       nav_tabs << :merge_requests
106     end
107
108     if can?(current_user, :admin_project, project)
109       nav_tabs << :settings
110     end
111
112     [:issues, :wiki, :wall, :snippets].each do |feature|
113       nav_tabs << feature if project.send :"#{feature}_enabled"
114     end
115
116     nav_tabs.flatten
117   end
118
119   def git_user_name
120     if current_user
121       current_user.name
122     else
123       "Your name"
124     end
125   end
126
127   def git_user_email
128     if current_user
129       current_user.email
130     else
131       "your@email.com"
132     end
133   end
134
135   def repository_size
136     "#{@project.repository.size} MB"
137   rescue
138     # In order to prevent 500 error
139     # when application cannot allocate memory
140     # to calculate repo size - just show 'Unknown'
141     'unknown'
142   end
143 end