diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index db16f63d6..9f8d25c7e 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 - resultObj = {status: 0, results: [], error_msg: '', time: Time.now} - student_work = find_or_save_student_work - unless student_work - resultObj[:status] = 100 + is_test = params[:is_test] == 'true' + resultObj = {status: 0, results: [], error_msg: '', time: Time.now.strftime('%Y-%m-%d %T')} + 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 @@ -142,6 +166,10 @@ class StudentWorkController < ApplicationController end def new + if @homework.homework_type==2 + redirect_to new_user_commit_homework_users_path(homework_id: @homework.id) + return + end @user = User.current @student_work = @homework.student_works.where("user_id = ?",User.current.id).first if @student_work.nil? diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 5bd124fb9..12b0f5140 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -347,6 +347,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 @@
<%= @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分
+第<%= @student_work.student_work_tests.count - index%>次测试
<%= test.created_at.to_s(:db) %> diff --git a/public/javascripts/homework.js b/public/javascripts/homework.js index 67bfd59c3..6813f90af 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,10 +34,13 @@ $(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); + if(data.index <=0){ + data.index = $('.ProResultTop').length+1; + } if (typeof cb == 'function') {cb(); return;} @@ -44,7 +48,7 @@ $(function(){ var html=bt('t:result-list',data); $('.ProResult').prepend(html); - if (data.status==0) { + if (data.status==0 && is_test != 'true') { var r=confirm("答题正确,是否立刻提交?"); if (r) { $(".HomeWorkCon form").submit();