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 @ 416:165e443660c4

History | View | Annotate | Download (9.7 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
  # Renders a tree of projects where the current user belongs
99
  # as a nested set of unordered lists
100
  # The given collection may be a subset of the whole project tree
101
  # (eg. some intermediate nodes are private and can not be seen)
102
  def render_my_project_hierarchy(projects)
103
    s = ''
104 69:dc22c3eb3c81 luisf
105
    a = ''
106
107
    # Flag to tell if user has any projects
108
    t = FALSE
109 68:60c0a4e08e09 luisf
110
    if projects.any?
111
      ancestors = []
112
      original_project = @project
113
      projects.each do |project|
114
        # set the project environment to please macros.
115
116
        @project = project
117
118
        if User.current.member_of?(project):
119
120 69:dc22c3eb3c81 luisf
          t = TRUE
121
122 68:60c0a4e08e09 luisf
          if (ancestors.empty? || project.is_descendant_of?(ancestors.last))
123
            s << "<ul class='projects #{ ancestors.empty? ? 'root' : nil}'>\n"
124
          else
125
            ancestors.pop
126
            s << "</li>"
127
            while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
128
              ancestors.pop
129
              s << "</ul></li>\n"
130
            end
131
          end
132
133
          classes = (ancestors.empty? ? 'root' : 'child')
134
          s << "<li class='#{classes}'><div class='#{classes}'>" +
135 133:1890a968b404 chris
                 link_to_project(project, {}, :class => "project my-project")
136
          if project.is_public?
137
            s << " <span class='public'>" << l("field_is_public") << "</span>"
138
          else
139
            s << " <span class='private'>" << l("field_is_private") << "</span>"
140
          end
141 335:7acd282bee3c chris
          s << render_project_short_description(project)
142 68:60c0a4e08e09 luisf
          s << "</div>\n"
143
          ancestors << project
144
        end
145
       end
146
        s << ("</li></ul>\n" * ancestors.size)
147
        @project = original_project
148
    end
149 69:dc22c3eb3c81 luisf
150
    if t == TRUE
151
      a << "<h2>"
152
      a <<  l("label_my_project_plural")
153
      a << "</h2>"
154
      a << s
155
    else
156
      a = s
157
    end
158
159
    a
160 68:60c0a4e08e09 luisf
  end
161
162 132:ab611b7c7ecc chris
  # Renders a tree of projects that the current user does not belong
163
  # to, or of all projects if the current user is not logged in.  The
164
  # given collection may be a subset of the whole project tree
165
  # (eg. some intermediate nodes are private and can not be seen).  We
166
  # are potentially interested in various things: the project name,
167
  # description, manager(s), creation date, last activity date,
168
  # general activity level, whether there is anything actually hosted
169
  # here for the project, etc.
170
  def render_project_table(projects)
171 68:60c0a4e08e09 luisf
172 132:ab611b7c7ecc chris
    s = ""
173
    s << "<div class='autoscroll'>"
174
    s << "<table class='list projects'>"
175
    s << "<thead><tr>"
176
177 205:05f9a2a9c753 chris
    s << sort_header_tag('name', :caption => l("field_name"))
178 132:ab611b7c7ecc chris
    s << "<th class='managers'>" << l("label_managers") << "</th>"
179
    s << sort_header_tag('created_on', :default_order => 'desc')
180
    s << sort_header_tag('updated_on', :default_order => 'desc')
181 100:1412841d48a3 Chris
182 132:ab611b7c7ecc chris
    s << "</tr></thead><tbody>"
183 68:60c0a4e08e09 luisf
184 132:ab611b7c7ecc chris
    original_project = @project
185 68:60c0a4e08e09 luisf
186 132:ab611b7c7ecc chris
    projects.each do |project|
187 205:05f9a2a9c753 chris
      s << render_project_in_table(project, cycle('odd', 'even'), 0)
188 68:60c0a4e08e09 luisf
    end
189 69:dc22c3eb3c81 luisf
190 132:ab611b7c7ecc chris
    s << "</table>"
191 69:dc22c3eb3c81 luisf
192 132:ab611b7c7ecc chris
    @project = original_project
193
194
    s
195 68:60c0a4e08e09 luisf
  end
196
197
198 205:05f9a2a9c753 chris
  def render_project_in_table(project, oddeven, level)
199
200
    # set the project environment to please macros.
201
    @project = project
202
203
    classes = (level == 0 ? 'root' : 'child')
204
205
    s = ""
206
207
    s << "<tr class='#{oddeven} #{classes} level#{level}'>"
208
    s << "<td class='firstcol' align=top><div class='name hosted_here"
209
    s << " no_description" if project.description.blank?
210
    s << "'>" << link_to_project(project, {}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}");
211
    s << "</div>"
212 335:7acd282bee3c chris
    s << render_project_short_description(project)
213 205:05f9a2a9c753 chris
214
    s << "<td class='managers' align=top>"
215
216
    u = project.users_by_role
217
    if u
218
      u.keys.each do |r|
219
        if r.allowed_to?(:edit_project)
220
          mgrs = []
221
          u[r].sort.each do |m|
222
            mgrs << link_to_user(m)
223
          end
224
          if mgrs.size < 3
225
            s << '<nobr>' << mgrs.join(', ') << '</nobr>'
226
          else
227
            s << mgrs.join(', ')
228
          end
229
        end
230
      end
231
    end
232
233
    s << "</td>"
234
    s << "<td class='created_on' align=top>" << format_date(project.created_on) << "</td>"
235
    s << "<td class='updated_on' align=top>" << format_date(project.updated_on) << "</td>"
236
237
    s << "</tr>"
238
239
    project.children.each do |child|
240 414:576a1dca2ee2 chris
      if child.is_public? or User.current.member_of?(child)
241
        s << render_project_in_table(child, oddeven, level + 1)
242
      end
243 205:05f9a2a9c753 chris
    end
244
245
    s
246
  end
247
248 68:60c0a4e08e09 luisf
249 0:513646585e45 Chris
  # Returns a set of options for a select field, grouped by project.
250
  def version_options_for_select(versions, selected=nil)
251
    grouped = Hash.new {|h,k| h[k] = []}
252
    versions.each do |version|
253
      grouped[version.project.name] << [version.name, version.id]
254
    end
255
    # Add in the selected
256
    if selected && !versions.include?(selected)
257
      grouped[selected.project.name] << [selected.name, selected.id]
258
    end
259
260
    if grouped.keys.size > 1
261
      grouped_options_for_select(grouped, selected && selected.id)
262
    else
263
      options_for_select((grouped.values.first || []), selected && selected.id)
264
    end
265
  end
266
267
  def format_version_sharing(sharing)
268
    sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing)
269
    l("label_version_sharing_#{sharing}")
270
  end
271
end