Chris@909: # encoding: utf-8 Chris@909: # Chris@441: # Redmine - project management software Chris@1494: # Copyright (C) 2006-2014 Jean-Philippe Lang Chris@0: # Chris@0: # This program is free software; you can redistribute it and/or Chris@0: # modify it under the terms of the GNU General Public License Chris@0: # as published by the Free Software Foundation; either version 2 Chris@0: # of the License, or (at your option) any later version. Chris@441: # Chris@0: # This program is distributed in the hope that it will be useful, Chris@0: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@0: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@0: # GNU General Public License for more details. Chris@441: # Chris@0: # You should have received a copy of the GNU General Public License Chris@0: # along with this program; if not, write to the Free Software Chris@0: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@0: Chris@0: module ProjectsHelper Chris@0: def link_to_version(version, options = {}) Chris@0: return '' unless version && version.is_a?(Version) Chris@0: link_to_if version.visible?, format_version_name(version), { :controller => 'versions', :action => 'show', :id => version }, options Chris@0: end Chris@441: Chris@0: def project_settings_tabs Chris@0: tabs = [{:name => 'info', :action => :edit_project, :partial => 'projects/edit', :label => :label_information_plural}, Chris@0: {:name => 'modules', :action => :select_project_modules, :partial => 'projects/settings/modules', :label => :label_module_plural}, Chris@0: {:name => 'members', :action => :manage_members, :partial => 'projects/settings/members', :label => :label_member_plural}, Chris@0: {:name => 'versions', :action => :manage_versions, :partial => 'projects/settings/versions', :label => :label_version_plural}, Chris@0: {:name => 'categories', :action => :manage_categories, :partial => 'projects/settings/issue_categories', :label => :label_issue_category_plural}, Chris@0: {:name => 'wiki', :action => :manage_wiki, :partial => 'projects/settings/wiki', :label => :label_wiki}, Chris@1115: {:name => 'repositories', :action => :manage_repository, :partial => 'projects/settings/repositories', :label => :label_repository_plural}, Chris@0: {:name => 'boards', :action => :manage_boards, :partial => 'projects/settings/boards', :label => :label_board_plural}, Chris@0: {:name => 'activities', :action => :manage_project_activities, :partial => 'projects/settings/activities', :label => :enumeration_activities} Chris@0: ] Chris@441: tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)} Chris@0: end Chris@441: Chris@0: def parent_project_select_tag(project) Chris@0: selected = project.parent Chris@0: # retrieve the requested parent project Chris@0: parent_id = (params[:project] && params[:project][:parent_id]) || params[:parent_id] Chris@0: if parent_id Chris@0: selected = (parent_id.blank? ? nil : Project.find(parent_id)) Chris@0: end Chris@441: Chris@0: options = '' Chris@1464: options << "" if project.allowed_parents.include?(nil) Chris@0: options << project_tree_options_for_select(project.allowed_parents.compact, :selected => selected) Chris@909: content_tag('select', options.html_safe, :name => 'project[parent_id]', :id => 'project_parent_id') Chris@0: end Chris@441: Chris@1517: def render_project_action_links Chris@1517: links = [] Chris@1517: links << link_to(l(:label_project_new), {:controller => 'projects', :action => 'new'}, :class => 'icon icon-add') if User.current.allowed_to?(:add_project, nil, :global => true) Chris@1517: links << link_to(l(:label_issue_view_all), issues_path) if User.current.allowed_to?(:view_issues, nil, :global => true) Chris@1517: links << link_to(l(:label_overall_spent_time), time_entries_path) if User.current.allowed_to?(:view_time_entries, nil, :global => true) Chris@1517: links << link_to(l(:label_overall_activity), { :controller => 'activities', :action => 'index', :id => nil }) Chris@1517: links.join(" | ").html_safe Chris@1517: end Chris@1517: Chris@1115: # Renders the projects index Chris@0: def render_project_hierarchy(projects) Chris@1115: render_project_nested_lists(projects) do |project| Chris@1115: s = link_to_project(project, {}, :class => "#{project.css_classes} #{User.current.member_of?(project) ? 'my-project' : nil}") Chris@1115: if project.description.present? Chris@1115: s << content_tag('div', textilizable(project.short_description, :project => project), :class => 'wiki description') Chris@0: end Chris@1115: s Chris@0: end Chris@0: end Chris@0: Chris@0: # Returns a set of options for a select field, grouped by project. Chris@0: def version_options_for_select(versions, selected=nil) Chris@0: grouped = Hash.new {|h,k| h[k] = []} Chris@0: versions.each do |version| Chris@0: grouped[version.project.name] << [version.name, version.id] Chris@0: end Chris@441: Chris@1464: selected = selected.is_a?(Version) ? selected.id : selected Chris@0: if grouped.keys.size > 1 Chris@1464: grouped_options_for_select(grouped, selected) Chris@0: else Chris@1464: options_for_select((grouped.values.first || []), selected) Chris@0: end Chris@0: end Chris@0: Chris@0: def format_version_sharing(sharing) Chris@0: sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing) Chris@0: l("label_version_sharing_#{sharing}") Chris@0: end Chris@0: end