To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / helpers / projects_helper.rb @ 420:2008fa7fda29

History | View | Annotate | Download (9.5 KB)

1 0:513646585e45 Chris
# redMine - project management software
2
# Copyright (C) 2006  Jean-Philippe Lang
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17
18
module ProjectsHelper
19
  def link_to_version(version, options = {})
20
    return '' unless version && version.is_a?(Version)
21
    link_to_if version.visible?, format_version_name(version), { :controller => 'versions', :action => 'show', :id => version }, options
22
  end
23
24
  def project_settings_tabs
25
    tabs = [{:name => 'info', :action => :edit_project, :partial => 'projects/edit', :label => :label_information_plural},
26 354:8c804ce943db chris
            {:name => 'overview', :action => :edit_project, :partial => 'projects/settings/overview', :label => :label_welcome_page},
27 0:513646585e45 Chris
            {:name => 'modules', :action => :select_project_modules, :partial => 'projects/settings/modules', :label => :label_module_plural},
28
            {:name => 'members', :action => :manage_members, :partial => 'projects/settings/members', :label => :label_member_plural},
29
            {:name => 'versions', :action => :manage_versions, :partial => 'projects/settings/versions', :label => :label_version_plural},
30
            {:name => 'categories', :action => :manage_categories, :partial => 'projects/settings/issue_categories', :label => :label_issue_category_plural},
31
            {:name => 'wiki', :action => :manage_wiki, :partial => 'projects/settings/wiki', :label => :label_wiki},
32
            {:name => 'repository', :action => :manage_repository, :partial => 'projects/settings/repository', :label => :label_repository},
33
            {:name => 'boards', :action => :manage_boards, :partial => 'projects/settings/boards', :label => :label_board_plural},
34
            {:name => 'activities', :action => :manage_project_activities, :partial => 'projects/settings/activities', :label => :enumeration_activities}
35
            ]
36
    tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)}
37
  end
38
39
  def parent_project_select_tag(project)
40
    selected = project.parent
41
    # retrieve the requested parent project
42
    parent_id = (params[:project] && params[:project][:parent_id]) || params[:parent_id]
43
    if parent_id
44
      selected = (parent_id.blank? ? nil : Project.find(parent_id))
45
    end
46
47
    options = ''
48
    options << "<option value=''></option>" if project.allowed_parents.include?(nil)
49
    options << project_tree_options_for_select(project.allowed_parents.compact, :selected => selected)
50
    content_tag('select', options, :name => 'project[parent_id]', :id => 'project_parent_id')
51
  end
52 335:7acd282bee3c chris
53
  def render_project_short_description(project)
54
    s = ''
55
    if (project.short_description)
56
      s << "<div class='description'>"
57
      s << textilizable(project.short_description, :project => project).gsub(/<[^>]+>/, '')
58
      s << "</div>"
59
    end
60
    s
61
  end
62 0:513646585e45 Chris
63
  # Renders a tree of projects as a nested set of unordered lists
64
  # The given collection may be a subset of the whole project tree
65
  # (eg. some intermediate nodes are private and can not be seen)
66
  def render_project_hierarchy(projects)
67
    s = ''
68
    if projects.any?
69
      ancestors = []
70
      original_project = @project
71
      projects.each do |project|
72
        # set the project environment to please macros.
73
        @project = project
74
        if (ancestors.empty? || project.is_descendant_of?(ancestors.last))
75
          s << "<ul class='projects #{ ancestors.empty? ? 'root' : nil}'>\n"
76
        else
77
          ancestors.pop
78
          s << "</li>"
79
          while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
80
            ancestors.pop
81
            s << "</ul></li>\n"
82
          end
83
        end
84
        classes = (ancestors.empty? ? 'root' : 'child')
85
        s << "<li class='#{classes}'><div class='#{classes}'>" +
86 14:1d32c0a0efbf Chris
               link_to_project(project, {}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}")
87 335:7acd282bee3c chris
        s << render_project_short_description(project)
88 0:513646585e45 Chris
        s << "</div>\n"
89
        ancestors << project
90
      end
91
      s << ("</li></ul>\n" * ancestors.size)
92
      @project = original_project
93
    end
94
    s
95
  end
96
97 68:60c0a4e08e09 luisf
98 420:2008fa7fda29 chris
  def render_my_project_in_hierarchy(project)
99
100
    s = ''
101
102
    if User.current.member_of?(project)
103
104
      # set the project environment to please macros.
105
      @project = project
106
107
      classes = (project.root? ? 'root' : 'child')
108
109
      s << "<li class='#{classes}'><div class='#{classes}'>" +
110
        link_to_project(project, {}, :class => "project my-project")
111
      if project.is_public?
112
        s << " <span class='public'>" << l("field_is_public") << "</span>"
113
      else
114
        s << " <span class='private'>" << l("field_is_private") << "</span>"
115
      end
116
      s << render_project_short_description(project)
117
      s << "</div>\n"
118
119
      cs = ''
120
      project.children.each do |child|
121
        cs << render_my_project_in_hierarchy(child)
122
      end
123
124
      if cs != ''
125
        s << "<ul class='projects'>\n" << cs << "</ul>\n";
126
      end
127
128
    end
129
130
    s
131
132
  end
133
134 68:60c0a4e08e09 luisf
  # Renders a tree of projects where the current user belongs
135
  # as a nested set of unordered lists
136
  # The given collection may be a subset of the whole project tree
137
  # (eg. some intermediate nodes are private and can not be seen)
138
  def render_my_project_hierarchy(projects)
139 420:2008fa7fda29 chris
140 68:60c0a4e08e09 luisf
    s = ''
141 69:dc22c3eb3c81 luisf
142 420:2008fa7fda29 chris
    original_project = @project
143 69:dc22c3eb3c81 luisf
144 420:2008fa7fda29 chris
    projects.each do |project|
145
      if project.root? || !projects.include?(project.parent)
146
        s << render_my_project_in_hierarchy(project)
147
      end
148 68:60c0a4e08e09 luisf
    end
149 69:dc22c3eb3c81 luisf
150 420:2008fa7fda29 chris
    @project = original_project
151
152
    if s != ''
153
      a = ''
154 69:dc22c3eb3c81 luisf
      a << "<h2>"
155
      a <<  l("label_my_project_plural")
156
      a << "</h2>"
157 420:2008fa7fda29 chris
      a << "<ul class='projects root'>\n"
158 69:dc22c3eb3c81 luisf
      a << s
159 420:2008fa7fda29 chris
      a << "</ul>\n"
160
      s = a
161 69:dc22c3eb3c81 luisf
    end
162 420:2008fa7fda29 chris
163
    s
164 69:dc22c3eb3c81 luisf
165 68:60c0a4e08e09 luisf
  end
166
167 132:ab611b7c7ecc chris
  # Renders a tree of projects that the current user does not belong
168
  # to, or of all projects if the current user is not logged in.  The
169
  # given collection may be a subset of the whole project tree
170
  # (eg. some intermediate nodes are private and can not be seen).  We
171
  # are potentially interested in various things: the project name,
172
  # description, manager(s), creation date, last activity date,
173
  # general activity level, whether there is anything actually hosted
174
  # here for the project, etc.
175
  def render_project_table(projects)
176 68:60c0a4e08e09 luisf
177 132:ab611b7c7ecc chris
    s = ""
178
    s << "<div class='autoscroll'>"
179
    s << "<table class='list projects'>"
180
    s << "<thead><tr>"
181
182 205:05f9a2a9c753 chris
    s << sort_header_tag('name', :caption => l("field_name"))
183 132:ab611b7c7ecc chris
    s << "<th class='managers'>" << l("label_managers") << "</th>"
184
    s << sort_header_tag('created_on', :default_order => 'desc')
185
    s << sort_header_tag('updated_on', :default_order => 'desc')
186 100:1412841d48a3 Chris
187 132:ab611b7c7ecc chris
    s << "</tr></thead><tbody>"
188 68:60c0a4e08e09 luisf
189 132:ab611b7c7ecc chris
    original_project = @project
190 68:60c0a4e08e09 luisf
191 132:ab611b7c7ecc chris
    projects.each do |project|
192 205:05f9a2a9c753 chris
      s << render_project_in_table(project, cycle('odd', 'even'), 0)
193 68:60c0a4e08e09 luisf
    end
194 69:dc22c3eb3c81 luisf
195 132:ab611b7c7ecc chris
    s << "</table>"
196 69:dc22c3eb3c81 luisf
197 132:ab611b7c7ecc chris
    @project = original_project
198
199
    s
200 68:60c0a4e08e09 luisf
  end
201
202
203 205:05f9a2a9c753 chris
  def render_project_in_table(project, oddeven, level)
204
205
    # set the project environment to please macros.
206
    @project = project
207
208
    classes = (level == 0 ? 'root' : 'child')
209
210
    s = ""
211
212
    s << "<tr class='#{oddeven} #{classes} level#{level}'>"
213
    s << "<td class='firstcol' align=top><div class='name hosted_here"
214
    s << " no_description" if project.description.blank?
215
    s << "'>" << link_to_project(project, {}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}");
216
    s << "</div>"
217 335:7acd282bee3c chris
    s << render_project_short_description(project)
218 205:05f9a2a9c753 chris
219
    s << "<td class='managers' align=top>"
220
221
    u = project.users_by_role
222
    if u
223
      u.keys.each do |r|
224
        if r.allowed_to?(:edit_project)
225
          mgrs = []
226
          u[r].sort.each do |m|
227
            mgrs << link_to_user(m)
228
          end
229
          if mgrs.size < 3
230
            s << '<nobr>' << mgrs.join(', ') << '</nobr>'
231
          else
232
            s << mgrs.join(', ')
233
          end
234
        end
235
      end
236
    end
237
238
    s << "</td>"
239
    s << "<td class='created_on' align=top>" << format_date(project.created_on) << "</td>"
240
    s << "<td class='updated_on' align=top>" << format_date(project.updated_on) << "</td>"
241
242
    s << "</tr>"
243
244
    project.children.each do |child|
245 414:576a1dca2ee2 chris
      if child.is_public? or User.current.member_of?(child)
246
        s << render_project_in_table(child, oddeven, level + 1)
247
      end
248 205:05f9a2a9c753 chris
    end
249
250
    s
251
  end
252
253 68:60c0a4e08e09 luisf
254 0:513646585e45 Chris
  # Returns a set of options for a select field, grouped by project.
255
  def version_options_for_select(versions, selected=nil)
256
    grouped = Hash.new {|h,k| h[k] = []}
257
    versions.each do |version|
258
      grouped[version.project.name] << [version.name, version.id]
259
    end
260
    # Add in the selected
261
    if selected && !versions.include?(selected)
262
      grouped[selected.project.name] << [selected.name, selected.id]
263
    end
264
265
    if grouped.keys.size > 1
266
      grouped_options_for_select(grouped, selected && selected.id)
267
    else
268
      options_for_select((grouped.values.first || []), selected && selected.id)
269
    end
270
  end
271
272
  def format_version_sharing(sharing)
273
    sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing)
274
    l("label_version_sharing_#{sharing}")
275
  end
276
end