|
|
|
@ -41,8 +41,9 @@ class ProjectsController < ApplicationController
|
|
|
|
|
# menu_item l(:label_course_file), :only => files
|
|
|
|
|
# menu_item l(:label_settings), :only => settings
|
|
|
|
|
|
|
|
|
|
before_filter :find_project, :except => [ :index, :search,:list, :new, :create, :copy, :statistics, :new_join]
|
|
|
|
|
before_filter :authorize, :except => [:new_join, :new_homework, :homework, :statistics, :search, :watcherlist, :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy, :member, :focus, :file, :statistics, :feedback]
|
|
|
|
|
before_filter :find_project, :except => [ :index, :search,:list, :new, :create, :copy, :statistics, :new_join, :course]
|
|
|
|
|
before_filter :authorize, :except => [:new_join, :new_homework, :homework, :statistics, :search, :watcherlist, :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy, :member, :focus, :file,
|
|
|
|
|
:statistics, :feedback, :course]
|
|
|
|
|
before_filter :authorize_global, :only => [:new, :create]
|
|
|
|
|
before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy, :calendar]
|
|
|
|
|
#by young
|
|
|
|
@ -110,8 +111,17 @@ class ProjectsController < ApplicationController
|
|
|
|
|
# @offset ||= @project_pages.offset
|
|
|
|
|
# @projects = Project.visible.offset(@offset).limit(@limit).order('lft').all
|
|
|
|
|
@project_type = params[:project_type]
|
|
|
|
|
@project_type = params[:project_type]
|
|
|
|
|
|
|
|
|
|
@offset, @limit = api_offset_and_limit({:limit => 10})
|
|
|
|
|
@projects_status = ProjectStatus.visible
|
|
|
|
|
@projects_status = ProjectStatus.visible.where("project_type <> ? or project_type is null", 1)
|
|
|
|
|
# @projects_status = ProjectStatus.visible
|
|
|
|
|
# @projects_status.each do |project|
|
|
|
|
|
# if Project.visible.find_by_id("#{project.project_id}")
|
|
|
|
|
# project.project_type = Project.visible.find_by_id("#{project.project_id}").project_type
|
|
|
|
|
# project.save
|
|
|
|
|
# end
|
|
|
|
|
# end
|
|
|
|
|
# @projects.each do |project|
|
|
|
|
|
# @admin = project.users_by_role[Role.find(3)]
|
|
|
|
|
# unless @admin.nil?
|
|
|
|
@ -192,7 +202,122 @@ class ProjectsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
@projects = []
|
|
|
|
|
@projects_status.each do |obj|
|
|
|
|
|
@projects << Project.visible.find_by_id("#{obj.project_id}") unless Project.visible.find_by_id("#{obj.project_id}").nil?
|
|
|
|
|
@projects << Project.visible.find_by_id("#{obj.project_id}") unless Project.visible.find_by_id("#{obj.project_id}").nil?
|
|
|
|
|
end
|
|
|
|
|
#end
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.html {
|
|
|
|
|
render :layout => 'base'
|
|
|
|
|
scope = Project
|
|
|
|
|
unless params[:closed]
|
|
|
|
|
scope = scope.active
|
|
|
|
|
end
|
|
|
|
|
}
|
|
|
|
|
format.api {
|
|
|
|
|
# @offset, @limit = api_offset_and_limit
|
|
|
|
|
# @project_count = Project.visible.count
|
|
|
|
|
# @projects = Project.visible.offset(@offset).limit(@limit).order('lft').all
|
|
|
|
|
}
|
|
|
|
|
format.atom {
|
|
|
|
|
projects = Project.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all
|
|
|
|
|
render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def course
|
|
|
|
|
#Modified by nie
|
|
|
|
|
# @offset, @limit = api_offset_and_limit({:limit => 10})
|
|
|
|
|
# @project_count = Project.visible.count
|
|
|
|
|
# @project_pages = Paginator.new @project_count, @limit, params['page']
|
|
|
|
|
# @offset ||= @project_pages.offset
|
|
|
|
|
# @projects = Project.visible.offset(@offset).limit(@limit).order('lft').all
|
|
|
|
|
|
|
|
|
|
@project_type = params[:project_type]
|
|
|
|
|
|
|
|
|
|
@offset, @limit = api_offset_and_limit({:limit => 10})
|
|
|
|
|
@projects_status = ProjectStatus.visible.where("project_type = ?", 1)
|
|
|
|
|
# @projects.each do |project|
|
|
|
|
|
# @admin = project.users_by_role[Role.find(3)]
|
|
|
|
|
# unless @admin.nil?
|
|
|
|
|
# @admin.each do |user|
|
|
|
|
|
# ProjectInfo.create(:user_id => user.id, :project_id => project.id)
|
|
|
|
|
# end
|
|
|
|
|
#
|
|
|
|
|
# end
|
|
|
|
|
# end
|
|
|
|
|
# @projects.each do |project|
|
|
|
|
|
# ProjectStatus.create(:changesets_count => project.changesets.count, :project_id => project.id, :watchers_count => project.watcher_users.count)
|
|
|
|
|
# end
|
|
|
|
|
#@projects_status = Project.visible.like(params[:name]) if params[:name].present?
|
|
|
|
|
@project_count = @projects_status.count
|
|
|
|
|
@project_pages = Paginator.new @project_count, @limit, params['page']
|
|
|
|
|
|
|
|
|
|
@offset ||= @project_pages.reverse_offset
|
|
|
|
|
|
|
|
|
|
#@projects = @projects.offset(@offset).limit(@limit).order('created_on DESC').all
|
|
|
|
|
if params[:project_sort_type].present?
|
|
|
|
|
case params[:project_sort_type]
|
|
|
|
|
when '0'
|
|
|
|
|
@offset ||= @project_pages.reverse_offset
|
|
|
|
|
unless @offset == 0
|
|
|
|
|
@projects_status = @projects_status.offset(@offset).limit(@limit).all.reverse
|
|
|
|
|
else
|
|
|
|
|
limit = @project_count % @limit
|
|
|
|
|
if limit == 0
|
|
|
|
|
limit = @limit
|
|
|
|
|
end
|
|
|
|
|
@projects_status = @projects_status.offset(@offset).limit(limit).all.reverse
|
|
|
|
|
end
|
|
|
|
|
@s_type = 0
|
|
|
|
|
# @projects = @projects.sort {|x,y| y.created_on <=> x.created_on }
|
|
|
|
|
# @projects = @projects[@offset, @limit]
|
|
|
|
|
when '1'
|
|
|
|
|
@offset ||= @project_pages.reverse_offset
|
|
|
|
|
unless @offset == 0
|
|
|
|
|
@projects_status = @projects_status.reorder('changesets_count').offset(@offset).limit(@limit).all.reverse
|
|
|
|
|
else
|
|
|
|
|
limit = @project_count % @limit
|
|
|
|
|
if limit == 0
|
|
|
|
|
limit = @limit
|
|
|
|
|
end
|
|
|
|
|
@projects_status = @projects_status.reorder('changesets_count').offset(@offset).limit(limit).all.reverse
|
|
|
|
|
end
|
|
|
|
|
@s_type = 1
|
|
|
|
|
|
|
|
|
|
#@projects = @projects[@offset, @limit]
|
|
|
|
|
when '2'
|
|
|
|
|
@offset ||= @project_pages.reverse_offset
|
|
|
|
|
unless @offset == 0
|
|
|
|
|
@projects_status = @projects_status.reorder('watchers_count').offset(@offset).limit(@limit).all.reverse
|
|
|
|
|
else
|
|
|
|
|
limit = @project_count % @limit
|
|
|
|
|
if limit == 0
|
|
|
|
|
limit = @limit
|
|
|
|
|
end
|
|
|
|
|
@projects_status = @projects_status.reorder('watchers_count').offset(@offset).limit(limit).all.reverse
|
|
|
|
|
end
|
|
|
|
|
@s_type = 2
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
@offset ||= @project_pages.reverse_offset
|
|
|
|
|
unless @offset == 0
|
|
|
|
|
@projects_status = @projects_status.reorder('changesets_count').offset(@offset).limit(@limit).all.reverse
|
|
|
|
|
else
|
|
|
|
|
limit = @project_count % @limit
|
|
|
|
|
if limit == 0
|
|
|
|
|
limit = @limit
|
|
|
|
|
end
|
|
|
|
|
@projects_status = @projects_status.reorder('changesets_count').offset(@offset).limit(limit).all.reverse
|
|
|
|
|
end
|
|
|
|
|
@s_type = 1
|
|
|
|
|
# @projects = @projects.sort {|x,y| y.created_on <=> x.created_on }
|
|
|
|
|
# @projects = @projects[@offset, @limit]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@projects = []
|
|
|
|
|
@projects_status.each do |obj|
|
|
|
|
|
@projects << Project.visible.find_by_id("#{obj.project_id}") unless Project.visible.find_by_id("#{obj.project_id}").nil?
|
|
|
|
|
end
|
|
|
|
|
#end
|
|
|
|
|
respond_to do |format|
|
|
|
|
@ -328,6 +453,7 @@ class ProjectsController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def new
|
|
|
|
|
@project_type = params[:project_type]
|
|
|
|
|
@course_tag = params[:course]
|
|
|
|
|
@issue_custom_fields = IssueCustomField.sorted.all
|
|
|
|
|
@trackers = Tracker.sorted.all
|
|
|
|
@ -340,7 +466,8 @@ class ProjectsController < ApplicationController
|
|
|
|
|
render :layout => 'base'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create
|
|
|
|
|
def create
|
|
|
|
|
|
|
|
|
|
@course_tag = params[:project][:project_type]
|
|
|
|
|
if(@course_tag=="1")
|
|
|
|
|
@course = Course.new
|
|
|
|
@ -385,7 +512,7 @@ class ProjectsController < ApplicationController
|
|
|
|
|
redirect_to new_project_path(:course => '1')
|
|
|
|
|
#Ended by young
|
|
|
|
|
else
|
|
|
|
|
redirect_to settings_project_path(@project)
|
|
|
|
|
redirect_to settings_project_path(@project,:project_type => 1)
|
|
|
|
|
end
|
|
|
|
|
}
|
|
|
|
|
format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) }
|
|
|
|
@ -482,6 +609,9 @@ class ProjectsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
# Show @project
|
|
|
|
|
def show
|
|
|
|
|
|
|
|
|
|
@project_type = params[:project_type]
|
|
|
|
|
|
|
|
|
|
# try to redirect to the requested menu item
|
|
|
|
|
if params[:jump] && redirect_to_project_menu_item(@project, params[:jump])
|
|
|
|
|
return
|
|
|
|
@ -491,7 +621,7 @@ class ProjectsController < ApplicationController
|
|
|
|
|
@subprojects = @project.children.visible.all
|
|
|
|
|
@news = @project.news.limit(5).includes(:author, :project).reorder("#{News.table_name}.created_on DESC").all
|
|
|
|
|
@trackers = @project.rolled_up_trackers
|
|
|
|
|
@user = User.find_by_id(ProjectInfo.find_by_project_id(@project.id).user_id)
|
|
|
|
|
@user = User.find_by_id(ProjectInfo.find_by_project_id(@project.id).user_id)
|
|
|
|
|
|
|
|
|
|
cond = @project.project_condition(Setting.display_subprojects_issues?)
|
|
|
|
|
@open_issues_by_tracker = Issue.visible.open.where(cond).count(:group => :tracker)
|
|
|
|
@ -614,9 +744,11 @@ class ProjectsController < ApplicationController
|
|
|
|
|
@project.safe_attributes = params[:project]
|
|
|
|
|
if validate_parent_id && @project.save
|
|
|
|
|
@course = Course.find_by_extra(@project.identifier)
|
|
|
|
|
@course.state = params[:project][:course][:state]
|
|
|
|
|
unless @course.nil?
|
|
|
|
|
@course.password = params[:project][:course][:password]
|
|
|
|
|
@course.term = params[:project][:course][:term]
|
|
|
|
|
@course.save
|
|
|
|
|
@course.save
|
|
|
|
|
end
|
|
|
|
|
@project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
|
|
|
|
|
|
|
|
|
|
if params[:project][:is_public] == '0'
|
|
|
|
|