socialforge/app/helpers/projects_helper.rb

150 lines
6.9 KiB
Ruby
Raw Normal View History

2013-08-01 10:33:49 +08:00
# encoding: utf-8
#
# Redmine - project management software
# Copyright (C) 2006-2013 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
module ProjectsHelper
def link_to_version(version, options = {})
return '' unless version && version.is_a?(Version)
link_to_if version.visible?, format_version_name(version), { :controller => 'versions', :action => 'show', :id => version }, options
end
def project_settings_tabs
tabs = [{:name => 'info', :action => :edit_project, :partial => 'projects/edit', :label => :label_information_plural},
{:name => 'modules', :action => :select_project_modules, :partial => 'projects/settings/modules', :label => :label_module_plural},
{:name => 'members', :action => :manage_members, :partial => 'projects/settings/members', :label => :label_member_plural},
{:name => 'versions', :action => :manage_versions, :partial => 'projects/settings/versions', :label => :label_version_plural},
{:name => 'categories', :action => :manage_categories, :partial => 'projects/settings/issue_categories', :label => :label_issue_category_plural},
# {:name => 'wiki', :action => :manage_wiki, :partial => 'projects/settings/wiki', :label => :label_wiki},
2013-08-01 10:33:49 +08:00
{:name => 'repositories', :action => :manage_repository, :partial => 'projects/settings/repositories', :label => :label_repository_plural},
{:name => 'boards', :action => :manage_boards, :partial => 'projects/settings/boards', :label => :label_board_plural},
{:name => 'activities', :action => :manage_project_activities, :partial => 'projects/settings/activities', :label => :enumeration_activities}
]
tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)}
2013-08-30 09:34:21 +08:00
2013-08-01 10:33:49 +08:00
end
2013-09-02 12:49:17 +08:00
def sort_project(state)
content = ''.html_safe
case state
when 0
2013-09-06 09:25:02 +08:00
2013-09-02 12:49:17 +08:00
content << content_tag('li', link_to(l(:label_sort_by_active), projects_path(:project_sort_type => '1')))
content << content_tag('li', link_to(l(:label_sort_by_influence), projects_path(:project_sort_type => '2')))
2013-09-06 09:25:02 +08:00
content << content_tag('li', link_to(l(:label_sort_by_time), projects_path(:project_sort_type => '0'), :class=>"selected"), :class=>"selected")
2013-09-02 12:49:17 +08:00
when 1
2013-09-06 09:25:02 +08:00
2013-09-02 12:49:17 +08:00
content << content_tag('li', link_to(l(:label_sort_by_active), projects_path(:project_sort_type => '1'), :class=>"selected"), :class=>"selected")
content << content_tag('li', link_to(l(:label_sort_by_influence), projects_path(:project_sort_type => '2')))
content << content_tag('li', link_to(l(:label_sort_by_time), projects_path(:project_sort_type => '0')))
2013-09-06 09:25:02 +08:00
when 2
2013-09-02 12:49:17 +08:00
content << content_tag('li', link_to(l(:label_sort_by_active), projects_path(:project_sort_type => '1')))
content << content_tag('li', link_to(l(:label_sort_by_influence), projects_path(:project_sort_type => '2'), :class=>"selected"), :class=>"selected")
2013-09-06 09:25:02 +08:00
content << content_tag('li', link_to(l(:label_sort_by_time), projects_path(:project_sort_type => '0')))
2013-09-02 12:49:17 +08:00
end
content = content_tag('ul', content)
content_tag('div', content, :class => "tabs")
end
2013-08-30 09:34:21 +08:00
#Added by young
def course_settings_tabs
2013-09-06 16:39:38 +08:00
tabs = [{:name => 'info', :action => :edit_project, :partial => 'projects/edit', :label => :label_information_plural, :course=>'1'},
2013-08-30 09:34:21 +08:00
{:name => 'boards', :action => :manage_boards, :partial => 'projects/settings/boards', :label => :label_board_plural},
2013-09-12 10:41:15 +08:00
# {:name => 'repositories', :action => :manage_repository, :partial => 'projects/settings/repositories', :label => :label_repository_plural},
{:name => 'members', :action => :manage_members, :partial => 'projects/settings/members', :label => :label_member_plural}
2013-08-30 09:34:21 +08:00
]
tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)}
end
#Ended by young
2013-09-12 10:41:15 +08:00
2013-08-01 10:33:49 +08:00
def parent_project_select_tag(project)
selected = project.parent
# retrieve the requested parent project
parent_id = (params[:project] && params[:project][:parent_id]) || params[:parent_id]
if parent_id
selected = (parent_id.blank? ? nil : Project.find(parent_id))
end
options = ''
options << "<option value=''></option>" if project.allowed_parents.include?(nil)
options << project_tree_options_for_select(project.allowed_parents.compact, :selected => selected)
content_tag('select', options.html_safe, :name => 'project[parent_id]', :id => 'project_parent_id')
end
# Renders the projects index
def render_project_hierarchy(projects)
render_project_nested_lists(projects) do |project|
2013-08-30 09:34:21 +08:00
#Modified by young
2013-09-23 16:42:19 +08:00
if (project.project_type==1)
s = link_to_project(project, {}, :class => "#{project.css_classes} #{User.current.member_of?(project) ? 'my-project' : nil}")+"<span style='color:#F00;'>(#{l(:label_course)})</span>".html_safe
else
s = link_to_project(project, {}, :class => "#{project.css_classes} #{User.current.member_of?(project) ? 'my-project' : nil}")
end
2013-08-30 09:34:21 +08:00
#Ended by young
2013-08-01 10:33:49 +08:00
if project.description.present?
#Delete by nie.
# s << content_tag('td', textilizable(project.short_description, :project => project), :class => 'wiki description')
end
s
end
end
# Returns a set of options for a select field, grouped by project.
def version_options_for_select(versions, selected=nil)
grouped = Hash.new {|h,k| h[k] = []}
versions.each do |version|
grouped[version.project.name] << [version.name, version.id]
end
if grouped.keys.size > 1
grouped_options_for_select(grouped, selected && selected.id)
else
options_for_select((grouped.values.first || []), selected && selected.id)
end
end
def format_version_sharing(sharing)
sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing)
l("label_version_sharing_#{sharing}")
end
# this method is used to get all projects that tagged one tag
# added by william
def get_projects_by_tag(tag_name)
Project.tagged_with(tag_name).order('updated_on desc')
2013-08-01 10:33:49 +08:00
end
2013-09-13 21:52:24 +08:00
# added by fq
def homework_type_option
type = []
option1 = []
option2 = []
option1 << '<27><>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD>Ը<EFBFBD><D4B8><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD>ύ'
2013-09-13 21:52:24 +08:00
option1 << 1
option2 << '<27><>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>ʽ<EFBFBD>ύ'
2013-09-13 21:52:24 +08:00
option2 << 2
type << option1
type << option2
end
2013-08-01 10:33:49 +08:00
end