增加一个弹框的通用接口pop_up_box

This commit is contained in:
yuanke 2016-05-16 16:57:18 +08:00
parent e24470db4c
commit 708cb35fd2
12 changed files with 183 additions and 110 deletions

View File

@ -81,6 +81,7 @@ class StudentWorkController < ApplicationController
#根据传入的tIndex确定是第几次测试
#之后如果觉得很卡 可以改成将结果传回JS再以参数形式传回来
def program_test_ex
tStarttime = Time.now
is_test = params[:is_test] == 'true'
@ -106,11 +107,19 @@ 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)
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
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(" ","□")
@ -123,9 +132,9 @@ class StudentWorkController < ApplicationController
#-1 默认值 0全部正确并结束 2 超时 -2 编译错误
resultObj[:status] = -1
resultObj[:results] = result["results"].first #本次测试结果
if result["status"].to_i == -2 #编译错误
# if result["status"].to_i == -2 #编译错误
result["error_msg"] = result["error_msg"][0..2047]
end
# end
resultObj[:error_msg] = result["error_msg"] #编译错误时的信息
#该状态用于存入CodeTests
@ -204,13 +213,20 @@ class StudentWorkController < ApplicationController
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
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
end
#找出该作业的所有提交作业
def find_all_student_work_by_homeid()

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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">
开课学期:&nbsp;&nbsp;<span><%= current_time_and_term course %></span>
学期:&nbsp;&nbsp;<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 %>

View File

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

View File

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

View File

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

View File

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

View File

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