From 708cb35fd22e432dca25fb12f88fd0e1c9ac9ab4 Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Mon, 16 May 2016 16:57:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=80=E4=B8=AA=E5=BC=B9?= =?UTF-8?q?=E6=A1=86=E7=9A=84=E9=80=9A=E7=94=A8=E6=8E=A5=E5=8F=A3pop=5Fup?= =?UTF-8?q?=5Fbox?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_work_controller.rb | 194 +++++++++++--------- app/views/admin/code_work_tests.html.erb | 8 +- app/views/blogs/_article.html.erb | 4 +- app/views/users/_course_boardlist.html.erb | 4 +- app/views/users/_course_newslist.html.erb | 4 +- app/views/users/_project_boardlist.html.erb | 4 +- app/views/users/_user_course_list.html.erb | 8 +- app/views/users/_user_project_list.html.erb | 4 +- lib/rails_kindeditor/config/routes.rb | 2 +- public/assets/kindeditor/pasteimg.js | 5 +- public/javascripts/application.js | 30 +++ public/javascripts/homework.js | 26 ++- 12 files changed, 183 insertions(+), 110 deletions(-) diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 589f232c5..3497e9fdd 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -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 diff --git a/app/views/admin/code_work_tests.html.erb b/app/views/admin/code_work_tests.html.erb index 64c3a41e1..2013bd322 100644 --- a/app/views/admin/code_work_tests.html.erb +++ b/app/views/admin/code_work_tests.html.erb @@ -24,8 +24,8 @@ 测试完成时间 - - 答题状态 + + 答题状态 耗时 @@ -76,6 +76,10 @@ <%= "代码超时" %> <% elsif test.status == -3 %> <%= "请求超时" %> + <% elsif test.status == -4 %> + <%= "judge代码出错!" %> + <% elsif test.status == -5 %> + <%= "trustie代码出错!" %> <% else %> <%= "答题错误" %> <% end %> diff --git a/app/views/blogs/_article.html.erb b/app/views/blogs/_article.html.erb index 4c00ee8a2..77aa3f9d8 100644 --- a/app/views/blogs/_article.html.erb +++ b/app/views/blogs/_article.html.erb @@ -43,8 +43,8 @@ <% count=activity.children.count%> <% end %>
  • - 发帖时间:<%= format_time(activity.created_on) %> - 更新时间:<%= format_time(activity.updated_on) %> + 发帖:<%= format_time(activity.created_on) %> + 更新:<%= format_time(activity.updated_on) %>

    <%= count>0 ? "#{count}" :"0" %> 回复 diff --git a/app/views/users/_course_boardlist.html.erb b/app/views/users/_course_boardlist.html.erb index c92d117ee..bf23d9a97 100644 --- a/app/views/users/_course_boardlist.html.erb +++ b/app/views/users/_course_boardlist.html.erb @@ -45,8 +45,8 @@

    <%=render :partial =>"users/intro_content_ex", :locals=>{:user_activity_id =>activity.id, :content=>content, :maxheight=>54, :maxwordsnum=>100} %>

    - 发帖时间:<%= format_time(activity.created_on) %> - 更新时间:<%= format_time(CourseActivity.where("course_act_type='#{activity.class}' and course_act_id =#{activity.id}").first.updated_at) %> + 发帖:<%= format_time(activity.created_on) %> + 更新:<%= format_time(CourseActivity.where("course_act_type='#{activity.class}' and course_act_id =#{activity.id}").first.updated_at) %> <% count=0 %> <% if activity.parent %> <% count=activity.parent.children.count%> diff --git a/app/views/users/_course_newslist.html.erb b/app/views/users/_course_newslist.html.erb index ff99e116e..0e5805112 100644 --- a/app/views/users/_course_newslist.html.erb +++ b/app/views/users/_course_newslist.html.erb @@ -33,8 +33,8 @@

    <%=render :partial =>"users/intro_content_ex", :locals=>{:user_activity_id =>activity.id, :content=>activity.description, :maxheight=>54, :maxwordsnum=>100} %>

    - 发布时间:<%= format_time(activity.created_on) %> - 更新时间:<%= format_time(CourseActivity.where("course_act_type='#{activity.class}' and course_act_id =#{activity.id}").first.updated_at) %> + 发布:<%= format_time(activity.created_on) %> + 更新:<%= format_time(CourseActivity.where("course_act_type='#{activity.class}' and course_act_id =#{activity.id}").first.updated_at) %> <% count=0 %> <% count=activity.comments.count %>

    <%= count>0 ? "#{count}" : "0" %>回复|<%= get_praise_num(activity) > 0 ? "#{get_praise_num(activity)}" : "0" %>

    diff --git a/app/views/users/_project_boardlist.html.erb b/app/views/users/_project_boardlist.html.erb index 5f61d26ef..928d682d8 100644 --- a/app/views/users/_project_boardlist.html.erb +++ b/app/views/users/_project_boardlist.html.erb @@ -45,8 +45,8 @@

    <%=render :partial =>"users/intro_content_ex", :locals=>{:user_activity_id =>activity.id, :content=>content, :maxheight=>54, :maxwordsnum=>100} %>

    - 发帖时间:<%= format_time(activity.created_on) %> - 更新时间:<%= format_time(ForgeActivity.where("forge_act_type='#{activity.class}' and forge_act_id =#{activity.id}").first.updated_at) %> + 发帖:<%= format_time(activity.created_on) %> + 更新:<%= format_time(ForgeActivity.where("forge_act_type='#{activity.class}' and forge_act_id =#{activity.id}").first.updated_at) %> <% count=0 %> <% if activity.parent %> <% count=activity.parent.children.count%> diff --git a/app/views/users/_user_course_list.html.erb b/app/views/users/_user_course_list.html.erb index 8ef0faa9e..5e3f48963 100644 --- a/app/views/users/_user_course_list.html.erb +++ b/app/views/users/_user_course_list.html.erb @@ -28,12 +28,10 @@
  • + + 更新:<%= format_time(course.updated_on) %> - 创建时间:<%= format_time(course.created_at) %> - - 更新时间:<%= format_time(course.updated_on) %> - - 开课学期:  <%= current_time_and_term course %> + 学期:  <%= current_time_and_term course %> <% if User.current.admin? || User.current.allowed_to?(:as_teacher,@course) %> <% homework_num = course.homework_commons.count %> diff --git a/app/views/users/_user_project_list.html.erb b/app/views/users/_user_project_list.html.erb index 1526da58f..6124b82d8 100644 --- a/app/views/users/_user_project_list.html.erb +++ b/app/views/users/_user_project_list.html.erb @@ -27,8 +27,8 @@
  • - 创建时间:<%= format_time(project.created_on) %> - 更新时间:<%= format_time(project.updated_at) %> + + 更新:<%= format_time(project.updated_at) %>

    <%= project.project_score.issue_num %>问题| <%= project.project_score.attach_num %>资源

  • diff --git a/lib/rails_kindeditor/config/routes.rb b/lib/rails_kindeditor/config/routes.rb index 86b888ad3..e205376d9 100644 --- a/lib/rails_kindeditor/config/routes.rb +++ b/lib/rails_kindeditor/config/routes.rb @@ -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 \ No newline at end of file diff --git a/public/assets/kindeditor/pasteimg.js b/public/assets/kindeditor/pasteimg.js index 7165b142a..97d5e33c5 100644 --- a/public/assets/kindeditor/pasteimg.js +++ b/public/assets/kindeditor/pasteimg.js @@ -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); diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 4cf64abb7..9820f66ff 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -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(""); + $('#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(); + } +} + + diff --git a/public/javascripts/homework.js b/public/javascripts/homework.js index 391774f0b..aaf70cd3f 100644 --- a/public/javascripts/homework.js +++ b/public/javascripts/homework.js @@ -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 = "
    您的程序引发了不知名异常,请在公共贴吧提交您的代码进行意见反馈,我们处理后会立即联系您,谢谢!
    点我进入反馈页面
    "; + pop_up_box(htmlvalue,580,30,50); + + $('#test-program-btn').show(); + return; + } + else if (data.status==-3){ + alert("对不起,服务器繁忙请稍后再试!"); + var htmlvalue = "
    对不起,服务器繁忙请稍后再试!
    "; + 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 = "
    您的答案超时了, 请检查代码是否存在死循环的错误!
    "; + pop_up_box(htmlvalue,580,30,50); } else { - alert("对不起,服务器繁忙请稍后再试!"); +// alert("对不起,服务器繁忙请稍后再试!"); + var htmlvalue = "
    对不起,服务器繁忙请稍后再试!
    "; + pop_up_box(htmlvalue,580,30,50); } $('#test-program-btn').show(); return;