Merge branch 'guange_homework' into szzh

This commit is contained in:
guange 2015-09-03 12:38:47 +08:00
commit 8ac8edeb71
5 changed files with 67 additions and 22 deletions

View File

@ -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?

View File

@ -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

View File

@ -19,6 +19,11 @@
<div class="homepagePostSubmit">
<%= user_for_homework_common homework_common,is_teacher %>
</div>
<% if homework_common.homework_type == 2 && is_teacher%>
<div class="homepagePostSubmit">
<%= link_to "模拟答题", new_user_commit_homework_users_path(homework_id: homework_common.id, is_test: true) %>
</div>
<% end %>
<div class="homepagePostDeadline">
<%= l(:label_end_time)%><%= homework_common.end_time%>
</div>

View File

@ -41,19 +41,21 @@
<div class="homepageRight">
<div class="HomeWork">
<div class="RightBanner">
<div class="NewsBannerName">提交作品</div>
<div class="NewsBannerName"><%= @is_test ? '模拟答题' : '提交作品' %></div>
</div>
<div class="HomeWorkBox">
<div class="">
<div class="homepagePostTitle fl"><%= @homework.name %></div><span class="fr c_grey">截止时间:<%= @homework.end_time %></span>
<div class="cl"></div>
<a href="javascript:void(0);" class="c_blue"><%= @homework.user.show_name %></a>
<p class="HomeWorkP"><%= @homework.description %> <br />
输入 2 1 1 4 4 2 3 6 5 <br />
输出 15<br />
<p class="HomeWorkP"><%= @homework.description.html_safe %> <br />
<% @homework.homework_tests.each do |test| %>
输入 <%=test.input%> <br />
输出 <%=test.output%><br />
<% end %>
</p>
</div>
<p class="c_grey mt15">注:迟交扣<span class="c_red">2</span>分,缺评一个作品扣<span class="c_red">2</span>分</p>
<!--p class="c_grey mt15">注:迟交扣<span class="c_red">2</span>分,缺评一个作品扣<span class="c_red">2</span>分</p-->
</div><!---HomeWorkBox end -->
<div class="HomeWorkCon">
<%= form_for(@student_work,
@ -64,7 +66,7 @@
:homework => @homework.id
},
:method => :post) do |f|%>
<input type="hidden" name="is_test" value="<%=@is_test%>">
<div class="mt15">
<span>请使用 <%= @homework.language_name %> 语言编写</span>
</div>
@ -76,13 +78,18 @@
</div>
<div class="mt10">
<a href="javascript:void(0);" class="BlueCirBtn fl" data-homework-id="<%=@homework.id%>" data-student-work-id="<%=@student_work.id%>" id="test-program-btn">测试代码</a>
<% unless @is_test %>
<a href="javascript:void(0);" class="BlueCirBtn fr" id="commit-program-work-btn">提交代码</a>
<% end %>
<div class="cl"></div>
</div>
<% end %>
</div><!----HomeWorkCon end-->
</div><!----HomeWork end-->
<div class="cl"></div>
<div class="ProResult mt10">
<% @student_work.student_work_tests.each_with_index do |test, index| %>
<div class="ProResultTop">
<p class="c_blue fl">第<%= @student_work.student_work_tests.count - index%>次测试</p><span class="fr c_grey"><%= test.created_at.to_s(:db) %></span>

View File

@ -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();