@@ -1,110 +1,110 | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | # |
|
3 | 3 | # Redmine - project management software |
|
4 | 4 | # Copyright (C) 2006-2011 Jean-Philippe Lang |
|
5 | 5 | # |
|
6 | 6 | # This program is free software; you can redistribute it and/or |
|
7 | 7 | # modify it under the terms of the GNU General Public License |
|
8 | 8 | # as published by the Free Software Foundation; either version 2 |
|
9 | 9 | # of the License, or (at your option) any later version. |
|
10 | 10 | # |
|
11 | 11 | # This program is distributed in the hope that it will be useful, |
|
12 | 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 | 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 | 14 | # GNU General Public License for more details. |
|
15 | 15 | # |
|
16 | 16 | # You should have received a copy of the GNU General Public License |
|
17 | 17 | # along with this program; if not, write to the Free Software |
|
18 | 18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
19 | 19 | |
|
20 | 20 | module ProjectsHelper |
|
21 | 21 | def link_to_version(version, options = {}) |
|
22 | 22 | return '' unless version && version.is_a?(Version) |
|
23 | 23 | link_to_if version.visible?, format_version_name(version), { :controller => 'versions', :action => 'show', :id => version }, options |
|
24 | 24 | end |
|
25 | 25 | |
|
26 | 26 | def project_settings_tabs |
|
27 | 27 | tabs = [{:name => 'info', :action => :edit_project, :partial => 'projects/edit', :label => :label_information_plural}, |
|
28 | 28 | {:name => 'modules', :action => :select_project_modules, :partial => 'projects/settings/modules', :label => :label_module_plural}, |
|
29 | 29 | {:name => 'members', :action => :manage_members, :partial => 'projects/settings/members', :label => :label_member_plural}, |
|
30 | 30 | {:name => 'versions', :action => :manage_versions, :partial => 'projects/settings/versions', :label => :label_version_plural}, |
|
31 | 31 | {:name => 'categories', :action => :manage_categories, :partial => 'projects/settings/issue_categories', :label => :label_issue_category_plural}, |
|
32 | 32 | {:name => 'wiki', :action => :manage_wiki, :partial => 'projects/settings/wiki', :label => :label_wiki}, |
|
33 | {:name => 'repositories', :action => :manage_repository, :partial => 'projects/settings/repositories', :label => :label_repository}, | |
|
33 | {:name => 'repositories', :action => :manage_repository, :partial => 'projects/settings/repositories', :label => :label_repository_plural}, | |
|
34 | 34 | {:name => 'boards', :action => :manage_boards, :partial => 'projects/settings/boards', :label => :label_board_plural}, |
|
35 | 35 | {:name => 'activities', :action => :manage_project_activities, :partial => 'projects/settings/activities', :label => :enumeration_activities} |
|
36 | 36 | ] |
|
37 | 37 | tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)} |
|
38 | 38 | end |
|
39 | 39 | |
|
40 | 40 | def parent_project_select_tag(project) |
|
41 | 41 | selected = project.parent |
|
42 | 42 | # retrieve the requested parent project |
|
43 | 43 | parent_id = (params[:project] && params[:project][:parent_id]) || params[:parent_id] |
|
44 | 44 | if parent_id |
|
45 | 45 | selected = (parent_id.blank? ? nil : Project.find(parent_id)) |
|
46 | 46 | end |
|
47 | 47 | |
|
48 | 48 | options = '' |
|
49 | 49 | options << "<option value=''></option>" if project.allowed_parents.include?(nil) |
|
50 | 50 | options << project_tree_options_for_select(project.allowed_parents.compact, :selected => selected) |
|
51 | 51 | content_tag('select', options.html_safe, :name => 'project[parent_id]', :id => 'project_parent_id') |
|
52 | 52 | end |
|
53 | 53 | |
|
54 | 54 | # Renders a tree of projects as a nested set of unordered lists |
|
55 | 55 | # The given collection may be a subset of the whole project tree |
|
56 | 56 | # (eg. some intermediate nodes are private and can not be seen) |
|
57 | 57 | def render_project_hierarchy(projects) |
|
58 | 58 | s = '' |
|
59 | 59 | if projects.any? |
|
60 | 60 | ancestors = [] |
|
61 | 61 | original_project = @project |
|
62 | 62 | projects.each do |project| |
|
63 | 63 | # set the project environment to please macros. |
|
64 | 64 | @project = project |
|
65 | 65 | if (ancestors.empty? || project.is_descendant_of?(ancestors.last)) |
|
66 | 66 | s << "<ul class='projects #{ ancestors.empty? ? 'root' : nil}'>\n" |
|
67 | 67 | else |
|
68 | 68 | ancestors.pop |
|
69 | 69 | s << "</li>" |
|
70 | 70 | while (ancestors.any? && !project.is_descendant_of?(ancestors.last)) |
|
71 | 71 | ancestors.pop |
|
72 | 72 | s << "</ul></li>\n" |
|
73 | 73 | end |
|
74 | 74 | end |
|
75 | 75 | classes = (ancestors.empty? ? 'root' : 'child') |
|
76 | 76 | s << "<li class='#{classes}'><div class='#{classes}'>" + |
|
77 | 77 | link_to_project(project, {}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}") |
|
78 | 78 | s << "<div class='wiki description'>#{textilizable(project.short_description, :project => project)}</div>" unless project.description.blank? |
|
79 | 79 | s << "</div>\n" |
|
80 | 80 | ancestors << project |
|
81 | 81 | end |
|
82 | 82 | s << ("</li></ul>\n" * ancestors.size) |
|
83 | 83 | @project = original_project |
|
84 | 84 | end |
|
85 | 85 | s.html_safe |
|
86 | 86 | end |
|
87 | 87 | |
|
88 | 88 | # Returns a set of options for a select field, grouped by project. |
|
89 | 89 | def version_options_for_select(versions, selected=nil) |
|
90 | 90 | grouped = Hash.new {|h,k| h[k] = []} |
|
91 | 91 | versions.each do |version| |
|
92 | 92 | grouped[version.project.name] << [version.name, version.id] |
|
93 | 93 | end |
|
94 | 94 | # Add in the selected |
|
95 | 95 | if selected && !versions.include?(selected) |
|
96 | 96 | grouped[selected.project.name] << [selected.name, selected.id] |
|
97 | 97 | end |
|
98 | 98 | |
|
99 | 99 | if grouped.keys.size > 1 |
|
100 | 100 | grouped_options_for_select(grouped, selected && selected.id) |
|
101 | 101 | else |
|
102 | 102 | options_for_select((grouped.values.first || []), selected && selected.id) |
|
103 | 103 | end |
|
104 | 104 | end |
|
105 | 105 | |
|
106 | 106 | def format_version_sharing(sharing) |
|
107 | 107 | sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing) |
|
108 | 108 | l("label_version_sharing_#{sharing}") |
|
109 | 109 | end |
|
110 | 110 | end |
General Comments 0
You need to be logged in to leave comments.
Login now