From dd4e67ebdb2ab95446d3269904eef026f82993a8 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Wed, 2 Sep 2015 18:09:52 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=96=B0=E7=9A=84?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E6=8F=90=E4=BA=A4=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_work_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 7726ab3da..3628f1d9b 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -134,6 +134,7 @@ class StudentWorkController < ApplicationController end def new + redirect_to new_user_commit_homework_users_path(homework_id: @homework.id) if @homework.homework_type==2 @student_work = @homework.student_works.where("user_id = ?",User.current.id).first if @student_work.nil? @student_work = StudentWork.new 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 2/5] =?UTF-8?q?=E8=80=81=E5=B8=88=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E5=8A=9F=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); From d07873cdf0a588dd34d19d16e5005d6e343b72ea Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Wed, 2 Sep 2015 21:44:08 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_work_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 95afa7264..8d5ab7a9b 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -13,7 +13,7 @@ class StudentWorkController < ApplicationController ### def program_test is_test = params[:is_test] == 'true' - resultObj = {status: 0, results: [], error_msg: '', time: Time.now} + resultObj = {status: 0, results: [], error_msg: '', time: Time.now.strftime('%Y-%m-%d %T')} unless is_test student_work = find_or_save_student_work @@ -56,7 +56,7 @@ class StudentWorkController < ApplicationController end resultObj[:status] = result["status"].to_i - resultObj[:time] = Time.now.strftime('%Y%m%d %T') + resultObj[:time] = Time.now.strftime('%Y-%m-%d %T') resultObj[:index] = 0 end From f6edbb238e5b58464ccd9800ea79028e29736a91 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Wed, 2 Sep 2015 21:47:07 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E9=9A=90=E5=8E=BB=E7=BC=96=E7=A8=8B?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E7=9A=84=E5=BE=97=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/new_user_commit_homework.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/users/new_user_commit_homework.html.erb b/app/views/users/new_user_commit_homework.html.erb index d06e99440..0ec78fb39 100644 --- a/app/views/users/new_user_commit_homework.html.erb +++ b/app/views/users/new_user_commit_homework.html.erb @@ -55,7 +55,7 @@ <% end %>

-

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

+
<%= form_for(@student_work, From a0c611378bc94e7b8bbc9e37b7ddac6801527578 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Wed, 2 Sep 2015 22:09:23 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E8=B7=B3=E8=BD=AC=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_work_controller.rb | 5 ++++- app/views/users/new_user_commit_homework.html.erb | 5 ++++- public/javascripts/homework.js | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 8d5ab7a9b..9f8d25c7e 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -166,7 +166,10 @@ class StudentWorkController < ApplicationController end def new - redirect_to new_user_commit_homework_users_path(homework_id: @homework.id) if @homework.homework_type==2 + 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/views/users/new_user_commit_homework.html.erb b/app/views/users/new_user_commit_homework.html.erb index 0ec78fb39..e4b1db757 100644 --- a/app/views/users/new_user_commit_homework.html.erb +++ b/app/views/users/new_user_commit_homework.html.erb @@ -41,7 +41,7 @@
-
提交作品
+
<%= @is_test ? '模拟答题' : '提交作品' %>
@@ -86,7 +86,10 @@ <% end %>
+ +
+ <% @student_work.student_work_tests.each_with_index do |test, index| %>

第<%= @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 e36c9ed86..6813f90af 100644 --- a/public/javascripts/homework.js +++ b/public/javascripts/homework.js @@ -38,6 +38,9 @@ $(function(){ function(data,status){ tested = true; console.log(data); + if(data.index <=0){ + data.index = $('.ProResultTop').length+1; + } if (typeof cb == 'function') {cb(); return;} @@ -45,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();