增加一个弹框的通用接口pop_up_box
This commit is contained in:
parent
e24470db4c
commit
708cb35fd2
|
@ -81,6 +81,7 @@ class StudentWorkController < ApplicationController
|
|||
#根据传入的tIndex确定是第几次测试
|
||||
#之后如果觉得很卡 可以改成将结果传回JS再以参数形式传回来
|
||||
def program_test_ex
|
||||
|
||||
tStarttime = Time.now
|
||||
|
||||
is_test = params[:is_test] == 'true'
|
||||
|
@ -106,108 +107,123 @@ class StudentWorkController < ApplicationController
|
|||
tEndtime = Time.now
|
||||
tUsedtime = (tEndtime.to_i-tStarttime.to_i)*1000+(tEndtime.usec - tStarttime.usec)/1000
|
||||
logger.debug "program_test_ex user wait time = #{tUsedtime} 毫秒"
|
||||
|
||||
#status 0:答案正确 -3http超时 -2:编译错误 -1:答案错误 2:程序运行超时
|
||||
#status 0:答案正确 -5program_test_ex 函数出错 -4judge代码出错 -3http超时 -2:编译错误 -1:答案错误 2:程序运行超时
|
||||
resultObj[:status] = -3
|
||||
CodeTests.create(:homework_id=>@homework.id,:language=>@homework.homework_detail_programing.language,:status=>-3,:wait_time=>tUsedtime,:student_work_id=>student_work.id)
|
||||
|
||||
end
|
||||
if result["status"].to_i != -2
|
||||
#result["results"].first['output'] = result["results"].first['output'].gsub(" ","□")
|
||||
#result["results"].first['result'] = result["results"].first['result'].gsub(" ","□")
|
||||
space_replace_1(result["results"].first['output'])
|
||||
space_replace_1(result["results"].first['result'])
|
||||
rescue
|
||||
#-4 judge代码 出错
|
||||
logger.debug "program_test_error 1"
|
||||
resultObj[:status] = -4
|
||||
tmpstatus = -4
|
||||
CodeTests.create(:homework_id=>@homework.id,:language=>@homework.homework_detail_programing.language,:status=>tmpstatus,:time_used=>0,:wait_time=>0,:student_work_id=>student_work.id)
|
||||
end
|
||||
|
||||
logger.debug result
|
||||
begin
|
||||
if resultObj[:status] != -3 && resultObj[:status] != -4
|
||||
if result["status"].to_i != -2
|
||||
#result["results"].first['output'] = result["results"].first['output'].gsub(" ","□")
|
||||
#result["results"].first['result'] = result["results"].first['result'].gsub(" ","□")
|
||||
space_replace_1(result["results"].first['output'])
|
||||
space_replace_1(result["results"].first['result'])
|
||||
end
|
||||
|
||||
#-1 默认值 0全部正确并结束 2 超时 -2 编译错误
|
||||
resultObj[:status] = -1
|
||||
resultObj[:results] = result["results"].first #本次测试结果
|
||||
if result["status"].to_i == -2 #编译错误
|
||||
result["error_msg"] = result["error_msg"][0..2047]
|
||||
end
|
||||
resultObj[:error_msg] = result["error_msg"] #编译错误时的信息
|
||||
logger.debug result
|
||||
|
||||
#该状态用于存入CodeTests
|
||||
tmpstatus = -1
|
||||
if result["status"].to_i == -2 #编译错误
|
||||
resultObj[:results] = result["error_msg"]
|
||||
resultObj[:status] = -2
|
||||
tmpstatus = -2
|
||||
elsif result["results"][0]["status"].to_i == 2
|
||||
resultObj[:status] = 2
|
||||
tmpstatus = 2
|
||||
end
|
||||
#-1 默认值 0全部正确并结束 2 超时 -2 编译错误
|
||||
resultObj[:status] = -1
|
||||
resultObj[:results] = result["results"].first #本次测试结果
|
||||
# if result["status"].to_i == -2 #编译错误
|
||||
result["error_msg"] = result["error_msg"][0..2047]
|
||||
# end
|
||||
resultObj[:error_msg] = result["error_msg"] #编译错误时的信息
|
||||
|
||||
if result["status"] == 0
|
||||
tmpstatus = 0
|
||||
end
|
||||
#该状态用于存入CodeTests
|
||||
tmpstatus = -1
|
||||
if result["status"].to_i == -2 #编译错误
|
||||
resultObj[:results] = result["error_msg"]
|
||||
resultObj[:status] = -2
|
||||
tmpstatus = -2
|
||||
elsif result["results"][0]["status"].to_i == 2
|
||||
resultObj[:status] = 2
|
||||
tmpstatus = 2
|
||||
end
|
||||
|
||||
unless student_work.save
|
||||
resultObj[:status] = 200
|
||||
else
|
||||
student_work.name = params[:title]
|
||||
student_work.description = params[:src]
|
||||
if result["status"] == 0
|
||||
tmpstatus = 0
|
||||
end
|
||||
|
||||
if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d")
|
||||
student_work.late_penalty = @homework.late_penalty
|
||||
else
|
||||
student_work.late_penalty = 0
|
||||
end
|
||||
unless student_work.save
|
||||
resultObj[:status] = 200
|
||||
else
|
||||
student_work.name = params[:title]
|
||||
student_work.description = params[:src]
|
||||
|
||||
#每次从数据库取出上次的结果加上本次的结果再存入数据库
|
||||
if result["status"].to_i != -2
|
||||
result["results"].first['user_wait'] = tUsedtime
|
||||
if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d")
|
||||
student_work.late_penalty = @homework.late_penalty
|
||||
else
|
||||
student_work.late_penalty = 0
|
||||
end
|
||||
|
||||
if result["results"][0]["status"].to_i == 2
|
||||
result["status"] = 2
|
||||
#每次从数据库取出上次的结果加上本次的结果再存入数据库
|
||||
if result["status"].to_i != -2
|
||||
result["results"].first['user_wait'] = tUsedtime
|
||||
|
||||
if result["results"][0]["status"].to_i == 2
|
||||
result["status"] = 2
|
||||
end
|
||||
end
|
||||
|
||||
status = result["status"]
|
||||
if index == 1
|
||||
student_work_test = student_work.student_work_tests.build(status: status,
|
||||
results: [resultObj[:results]],src: params[:src])
|
||||
student_work_test.save!
|
||||
resultObj[:testid] = student_work_test.id
|
||||
else
|
||||
#先从数据库取出result
|
||||
student_work_test = StudentWorkTest.find(params[:testid])
|
||||
results = student_work_test.results
|
||||
results << resultObj[:results]
|
||||
student_work_test.results = results
|
||||
student_work_test.status = (result["status"] != 0 ? result["status"] : student_work_test.status)
|
||||
student_work_test.save!
|
||||
status = student_work_test.status
|
||||
resultObj[:testid] = student_work_test.id
|
||||
end
|
||||
|
||||
#超时或编译错误则直接返回了并存入数据库
|
||||
if resultObj[:status] == 2 || resultObj[:status] == -2 || index == @homework.homework_tests.size
|
||||
if status == 0
|
||||
resultObj[:status] = 0
|
||||
end
|
||||
student_work.save!
|
||||
resultObj[:time] = student_work_test.created_at.to_s(:db)
|
||||
resultObj[:index] = student_work.student_work_tests.count
|
||||
end
|
||||
|
||||
#将每次用户等待时间都存起来以便管理界面显示用
|
||||
tEndtime = Time.now
|
||||
tUsedtime = (tEndtime.to_i-tStarttime.to_i)*1000+(tEndtime.usec - tStarttime.usec)/1000
|
||||
logger.debug "program_test_ex user wait time = #{tUsedtime} 毫秒"
|
||||
|
||||
time_used = 0
|
||||
if result["status"].to_i != -2
|
||||
#至少一毫秒
|
||||
time_used = result["results"].first['time_used'] == 0 ? 1:result["results"].first['time_used']
|
||||
end
|
||||
#0:答案正确 -3http超时 -2:编译错误 -1:答案错误 2:程序运行超时
|
||||
CodeTests.create(:homework_id=>@homework.id,:language=>@homework.homework_detail_programing.language,:status=>tmpstatus,:time_used=>time_used,:wait_time=>tUsedtime,:student_work_id=>student_work.id)
|
||||
end
|
||||
end
|
||||
|
||||
status = result["status"]
|
||||
if index == 1
|
||||
student_work_test = student_work.student_work_tests.build(status: status,
|
||||
results: [resultObj[:results]],src: params[:src])
|
||||
student_work_test.save!
|
||||
resultObj[:testid] = student_work_test.id
|
||||
else
|
||||
#先从数据库取出result
|
||||
student_work_test = StudentWorkTest.find(params[:testid])
|
||||
results = student_work_test.results
|
||||
results << resultObj[:results]
|
||||
student_work_test.results = results
|
||||
student_work_test.status = (result["status"] != 0 ? result["status"] : student_work_test.status)
|
||||
student_work_test.save!
|
||||
status = student_work_test.status
|
||||
resultObj[:testid] = student_work_test.id
|
||||
end
|
||||
|
||||
#超时或编译错误则直接返回了并存入数据库
|
||||
if resultObj[:status] == 2 || resultObj[:status] == -2 || index == @homework.homework_tests.size
|
||||
if status == 0
|
||||
resultObj[:status] = 0
|
||||
end
|
||||
student_work.save!
|
||||
resultObj[:time] = student_work_test.created_at.to_s(:db)
|
||||
resultObj[:index] = student_work.student_work_tests.count
|
||||
end
|
||||
|
||||
#将每次用户等待时间都存起来以便管理界面显示用
|
||||
tEndtime = Time.now
|
||||
tUsedtime = (tEndtime.to_i-tStarttime.to_i)*1000+(tEndtime.usec - tStarttime.usec)/1000
|
||||
logger.debug "program_test_ex user wait time = #{tUsedtime} 毫秒"
|
||||
|
||||
time_used = 0
|
||||
if result["status"].to_i != -2
|
||||
#至少一毫秒
|
||||
time_used = result["results"].first['time_used'] == 0 ? 1:result["results"].first['time_used']
|
||||
end
|
||||
#0:答案正确 -3http超时 -2:编译错误 -1:答案错误 2:程序运行超时
|
||||
CodeTests.create(:homework_id=>@homework.id,:language=>@homework.homework_detail_programing.language,:status=>tmpstatus,:time_used=>time_used,:wait_time=>tUsedtime,:student_work_id=>student_work.id)
|
||||
|
||||
#渲染返回结果
|
||||
render :json => resultObj
|
||||
rescue
|
||||
#-5 program_test_ex 函数出错
|
||||
logger.debug "program_test_error 2"
|
||||
resultObj[:status] = -5
|
||||
tmpstatus = -5
|
||||
CodeTests.create(:homework_id=>@homework.id,:language=>@homework.homework_detail_programing.language,:status=>tmpstatus,:time_used=>0,:wait_time=>0,:student_work_id=>student_work.id)
|
||||
end
|
||||
#渲染返回结果
|
||||
render :json => resultObj
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
<th style="width: 100px;">
|
||||
测试完成时间
|
||||
</th>
|
||||
<th style="width: 60px;">
|
||||
<span style="float:left; margin-left:20px;">答题状态</span>
|
||||
<th style="width: 80px;">
|
||||
<span style="float:left; margin-left:30px;">答题状态</span>
|
||||
</th>
|
||||
<th style="width: 50px;">
|
||||
<span style="float:left; margin-left:20px;">耗时</span>
|
||||
|
@ -76,6 +76,10 @@
|
|||
<%= "代码超时" %>
|
||||
<% elsif test.status == -3 %>
|
||||
<%= "请求超时" %>
|
||||
<% elsif test.status == -4 %>
|
||||
<%= "judge代码出错!" %>
|
||||
<% elsif test.status == -5 %>
|
||||
<%= "trustie代码出错!" %>
|
||||
<% else %>
|
||||
<%= "答题错误" %>
|
||||
<% end %>
|
||||
|
|
|
@ -43,8 +43,8 @@
|
|||
<% count=activity.children.count%>
|
||||
<% end %>
|
||||
<li class="ml15">
|
||||
<span class="grayTxt">发帖时间:<%= format_time(activity.created_on) %></span>
|
||||
<span class="grayTxt">更新时间:<%= format_time(activity.updated_on) %></span>
|
||||
<span class="grayTxt">发帖:<%= format_time(activity.created_on) %></span>
|
||||
<span class="grayTxt">更新:<%= format_time(activity.updated_on) %></span>
|
||||
<p class="list-info fr grayTxt">
|
||||
<span><%= count>0 ? "#{count}" :"0" %></span>
|
||||
<span>回复</span>
|
||||
|
|
|
@ -45,8 +45,8 @@
|
|||
<p><%=render :partial =>"users/intro_content_ex", :locals=>{:user_activity_id =>activity.id, :content=>content, :maxheight=>54, :maxwordsnum=>100} %></p>
|
||||
</div>
|
||||
<div class="ml15 mt10">
|
||||
<span class="grayTxt">发帖时间:<%= format_time(activity.created_on) %></span>
|
||||
<span class="grayTxt">更新时间:<%= format_time(CourseActivity.where("course_act_type='#{activity.class}' and course_act_id =#{activity.id}").first.updated_at) %></span>
|
||||
<span class="grayTxt">发帖:<%= format_time(activity.created_on) %></span>
|
||||
<span class="grayTxt">更新:<%= format_time(CourseActivity.where("course_act_type='#{activity.class}' and course_act_id =#{activity.id}").first.updated_at) %></span>
|
||||
<% count=0 %>
|
||||
<% if activity.parent %>
|
||||
<% count=activity.parent.children.count%>
|
||||
|
|
|
@ -33,8 +33,8 @@
|
|||
<p><%=render :partial =>"users/intro_content_ex", :locals=>{:user_activity_id =>activity.id, :content=>activity.description, :maxheight=>54, :maxwordsnum=>100} %></p>
|
||||
</div>
|
||||
<div class="ml15 mt10">
|
||||
<span class="grayTxt">发布时间:<%= format_time(activity.created_on) %></span>
|
||||
<span class="grayTxt">更新时间:<%= format_time(CourseActivity.where("course_act_type='#{activity.class}' and course_act_id =#{activity.id}").first.updated_at) %></span>
|
||||
<span class="grayTxt">发布:<%= format_time(activity.created_on) %></span>
|
||||
<span class="grayTxt">更新:<%= format_time(CourseActivity.where("course_act_type='#{activity.class}' and course_act_id =#{activity.id}").first.updated_at) %></span>
|
||||
<% count=0 %>
|
||||
<% count=activity.comments.count %>
|
||||
<p class="list-info fr grayTxt"><span><%= count>0 ? "#{count}" : "0" %></span><span>回复</span><span>|</span><span><%= get_praise_num(activity) > 0 ? "#{get_praise_num(activity)}" : "0" %></span><span>赞</span></p>
|
||||
|
|
|
@ -45,8 +45,8 @@
|
|||
<p><%=render :partial =>"users/intro_content_ex", :locals=>{:user_activity_id =>activity.id, :content=>content, :maxheight=>54, :maxwordsnum=>100} %></p>
|
||||
</div>
|
||||
<div class="ml15 mt10">
|
||||
<span class="grayTxt">发帖时间:<%= format_time(activity.created_on) %></span>
|
||||
<span class="grayTxt">更新时间:<%= format_time(ForgeActivity.where("forge_act_type='#{activity.class}' and forge_act_id =#{activity.id}").first.updated_at) %></span>
|
||||
<span class="grayTxt">发帖:<%= format_time(activity.created_on) %></span>
|
||||
<span class="grayTxt">更新:<%= format_time(ForgeActivity.where("forge_act_type='#{activity.class}' and forge_act_id =#{activity.id}").first.updated_at) %></span>
|
||||
<% count=0 %>
|
||||
<% if activity.parent %>
|
||||
<% count=activity.parent.children.count%>
|
||||
|
|
|
@ -28,12 +28,10 @@
|
|||
</li>
|
||||
<div class="cl"></div>
|
||||
<li class="ml15">
|
||||
<!--<span class="grayTxt">创建:<%#= format_time(course.created_at) %></span>-->
|
||||
<span class="grayTxt">更新:<%= format_time(course.updated_on) %></span>
|
||||
<span class="grayTxt">
|
||||
创建时间:<%= format_time(course.created_at) %>
|
||||
</span>
|
||||
<span class="grayTxt">更新时间:<%= format_time(course.updated_on) %></span>
|
||||
<span class="grayTxt">
|
||||
开课学期: <span><%= current_time_and_term course %></span>
|
||||
学期: <span><%= current_time_and_term course %></span>
|
||||
</span>
|
||||
<% if User.current.admin? || User.current.allowed_to?(:as_teacher,@course) %>
|
||||
<% homework_num = course.homework_commons.count %>
|
||||
|
|
|
@ -27,8 +27,8 @@
|
|||
</li>
|
||||
<div class="cl"></div>
|
||||
<li class="ml15">
|
||||
<span class="grayTxt">创建时间:<%= format_time(project.created_on) %></span>
|
||||
<span class="grayTxt">更新时间:<%= format_time(project.updated_at) %></span>
|
||||
<!--<span class="grayTxt">创建时间:<%#= format_time(project.created_on) %></span>-->
|
||||
<span class="grayTxt">更新:<%= format_time(project.updated_at) %></span>
|
||||
<p class="list-info fr grayTxt"><span><%= project.project_score.issue_num %></span><span>问题</span><span>|</span><span> <%= project.project_score.attach_num %></span><span>资源</span></p>
|
||||
</li>
|
||||
<div class="cl"></div>
|
||||
|
|
|
@ -2,6 +2,6 @@ Rails.application.routes.draw do
|
|||
namespace :kindeditor do
|
||||
post "/upload" => "assets#create"
|
||||
get "/filemanager" => "assets#list"
|
||||
get "/uploadpic" => "assets#uploadpic"
|
||||
post "/uploadpic" => "assets#uploadpic"
|
||||
end
|
||||
end
|
|
@ -370,6 +370,9 @@ function df(myself) {
|
|||
else
|
||||
sstr += that.attr("src") + "|";
|
||||
}
|
||||
else if (that.attr("src").indexOf("data:image") >= 0){
|
||||
that.parents().removeAttr("href"); //删除所有父节点的href
|
||||
}
|
||||
}
|
||||
});
|
||||
uploadpic(sstr,myself);
|
||||
|
@ -397,7 +400,7 @@ function uploadpic(piclist,myself) {
|
|||
$.ajax({
|
||||
url: "/kindeditor/uploadpic",
|
||||
data:{"pic":piclist},
|
||||
type: "GET",
|
||||
type: "POST",
|
||||
beforeSend: function () {
|
||||
// $("#ajax-indicator span").text("图片上传中请稍等...");
|
||||
keShadow(myself);
|
||||
|
|
|
@ -1261,3 +1261,33 @@ function description_showwords_ellipsis(id,num){
|
|||
$("#intro_content_"+id).show();
|
||||
|
||||
}
|
||||
|
||||
//by yk 弹框 tWidth = 580 tTop=30 tLeft=50
|
||||
function pop_up_box(value,tWidth,tTop,tLeft){
|
||||
|
||||
if(!tWidth){
|
||||
var tWidth = 580;
|
||||
}
|
||||
|
||||
if(!tTop){
|
||||
var tTop = 30;
|
||||
}
|
||||
|
||||
if(!tLeft){
|
||||
var tLeft = 50;
|
||||
}
|
||||
|
||||
$("#ajax-modal").html(value);
|
||||
showModal('ajax-modal', tWidth + "px");
|
||||
$('#ajax-modal').siblings().remove();
|
||||
$('#ajax-modal').before("<a href='javascript:void(0)' onclick='hideModal();' style='margin-right: 5px; margin-top:-10px;right:0;' class='resourceClose'></a>");
|
||||
$('#ajax-modal').parent().css("top", tTop+"%").css("left", tLeft+"%").css("padding-top", "10px").css("position", "fixed");
|
||||
$('#ajax-modal').parent().addClass("resourceUploadPopup");
|
||||
$('#ajax-modal').css("padding-left", "16px").css("padding-bottom", "16px");
|
||||
|
||||
function hideModal(){
|
||||
$('#ajax-modal').hide();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -66,6 +66,24 @@ $(function(){
|
|||
src: src, title: title, is_test: is_test,tIndex:i,
|
||||
testid: testid},
|
||||
function(data,status){
|
||||
if (data.status==-4 || data.status==-5 ){
|
||||
// alert("非常抱歉,您的程序引起了后台问题,请在公共贴吧提交您的代码进行意见反馈,谢谢!");
|
||||
//弹框
|
||||
var root_path = getRootPath();
|
||||
var forums_1_path = root_path + "/forums/1"
|
||||
var htmlvalue = "</br><div style='width:400px;text-align:center;margin:0 auto' >您的程序引发了不知名异常,请在公共贴吧提交您的代码进行意见反馈,我们处理后会立即联系您,谢谢!</div><div style='width:550px;text-align:center'><a target='_Blank' href="+forums_1_path+">点我进入反馈页面</a></div>";
|
||||
pop_up_box(htmlvalue,580,30,50);
|
||||
|
||||
$('#test-program-btn').show();
|
||||
return;
|
||||
}
|
||||
else if (data.status==-3){
|
||||
alert("对不起,服务器繁忙请稍后再试!");
|
||||
var htmlvalue = "</br><div style='width:550px;text-align:center'>对不起,服务器繁忙请稍后再试!</div>";
|
||||
pop_up_box(htmlvalue,580,30,50);
|
||||
$('#test-program-btn').show();
|
||||
return;
|
||||
}
|
||||
var tSeq = data.tseq;
|
||||
var tCount = data.tcount;
|
||||
console.log("tSeq="+tSeq);
|
||||
|
@ -100,9 +118,13 @@ $(function(){
|
|||
}
|
||||
).fail(function(xhr, status){
|
||||
if(status == 'timeout'){
|
||||
alert("您的答案超时了, 请检查代码是否存在死循环的错误.");
|
||||
// alert("您的答案超时了, 请检查代码是否存在死循环的错误.");
|
||||
var htmlvalue = "</br><div style='width:550px;text-align:center'>您的答案超时了, 请检查代码是否存在死循环的错误!</div>";
|
||||
pop_up_box(htmlvalue,580,30,50);
|
||||
} else {
|
||||
alert("对不起,服务器繁忙请稍后再试!");
|
||||
// alert("对不起,服务器繁忙请稍后再试!");
|
||||
var htmlvalue = "</br><div style='width:550px;text-align:center'>对不起,服务器繁忙请稍后再试!</div>";
|
||||
pop_up_box(htmlvalue,580,30,50);
|
||||
}
|
||||
$('#test-program-btn').show();
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue