To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / app / helpers / .svn / text-base / projects_helper.rb.svn-base @ 441:cbce1fd3b1b7
History | View | Annotate | Download (5.07 KB)
| 1 | 441:cbce1fd3b1b7 | Chris | # Redmine - project management software |
|---|---|---|---|
| 2 | # Copyright (C) 2006-2011 Jean-Philippe Lang |
||
| 3 | 0:513646585e45 | Chris | # |
| 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 | 441:cbce1fd3b1b7 | Chris | # |
| 9 | 0:513646585e45 | Chris | # 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 | 441:cbce1fd3b1b7 | Chris | # |
| 14 | 0:513646585e45 | Chris | # 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 | 441:cbce1fd3b1b7 | Chris | |
| 24 | 0:513646585e45 | Chris | def project_settings_tabs |
| 25 | tabs = [{:name => 'info', :action => :edit_project, :partial => 'projects/edit', :label => :label_information_plural},
|
||
| 26 | {:name => 'modules', :action => :select_project_modules, :partial => 'projects/settings/modules', :label => :label_module_plural},
|
||
| 27 | {:name => 'members', :action => :manage_members, :partial => 'projects/settings/members', :label => :label_member_plural},
|
||
| 28 | {:name => 'versions', :action => :manage_versions, :partial => 'projects/settings/versions', :label => :label_version_plural},
|
||
| 29 | {:name => 'categories', :action => :manage_categories, :partial => 'projects/settings/issue_categories', :label => :label_issue_category_plural},
|
||
| 30 | {:name => 'wiki', :action => :manage_wiki, :partial => 'projects/settings/wiki', :label => :label_wiki},
|
||
| 31 | {:name => 'repository', :action => :manage_repository, :partial => 'projects/settings/repository', :label => :label_repository},
|
||
| 32 | {:name => 'boards', :action => :manage_boards, :partial => 'projects/settings/boards', :label => :label_board_plural},
|
||
| 33 | {:name => 'activities', :action => :manage_project_activities, :partial => 'projects/settings/activities', :label => :enumeration_activities}
|
||
| 34 | ] |
||
| 35 | 441:cbce1fd3b1b7 | Chris | tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)}
|
| 36 | 0:513646585e45 | Chris | end |
| 37 | 441:cbce1fd3b1b7 | Chris | |
| 38 | 0:513646585e45 | Chris | def parent_project_select_tag(project) |
| 39 | selected = project.parent |
||
| 40 | # retrieve the requested parent project |
||
| 41 | parent_id = (params[:project] && params[:project][:parent_id]) || params[:parent_id] |
||
| 42 | if parent_id |
||
| 43 | selected = (parent_id.blank? ? nil : Project.find(parent_id)) |
||
| 44 | end |
||
| 45 | 441:cbce1fd3b1b7 | Chris | |
| 46 | 0:513646585e45 | Chris | options = '' |
| 47 | options << "<option value=''></option>" if project.allowed_parents.include?(nil) |
||
| 48 | options << project_tree_options_for_select(project.allowed_parents.compact, :selected => selected) |
||
| 49 | content_tag('select', options, :name => 'project[parent_id]', :id => 'project_parent_id')
|
||
| 50 | end |
||
| 51 | 441:cbce1fd3b1b7 | Chris | |
| 52 | 0:513646585e45 | Chris | # Renders a tree of projects as a nested set of unordered lists |
| 53 | # The given collection may be a subset of the whole project tree |
||
| 54 | # (eg. some intermediate nodes are private and can not be seen) |
||
| 55 | def render_project_hierarchy(projects) |
||
| 56 | s = '' |
||
| 57 | if projects.any? |
||
| 58 | ancestors = [] |
||
| 59 | original_project = @project |
||
| 60 | projects.each do |project| |
||
| 61 | # set the project environment to please macros. |
||
| 62 | @project = project |
||
| 63 | if (ancestors.empty? || project.is_descendant_of?(ancestors.last)) |
||
| 64 | s << "<ul class='projects #{ ancestors.empty? ? 'root' : nil}'>\n"
|
||
| 65 | else |
||
| 66 | ancestors.pop |
||
| 67 | s << "</li>" |
||
| 68 | 441:cbce1fd3b1b7 | Chris | while (ancestors.any? && !project.is_descendant_of?(ancestors.last)) |
| 69 | 0:513646585e45 | Chris | ancestors.pop |
| 70 | s << "</ul></li>\n" |
||
| 71 | end |
||
| 72 | end |
||
| 73 | classes = (ancestors.empty? ? 'root' : 'child') |
||
| 74 | s << "<li class='#{classes}'><div class='#{classes}'>" +
|
||
| 75 | 14:1d32c0a0efbf | Chris | link_to_project(project, {}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}")
|
| 76 | 0:513646585e45 | Chris | s << "<div class='wiki description'>#{textilizable(project.short_description, :project => project)}</div>" unless project.description.blank?
|
| 77 | s << "</div>\n" |
||
| 78 | ancestors << project |
||
| 79 | end |
||
| 80 | s << ("</li></ul>\n" * ancestors.size)
|
||
| 81 | @project = original_project |
||
| 82 | end |
||
| 83 | s |
||
| 84 | end |
||
| 85 | |||
| 86 | # Returns a set of options for a select field, grouped by project. |
||
| 87 | def version_options_for_select(versions, selected=nil) |
||
| 88 | grouped = Hash.new {|h,k| h[k] = []}
|
||
| 89 | versions.each do |version| |
||
| 90 | grouped[version.project.name] << [version.name, version.id] |
||
| 91 | end |
||
| 92 | # Add in the selected |
||
| 93 | if selected && !versions.include?(selected) |
||
| 94 | grouped[selected.project.name] << [selected.name, selected.id] |
||
| 95 | end |
||
| 96 | 441:cbce1fd3b1b7 | Chris | |
| 97 | 0:513646585e45 | Chris | if grouped.keys.size > 1 |
| 98 | grouped_options_for_select(grouped, selected && selected.id) |
||
| 99 | else |
||
| 100 | options_for_select((grouped.values.first || []), selected && selected.id) |
||
| 101 | end |
||
| 102 | end |
||
| 103 | |||
| 104 | def format_version_sharing(sharing) |
||
| 105 | sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing) |
||
| 106 | l("label_version_sharing_#{sharing}")
|
||
| 107 | end |
||
| 108 | end |