From 66636efda9cf76da85b9562057b74c9a9fa45f75 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Fri, 11 Sep 2015 09:15:54 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=99=AE=E9=80=9A?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_common_controller.rb | 133 ++++-------------- app/views/users/_user_homework_form.html.erb | 6 +- 2 files changed, 31 insertions(+), 108 deletions(-) diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 862e6c80e..b60b12d36 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -142,116 +142,37 @@ class HomeworkCommonController < ApplicationController end def update - @homework.name = params[:homework_common][:name] - @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] if params[:homework_common][:homework_type] - unless @homework.late_penalty == params[:late_penalty] - @homework.student_works.where("created_at > '#{@homework.end_time} 23:59:59'").each do |student_work| - student_work.late_penalty = params[:late_penalty] - student_work.save - end - @homework.late_penalty = params[:late_penalty] - end - # @homework.course_id = @course.id + if params[:homework_common] + @homework.name = params[:homework_common][:name] + @homework.description = params[:homework_common][:description] + @homework.end_time = params[:homework_common][:end_time] || Time.now + @homework.course_id = params[:course_id] - #匿评作业相关属性 - if @homework.homework_type == 1 && @homework_detail_manual - @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] - unless @homework_detail_manual.absence_penalty == params[:absence_penalty] - if @homework_detail_manual.comment_status == 3 #当前作业处于匿评结束状态,修改缺评扣分才会修改每个作品应扣分的值 - work_ids = "(" + @homework.student_works.map(&:id).join(",") + ")" - @homework.student_works.each do |student_work| - absence_penalty_count = student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - student_work.user.student_works_scores.where("student_work_id IN #{work_ids}").count - student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * @homework_detail_manual.absence_penalty : 0 - student_work.save - end - end - @homework_detail_manual.absence_penalty = params[:absence_penalty] - end - elsif @homework.homework_type == 0 #普通作业,缺评扣分为0分,每个作品的缺评扣分改为0分,防止某些作业在结束匿评之后改为普通作业 - @homework.student_works.where("absence_penalty != 0").each do |student_work| - student_work.late_penalty = 0 - student_work.save - end - @homework_detail_manual.absence_penalty = 0 if @homework_detail_manual - end + @homework.save_attachments(params[:attachments]) + render_attachment_warning_if_needed(@homework) - if @homework.homework_type == 2 && @homework_detail_programing #编程作业 - @homework_detail_programing.language = params[:language] - @homework_detail_programing.standard_code = params[:standard_code] - @homework_detail_programing.ta_proportion = params[:ta_proportion] || 0.6 - 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[:result] - 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] - homework_test.result = params[:result][k] - homework_test.error_msg = params[:error_msg] - else #不存在的测试,增加 - homework_test = HomeworkTest.new - homework_test.input = v - homework_test.output = params[:output][k] - homework_test.result = params[:result][k] - homework_test.error_msg = params[:error_msg] - homework_test.homework_common = @homework - end - homework_test.save - end - end + #编程作业相关属性 + if @homework.homework_type == 2 + # homework_detail_programing = HomeworkDetailPrograming.new + # homework.homework_detail_programing = homework_detail_programing + # homework_detail_programing.ta_proportion = params[:ta_proportion] || 0.6 + # homework_detail_programing.language = params[:language_type].to_i + # + # inputs = params[:program][:input] + # if Array === inputs + # inputs.each_with_index do |val, i| + # homework.homework_tests << HomeworkTest.new( + # input: val, + # output: params[:program][:output][i] + # ) + # end + # end end - #发送修改作业的请求 - question = {title:@homework.name,content:@homework.description} - question[:input] = [] - question[:output] = [] - @homework.homework_tests.each do |test| - question[:input] << test.input - question[:output] << test.output - end - # uri = URI("http://192.168.80.21:8080/api/questions/#{@homework_detail_programing.question_id}.json") - # body = question.to_json - # res = Net::HTTP.new(uri.host, uri.port).start do |client| - # request = Net::HTTP::Put.new(uri.path) - # request.body = body - # request["Content-Type"] = "application/json" - # client.request(request) - # end - # result = JSON.parse(res.body) - end - - @homework.save_attachments(params[:attachments]) - render_attachment_warning_if_needed(@homework) - - 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) - redirect_to homework_common_index_path(:course => @course.id) - } - end - return - else - respond_to do |format| - format.html { - flash[:notice] = l(:notice_failed_edit) - redirect_to edit_homework_common_path(@homework) - } + if @homework.save + @homework_detail_manual.save if @homework_detail_manual + @homework_detail_programing.save if @homework_detail_programing + redirect_to user_homeworks_user_path(User.current.id) end end end diff --git a/app/views/users/_user_homework_form.html.erb b/app/views/users/_user_homework_form.html.erb index dfb48ef95..988c95643 100644 --- a/app/views/users/_user_homework_form.html.erb +++ b/app/views/users/_user_homework_form.html.erb @@ -45,11 +45,13 @@