Merge branch 'sw_new_course' of http://repository.trustie.net/xianbo/trustie2 into sw_new_course

This commit is contained in:
z9hang 2015-03-24 08:43:54 +08:00
commit a2ec9c661a
11 changed files with 306 additions and 578 deletions

View File

@ -15,7 +15,7 @@ class BidsController < ApplicationController
before_filter :can_show_contest,only: []
#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_courseEx,: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
@ -48,7 +48,7 @@ class BidsController < ApplicationController
format.js
end
end
def index
@project_type = params[:project_type]
@ -57,8 +57,8 @@ class BidsController < ApplicationController
@offset, @limit = api_offset_and_limit({:limit => 10})
if @project_type == '1'
@bids = Bid.visible.where('reward_type = ?', 3)
# elsif
# @bids = Bid.visible.where('reward_type = ? or reward_type = ?', 4)
# elsif
# @bids = Bid.visible.where('reward_type = ? or reward_type = ?', 4)
else
@bids = Bid.visible.where('reward_type = ?', 1)
end
@ -71,33 +71,33 @@ class BidsController < ApplicationController
#added by nie
if params[:bid_sort_type].present?
case params[:bid_sort_type]
when '0'
unless @offset == 0
@bids = @bids.offset(@offset).limit(@limit).all.reverse
else
limit = @bid_count % @limit
limit = @limit if limit == 0
@bids = @bids.offset(@offset).limit(limit).all.reverse
end
@s_state = 0
when '1'
unless @offset == 0
@bids = @bids.reorder('bids.commit').offset(@offset).limit(@limit).all.reverse
else
limit = @bid_count % @limit
limit = @limit if limit == 0
@bids = @bids.reorder('bids.commit').offset(@offset).limit(limit).all.reverse
end
@s_state = 1
when '2'
unless @offset == 0
@bids = @bids.offset(@offset).limit(@limit).all.reverse
else
limit = @bid_count % @limit
limit = @limit if limit == 0
@bids = @bids.offset(@offset).limit(@limit).all.reverse
end
@s_state = 0
when '0'
unless @offset == 0
@bids = @bids.offset(@offset).limit(@limit).all.reverse
else
limit = @bid_count % @limit
limit = @limit if limit == 0
@bids = @bids.offset(@offset).limit(limit).all.reverse
end
@s_state = 0
when '1'
unless @offset == 0
@bids = @bids.reorder('bids.commit').offset(@offset).limit(@limit).all.reverse
else
limit = @bid_count % @limit
limit = @limit if limit == 0
@bids = @bids.reorder('bids.commit').offset(@offset).limit(limit).all.reverse
end
@s_state = 1
when '2'
unless @offset == 0
@bids = @bids.offset(@offset).limit(@limit).all.reverse
else
limit = @bid_count % @limit
limit = @limit if limit == 0
@bids = @bids.offset(@offset).limit(@limit).all.reverse
end
@s_state = 0
end
else
unless @offset == 0
@ -109,7 +109,7 @@ class BidsController < ApplicationController
end
@s_state = 1
end
#end
#end
end
#huang
def contest
@ -130,33 +130,33 @@ class BidsController < ApplicationController
#added by nie
if params[:contest_sort_type].present?
case params[:contest_sort_type]
when '0'
unless @offset == 0
@bids = @bids.offset(@offset).limit(@limit).all.reverse
else
limit = @bid_count % @limit
limit = @limit if limit == 0
@bids = @bids.offset(@offset).limit(limit).all.reverse
end
@s_state = 0
when '1'
unless @offset == 0
@bids = @bids.reorder('bids.commit').offset(@offset).limit(@limit).all.reverse
else
limit = @bid_count % @limit
limit = @limit if limit == 0
@bids = @bids.reorder('bids.commit').offset(@offset).limit(limit).all.reverse
end
@s_state = 1
when '2'
unless @offset == 0
@bids = @bids.offset(@offset).limit(@limit).all.reverse
else
limit = @bid_count % @limit
limit = @limit if limit == 0
@bids = @bids.offset(@offset).limit(@limit).all.reverse
end
@s_state = 0
when '0'
unless @offset == 0
@bids = @bids.offset(@offset).limit(@limit).all.reverse
else
limit = @bid_count % @limit
limit = @limit if limit == 0
@bids = @bids.offset(@offset).limit(limit).all.reverse
end
@s_state = 0
when '1'
unless @offset == 0
@bids = @bids.reorder('bids.commit').offset(@offset).limit(@limit).all.reverse
else
limit = @bid_count % @limit
limit = @limit if limit == 0
@bids = @bids.reorder('bids.commit').offset(@offset).limit(limit).all.reverse
end
@s_state = 1
when '2'
unless @offset == 0
@bids = @bids.offset(@offset).limit(@limit).all.reverse
else
limit = @bid_count % @limit
limit = @limit if limit == 0
@bids = @bids.offset(@offset).limit(@limit).all.reverse
end
@s_state = 0
end
else
unless @offset == 0
@ -168,7 +168,7 @@ class BidsController < ApplicationController
end
@s_state = 1
end
#end
#end
end
def fork
@ -176,7 +176,7 @@ class BidsController < ApplicationController
@membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
@membership.each do |membership|
if membership.project.project_type == 1
@courses << membership.project
@courses << membership.project
end
end
end
@ -229,12 +229,12 @@ class BidsController < ApplicationController
layout_file = ''
case @bid.reward_type
when 3
html_title(l(:label_question_student))
layout_file = 'base_homework'
when 1
layout_file = 'base_bids'
else
layout_file = 'base_contest'
html_title(l(:label_question_student))
layout_file = 'base_homework'
when 1
layout_file = 'base_bids'
else
layout_file = 'base_contest'
end
format.html {
render :layout => layout_file
@ -242,7 +242,7 @@ class BidsController < ApplicationController
format.api
end
end
def join_in_contest
if @bid.reward_type == 2 && params[:course_password] == @bid.password
JoinInContest.create(:user_id => User.current.id, :bid_id => @bid.id)
@ -250,49 +250,49 @@ class BidsController < ApplicationController
else
@state = 1
end
respond_to do |format|
# format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
# TO_DO
format.js { render :partial => 'set_join', :locals => {:user => User.current, :object_id => params[:id]} }
end
end
def unjoin_in_contest
joined = JoinInContest.where('bid_id = ? and user_id = ?', @bid.id, User.current.id)
joined.each do |join|
join.delete
end
respond_to do |format|
# format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
format.js { render :partial => 'set_join', :locals => {:user => User.current, :object_id => params[:id]} }
end
end
def new_join
# added by fq
end
# added by bai 增加了参与者和竞赛设置
def show_participator
render :layout => 'base_contest'
end
def settings
if @bid.author.id == User.current.id
if @bid.reward_type == 2
@contest = Bid.find_by_reward_type(@bid.reward_type)
render :layout => 'base_contest'
end
else
render_403 :message => :notice_not_contest_setting_authorized
end
if @bid.author.id == User.current.id
if @bid.reward_type == 2
@contest = Bid.find_by_reward_type(@bid.reward_type)
render :layout => 'base_contest'
end
else
render_403 :message => :notice_not_contest_setting_authorized
end
end
#end
@ -311,12 +311,12 @@ class BidsController < ApplicationController
}
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
@ -337,12 +337,12 @@ class BidsController < ApplicationController
}
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
@ -365,12 +365,12 @@ class BidsController < ApplicationController
}
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
@ -569,12 +569,12 @@ class BidsController < ApplicationController
}
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
@ -586,19 +586,19 @@ class BidsController < ApplicationController
bid_message = params[:bid_for_save][:bid_message]
if BidingProject.where("project_id = ? and bid_id = ?", project.id, @bid.id).size == 0
if BidingProject.cerate_bidding(@bid.id, project.id, bid_message)
# added by bai type ==1 需求type==2 竞赛, type==3 作业
if @bid.reward_type == 1
flash.now[:notice] = l(:label_bidding_succeed)
elsif @bid.reward_type == 2
flash.now[:notice] = l(:label_bidding_contest_succeed)
else @bid.reward_type == 3
flash.now[:notice] = l(:label_bidding_homework_succeed)
flash.now[:notice] = l(:label_bidding_homework_succeed)
end
# end
end
else
if @bid.reward_type == 3
@ -609,11 +609,11 @@ class BidsController < ApplicationController
end
@bidding_project = @bid.biding_projects
respond_to do |format|
# format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}}
# format.html
# format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}}
# format.html
format.html { redirect_to :back }
format.js
#format.api { render_api_ok }
#format.api { render_api_ok }
end
end
@ -647,7 +647,7 @@ class BidsController < ApplicationController
@bid.set_commit(@feedback_count)
respond_to do |format|
format.js
#format.api { render_api_ok }
#format.api { render_api_ok }
end
end
@ -674,9 +674,9 @@ class BidsController < ApplicationController
# @message_count = a_message.count
respond_to do |format|
# format.html
# format.html
format.js
#format.api { render_api_ok }
#format.api { render_api_ok }
end
end
@ -689,7 +689,7 @@ class BidsController < ApplicationController
respond_to do |format|
format.html { redirect_to :back }
format.js
#format.api { render_api_ok }
#format.api { render_api_ok }
end
end
@ -698,11 +698,11 @@ class BidsController < ApplicationController
def new
@jour = JournalsForMessage.find(params[:journal_id]) if params[:journal_id]
if @jour
user = @jour.user
text = @jour.notes
user = @jour.user
text = @jour.notes
else
user = @bid.author
text = @bid.description
user = @bid.author
text = @bid.description
end
# Replaces pre blocks with [...]
text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
@ -711,7 +711,7 @@ class BidsController < ApplicationController
@id = user.id
rescue ActiveRecord::RecordNotFound
render_404
end
end
##新建需求
def new_bid
@ -743,15 +743,15 @@ class BidsController < ApplicationController
end
end
# added by bai
def update_contest
# added by bai
def update_contest
@bid = Bid.find(params[:id])
@bid.name = params[:bid][:name]
@bid.description = params[:bid][:description]
@bid.reward_type = 2
@bid.budget = params[:bid][:budget]
@bid.deadline = params[:bid][:deadline]
@bid.password = params[:bid][:password]
@bid.password = params[:bid][:password]
@bid.author_id = User.current.id
@bid.commit = 0
if @bid.save
@ -825,31 +825,31 @@ class BidsController < ApplicationController
@course = Course.find_by_id(params[:course_id])
@course_id = @course.id
#respond_to do |format|
# format.html { redirect_to new_homework_course_path(params[:course_id]),:layout => 'base_courses'}
# format.api { render_validation_errors(@bid) }
#end
# format.html { redirect_to new_homework_course_path(params[:course_id]),:layout => 'base_courses'}
# format.api { render_validation_errors(@bid) }
#end
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.allowed_to?(:as_teacher,@bid.courses.first))
@course_id = params[:course_id]
respond_to do |format|
format.html {
@course = Course.find(params[:course_id])
@user= User.find(User.current.id)
render :layout => 'base_courses'
}
end
def edit
@bid = Bid.find(params[:bid_id])
if (User.current.admin?||User.current.allowed_to?(:as_teacher,@bid.courses.first))
@course_id = params[:course_id]
respond_to do |format|
format.html {
@course = Course.find(params[:course_id])
@user= User.find(User.current.id)
render :layout => 'base_courses'
}
end
else
render_403
end
end
def update
@bid = Bid.find(params[:id])
@course = @bid.courses.first#Project.find(params[:course_id])
@ -881,38 +881,38 @@ class BidsController < ApplicationController
find_bid
render :layout => 'base_homework'
end
def add_homework
if User.current.logged? && (!Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id =?',5, 10, 7)).size >0)
# homework = HomeworkAttach.create(:bid_id => @bid.id, :user_id => User.current.id)
# homework.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads]))
if hadcommittedhomework(User.current.id, @bid.id) == true
@homework_flag = l(:label_bidding_homework_committed)
else
@homework = HomeworkAttach.new
@homework.safe_attributes = params[:homeworkattach]
@homework.bid_id = @bid.id
@homework.user_id = User.current.id
@homework.save_attachments(params[:attachments])
render_attachment_warning_if_needed(@homework)
@homework_flag = if @homework.save
l(:label_bidding_homework_succeed)
else
l(:label_bidding_homework_failed)
end
if @homework.attachments.empty?
@homework.delete
#flash[:error] = l(:no_attachmens_allowed)
@homework_flag = l(:no_attachmens_allowed)
# else
end
end
if hadcommittedhomework(User.current.id, @bid.id) == true
@homework_flag = l(:label_bidding_homework_committed)
else
@homework = HomeworkAttach.new
@homework.safe_attributes = params[:homeworkattach]
@homework.bid_id = @bid.id
@homework.user_id = User.current.id
@homework.save_attachments(params[:attachments])
render_attachment_warning_if_needed(@homework)
@homework_flag = if @homework.save
l(:label_bidding_homework_succeed)
else
l(:label_bidding_homework_failed)
end
if @homework.attachments.empty?
@homework.delete
#flash[:error] = l(:no_attachmens_allowed)
@homework_flag = l(:no_attachmens_allowed)
# else
end
end
end
@homework_list = @bid.homeworks
respond_to do |format|
format.html{
@ -931,7 +931,7 @@ class BidsController < ApplicationController
@member = []
@course.memberships.each do |member|
unless (member.roles && Role.where('id = ? ', 3)).empty?
@member.push member
@member.push member
end
end
if @bid.homework_type = 1
@ -958,7 +958,7 @@ class BidsController < ApplicationController
respond_to do |format|
format.html { redirect_to :back }
format.js
#format.api { render_api_ok }
#format.api { render_api_ok }
end
end
@ -970,7 +970,7 @@ class BidsController < ApplicationController
respond_to do |format|
format.html { redirect_to :back }
format.js
#format.api { render_api_ok }
#format.api { render_api_ok }
end
end
@ -999,7 +999,7 @@ class BidsController < ApplicationController
def manage
end
# 启动匿评
def start_anonymous_comment
@bid = Bid.find(params[:id])
@ -1031,7 +1031,7 @@ class BidsController < ApplicationController
end
end
def stop_anonymous_comment
def stop_anonymous_comment
@bid = Bid.find(params[:id])
@bid.update_column('comment_status', 2)
@ -1039,7 +1039,7 @@ class BidsController < ApplicationController
respond_to do |format|
format.js
end
end
end
def alert_anonymous_comment
@bid = Bid.find params[:id]
@ -1060,7 +1060,7 @@ class BidsController < ApplicationController
end
private
def get_assigned_homeworks(homeworks, n, index)
homeworks += homeworks
homeworks[index + 1 .. index + n]

View File

@ -33,28 +33,6 @@ class CoursesController < ApplicationController
join = cs.join_course params,User.current
@state = join[:state]
course = join[:course]
#course = Course.find_by_id params[:object_id]
#if course
# if course_endTime_timeout? course
# @state = 2
# else
# if User.current.member_of_course?(course)
# @state = 3
# else
# if params[:course_password] == course.password
# members = []
# members << Member.new(:role_ids => [10], :user_id => User.current.id)
# course.members << members
# StudentsForCourse.create(:student_id => User.current.id, :course_id => params[:object_id])
# @state = 0
# else
# @state = 1
# end
# end
# end
#else
# @state = 4
#end
else
@state = 5 #未登录
end
@ -71,25 +49,14 @@ class CoursesController < ApplicationController
def unjoin
if User.current.logged?
#
# @member = Member.where('course_id = ? and user_id = ?', params[:object_id], User.current.id)
# @member.first.destroy
#
# joined = StudentsForCourse.where('student_id = ? and course_id = ?', User.current.id, params[:object_id])
# joined.each do |join|
# join.delete
# end
cs = CoursesService.new
cs.exit_course params,User.current
end
respond_to do |format|
# format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => Course.find(params[:object_id]), :object_id => params[:object_id]} }
end
end
def join_private_courses
respond_to do |format|
@ -119,36 +86,6 @@ class CoursesController < ApplicationController
format.api { render_validation_errors(@course) }
end
end
#@course.safe_attributes = params[:course]
#@course.time = params[:time]
#@course.term = params[:term]
#@course.class_period = params[:class_period]
#if @course.save
# if params[:course][:is_public] == '0'
# course_status = CourseStatus.find_by_course_id(@course.id)
# course_status.destroy if course_status
# elsif params[:course][:is_public] == '1'
# course_status = CourseStatus.find_by_course_id(@course.id)
# course_status.destroy if course_status
# course_status = CourseStatus.create(:course_id => @course.id, :grade => 0)
# end
#
# respond_to do |format|
# format.html {
# flash[:notice] = l(:notice_successful_update)
# redirect_to settings_course_url(@course)
# }
# format.api { render_api_ok }
# end
#else
# respond_to do |format|
# format.html {
# settings
# render :action => 'settings'
# }
# format.api { render_validation_errors(@course) }
# end
#end
end
def new_join
@ -160,7 +97,6 @@ class CoursesController < ApplicationController
def search
courses_all = Course.all_course
name = params[:name]
#(redirect_to courses_url, :notice => l(:label_sumbit_empty);return) if name.blank?
if name.blank?
@courses = []
@courses_all = []
@ -347,22 +283,15 @@ class CoursesController < ApplicationController
@score_sort_by = "desc"
if params[:group_id] && params[:group_id] != "0"
@group = CourseGroup.find(params[:group_id])
@results = student_homework_score(@group.id,0, 0,"desc")
@results = paginateHelper @results, 10
else
page_from = params[:page].nil? ? 0 : (params[:page].to_i - 1)
@results = student_homework_score(0,page_from, 10,"desc")
@results = paginateHelper_for_members @results, 10
end
end
def member
## 有角色参数的才是课程,没有的就是项目
if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course)))
@ -383,12 +312,8 @@ class CoursesController < ApplicationController
@subPage_title = l :label_student_list
page = params[:page].nil? ? 0 : (params['page'].to_i - 1)
@all_members = student_homework_score(0,page, 10,"desc")
@members = paginateHelper_for_members @all_members, 10
end
respond_to do |format|
if params[:page]
format.js
@ -396,12 +321,9 @@ class CoursesController < ApplicationController
format.html {render :layout => 'base_courses'}
end
end
# render :layout => 'base_courses'
else
render_403
end
end
def export_course_member_excel
@ -415,20 +337,9 @@ class CoursesController < ApplicationController
end
def member_score_sort
# @teachers= searchTeacherAndAssistant(@course)
@canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
# @role = params[:role]
# @course_groups = @course.course_groups if @course.course_groups
# @show_serch = params[:role] == '2'
@subPage_title = l :label_student_list
@render_file = 'member_list'
# @results = params[:result] if params[:result]
# unless @result.nil?
# @results = @result.reverse
#
# end
# @results = paginateHelper @results@score_sort_by = "desc"
@render_file = 'member_list'
@is_remote = true
@score_sort_by = params[:sort_by] if params[:sort_by]
@search_name = params[:search_name] if params[:search_name]
@ -436,7 +347,6 @@ class CoursesController < ApplicationController
if !@search_name.nil?
if group_id == '0'
page = params[:page].nil? ? 0 : (params['page'].to_i - 1)
@results = searchmember_by_name(student_homework_score(0,0,0,@score_sort_by), @search_name)
@result_count = @results.count
@results = paginateHelper @results, 10
@ -450,7 +360,6 @@ class CoursesController < ApplicationController
if group_id == '0'
page = params[:page].nil? ? 0 : (params['page'].to_i - 1)
@results = student_homework_score(0,page, 10,@score_sort_by)
@results = paginateHelper_for_members @results, 10
else
@group = CourseGroup.find(group_id)
@ -458,32 +367,25 @@ class CoursesController < ApplicationController
@results = paginateHelper @results, 10
end
end
end
# 显示每个学生的作业评分详情
def show_member_score
@member_score = Member.find(params[:member_id]) if params[:member_id]
respond_to do |format|
format.html {render :layout => 'course_base'}
format.js
end
end
def handle_course courses, activities
course_activity_count_array=activities.values()
course_array=[]
i=0;
courses.each do |course|
course_array[i]=course
i=i+1
end
courses=desc_sort_course_by_avtivity(course_activity_count_array, course_array)
return courses
end
@ -522,57 +424,6 @@ class CoursesController < ApplicationController
format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'courses', :action => 'show', :id => @course.id) }
end
end
#if User.current.user_extensions.identity
# @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[:course]
# @course.tea_id = User.current.id
# # added by bai
# @course.term = params[:term]
# @course.time = params[:time]
# #@course.school_id = params[:occupation]
# @course.school_id = User.current.user_extensions.school_id
# @course.setup_time = params[:setup_time]
# @course.endup_time = params[:endup_time]
# @course.class_period = params[:class_period]
#end
#
#@issue_custom_fields = IssueCustomField.sorted.all
#@trackers = Tracker.sorted.all
#
#if @course.save
# #unless User.current.admin?
# 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])
# m.project_id = -1
# course = CourseInfos.new(:user_id => User.current.id, :course_id => @course.id)
# #user_grades = UserGrade.create(:user_id => User.current.id, :course_id => @course.id)
# if params[:course][:is_public] == '1'
# course_status = CourseStatus.create(:course_id => @course.id, :watchers_count => 0, :changesets_count => 0, :grade => 0, :course_type => @course_tag)
# end
# @course.members << m
# @course.course_infos << course
# #end
# respond_to do |format|
# format.html {
# flash[:notice] = l(:notice_successful_create)
# if params[:continue]
# redirect_to new_course_url(attrs, :course => '0')
# elsif params[:course_continue]
# redirect_to new_course_url(:course => '1')
# else
# redirect_to settings_course_url(@course, :course_type => 1)
# end
# }
# format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'courses', :action => 'show', :id => @course.id) }
# end
# else
# #@course.destroy
# respond_to do |format|
# format.html { render :action => 'new', :layout => 'base' } #Added by young
# format.api { render_validation_errors(@course) }
# end
# end
end
def course
@ -590,54 +441,28 @@ class CoursesController < ApplicationController
@course_count = @courses_all.count
@course_pages = Paginator.new @course_count, per_page_option, params['page']
#gcm activity count
@course_activity_count=Hash.new
#count initialize
@courses_all.each do |course|
@course_activity_count[course.id]=0
end
#@course_activity_count=get_course_activity @courses_all,@course_activity_count
#gcm end
case params[:course_sort_type]
when '0'
@courses = @courses_all.order("created_on desc")
@s_type = 0
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
#gcm
@course_activity_count=get_course_activity @courses,@course_activity_count
#gcmend
when '1'
@courses = @courses_all.order("course_ac_para desc")
@s_type = 1
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
#gcm
@course_activity_count=get_course_activity @courses,@course_activity_count
#gcmend
when '2'
@courses = @courses_all.order("watchers_count desc")
@s_type = 2
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
#gcm
@course_activity_count=get_course_activity @courses,@course_activity_count
#gcmend
#gcm
when '3'
#gcm
@course_activity_count=get_course_activity @courses_all,@course_activity_count
#gcmend
@courses=handle_course @courses_all,@course_activity_count
@s_type = 3
@courses = @courses[@course_pages.offset, @course_pages.per_page]
@ -645,11 +470,7 @@ class CoursesController < ApplicationController
@s_type = 0
@courses = @courses_all.order("created_on desc")
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
#gcm
@course_activity_count=get_course_activity @courses,@course_activity_count
#gcmend
end
respond_to do |format|
@ -657,9 +478,6 @@ class CoursesController < ApplicationController
render :layout => 'base'
}
format.api {
# @offset, @limit = api_offset_and_limit
# @course_count = Course.visible.count
# @courses = Course.visible.offset(@offset).limit(@limit).order('lft').all
}
format.atom {
courses = Course.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all
@ -668,20 +486,16 @@ class CoursesController < ApplicationController
end
end
def new
@course_type = params[:course_type] ||= params[:course]
@issue_custom_fields = IssueCustomField.sorted.all
@trackers = Tracker.sorted.all
@course = Course.new
@course.safe_attributes = params[:course]
month = Time.now.month
render :layout => 'base'
end
def desc_sort_course_by_avtivity(activity_count, courses)
return courses if activity_count.size<2
(activity_count.size-2).downto(0) do |i|
@ -762,22 +576,7 @@ class CoursesController < ApplicationController
bids = bids.like(params[:name]) if params[:name].present?
@bids = paginateHelper bids,10
@is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course))
#
# @offset, @limit = api_offset_and_limit({:limit => 10})
#
# @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
# if limit == 0
# limit = 10
# end
# @bids = @bids.offset(@offset).limit(limit).all.reverse
# end
@is_student = User.current.logged? && (User.current.admin? || (User.current.member_of_course?(@course) && !@is_teacher))
render :layout => 'base_courses'
else
render_403
@ -853,26 +652,19 @@ class CoursesController < ApplicationController
end
def show
# try to redirect to the requested menu item
if params[:jump] && redirect_to_course_menu_item(@course, params[:jump])
return
end
@users_by_role = @course.users_by_role
if(User.find_by_id(CourseInfos.find_by_course_id(@course.id).try(:user_id)))
@user = User.find_by_id(CourseInfos.find_by_course_id(@course.id).user_id)
end
@key = User.current.rss_key
#新增内容
@days = Setting.activity_days_default.to_i
if params[:from]
begin; @date_to = params[:from].to_date + 1; rescue; end
end
has = {
"show_course_files" => true,
"show_course_news" => true,
@ -881,9 +673,7 @@ class CoursesController < ApplicationController
"show_course_journals_for_messages" => true
}
@date_to ||= Date.today + 1
#
@date_from = (@date_to - @days) > @course.created_at.to_date ? (@date_to - @days) : @course.created_at.to_date
#@date_from = @date_to - @days-1.years
@author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id]))
# 决定显示所用用户或单个用户活动
@activity = Redmine::Activity::Fetcher.new(User.current, :course => @course,
@ -892,13 +682,11 @@ class CoursesController < ApplicationController
@activity.scope_select {|t| has["show_#{t}"]}
# modify by nwb
# 添加私密性判断
if User.current.member_of_course?(@course)|| User.current.admin?
events = @activity.events(@days, @course.created_at)
else
events = @activity.events(@days, @course.created_at, :is_public => 1)
end
# 无新动态时,显示老动态
if events.count == 0
if User.current.member_of_course?(@course)|| User.current.admin?
@ -907,21 +695,10 @@ class CoursesController < ApplicationController
events = @activity.events(:is_public => 1)
end
end
# @offset, @limit = api_offset_and_limit({:limit => 10})
# @events_count = events.count
# @events_pages = Paginator.new @events_count, @limit, params['page']
# @offset ||= @events_pages.offset
# events = events.slice(@offset,@limit)
events = paginateHelper events,10
@events_by_day = events.group_by {|event| User.current.time_to_date(event.event_datetime)}
# documents
@sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
# 这写变量发现没有用而且拖慢速度
#@teachers= searchTeacherAndAssistant(@course)
#@canShowRealName = isCourseTeacher(User.current.id,@course)
if(User.find_by_id(CourseInfos.find_by_course_id(@course.id).try(:user_id)))
@user = User.find_by_id(CourseInfos.find_by_course_id(@course.id).user_id)
end
@ -951,10 +728,6 @@ class CoursesController < ApplicationController
offset = @jours.count(:conditions => ["#{JournalsForMessage.table_name}.id > ?", params[:r].to_i])
page = 1 + offset / @limit
end
#@feedback_count = @jours.count
#@feedback_pages = Paginator.new @feedback_count, @limit, page
#@offset ||= @feedback_pages.offset
@jour = paginateHelper @jours,10
@state = false
respond_to do |format|
@ -994,7 +767,6 @@ class CoursesController < ApplicationController
end
private
def allow_join course
if course_endTime_timeout? course
respond_to do |format|

View File

@ -694,16 +694,46 @@ module CoursesHelper
end
def bid_anonymous_comment bid
if bid.open_anonymous_evaluation == 1 && bid.homeworks.count >= 2
if bid.open_anonymous_evaluation == 1
if bid.homeworks.count >= 2
case bid.comment_status
when 0
link = link_to '启动匿评', alert_anonymous_comment_bid_path(bid), id: "#{bid.id}_start_anonymous_comment", remote: true, disable_with: '加载中...',:class => 'fr mr10 work_edit'
when 1
link = link_to '关闭匿评', alert_anonymous_comment_bid_path(bid), id: "#{bid.id}_stop_anonymous_comment", remote: true,:class => 'fr mr10 work_edit'
when 2
link = "<span class='fr mr10 pr_join_span ' title='匿评结束'>匿评结束</span>".html_safe
end
else
link = "<span class='fr mr10 pr_join_span ' title='学生提交作业数大于2时才可以启动匿评'>启动匿评</span>".html_safe
end
else
link = "<span class='fr mr10 pr_join_span ' title='未开启匿评作业不可以启动匿评'>启动匿评</span>".html_safe
end
link
end
def student_new_homework bid
user_homework = cur_user_homework_for_bid bid
if user_homework && user_homework.empty?
link_to l(:label_commit_homework), new_exercise_book_path(bid),:class => 'fr mr10 work_edit'
else
"<span class='fr mr10 pr_join_span '>作业已交</span>".html_safe
end
end
def student_anonymous_comment bid
if bid.open_anonymous_evaluation == 1
case bid.comment_status
when 0
# <a href="#" class="fr mr10 work_edit">关闭匿评</a>
link_to '启动匿评', alert_anonymous_comment_bid_path(bid), id: "#{bid.id}_start_anonymous_comment", remote: true, disable_with: '加载中...',:class => 'fr mr10 work_edit'
"<span class='fr mr10 pr_join_span '>未开启匿评</span>".html_safe
when 1
link_to '关闭匿评', alert_anonymous_comment_bid_path(bid), id: "#{bid.id}_stop_anonymous_comment", remote: true,:class => 'fr mr10 work_edit'
"<span class='fr mr10 pr_join_span '>正在匿评中</span>".html_safe
when 2
"<span class='fr mr10 pr_join_span '>匿评结束</span>".html_safe
"<span class='fr mr10 pr_join_span '>匿评结束</span>".html_safe
end
else
"<span class='fr mr10 pr_join_span '>未启用匿评</span>".html_safe
end
end
end

View File

@ -31,7 +31,7 @@
<span class="add_attachment" style="font-weight:normal;">
<%#= button_tag "浏览", :type=>"button", :onclick=>"CompatibleSend();" %>
<!--%= link_to image_tag(),"javascript:void(0)", :onclick => "_file.click()"%-->
<%= button_tag "文件浏览", :type=>"button", :onclick=>"_file.click()",:onmouseover => 'this.focus()',:class => 'sb' %>
<%= button_tag "文件浏览", :type=>"button", :onclick=>"_file.click()",:onmouseover => 'this.focus()',:class => 'sub_btn' %>
<%= file_field_tag 'attachments[dummy][file]',
:id => '_file',
:class => 'file_selector',

View File

@ -6,36 +6,41 @@
</div>
<div class="hwork_new">
<ul>
<li class="ml45">
<label><span class="c_red">*</span>&nbsp;<%= l(:field_name)%>&nbsp;&nbsp;</label>
<input type="text" name="bid[name]" id="bid_name" class="hwork_input" maxlength="<%= Bid::NAME_LENGTH_LIMIT%>" onkeyup="regex_bid_name();" value="<%= @homework.name%>" >
<p id="bid_name_span" class="c_red" style="padding-left: 55px;"></p>
</li>
<li class="ml45">
<label class="fl" >&nbsp;&nbsp;<%= l(:field_quote)%>&nbsp;&nbsp;</label>
<textarea name="bid[description]" placeholder="最多3000个汉字(或6000个英文字符)" class="hwork_text fl" ></textarea>
</li>
<li class="ml45">
<label><span class="c_red">*</span>&nbsp;<%= l(:field_name)%>&nbsp;&nbsp;</label>
<input type="text" name="bid[name]" id="bid_name" class="hwork_input" maxlength="<%= Bid::NAME_LENGTH_LIMIT%>" onkeyup="regex_bid_name();" value="<%= bid.name%>" >
<p id="bid_name_span" class="c_red" style="padding-left: 55px;"></p>
</li>
<li class="ml45">
<label class="fl" >&nbsp;&nbsp;<%= l(:field_quote)%>&nbsp;&nbsp;</label>
<textarea name="bid[description]" placeholder="最多3000个汉字(或6000个英文字符)" class="hwork_text fl"><%= bid.description%></textarea>
</li>
<div class="cl"></div>
<li class="ml21">
<label><span class="c_red">*</span>&nbsp;<%= l(:label_limit_time)%>&nbsp;&nbsp;</label>
<input type="text" name="bid[deadline]" id="bid_deadline" class="hwork_input02" onchange="regexDeadLine();" readonly="readonly" value="<%= bid.deadline%>" >
<%= calendar_for('bid_deadline')%>
</li>
<li class=" mb5 ml30">
<label ><%= l(:label_open_anonymous_evaluation)%>&nbsp;&nbsp;</label>
<input type="checkbox" name="bid[open_anonymous_evaluation]" id="bid_open_anonymous_evaluation" checked="<%= bid.open_anonymous_evaluation == 1 ? 'checked' : ''%>" >
<div class="cl"></div>
<li class="ml21">
<label><span class="c_red">*</span>&nbsp;<%= l(:label_limit_time)%>&nbsp;&nbsp;</label>
<input type="text" name="bid[deadline]" id="bid_deadline" class="hwork_input02" onchange="regexDeadLine();" readonly="readonly" >
<%= calendar_for('bid_deadline')%>
</li>
<li class=" mb5 ml30">
<label ><%= l(:label_open_anonymous_evaluation)%>&nbsp;&nbsp;</label>
<input type="checkbox" name="bid[open_anonymous_evaluation]" id="bid_open_anonymous_evaluation" checked="checked" >
<div class="cl"></div>
</li>
<li class="ml9">
<label><span class="c_red">*</span>&nbsp;<%= l(:field_evaluation_num)%>&nbsp;&nbsp;</label>
<input type="text" name="bid[evaluation_num]" id="bid_evaluation_num" class="hwork_input02" onkeyup="regex_evaluation_num();">
<span><%= l(:label_evaluation_description)%></span>
<p id="bid_evaluation_num_span" class="c_red" style="padding-left: 90px;"></p>
</li>
<li class="ml45">
<label>&nbsp;&nbsp;<%= l(:label_attachment_plural) %>&nbsp;&nbsp;</label>
<%= render :partial => 'attachments/form', :locals => {:container => @homework} %>
</li>
</li>
<li class="ml9">
<label><span class="c_red">*</span>&nbsp;<%= l(:field_evaluation_num)%>&nbsp;&nbsp;</label>
<input type="text" name="bid[evaluation_num]" id="bid_evaluation_num" class="hwork_input02" onkeyup="regex_evaluation_num();" value="<%= bid.evaluation_num%>">
<span><%= l(:label_evaluation_description)%></span>
<p id="bid_evaluation_num_span" class="c_red" style="padding-left: 90px;"></p>
</li>
<li class="ml45">
<label>&nbsp;&nbsp;<%= l(:label_attachment_plural) %>&nbsp;&nbsp;</label>
<%= render :partial => 'attachments/form', :locals => {:container => bid} %>
</li>
<li class=" ml90" >
<a class="blue_btn fl c_white" onclick="submit_new_bid('<%= bid_id%>');" href="#"><%= l(:button_create)%></a>
<%= link_to l(:button_cancel), homework_course_path(@course), :class => "blue_btn grey_btn fl c_white"%>
<div class="cl"></div>
</li>
</ul>
</div>
<div class="cl"></div>

View File

@ -1,129 +1,3 @@
<script type="text/javascript">
function regexName()
{
var name = $.trim($("#bid_name").val());
if(name=="")
{
$("#bid_name_span").text("名称不能为空");
$("#bid_name_span").css('color','#ff0000');
return false;
}
else
{
$("#bid_name_span").text("填写正确");
$("#bid_name_span").css('color','#008000');
return true;
}
}
function regexDeadLine()
{
var deadline = $.trim($("#bid_deadline").val());
var regex = /^\d{4}-\d{2}-\d{2}$/;
if(deadline=="")
{
$("#bid_deadline_span").text("截止日期不能为空");
$("#bid_deadline_span").css('color','#ff0000');
return false;
}
else if(regex.test(deadline))
{
$("#bid_deadline_span").text("填写正确");
$("#bid_deadline_span").css('color','#008000');
return true;
}
else
{
$("#bid_deadline_span").text("截止日期格式错误");
$("#bid_deadline_span").css('color','#ff0000');
return false;
}
}
function regexEvaluationNum()
{
var evaluation_num = $.trim($("#bid_evaluation_num").val());
var regex = /^\d+$/;
if($("#bid_open_anonymous_evaluation").attr("checked") == "checked")
{
if(evaluation_num=="")
{
$("#bid_evaluation_num_span").text("匿评分配数量不能为空");
$("#bid_evaluation_num_span").css('color','#ff0000');
return false;
}
else if(regex.test(evaluation_num))
{
if(evaluation_num > 0)
{
$("#bid_evaluation_num_span").text("填写正确");
$("#bid_evaluation_num_span").css('color','#008000');
return true;
}
else
{
$("#bid_evaluation_num_span").text("匿评分配数量必须为大于0");
$("#bid_evaluation_num_span").css('color','#ff0000');
return false;
}
}
else
{
$("#bid_evaluation_num_span").text("匿评分配数量只能为数字");
$("#bid_evaluation_num_span").css('color','#ff0000');
return false;
}
}
else
{
return true;
}
}
$(function(){
$("#bid_open_anonymous_evaluation").click(function(){
if($("#bid_open_anonymous_evaluation").attr("checked") == "checked")
{
$("#evaluation_num_p").slideDown();
}
else
{
$("#evaluation_num_p").slideUp();
}
});
});
$(function(){
$("#bid_open_anonymous_evaluation").click(function(){
if($("#bid_open_anonymous_evaluation").attr("checked") == "checked")
{
$("#evaluation_num_p").slideDown();
$("#open_anonymous_evaluation_span").slideUp();
}
else
{
$("#evaluation_num_p").slideUp();
$("#open_anonymous_evaluation_span").slideDown();
}
});
});
function submitHomework(id)
{
if(regexDeadLine()&&regexName()&&regexEvaluationNum())
{
$("#edit_bid_" + id).submit();
}
}
</script>
<h3><%= l(:label_edit_homework) %></h3>
<%= labelled_form_for @bid do |f| %>
<div class="box tabular">
<%#= render :partial => 'homework_form', :locals => { :f => f } %>
<%= render :partial => 'homework_form', :locals => { :f => f } %>
<!--<input type="button" onclick="submitHomework(<%#= @bid.id%>);" value="<%#= l(:button_create)%>" class="enterprise">-->
<a href="#" onclick="submitHomework(<%= @bid.id%>);" class="ButtonColor m3p10" >
<%= l(:button_create)%>
</a>
<% end %>
</div>
<%= render :partial => 'new_homework_form', :locals => { :bid => @bid, :bid_id => "edit_bid_#{@bid.id}"} %>
<% end %>

View File

@ -22,6 +22,9 @@
<% if @is_teacher%>
<%= bid_anonymous_comment(bid)%>
<%= link_to(l(:button_edit),edit_bid_path(:course_id =>@course.id, :bid_id => bid.id), :class => "fr mr10 work_edit") %>
<% elsif @is_student%>
<%= student_anonymous_comment bid %>
<%= student_new_homework bid %>
<% end %>
<div class="cl"></div>
<p id="bid_description_<%= bid.id%>" class="news_description mt5">

View File

@ -1,8 +1,3 @@
<%= labelled_form_for @homework, :url => {:controller => 'bids', :action => 'create_homework',:course_id => "#{params[:id] || params[:course_id]}"} do |f| %>
<%= render :partial => 'bids/new_homework_form', :locals => { :f => f } %>
<li class=" ml90" >
<a class="blue_btn fl c_white" onclick="submit_new_bid();" href="#"><%= l(:button_create)%></a>
<%= link_to l(:button_cancel), homework_course_path(@course), :class => "blue_btn grey_btn fl c_white"%>
<div class="cl"></div>
</li>
<%= render :partial => 'bids/new_homework_form', :locals => { :bid => @homework,:bid_id => "new_bid" } %>
<% end %>

View File

@ -120,10 +120,10 @@ $(function(){
});
});
function submit_new_bid()
function submit_new_bid(id)
{
if(regex_bid_name()&&regex_evaluation_num())
{
$("#new_bid").submit();
$("#"+id).submit();
}
}

View File

@ -44,11 +44,13 @@ a:hover.tb_all{ background:#eaeaea; text-decoration:none;}
.dis ul li.wping{margin-left:12px; }
.dis ul li.wping a{ margin-top:18px; margin-bottom:3px; width:43px; height:23px; background:#15bccf; color:#fff; text-align:center; padding-top:3px;}
.dis ul li.wping a:hover{ background-color:#03a1b3;}
/****翻页***/
ul.wlist{ float:right; border-bottom:none; height:30px; margin-top:20px; }
.wlist span{ border:1px solid #15bccf; padding:0 5px; margin-left:3px;}
.wlist a{ border:1px solid #15bccf; padding:0 5px; margin-left:3px;}
.wlist a:hover{ background:#15bccf; color:#fff; text-decoration:none;}
.wlist_select { background-color:#64bdd9; color:#fff; padding:0 5px; margin-left:3px; border:1px solid #64bdd9;}
ul.wlist li{float: left;}
ul.wlist li a{ border:1px solid #15bccf; padding: 1px 4px 1px 4px; margin-left:3px;}
ul.wlist li a:hover{ background:#15bccf; color:#fff; text-decoration:none;}
.wlist_select { background-color:#64bdd9; color:#fff; padding: 1px 5px 0px 5px; margin-left:3px;margin-top: -2px; border:1px solid #64bdd9;}
.code_list{ float:right; font-size:12px; color:#484848; padding:5px 3px; border-bottom:2px solid #15bccf; width:687px; }
.code_list a{ color:#787878;}
.fr{ float:right;}

View File

@ -214,6 +214,53 @@ html>body #ajax-indicator { position: fixed; }
padding-left: 26px;
vertical-align: bottom;
}
/***** end Ajax indicator ******/
/***** Flash & error messages ****/
#errorExplanation, div.flash, .nodata, .warning, .conflict {
padding: 4px 4px 4px 30px;
margin-bottom: 12px;
font-size: 1.1em;
border: 2px solid;
}
div.flash {margin-top: 8px;}
div.flash.error, #errorExplanation {
background: url(../images/exclamation.png) 8px 50% no-repeat;
background-color: #ffe3e3;
border-color: #dd0000;
color: #880000;
}
div.flash.notice {
background: url(../images/true.png) 8px 5px no-repeat;
background-color: #dfffdf;
border-color: #9fcf9f;
color: #005f00;
}
div.flash.warning, .conflict {
background: url(../images/warning.png) 8px 5px no-repeat;
background-color: #FFEBC1;
border-color: #FDBF3B;
color: #A6750C;
text-align: left;
}
.nodata, .warning {
text-align: center;
background-color: #FFEBC1;
border-color: #FDBF3B;
color: #A6750C;
}
#errorExplanation ul { font-size: 0.9em;}
#errorExplanation h2, #errorExplanation p { display: none; }
.conflict-details {font-size:80%;}
/***** end Flash & error messages ****/
/*弹出框*/
.black_overlay{display:none;position:fixed;top:0px;left:0px;width:100%;height:100%;background-color:black;z-index:1001;-moz-opacity:0.8;opacity:.80;filter:alpha(opacity=80);}
.white_content{display:none;position:fixed;top:15%;left:30%;width:420px;height: auto; margin-bottom:20px;padding:16px;border:3px solid #15bccf;background-color:white;z-index:1002;overflow:auto;}