From a69cee4b265beee4ed678ad4c1ecfac4fe470752 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Wed, 2 Sep 2015 21:38:13 +0800 Subject: [PATCH] =?UTF-8?q?=E8=80=81=E5=B8=88=E6=B5=8B=E8=AF=95=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_work_controller.rb | 50 ++++++++++++++----- app/controllers/users_controller.rb | 1 + app/views/users/_user_homework_list.html.erb | 5 ++ .../users/new_user_commit_homework.html.erb | 12 +++-- public/javascripts/homework.js | 3 +- 5 files changed, 53 insertions(+), 18 deletions(-) diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 3628f1d9b..6b091def9 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -12,10 +12,37 @@ class StudentWorkController < ApplicationController ### def program_test + is_test = params[:is_test] == 'true' resultObj = {status: 0, results: [], error_msg: '', time: Time.now} - student_work = find_or_save_student_work - unless student_work - resultObj[:status] = 100 + unless is_test + student_work = find_or_save_student_work + + unless student_work + resultObj[:status] = 100 + else + if @homework.homework_type == 2 && @homework.homework_detail_programing + result = test_realtime(student_work, params[:src]) + logger.debug result + resultObj[:status] = result["status"] + resultObj[:results] = result["results"] + resultObj[:error_msg] = result["error_msg"] + results = result["results"] + if result["status"].to_i == -2 #编译错误 + results = [result["error_msg"]] + end + student_work_test = student_work.student_work_tests.build(status: result["status"], results: results, + src: params[:src]) + unless student_work.save + resultObj[:status] = 200 + else + resultObj[:status] = result["status"].to_i + resultObj[:time] = student_work_test.created_at.to_s(:db) + resultObj[:index] = student_work.student_work_tests.count + end + + end + end + else if @homework.homework_type == 2 && @homework.homework_detail_programing result = test_realtime(student_work, params[:src]) @@ -27,18 +54,15 @@ class StudentWorkController < ApplicationController if result["status"].to_i == -2 #编译错误 results = [result["error_msg"]] end - student_work_test = student_work.student_work_tests.build(status: result["status"], results: results, - src: params[:src]) - unless student_work.save - resultObj[:status] = 200 - else - resultObj[:status] = result["status"].to_i - resultObj[:time] = student_work_test.created_at.to_s(:db) - resultObj[:index] = student_work.student_work_tests.count - end - + + resultObj[:status] = result["status"].to_i + resultObj[:time] = Time.now.strftime('%Y%m%d %T') + resultObj[:index] = 0 end + end + + render :json => resultObj end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 281924f55..ce2de336b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -345,6 +345,7 @@ class UsersController < ApplicationController def new_user_commit_homework @user = User.current @homework = HomeworkCommon.find(params[:homework_id]) + @is_test = params[:is_test] == 'true' @student_work = @homework.student_works.where(user_id: User.current.id).first if @student_work.nil? @student_work = StudentWork.new diff --git a/app/views/users/_user_homework_list.html.erb b/app/views/users/_user_homework_list.html.erb index 076383607..273b815c3 100644 --- a/app/views/users/_user_homework_list.html.erb +++ b/app/views/users/_user_homework_list.html.erb @@ -19,6 +19,11 @@
<%= user_for_homework_common homework_common,is_teacher %>
+ <% if homework_common.homework_type == 2 && is_teacher%> +
+ <%= link_to "模拟答题", new_user_commit_homework_users_path(homework_id: homework_common.id, is_test: true) %> +
+ <% end %>
<%= l(:label_end_time)%>:<%= homework_common.end_time%>
diff --git a/app/views/users/new_user_commit_homework.html.erb b/app/views/users/new_user_commit_homework.html.erb index a150c39ba..d06e99440 100644 --- a/app/views/users/new_user_commit_homework.html.erb +++ b/app/views/users/new_user_commit_homework.html.erb @@ -48,9 +48,11 @@
<%= @homework.name %>
截止时间:<%= @homework.end_time %>
<%= @homework.user.show_name %> -

<%= @homework.description %>
-输入 2 1 1 4 4 2 3 6 5
-输出 15
+

<%= @homework.description.html_safe %>
+ <% @homework.homework_tests.each do |test| %> +输入 <%=test.input%>
+输出 <%=test.output%>
+ <% end %>

注:迟交扣2分,缺评一个作品扣2

@@ -64,7 +66,7 @@ :homework => @homework.id }, :method => :post) do |f|%> - +
请使用 <%= @homework.language_name %> 语言编写
@@ -76,7 +78,9 @@
测试代码 + <% unless @is_test %> 提交代码 + <% end %>
<% end %> diff --git a/public/javascripts/homework.js b/public/javascripts/homework.js index 67bfd59c3..e36c9ed86 100644 --- a/public/javascripts/homework.js +++ b/public/javascripts/homework.js @@ -26,6 +26,7 @@ $(function(){ var student_work_id = $('#test-program-btn').attr('data-student-work-id'); var src = $('#program-src').val(); var title = $('#program-title').val(); + var is_test = $('input[name=is_test]').val(); if(!valid_form()){ return; @@ -33,7 +34,7 @@ $(function(){ $.post( '/student_work/program_test', - {homework: homework_id, student_work_id: student_work_id, src: src, title: title}, + {homework: homework_id, student_work_id: student_work_id, src: src, title: title, is_test: is_test}, function(data,status){ tested = true; console.log(data);