@ -15,20 +15,40 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class ProjectsController < ApplicationController
# if @project.project_type == 1
layout 'base_projects' # by young
menu_item :overview
menu_item :roadmap , :only = > :roadmap
menu_item :settings , :only = > :settings
menu_item l ( :label_sort_by_time ) , :only = > :index
menu_item l ( :label_sort_by_active ) , :only = > :index
menu_item l ( :label_sort_by_influence ) , :only = > :index
before_filter :find_project , :except = > [ :index , :search , :list , :new , :create , :copy ]
before_filter :authorize , :except = > [ :watcherlist , :index , :search , :list , :new , :create , :copy , :archive , :unarchive , :destroy , :member , :focus , :file , :statistics , :feedback , :project_respond ]
menu_item l ( :label_homework ) , :only = > :homework
menu_item l ( :label_course_file ) , :only = > :index
menu_item l ( :label_course_news ) , :only = > :index
# end
# layout 'base_courses'# by young
# menu_item :overview
# menu_item l(:label_homework), :only => :homework
# menu_item :files, :only => :files
#
# layout 'base_courses'
# menu_item l(:label_homework), :only => homework
# 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 :authorize_global , :only = > [ :new , :create ]
before_filter :require_admin , :only = > [ :copy , :archive , :unarchive , :destroy ]
before_filter :require_admin , :only = > [ :copy , :archive , :unarchive , :destroy , :calendar ]
#by young
before_filter :member , :file , :statistics , :watcherlist
# before_filter :member, :file, :statistics, :watcherlist
# modified by fq
before_filter :file , :statistics , :watcherlist
#
accept_rss_auth :index
accept_api_auth :index , :show , :create , :update , :destroy
@ -39,6 +59,8 @@ class ProjectsController < ApplicationController
end
end
helper :bids
include BidsHelper
helper :sort
include SortHelper
helper :custom_fields
@ -222,6 +244,43 @@ class ProjectsController < ApplicationController
end
end
# added by fq
def new_join
@course = Project . find ( params [ :object_id ] )
end
#Added by young
def homework
@offset , @limit = api_offset_and_limit ( { :limit = > 10 } )
@bids = @project . homeworks
@bids = @bids . like ( params [ :name ] ) if params [ :name ] . present?
@bid_count = @bids . count
@bid_pages = Paginator . new @bid_count , @limit , params [ 'page' ]
@offset || = @bid_pages . reverse_offset
#@bids = @bids.offset(@offset).limit(@limit).all.reverse
unless @offset == 0
@bids = @bids . offset ( @offset ) . limit ( @limit ) . all . reverse
else
limit = @bid_count % @limit
@bids = @bids . offset ( @offset ) . limit ( limit ) . all . reverse
end
render :layout = > 'base_courses'
end
def new_homework
if User . current . logged? && ( User . current . admin? || ( ! Member . where ( 'user_id = ? and project_id = ?' , User . current . id , @project . id ) . first . nil? && ( Member . where ( 'user_id = ? and project_id = ?' , User . current . id , @project . id ) . first . roles & Role . where ( 'id = ? or id = ?' , 3 , 7 ) ) . size > 0 ) )
@homework = Bid . new
@homework . safe_attributes = params [ :bid ]
render :layout = > 'base_courses'
else
render_404
end
end
#Ended by young
def feedback
@jours = @project . journals_for_messages . reverse
@limit = 10
@ -269,18 +328,36 @@ class ProjectsController < ApplicationController
end
def new
@course_tag = params [ :course ]
@issue_custom_fields = IssueCustomField . sorted . all
@trackers = Tracker . sorted . all
@project = Project . new
@project . safe_attributes = params [ :project ]
##add by huang
@course = Course . new
@course . safe_attributes = params [ :course ]
##end
render :layout = > 'base'
end
def create
@course_tag = params [ :project ] [ :project_type ]
if ( @course_tag == " 1 " )
@course = Course . new
@course . extra = 'course' + DateTime . parse ( Time . now . to_s ) . strftime ( '%Y-%m-%d_%H-%M-%S' ) . to_s
@course . safe_attributes = params [ :project ] [ :course ]
@course . tea_id = User . current . id
@course . save
# project = ProjectInfo.create(:user_id => User.current.id, :project_id => @project.id)
# project_status = ProjectStatus.create(:project_id => @project.id)
end
@issue_custom_fields = IssueCustomField . sorted . all
@trackers = Tracker . sorted . all
@project = Project . new
@project . safe_attributes = params [ :project ]
if @course_tag == '1'
@project . identifier = @course . extra
end
if validate_parent_id && @project . save
@project . set_allowed_parent! ( params [ :project ] [ 'parent_id' ] ) if params [ :project ] . has_key? ( 'parent_id' )
@ -289,7 +366,7 @@ class ProjectsController < ApplicationController
r = Role . givable . find_by_id ( Setting . new_project_user_role_id . to_i ) || Role . givable . first
m = Member . new ( :user = > User . current , :roles = > [ r ] )
project = ProjectInfo . new ( :user_id = > User . current . id , :project_id = > @project . id )
if params [ :project ] [ :is_public ] == 1
if params [ :project ] [ :is_public ] == '1' || @course_tag == " 1 "
project_status = ProjectStatus . create ( :project_id = > @project . id , :watchers_count = > 0 , :changesets_count = > 0 )
end
@project . members << m
@ -300,7 +377,12 @@ class ProjectsController < ApplicationController
flash [ :notice ] = l ( :notice_successful_create )
if params [ :continue ]
attrs = { :parent_id = > @project . parent_id } . reject { | k , v | v . nil? }
redirect_to new_project_path ( attrs )
redirect_to new_project_path ( attrs , :course = > '0' )
#Added by young
elsif params [ :course_continue ]
redirect_to new_project_path ( :course = > '1' )
#Ended by young
else
redirect_to settings_project_path ( @project )
end
@ -358,7 +440,6 @@ class ProjectsController < ApplicationController
@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 )
@total_issues_by_tracker = Issue . visible . where ( cond ) . count ( :group = > :tracker )
@ -378,7 +459,9 @@ class ProjectsController < ApplicationController
" show_issues " = > true ,
" show_files " = > true ,
" show_documents " = > true ,
" show_messages " = > true
" show_messages " = > true ,
" show_news " = > true ,
" show_bids " = > true
}
@date_to || = Date . today + 1
@date_from = @date_to - @days
@ -415,8 +498,9 @@ class ProjectsController < ApplicationController
end
@document = @project . documents . build
#
@base_courses_tag = @project . project_type
respond_to do | format |
format . html
format . html { render :layout = > 'base_courses' if @base_courses_tag == 1 }
format . api
end
end
@ -427,6 +511,16 @@ class ProjectsController < ApplicationController
@member || = @project . members . new
@trackers = Tracker . sorted . all
@wiki || = @project . wiki
#Added by young
# @course_tag = params[:course]
# if @course_tag == '1'
if @project . project_type == 1
@course = Course . find_by_extra ( @project . identifier )
render :layout = > 'base_courses'
else
render :layout = > 'base_projects'
end
#Ended by young
end
def edit
@ -434,9 +528,27 @@ class ProjectsController < ApplicationController
#by young
def member
if @project . project_type == 1
render :layout = > 'base_courses'
end
end
# def news
# if @project.project_type == 1
# render :layout => 'base_courses'
# end
# end
def file
# if @project.project_type == 1
# render :layout => 'base_courses'
# end
# @course_tag = params[:course]
# if @course_tag == '1'
# render :layout => 'base_courses'
# end
# User.current
end
def statistics
@ -447,6 +559,10 @@ class ProjectsController < ApplicationController
def update
@project . safe_attributes = params [ :project ]
if validate_parent_id && @project . save
@course = Course . find_by_extra ( @project . identifier )
@course . state = params [ :project ] [ :course ] [ :state ]
@course . term = params [ :project ] [ :course ] [ :term ]
@course . save
@project . set_allowed_parent! ( params [ :project ] [ 'parent_id' ] ) if params [ :project ] . has_key? ( 'parent_id' )
if params [ :project ] [ :is_public ] == '0'
@ -459,7 +575,7 @@ class ProjectsController < ApplicationController
respond_to do | format |
format . html {
flash [ :notice ] = l ( :notice_successful_update )
redirect_to settings_project_path ( @project )
redirect_to settings_project_path ( @project ,:course = > @project . project_type )
}
format . api { render_api_ok }
end