annotate .svn/pristine/64/6453475106e156ddd20fc32236e1e2b88b1df72a.svn-base @ 1477:f2ad2199b49a bibplugin_integration

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