Merge branch 'CourseModify' into szzh

Conflicts:
	app/views/layouts/base_courses.html.erb
	app/views/layouts/base_homework.html.erb
	app/views/projects/_course.html.erb
	db/schema.rb
	lib/redmine/activity/fetcher.rb
GitlabVersion
nwb 11 years ago
commit 7425178419

@ -0,0 +1,2 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

@ -0,0 +1,2 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

@ -0,0 +1,4 @@
/*
Place all the styles related to the matching controller here.
They will automatically be included in application.css.
*/

@ -0,0 +1,4 @@
/*
Place all the styles related to the matching controller here.
They will automatically be included in application.css.
*/

@ -233,7 +233,15 @@ class ApplicationController < ActionController::Base
# Authorize the user for the requested action
def authorize(ctrl = params[:controller], action = params[:action], global = false)
allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project || @projects, :global => global)
#modify by NWB
if @project
allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project || @projects, :global => global)
elsif @course
allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @course || @courses, :global => global)
else
allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project || @projects, :global => global)
end
if allowed
true
else
@ -245,6 +253,24 @@ class ApplicationController < ActionController::Base
end
end
def authorize_course(ctrl = params[:controller], action = params[:action], global = false)
allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @course || @course, :global => global)
if allowed
true
else
if @course && @course.archived?
render_403 :message => :notice_not_authorized_archived_project
else
deny_access
end
end
end
def authorize_course_global(ctrl = params[:controller], action = params[:action], global = true)
authorize_course(ctrl, action, global)
end
# Authorize the user for the requested action outside a project
def authorize_global(ctrl = params[:controller], action = params[:action], global = true)
authorize(ctrl, action, global)
@ -259,9 +285,13 @@ class ApplicationController < ActionController::Base
# Find project of id params[:project_id]
def find_project_by_project_id
@project = Project.find(params[:project_id])
if params[:project_id]
@project = Project.find(params[:project_id])
elsif params[:course_id]
@course = Course.find(params[:course_id])
end
rescue ActiveRecord::RecordNotFound
render_404
render_404
end
def find_contest_by_contest_id
@ -301,6 +331,10 @@ class ApplicationController < ActionController::Base
render_404 unless @object.present?
@project = @object.project
if @project == nil && @object.has_attribute?('course_id')
@course = @object.course
end
end
def find_contest_from_association
@ -319,6 +353,14 @@ class ApplicationController < ActionController::Base
render_404
end
#added by nwb
#»ñÈ¡¿Î³Ì
def find_course
@course= Course.find(params[:id])
rescue ActiveRecord::RecordNotFound
render_404
end
# def find_model_object_contest
# model = self.class.model_object
# if model

@ -126,10 +126,19 @@ class AttachmentsController < ApplicationController
end
respond_to do |format|
if @project.nil?
format.html { redirect_to_referer_or forum_memo_path(@attachment.container.forum,@attachment.container) }
# modify by nwb
if @attachment.container_type == 'Course'
if @course.nil?
format.html { redirect_to_referer_or forum_memo_path(@attachment.container.forum, @attachment.container) }
else
format.html { redirect_to_referer_or course_path(@course) }
end
else
format.html { redirect_to_referer_or project_path(@project)}
if @project.nil?
format.html { redirect_to_referer_or forum_memo_path(@attachment.container.forum, @attachment.container) }
else
format.html { redirect_to_referer_or project_path(@project) }
end
end
format.js
@ -192,9 +201,14 @@ private
def find_project
@attachment = Attachment.find(params[:id])
# Show 404 if the filename in the url is wrong
# modify by nwb
raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename
unless @attachment.container_type == 'Bid' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo' || @attachment.container_type == 'Softapplication'
@project = @attachment.project
if @attachment.container_type == 'Course'
@course = @attachment.course
else
unless @attachment.container_type == 'Bid' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo' || @attachment.container_type == 'Softapplication'
@project = @attachment.project
end
end
rescue ActiveRecord::RecordNotFound
render_404

@ -8,7 +8,7 @@ class BidsController < ApplicationController
menu_item :homework_statistics, :only => :homework_statistics
#Ended by young
before_filter :find_bid, :only => [:show, :show_project, :create,:destroy,:more,:back,:add,:delete,:new,:show_results,:set_reward, :add_homework, :fork, :create_fork,
:show_course, :show_bid_project, :show_bid_user, :join_in_contest, :unjoin_in_contest, :new_join,:show_participator, :settings]
:show_course, :show_courseEx,:show_bid_project, :show_bid_user, :join_in_contest, :unjoin_in_contest, :new_join,:show_participator, :settings]
# added by fq
before_filter :require_login, :only => [:join_in_contest, :unjoin_in_contest]
# end
@ -189,7 +189,7 @@ class BidsController < ApplicationController
@homework.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads]))
# @bid.
if @homework.save
HomeworkForCourse.create(:project_id => params[:course], :bid_id => @homework.id)
HomeworkForCourse.create(:course_id => params[:course], :bid_id => @homework.id)
unless @bid.watched_by?(User.current)
if @bid.add_watcher(User.current)
flash[:notice] = l(:label_bid_succeed)
@ -199,11 +199,9 @@ class BidsController < ApplicationController
else
@bid.safe_attributes = params[:bid]
@courses = []
@membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
@membership = User.current.coursememberships.all#(:conditions => Project.visible_condition(User.current))
@membership.each do |membership|
if membership.project.project_type == 1
@courses << membership.project
end
@courses << membership.course
end
render :action => 'fork'
end
@ -289,6 +287,7 @@ class BidsController < ApplicationController
end
#end
# 显示课程
def show_course
bids = Bid.where('parent_id = ?', @bid.id)
@courses = []
@ -377,7 +376,7 @@ class BidsController < ApplicationController
unless(membership.project.project_type==1)
membership.member_roles.each{|role|
if(role.role_id == 3)
@option << membership.project
@option << membership.project
end
}
end
@ -399,18 +398,96 @@ class BidsController < ApplicationController
end
@bidding_project = @temp
else
#added by nie
@temp = []
@bidding_project.each do |pro|
if pro.project && pro.project.project_status
@temp << pro
#added by nie
@temp = []
@bidding_project.each do |pro|
if pro.project && pro.project.project_status
@temp << pro
end
@temp
end
@temp
end
if @temp.size > 0
if @temp.size > 0
@bidding_project = @temp.sort {|a,b| b.project.project_status.grade <=> a.project.project_status.grade}
end
#ended
end
if @bid.homework_type == 1
@homework = HomeworkAttach.new
#@homework_list = @bid.homeworks
#增加作业按评分排序,
@homework_list = @bid.homeworks.eager_load(:rate_averages, :user, :attachments).order('seems_rateable_cached_ratings.avg DESC').order("#{HomeworkAttach.table_name}.created_at ASC")
if params[:student_id].present?
@temp = []
@homework_list.each do |pro|
if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id
@temp << pro
end
@temp
end
@homework_list = @temp
end
end
#ended
respond_to do |format|
if @bid.reward_type == 3
format.html {
render :layout => 'base_homework'
}
elsif @bid.reward_type == 1
format.html {
render :layout => 'base_bids'
}
else
format.html {
render :layout => 'base_contest'
}
end
format.api
end
end
# 显示作业课程
# add by nwb
def show_courseEx
# flash[:notice] = ""
@membership = User.current.coursememberships.all(:conditions => Course.visible_condition(User.current))
@option = []
@membership.each do |membership|
membership.member_roles.each{|role|
if(role.role_id == 3)
@option << membership.course
end
}
end
@user = @bid.author
@bidding_project = @bid.biding_projects.all
if params[:student_id].present?
@temp = []
@bidding_project.each do |pro|
if pro.project && pro.project.project_status
if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id
@temp << pro
end
end
@temp
end
@bidding_project = @temp
else
#added by nie
@temp = []
@bidding_project.each do |pro|
if pro.project && pro.project.project_status
@temp << pro
end
@temp
end
if @temp.size > 0
@bidding_project = @temp.sort {|a,b| b.project.project_status.grade <=> a.project.project_status.grade}
end
#ended
end
if @bid.homework_type == 1
@ -421,9 +498,9 @@ class BidsController < ApplicationController
if params[:student_id].present?
@temp = []
@homework_list.each do |pro|
if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id
@temp << pro
end
if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id
@temp << pro
end
@temp
end
@homework_list = @temp
@ -432,17 +509,17 @@ class BidsController < ApplicationController
respond_to do |format|
if @bid.reward_type == 3
format.html {
render :layout => 'base_homework'
}
format.html {
render :layout => 'base_homework'
}
elsif @bid.reward_type == 1
format.html {
render :layout => 'base_bids'
}
render :layout => 'base_bids'
}
else
format.html {
render :layout => 'base_contest'
}
format.html {
render :layout => 'base_contest'
}
end
format.api
end
@ -711,7 +788,7 @@ class BidsController < ApplicationController
@bid.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads]))
# @bid.
if @bid.save
HomeworkForCourse.create(:project_id => params[:course_id], :bid_id => @bid.id)
HomeworkForCourse.create(:course_id => params[:course_id], :bid_id => @bid.id)
unless @bid.watched_by?(User.current)
if @bid.add_watcher(User.current)
flash[:notice] = l(:label_bid_succeed)
@ -721,19 +798,21 @@ class BidsController < ApplicationController
else
@bid.safe_attributes = params[:bid]
@homework = @bid
@project = Project.find_by_id(params[:course_id])
@project_id = @project.id
render file: 'projects/new_homework', layout: 'base_courses'
@course = Course.find_by_id(params[:course_id])
@course_id = @course.id
render file: 'courses/new_homework', layout: 'base_courses'
end
end
# modify by nwb\
# 编辑作业
def edit
@bid = Bid.find(params[:bid_id])
if (User.current.admin?||User.current.id==@bid.author_id)
@project_id = params[:project_id]
@course_id = params[:course_id]
respond_to do |format|
format.html {
@project = Project.find(params[:project_id])
@course = Course.find(params[:course_id])
@user= User.find(User.current.id)
render :layout => 'base_courses'
}
@ -745,11 +824,11 @@ class BidsController < ApplicationController
def update
@bid = Bid.find(params[:id])
@project = @bid.courses.first#Project.find(params[:course_id])
@course = @bid.courses.first#Project.find(params[:course_id])
@bid.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads]))
if @bid.update_attributes(params[:bid]) && @bid.save
flash[:notice] = l(:label_update_homework_succeed)
redirect_to project_homework_path(@project)
redirect_to course_homework_path(@course)
else
@bid.safe_attributes = params[:bid]
render :action => 'edit', :layout =>'base_courses'
@ -894,9 +973,9 @@ class BidsController < ApplicationController
def memberAccess
# 是课程,则判断当前用户是否参加了课程
return true if current_user.admin?
return 0 if @bid.courses.first.project_type == Project::ProjectType_project
#return 0 if @bid.courses.first.project_type == Project::ProjectType_project
currentUser = User.current
render_403 unless currentUser.member_of?(@bid.courses.first)
render_403 unless currentUser.member_of_cousrse?(@bid.courses.first)
end
end

@ -28,17 +28,25 @@ class BoardsController < ApplicationController
helper :watchers
def index
@boards = @project.boards.includes(:last_message => :author).all
@boards = [] << @boards[0] if @boards.any?
if @boards.size == 1
@board = @boards.first
show and return
end
if @project.project_type == 1
render :layout => 'base_courses'
else
render :layout => false if request.xhr?
#modify by nwb
if @project
@boards = @project.boards.includes(:last_message => :author).all
@boards = [] << @boards[0] if @boards.any?
if @boards.size == 1
@board = @boards.first
show and return
end
render :layout => false if request.xhr?
elsif @course
@boards = @course.boards.includes(:last_message => :author).all
@boards = [] << @boards[0] if @boards.any?
if @boards.size == 1
@board = @boards.first
show and return
end
render :layout => 'base_courses'
end
end
def show
@ -60,10 +68,11 @@ class BoardsController < ApplicationController
preload(:author, {:last_reply => :author}).
all
@message = Message.new(:board => @board)
if @project.project_type ==1
render :action => 'show', :layout => 'base_courses'
else
#modify by nwb
if @project
render :action => 'show', :layout => !request.xhr?
elsif @course
render :action => 'show', :layout => 'base_courses'
end
}
format.atom {
@ -72,7 +81,12 @@ class BoardsController < ApplicationController
includes(:author, :board).
limit(Setting.feeds_limit.to_i).
all
render_feed(@messages, :title => "#{@project}: #{@board}")
if @project
render_feed(@messages, :title => "#{@project}: #{@board}")
elsif @course
render_feed(@messages, :title => "#{@course}: #{@board}")
end
}
end
end

@ -74,6 +74,25 @@ class ContestsController < ApplicationController
end
end
def homework
@offset, @limit = api_offset_and_limit({:limit => 10})
@bids = @course.homeworks.order('deadline DESC')
@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
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 show_contest
@user = @contest.author
@jours = @contest.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')

File diff suppressed because it is too large Load Diff

@ -32,14 +32,16 @@ class FilesController < ApplicationController
'filename' => "#{Attachment.table_name}.filename",
'size' => "#{Attachment.table_name}.filesize",
'downloads' => "#{Attachment.table_name}.downloads"
@containers = [ Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)] #modify by Long Jun
@containers += @project.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort
if @project.project_type == 1
if params[:project_id]
@isproject = true
@containers = [ Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)]
@containers += @project.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort
render :layout => !request.xhr?
elsif params[:course_id]
@isproject = false
@containers = [ Course.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@course.id)]
render :layout => 'base_courses'
else
render :layout => !request.xhr?
end
end
@ -60,37 +62,66 @@ class FilesController < ApplicationController
respond_to do |format|
format.js
end
else
@addTag=false
container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id]))
attachments = Attachment.attach_filesex(container, params[:attachments],params[:attachment_type])
render_attachment_warning_if_needed(container)
if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added')
Mailer.attachments_added(attachments[:files]).deliver
end
# TODO: 临时用 nyan
sort_init 'created_on', 'desc'
sort_update 'created_on' => "#{Attachment.table_name}.created_on",
'filename' => "#{Attachment.table_name}.filename",
'size' => "#{Attachment.table_name}.filesize",
'downloads' => "#{Attachment.table_name}.downloads"
@containers = [ Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)] #modify by Long Jun
@containers += @project.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort
@attachtype = 0
@contenttype = 0
respond_to do |format|
format.js
format.html {
redirect_to project_files_path(@project)
}
end
else
#modify by nwb
if @project
@addTag=false
container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id]))
attachments = Attachment.attach_filesex(container, params[:attachments], params[:attachment_type])
render_attachment_warning_if_needed(container)
if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added')
Mailer.attachments_added(attachments[:files]).deliver
end
# TODO: 临时用 nyan
sort_init 'created_on', 'desc'
sort_update 'created_on' => "#{Attachment.table_name}.created_on",
'filename' => "#{Attachment.table_name}.filename",
'size' => "#{Attachment.table_name}.filesize",
'downloads' => "#{Attachment.table_name}.downloads"
@containers = [Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)] #modify by Long Jun
@containers += @project.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort
@attachtype = 0
@contenttype = 0
respond_to do |format|
format.js
format.html {
redirect_to project_files_path(@project)
}
end
elsif @course
@addTag=false
attachments = Attachment.attach_filesex(@course, params[:attachments], params[:attachment_type])
if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added')
Mailer.attachments_added(attachments[:files]).deliver
end
# TODO: 临时用 nyan
sort_init 'created_on', 'desc'
sort_update 'created_on' => "#{Attachment.table_name}.created_on",
'filename' => "#{Attachment.table_name}.filename",
'size' => "#{Attachment.table_name}.filesize",
'downloads' => "#{Attachment.table_name}.downloads"
@containers = [Course.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@course.id)]
@attachtype = 0
@contenttype = 0
respond_to do |format|
format.js
format.html {
redirect_to course_files_path(@course)
}
end
end
end
end
end
def tag_saveEx
@ -115,6 +146,8 @@ class FilesController < ApplicationController
@obj = Contest.find_by_id(@obj_id)
when '8'
@obj = OpenSourceProject.find_by_id(@obj_id)
when '9'
@obj = Course.find_by_id(@obj_id)
else
@obj = nil
end
@ -131,16 +164,21 @@ class FilesController < ApplicationController
end
# 返回制定资源类型的资源列表
# added by nwb
def getattachtype
sort_init 'created_on', 'desc'
sort_update 'created_on' => "#{Attachment.table_name}.created_on",
'filename' => "#{Attachment.table_name}.filename",
'size' => "#{Attachment.table_name}.filesize",
'downloads' => "#{Attachment.table_name}.downloads"
@containers = [ Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)] #modify by Long Jun
@containers += @project.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort
if @project
@containers = [ Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)]
@containers += @project.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort
elsif @course
@containers = [ Course.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@course.id)]
end
@attachtype = params[:type].to_i
@contenttype = params[:contentType].to_s

@ -2,21 +2,21 @@ class HomeworkAttachController < ApplicationController
include CoursesHelper
###############################
#判断当前角色权限时需先找到当前操作的project
before_filter :find_project_by_bid_id, :only => [:new]
before_filter :find_project_by_hoemwork_id, :only => [:edit,:update,:destroy,:show,:add_homework_users,:destory_homework_users]
before_filter :find_course_by_bid_id, :only => [:new]
before_filter :find_course_by_hoemwork_id, :only => [:edit,:update,:destroy,:show,:add_homework_users,:destory_homework_users]
#判断当前角色是否有操作权限
#勿删 before_filter :authorize, :only => [:new,:edit,:update,:destroy]
def find_project_by_bid_id
def find_course_by_bid_id
@bid = Bid.find(params[:id])
@project = @bid.courses[0]
@course = @bid.courses[0]
rescue ActiveRecord::RecordNotFound
render_404
end
def find_project_by_hoemwork_id
def find_course_by_hoemwork_id
@homework = HomeworkAttach.find(params[:id])
@project = @homework.bid.courses[0]
@course = @homework.bid.courses[0]
end
#获取作业的成员
@ -36,7 +36,7 @@ class HomeworkAttachController < ApplicationController
#作业添加成员(参与人员)
def add_homework_users
if User.current.admin? || User.current.member_of?(@homework.bid.courses.first)
if User.current.admin? || User.current.member_of_course?(@homework.bid.courses.first)
#@homework = HomeworkAttach.find(params[:id])
if params[:membership]
if params[:membership][:user_ids]
@ -60,7 +60,7 @@ class HomeworkAttachController < ApplicationController
#作业删除成员(参与人员)
def destory_homework_users
#@homework = HomeworkAttach.find(params[:id])
if User.current.admin? || User.current.member_of?(@homework.bid.courses.first)
if User.current.admin? || User.current.member_of_course?(@homework.bid.courses.first)
homework_user = @homework.homework_users.where("user_id = #{params[:user_id]}").first
homework_user.destroy
get_homework_member @homework
@ -74,7 +74,7 @@ class HomeworkAttachController < ApplicationController
def create
bid = Bid.find params[:bid_id]
if User.current.admin? || User.current.member_of?(bid.courses.first)
if User.current.admin? || User.current.member_of_course?(bid.courses.first) # modify by nwb
if bid.homeworks.where("user_id = ?",User.current).count == 0
user_id = params[:user_id]
bid_id = params[:bid_id]
@ -108,7 +108,7 @@ class HomeworkAttachController < ApplicationController
if @homework.save
respond_to do |format|
format.html { redirect_to project_for_bid_path @homework.bid }
format.html { redirect_to course_for_bid_path @homework.bid }
format.json { head :no_content }
end
else
@ -124,7 +124,7 @@ class HomeworkAttachController < ApplicationController
def new
@bid = Bid.find(params[:id])
if User.current.admin? || User.current.member_of?(@bid.courses.first)
if User.current.admin? || User.current.member_of_course?(@bid.courses.first) #nwb
#该课程的学生的集合(新建不实现功能:添加成员)
#@members = @bid.courses.first.members.joins(:member_roles).where("member_roles.role_id IN (:role_id) and user_id <> #{User.current.id}", {:role_id => [5, 10]})
@ -149,7 +149,7 @@ class HomeworkAttachController < ApplicationController
def get_homework_member_list
@homework = HomeworkAttach.find(params[:bid_id])
course = @homework.bid.courses.first
if User.current.admin? || User.current.member_of?(course)
if User.current.admin? || User.current.member_of_course?(course)
get_homework_member @homework
else
raise "error"
@ -174,7 +174,7 @@ class HomeworkAttachController < ApplicationController
def edit
#@homework = HomeworkAttach.find(params[:id])
if User.current.admin? || User.current.member_of?(@homework.bid.courses.first)
if User.current.admin? || User.current.member_of_course?(@homework.bid.courses.first)
#@members = @homework.bid.courses.first.members.joins(:member_roles).where("member_roles.role_id IN (:role_id)", {:role_id => [5, 10]})
get_homework_member @homework
else
@ -185,7 +185,7 @@ class HomeworkAttachController < ApplicationController
def update
#@homework = HomeworkAttach.find(params[:id])
course = @homework.bid.courses.first
if User.current.admin? || User.current.member_of?(course)
if User.current.admin? || User.current.member_of_course?(course)
name = params[:homework_name]
description = params[:homework_description]
if params[:homework_attach]
@ -205,7 +205,7 @@ class HomeworkAttachController < ApplicationController
end
if @homework.save
respond_to do |format|
format.html { redirect_to project_for_bid_path @homework.bid }
format.html { redirect_to course_for_bid_path @homework.bid }
format.json { head :no_content }
end
else
@ -220,7 +220,7 @@ class HomeworkAttachController < ApplicationController
if User.current.admin? || User.current == @homework.user
if @homework.destroy
respond_to do |format|
format.html { redirect_to project_for_bid_path @homework.bid }
format.html { redirect_to course_for_bid_path @homework.bid }
format.json { head :no_content }
end
else
@ -233,7 +233,7 @@ class HomeworkAttachController < ApplicationController
#显示作业信息
def show
#@homework = HomeworkAttach.find(params[:id])
if User.current.admin? || User.current.member_of?(@homework.bid.courses.first)
if User.current.admin? || User.current.member_of_course?(@homework.bid.courses.first)
# 打分统计
stars_reates = @homework.
rates(:quality)

File diff suppressed because it is too large Load Diff

@ -49,7 +49,7 @@ class MessagesController < ApplicationController
all
@reply = Message.new(:subject => "RE: #{@message.subject}")
if @message.board.project.project_type ==1
if @course
render :action => "show", :layout => "base_courses"#by young
else
render :action => "show", :layout => "base_projects"#by young
@ -138,8 +138,14 @@ private
end
def find_board
@board = Board.find(params[:board_id], :include => :project)
@project = @board.project
#modify by nwb
@board = Board.find(params[:board_id])
if @board.project_id != -1 && @board.project_id != nil
@project = @board.project
elsif @board.course_id
@course = @board.course
end
rescue ActiveRecord::RecordNotFound
render_404
nil

@ -38,37 +38,62 @@ class NewsController < ApplicationController
@limit = 10
end
scope = @project ? @project.news.visible : News.visible
@news_count = scope.count
@news_pages = Paginator.new @news_count, @limit, params['page']
@offset ||= @news_pages.offset
@newss = scope.all(:include => [:author, :project],
:order => "#{News.table_name}.created_on DESC",
:offset => @offset,
:limit => @limit)
respond_to do |format|
format.html {
@news = News.new # for adding news inline
# huang
if @project.project_type == 1
render :layout => 'base_courses'
else
render :layout => false if request.xhr?
# modify by nwb
if params[:course_id] && @course==nil
@course = Course.find(params[:course_id])
end
if @project
scope = @project ? @project.news.visible : News.visible
@news_count = scope.count
@news_pages = Paginator.new @news_count, @limit, params['page']
@offset ||= @news_pages.offset
@newss = scope.all(:include => [:author, :project],
:order => "#{News.table_name}.created_on DESC",
:offset => @offset,
:limit => @limit)
respond_to do |format|
format.html {
@news = News.new # for adding news inline
# huang
render :layout => false if request.xhr?
}
format.api
format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
end
elsif @course
scope = @course ? @course.news.course_visible : News.course_visible
@news_count = scope.count
@news_pages = Paginator.new @news_count, @limit, params['page']
@offset ||= @news_pages.offset
@newss = scope.all(:include => [:author, :course],
:order => "#{News.table_name}.created_on DESC",
:offset => @offset,
:limit => @limit)
respond_to do |format|
format.html {
@news = News.new
render :layout => 'base_courses'
}
format.api
format.atom { render_feed(@newss, :title => (@course ? @course.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
end
}
format.api
format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
end
end
end
def show
@comments = @news.comments
@comments.reverse! if User.current.wants_comments_in_reverse_order?
if @project.project_type == 1
render :layout => 'base_courses'
@comments.reverse! if User.current.wants_comments_in_reverse_order?
#modify by nwb
if @news.course_id
@course = Course.find(@news.course_id)
if @course
render :layout => 'base_courses'
end
end
end
@ -81,16 +106,31 @@ class NewsController < ApplicationController
end
def create
@news = News.new(:project => @project, :author => User.current)
@news.safe_attributes = params[:news]
@news.save_attachments(params[:attachments])
if @news.save
render_attachment_warning_if_needed(@news)
flash[:notice] = l(:notice_successful_create)
redirect_to project_news_index_path(@project)
else
layout_file = (@project.project_type == 1) ? 'base_courses' : 'base_projects'
render :action => 'new', :layout => layout_file
#modify by nwb
if @project
@news = News.new(:project => @project, :author => User.current)
@news.safe_attributes = params[:news]
@news.save_attachments(params[:attachments])
if @news.save
render_attachment_warning_if_needed(@news)
flash[:notice] = l(:notice_successful_create)
redirect_to project_news_index_path(@project)
else
layout_file = (@project.project_type == 1) ? 'base_courses' : 'base_projects'
render :action => 'new', :layout => layout_file
end
elsif @course
@news = News.new(:course => @course, :author => User.current)
@news.safe_attributes = params[:news]
@news.save_attachments(params[:attachments])
if @news.save
render_attachment_warning_if_needed(@news)
flash[:notice] = l(:notice_successful_create)
redirect_to course_news_index_path(@course)
else
layout_file = 'base_courses'
render :action => 'new', :layout => layout_file
end
end
end
@ -111,7 +151,13 @@ class NewsController < ApplicationController
def destroy
@news.destroy
redirect_to project_news_index_path(@project)
# modify by nwb
if @project
redirect_to project_news_index_path(@project)
elsif @course
redirect_to course_news_index_path(@course)
end
end
private

@ -353,11 +353,6 @@ class ProjectsController < ApplicationController
#gcmend
# 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})

@ -4,7 +4,8 @@ class TagsController < ApplicationController
layout "base_tags"
before_filter :require_admin,:only => :show
include CoursesHelper
include ProjectsHelper
include IssuesHelper
include UsersHelper
@ -14,6 +15,7 @@ class TagsController < ApplicationController
include ContestsHelper
include ActsAsTaggableOn::TagsHelper
helper :projects
helper :courses
include TagsHelper
helper :tags
include OpenSourceProjectsHelper
@ -64,6 +66,7 @@ class TagsController < ApplicationController
# 获取搜索结果
@obj,@obj_pages,@results_count,@users_results,
@projects_results,
@@courses_results,
@issues_results,
@bids_results,
@forums_results,
@ -96,6 +99,7 @@ class TagsController < ApplicationController
# 获取搜索结果
@obj,@obj_pages,@results_count,@users_results,
@projects_results,
@@courses_results,
@issues_results,
@bids_results,
@forums_results,
@ -114,6 +118,7 @@ class TagsController < ApplicationController
# 获取搜索结果
@obj,@obj_pages,@results_count,@users_results,
@projects_results,
@@courses_results,
@issues_results,
@bids_results,
@forums_results,
@ -188,6 +193,7 @@ class TagsController < ApplicationController
@obj_pages = nil
@obj = nil
@result = nil
@courses_results = nil
# 这里为了提高系统的响应速度 把搜索结果放到case中去了
case obj_flag
@ -219,6 +225,9 @@ class TagsController < ApplicationController
when '8'
@obj = OpenSourceProject.find_by_id(obj_id)
@obj_pages, @open_source_projects_results, @results_count = for_pagination(get_open_source_projects_by_tag(selected_tags))
when '9' then
@obj = Course.find_by_id(obj_id)
@obj_pages, @courses_results, @results_count = for_pagination(get_courses_by_tag(selected_tags))
else
@obj = nil
end
@ -232,6 +241,7 @@ class TagsController < ApplicationController
@forums_results,
attachments_results,
@contests_results,
@courses_results,
@open_source_projects_results]
end
@ -279,6 +289,8 @@ class TagsController < ApplicationController
return 'Contest'
when '8'
return 'OpenSourceProject'
when '9'
return 'Course'
else
render_error :message => e.message
return

@ -206,19 +206,19 @@ class UsersController < ApplicationController
end
end
membership = @user.memberships.all(:conditions => Project.visible_condition(User.current))
membership = @user.coursememberships.all#@user.coursememberships.all(:conditions => Course.visible_condition(User.current))
membership.sort! {|older, newer| newer.created_on <=> older.created_on }
@memberships = []
membership.collect { |e|
@memberships.push(e) if(e.project.project_type == 1)
@memberships.push(e)
}
## 判断课程是否过期 [需封装]
@memberships_doing = []
@memberships_done = []
now_time = Time.now.year
@memberships.map { |e|
end_time = e.project.course_extra.get_time.year
isDone = course_endTime_timeout?(e.project)
end_time = e.course.get_time.year
isDone = course_endTime_timeout?(e.course)
if isDone
@memberships_done.push e
else
@ -675,6 +675,8 @@ class UsersController < ApplicationController
@obj = Contest.find_by_id(@obj_id)
when '8'
@obj = OpenSourceProject.find_by_id(@obj_id)
when '9'
@obj = Course.find_by_id(@obj_id)
else
@obj = nil
end
@ -716,6 +718,8 @@ class UsersController < ApplicationController
@obj = Contest.find_by_id(@obj_id)
when '8'
@obj = OpenSourceProject.find_by_id(@obj_id)
when '9'
@obj = Course.find_by_id(@obj_id)
else
@obj = nil
end

@ -163,6 +163,20 @@ class WordsController < ApplicationController
end
end
# add by nwb
def leave_course_message
user = User.current
message = params[:new_form][:course_message]
feedback = Course.add_new_jour(user, message, params[:id])
if(feedback.errors.empty?)
redirect_to course_feedback_path(params[:id]), notice: l(:label_feedback_success)
else
flash[:error] = feedback.errors.full_messages[0]
redirect_to course_feedback_path(params[:id])
end
end
def add_brief_introdution
user = User.current
@ -182,10 +196,14 @@ class WordsController < ApplicationController
end
def obj_distinguish_url_origin
#modify by nwb
#添加对课程留言的支持
referer = request.headers["Referer"]
obj_id = referer.match(%r(/([0-9]{1,})(/|$)))[1]
if referer.match(/project/)
obj = Project.find_by_id(obj_id)
elsif referer.match(/course/)
obj = Course.find_by_id(obj_id)
elsif referer.match(/user/)
obj = User.find_by_id(obj_id)
elsif ( referer.match(/bids/) || referer.match(/calls/) )
@ -203,11 +221,15 @@ class WordsController < ApplicationController
end
def add_reply_adapter options
#modify by nwb
#添加对课程留言的支持
obj = obj_distinguish_url_origin
if obj.kind_of? User
obj.add_jour(nil, nil, nil, options)
elsif obj.kind_of? Project
Project.add_new_jour(nil, nil, obj.id, options)
elsif obj.kind_of? Course
Course.add_new_jour(nil, nil, obj.id, options)
elsif obj.kind_of? Bid
obj.add_jour(nil, nil, nil, options)
elsif obj.kind_of? Contest

@ -37,7 +37,7 @@ class ZipdownController < ApplicationController
#下载某一学生的作业的所有文件
def download_user_homework
homework = HomeworkAttach.find params[:homework]
if homework != nil && (User.current.admin? || User.current.member_of?(homework.bid.courses.first))
if homework != nil && (User.current.admin? || User.current.member_of_course?(homework.bid.courses.first))
zipfile = zip_homework_by_user homework
send_file zipfile, :filename => homework.name+".zip", :type => detect_content_type(zipfile) if zipfile
else

@ -46,6 +46,11 @@ module ApplicationHelper
def authorize_for(controller, action)
User.current.allowed_to?({:controller => controller, :action => action}, @project)
end
# add by nwb
def authorize_for_course(controller, action)
User.current.allowed_to?({:controller => controller, :action => action}, @course)
end
def authorize_for_contest(controller, action)
User.current.allowed_to?({:controller => controller, :action => action}, @contest)
@ -177,6 +182,18 @@ module ApplicationHelper
end
end
def link_to_course(course, options={}, html_options = nil)
if course.archived?
h(course.name)
elsif options.key?(:action)
ActiveSupport::Deprecation.warn "#link_to_course with :action option is deprecated and will be removed in Redmine 3.0."
url = {:controller => 'courses', :action => 'show', :id => project}.merge(options)
link_to course.name, url, html_options
else
link_to course.name, course_path(course, options), html_options
end
end
# Generates a link to a project settings if active
def link_to_project_settings(project, options={}, html_options=nil)
if project.active?
@ -303,7 +320,41 @@ module ApplicationHelper
@project = original_project
end
s.html_safe
end
def render_course_nested_lists(courses)
s = ''
if courses.any?
ancestors = []
original_course = @course
#modified by nie
courses.each do |course|
# set the project environment to please macros.
@course = course
if (ancestors.empty? )#|| course.is_descendant_of?(ancestors.last))
s << "<ul class=courses'>\n"
else
ancestors.pop
s << "</li>"
while (ancestors.any? )#&& !course.is_descendant_of?(ancestors.last))
ancestors.pop
s << "</ul></li>\n"
end
end
classes = (ancestors.empty? ? 'root' : 'child')
s << "<li class='project-table'><div class='#{classes}'>"
s << (render :partial => 'courses/course', :locals => {:course => course}).to_s
s << "</div>\n"
ancestors << course
end
s << ("</li></ul>\n" * ancestors.size)
@course = original_course
end
s.html_safe
end
#added by young
def render_project_nested_lists_new(projects)
s = ''
@ -1645,9 +1696,9 @@ module ApplicationHelper
main_project_link = link_to l(:label_project_deposit), {:controller => 'welcome', :action => 'index', :host => Setting.project_domain}
main_contest_link = link_to l(:label_contest_innovate), {:controller => 'welcome', :action => 'index', :host => Setting.contest_domain}
course_all_course_link = link_to l(:label_course_all), {:controller => 'projects', :action => 'course', :project_type => 1, :host => Setting.course_domain}
course_all_course_link = link_to l(:label_course_all), {:controller => 'courses', :action => 'index'}
course_teacher_all_link = link_to l(:label_teacher_all), {:controller => 'users', :action => 'index', :role => 'teacher', :host => Setting.course_domain}
courses_link = link_to l(:label_course_practice), {:controller => 'projects', :action => 'course', :project_type => 1, :host => Setting.course_domain}
courses_link = link_to l(:label_course_practice), {:controller => 'courses', :action => 'index'}
projects_link = link_to l(:label_project_deposit), {:controller => 'projects', :action => 'index', :project_type => 0, :host => Setting.project_domain}
users_link = link_to l(:label_software_user), {:controller => 'users', :action => 'index', :host => Setting.user_domain}
contest_link = link_to l(:label_contest_innovate), {:controller => 'contests', :action => 'index'}

@ -42,7 +42,7 @@ module AvatarHelper
end
def get_avatar?(source)
if File.exist?(disk_filename(source.class,source.id))
if source && File.exist?(disk_filename(source.class,source.id))
return true
else
return false

@ -29,6 +29,19 @@ module BoardsHelper
breadcrumb links
end
# add by nwb
def course_board_breadcrumb(item)
board = item.is_a?(Message) ? item.board : item
links = [link_to(l(:label_board_plural), course_boards_path(item.course))]
boards = board.ancestors.reverse
if item.is_a?(Message)
boards << board
end
links += boards.map {|ancestor| link_to(h(ancestor.name), course_board_path(ancestor.course, ancestor))}
breadcrumb links
end
def boards_options_for_select(boards)
options = []
Board.board_tree(boards) do |board, level|

@ -55,8 +55,9 @@ module ContestsHelper
content_tag('div', content, :class => "tabs_enterprise")
end
#end
#huang
def sort_contest(state)
content = ''.html_safe

@ -31,6 +31,39 @@ module CoursesHelper
# searchStudent(project).count
end
# 判断用户是否是课程的管理员
# add by nwb
def is_course_manager?(user_id,course_id)
@result = false
@user_id = CourseInfo.find_by_course_id(course_id)
if @user_id == user.id
@result = true
end
return @result
end
# 返回课程设置界面
def course_settings_tabs
tabs = [{:name => 'info', :action => :edit_course, :partial => 'courses/edit', :label => :label_information_plural},
{:name => 'members', :action => :manage_members, :partial => 'courses/settings/members', :label => :label_member_plural}
]
tabs.select { |tab| User.current.allowed_to?(tab[:action], @course) }
end
#是否启动互评下拉框
def is_evaluation_option
type = []
option1 = []
option2 = []
option1 << l(:lable_start_mutual_evaluation)
option1 << 1
option2 << l(:lable_close_mutual_evaluation)
option2 << 2
type << option1
type << option2
end
# garble count 混淆数量
# alias projectCountOrigin projectCount
# def projectCount project
@ -38,6 +71,19 @@ module CoursesHelper
# garble count
# end
def homework_type_option
type = []
option1 = []
option2 = []
option1 << l(:label_task_submit_form_accessory)
option1 << 1
option2 << l(:label_task_submit_form_project)
option2 << 2
type << option1
type << option2
end
alias teacherCountOrigin teacherCount
def teacherCount project
count = teacherCountOrigin project
@ -45,11 +91,26 @@ module CoursesHelper
end
alias studentCountOrigin studentCount
def studentCount project
count = studentCountOrigin project
def studentCount course
count = studentCountOrigin course
garble count
end
def eventToLanguageCourse event_type, course
case event_type
when "issue-note"
l :label_issue
when "issue"
l :label_issue
when "attachment"
l :label_attachment
when "news"
l :label_notification
else
""
end
end
def garble count
count = count.round( 1-count.to_s.size ).to_i
return count.to_s if count.to_s.size.eql?(1)
@ -82,6 +143,35 @@ module CoursesHelper
members
end
def sort_courses(state)
content = ''.html_safe
case state
when 0
content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:courses_sort_type => '1')))
content << content_tag('li', link_to(l(:label_sort_by_influence), courses_path(:courses_sort_type => '2')))
content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:courses_sort_type => '0'), :class=>"selected"), :class=>"selected")
when 1
content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:courses_sort_type => '1'), :class=>"selected"), :class=>"selected")
content << content_tag('li', link_to(l(:label_sort_by_influence), courses_path(:courses_sort_type => '2')))
content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:courses_sort_type => '0')))
when 2
content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:courses_sort_type => '1')))
content << content_tag('li', link_to(l(:label_sort_by_influence), courses_path(:courses_sort_type => '2'), :class=>"selected"), :class=>"selected")
content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:courses_sort_type => '0')))
end
content = content_tag('ul', content)
content_tag('div', content, :class => "tabs")
end
def render_course_hierarchy(courses)
render_course_nested_lists(courses) do |course|
s = link_to_course(course, {}, :class => "#{course.css_classes} #{User.current.member_of?(course) ? 'my-course' : nil}").html_safe
s
end
end
#useless
def searchMembersByRole project, role_id
members = []
@ -93,6 +183,36 @@ module CoursesHelper
members
end
def sort_course(state, school_id)
content = ''.html_safe
case state
when 0
content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:course_sort_type => '0'), :school_id => school_id, :class=>"selected"), :class=>"selected")
content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:course_sort_type => '1', :school_id => school_id)))
content << content_tag('li', link_to(l(:label_sort_by_activity), courses_path(:course_sort_type => '3', :school_id => school_id)))
when 1
content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:course_sort_type => '0', :school_id => school_id)))
content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:course_sort_type => '1', :school_id => school_id), :class=>"selected"), :class=>"selected")
content << content_tag('li', link_to(l(:label_sort_by_activity), courses_path(:course_sort_type => '3', :school_id => school_id)))
when 2
content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:course_sort_type => '0', :school_id => school_id)))
content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:course_sort_type => '1', :school_id => school_id)))
content << content_tag('li', link_to(l(:label_sort_by_activity), courses_path(:course_sort_type => '3', :school_id => school_id)))
#gcm
when 3
content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:course_sort_type => '0', :school_id => school_id)))
content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:course_sort_type => '1', :school_id => school_id)))
content << content_tag('li', link_to(l(:label_sort_by_activity), courses_path(:course_sort_type => '3', :school_id => school_id), :class=>"selected"), :class=>"selected")
end
#gcmend
content = content_tag('ul', content)
content_tag('div', content, :class => "tabs")
end
def findCourseTime project
str = ""
begin
@ -109,8 +229,9 @@ module CoursesHelper
str
end
def get_course_term project
str = ( project.try(:course_extra).try(:time).to_s << '.' << project.try(:course_extra).try(:term).to_s )
# added by nwb
def get_course_term course
str = ( course.try(:time).to_s << '.' << course.try(:term).to_s )
str[0..-4]
end
@ -123,7 +244,7 @@ module CoursesHelper
end
# 截至到2014-03-17 这个是最终的判断课程是否过期的方法
def course_endTime_timeout? project
end_time_str = Course.find_by_extra(project.try(:identifier)).try(:endup_time)
end_time_str = Course.find_by_extra(project.try(:extra)).try(:endup_time)
begin
cTime = Time.parse(end_time_str.to_s)
rescue TypeError,ArgumentError

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save