编程作业编辑功能
This commit is contained in:
parent
d23189b933
commit
b952595660
|
@ -125,22 +125,54 @@ class HomeworkCommonController < ApplicationController
|
|||
@homework.description = params[:homework_common][:description]
|
||||
@homework.end_time = params[:homework_common][:end_time]
|
||||
@homework.publish_time = params[:homework_common][:publish_time]
|
||||
@homework.homework_type = params[:homework_common][:homework_type]
|
||||
@homework.late_penalty = params[:late_penalty]
|
||||
@homework.user_id = User.current.id
|
||||
@homework.course_id = @course.id
|
||||
|
||||
#匿评作业相关属性
|
||||
@homework_detail_manual.ta_proportion = params[:ta_proportion] || 0.6
|
||||
@homework_detail_manual.evaluation_start = params[:evaluation_start]
|
||||
@homework_detail_manual.evaluation_end = params[:evaluation_end]
|
||||
@homework_detail_manual.evaluation_num = params[:evaluation_num]
|
||||
@homework_detail_manual.absence_penalty = params[:absence_penalty]
|
||||
@homework_detail_programing = @homework.homework_detail_programing
|
||||
if @homework.homework_type == 2 #编程作业
|
||||
@homework_detail_programing.language = "C++"
|
||||
@homework_detail_programing.standard_code = params[:standard_code]
|
||||
homework_tests = @homework.homework_tests
|
||||
#需要删除的测试
|
||||
ids = homework_tests.map(&:id) - params[:input].keys.map(&:to_i)
|
||||
ids.each do |id|
|
||||
homework_test = HomeworkTest.find id
|
||||
homework_test.destroy if homework_test
|
||||
end
|
||||
|
||||
if params[:input] && params[:output]
|
||||
params[:input].each do |k,v|
|
||||
if params[:output].include? k
|
||||
homework_test = HomeworkTest.find_by_id k
|
||||
if homework_test #已存在的测试,修改
|
||||
homework_test.input = v
|
||||
homework_test.output = params[:output][k]
|
||||
else #不存在的测试,增加
|
||||
homework_test = HomeworkTest.new
|
||||
homework_test.input = v
|
||||
homework_test.output = params[:output][k]
|
||||
homework_test.homework_common = @homework
|
||||
end
|
||||
homework_test.save
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
#匿评作业相关属性
|
||||
@homework_detail_manual.ta_proportion = params[:ta_proportion] || 0.6
|
||||
@homework_detail_manual.evaluation_start = params[:evaluation_start]
|
||||
@homework_detail_manual.evaluation_end = params[:evaluation_end]
|
||||
@homework_detail_manual.evaluation_num = params[:evaluation_num]
|
||||
@homework_detail_manual.absence_penalty = params[:absence_penalty]
|
||||
end
|
||||
|
||||
@homework.save_attachments(params[:attachments])
|
||||
render_attachment_warning_if_needed(@homework)
|
||||
|
||||
if @homework.save && @homework_detail_manual.save
|
||||
if @homework.save
|
||||
@homework_detail_manual.save if @homework_detail_manual
|
||||
@homework_detail_programing.save if @homework_detail_programing
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash[:notice] = l(:notice_successful_edit)
|
||||
|
|
Loading…
Reference in New Issue