This commit is contained in:
huang 2015-08-04 17:06:41 +08:00
commit f16d269101
8 changed files with 99 additions and 12 deletions

View File

@ -23,7 +23,7 @@ class HomeworkCommonController < ApplicationController
#
# @homework = HomeworkCommon.new
# @homework.safe_attributes = params[:homework_common]
# @homework.late_penalty = 0
# @homework.late_penalty = 2
# @homework.end_time = (Time.now + 3600 * 24).strftime('%Y-%m-%d')
# @homework.publish_time = Time.now.strftime('%Y-%m-%d')
#
@ -31,7 +31,7 @@ class HomeworkCommonController < ApplicationController
# #匿评作业相关属性
# @homework_detail_manual = HomeworkDetailManual.new
# @homework_detail_manual.ta_proportion = 0.6
# @homework_detail_manual.absence_penalty = 0
# @homework_detail_manual.absence_penalty = 2
# @homework_detail_manual.evaluation_num = 3
# @homework_detail_manual.evaluation_start = Time.now.strftime('%Y-%m-%d')
# @homework_detail_manual.evaluation_end = (Time.now + 3600 * 24).strftime('%Y-%m-%d')
@ -52,7 +52,7 @@ class HomeworkCommonController < ApplicationController
@homework = HomeworkCommon.new
@homework.safe_attributes = params[:homework_common]
@homework.late_penalty = 0
@homework.late_penalty = 2
@homework.end_time = (Time.now + 3600 * 24).strftime('%Y-%m-%d')
@homework.publish_time = Time.now.strftime('%Y-%m-%d')
@ -60,7 +60,7 @@ class HomeworkCommonController < ApplicationController
#匿评作业相关属性
@homework_detail_manual = HomeworkDetailManual.new
@homework_detail_manual.ta_proportion = 0.6
@homework_detail_manual.absence_penalty = 0
@homework_detail_manual.absence_penalty = 2
@homework_detail_manual.evaluation_num = 3
@homework_detail_manual.evaluation_start = Time.now.strftime('%Y-%m-%d')
@homework_detail_manual.evaluation_end = (Time.now + 3600 * 24).strftime('%Y-%m-%d')
@ -107,6 +107,7 @@ class HomeworkCommonController < ApplicationController
homework_test.input = v
homework_test.output = params[:output][k]
homework_test.result = params[:result][k]
homework_test.error_msg = params[:error_msg]
homework.homework_tests << homework_test
question[:input] << homework_test.input
question[:output] << homework_test.output
@ -231,11 +232,13 @@ class HomeworkCommonController < ApplicationController
homework_test.input = v
homework_test.output = params[:output][k]
homework_test.result = params[:result][k]
homework_test.error_msg = params[:error_msg]
else #不存在的测试,增加
homework_test = HomeworkTest.new
homework_test.input = v
homework_test.output = params[:output][k]
homework_test.result = params[:result][k]
homework_test.error_msg = params[:error_msg]
homework_test.homework_common = @homework
end
homework_test.save
@ -367,6 +370,7 @@ class HomeworkCommonController < ApplicationController
client.request(request)
end
result = JSON.parse(res.body)
@err_msg = result["compile_error_msg"]
result["results"].each do |re|
@result = re["status"]
end

View File

@ -2378,4 +2378,26 @@ module ApplicationHelper
end
notice.html_safe
end
def stantard_code
"// 这是一个C语言的样例程序
//
//
// 123
// 347
//
//
// argv传入
//
#include <stdio.h> //引用必须头文件
int main(int argc, char** argv) {
int a = atoi(argv[1]); //
int b = atoi(argv[2]); //
printf(\"%d\",a+b); //输出a+b
return 0;
}".html_safe
end
end

View File

@ -66,4 +66,31 @@ module HomeworkCommonHelper
link
end
#将状态转换为错误信息
def status_to_err_msg status
case status.to_i
when -1
'编译出错'
when -2
'输入和输出不匹配'
when -3
'输入和输出不匹配'
when 1
'运行出错'
when 2
'超时'
when 3
'内存超出'
when 4
'输出超出'
when 5
'禁用函数'
when 6
'其他错误'
when 0
'成功'
else
'未知错误'
end
end
end

View File

@ -78,7 +78,7 @@
<li >
<label class="label02">&nbsp;标准代码:&nbsp;</label>
<textarea name="standard_code" class=" w547 h150 mb10 fl" oninput="init_programing_test();" onpropertychange="init_programing_test()"><%= homework.homework_detail_programing.standard_code%></textarea>
<textarea name="standard_code" class=" w547 h350 mb10 fl" oninput="init_programing_test();" onpropertychange="init_programing_test()"><%= homework.homework_detail_programing.standard_code || stantard_code%></textarea>
<div class="cl"></div>
</li>
@ -98,7 +98,7 @@
<a class="icon_remove" href="javascript:void(0);" title="删除测试" onclick="remove_programing_test($(this).parent().parent())"></a>
<% if homework_test.result && !homework_test.result.to_s.empty?%>
<% if homework_test.result == 0%>
<a class="green_btn fl ml5 mt1 programing_test" onclick="programing_test('<%= homework_test.id%>')" id="test_send_<%= homework_test.id%>">成功</a>
<a class="green_btn fl ml5 mt1 programing_test" onclick="programing_test('<%= homework_test.id%>')" id="test_send_<%= homework_test.id%>">正确</a>
<% else%>
<a class="red_btn fl ml5 mt1 programing_test" onclick="programing_test('<%= homework_test.id%>')" id="test_send_<%= homework_test.id%>">错误</a>
<% end%>
@ -114,11 +114,11 @@
<div>
<li>
<label class="label02">&nbsp;测试输入:&nbsp;</label>
<input type="text" class="fl h26 w190 mb10" name="input[0]" />
<input type="text" class="fl h26 w190 mb10" name="input[0]" value="1 2"/>
</li>
<li >
<label class=" fl f14 ml10">&nbsp;输出:&nbsp;</label>
<input type="text" class="fl h26 w190 mb10" name="output[0]" />
<input type="text" class="fl h26 w190 mb10" name="output[0]" value="3"/>
</li>
<li>
<a class="icon_add ml10 " href="javascript:void(0);" title="添加测试" onclick="add_programing_test($(this).parent().parent())"></a>
@ -129,6 +129,21 @@
<div class="cl"></div>
</div>
<% end %>
<input type="hidden" name="error_msg" id="homework_test_error_msg" value="<%= homework.homework_tests.first.error_msg if homework.homework_tests.first && homework.homework_tests.first && homework.homework_tests.first.error_msg%>">
<table class="border_ce" cellpadding="0" cellspacing="0" id="homework_work_test_show" style="display: <%= homework.homework_tests.first && homework.homework_tests.first && homework.homework_tests.first.error_msg && !homework.homework_tests.first.error_msg.empty? ? "block" : "none"%>">
<tbody>
<tr class="border_t" >
<td class="td_end fb c_red w60 td_board_left">
错误信息:
</td>
<td class="td_end wl" id="homework_work_test_desc">
<% if homework.homework_tests.first && homework.homework_tests.first && homework.homework_tests.first.error_msg %>
<%= homework.homework_tests.first.error_msg%>
<% end%>
</td>
</tr>
</tbody>
</table>
</ul>
</div>

View File

@ -1,2 +1,12 @@
$("#test_send_<%= @index%>").replaceWith("<a class='<%= @result == 0 ? 'green_btn' : 'red_btn'%> fl ml5 mt1 programing_test' onclick='programing_test(<%= @index%>)' id='test_send_<%= @index%>'><%= @result == 0 ? '正确' : '错误'%></a>");
$("#test_result_<%= @index%>").val("<%= @result%>");
$("#test_result_<%= @index%>").val("<%= @result%>");
<% if @err_msg || @result != 0%>
$("#homework_work_test_show").show();
$("#homework_work_test_desc").text("<%= escape_javascript(@err_msg || status_to_err_msg(@result))%>");
<% if @err_msg%>
$("#homework_test_error_msg").val("<%= escape_javascript(@err_msg)%>");
<% end%>
<% else%>
$("#homework_work_test_show").hide();
$("#homework_test_error_msg").val("");
<% end%>

View File

@ -44,7 +44,7 @@
</p>
<div class="cl"></div>
<p id="about_project" class="about_project" >
<label class="fl">&nbsp;&nbsp;&nbsp;关联项目&nbsp;&nbsp;&nbsp;&nbsp;</label>
<label class="fl">&nbsp;&nbsp;&nbsp;选择项目&nbsp;&nbsp;&nbsp;&nbsp;</label>
<%= f.select :project_id,options_for_select(user_projects_option), {},{:class => "bo02 mb10"} %>
</p>
<div class="cl"></div>
@ -54,7 +54,11 @@
<%= @homework.homework_type == 2 ? "提交代码" : "作品描述"%>
&nbsp;&nbsp;&nbsp;
</label>
<%= f.text_area "description", :class => "w620 hwork_txt ", :placeholder => "作品描述不能为空", :onkeyup => "regexStudentWorkDescription();"%>
<% if @homework.homework_type == 2%>
<%= f.text_area "description", :class => "w620 hwork_txt h350", :placeholder => "作品描述不能为空", :onkeyup => "regexStudentWorkDescription();", :value => stantard_code%>
<% else %>
<%= f.text_area "description", :class => "w620 hwork_txt", :placeholder => "作品描述不能为空", :onkeyup => "regexStudentWorkDescription();"%>
<% end%>
<div class="cl"></div>
<p id="student_work_description_textarea" class="c_red ml90 mb10"></p>
</p>

View File

@ -10,7 +10,7 @@
</span>
<a href="<%= user_path(rec[:item].user.id) %>" class="c_orange course_name fl mr5" title="<%= rec[:item].user.show_name %>"><%= rec[:item].user.show_name %></a>
<span class="fl mr5 c_grey"><%= get_activity_opt(rec[:item],rec[:e]) %></span>
<% if( rec[:e].is_public == false || rec[:e].is_public == 0 ) %>
<% if(( rec[:e].is_public == false || rec[:e].is_public == 0 )&& !rec[:e].visible?)%>
<a href="<%= get_activity_url(rec[:item],rec[:e]) %>"
class="c_grey fl users_courses_txt hidepic"
title="<% if(rec[:item].activity_container_type=='Project')%><%='该项目是私有的,您无权查看。'%><% else %><%='该课程是私有的,您无权查看。' %><% end %>">

View File

@ -226,6 +226,7 @@ a:hover.ping_sub{ background:#14a8b9;}
.w430{ width:470px;}
.w557{ width:557px;}
.w350{ width:350px;}
.h350{height: 350px !important;}
.w620{ width:480px; height:160px; border:1px solid #CCC;}
.bo{height:26px; border:1px solid #CCC; padding-left:5px; background:#fff;width:470px; }
.bo02{height:26px; border:1px solid #CCC; padding-left:5px; background:#fff;width:480px; margin-left:2px; color: #999; }
@ -694,6 +695,9 @@ a.work_list_tit{width:580px; display:block; overflow:hidden; font-size:14px; f
.border_l{border-left:1px solid #e4e4e4;}
.border_t{ border-top:1px solid #e4e4e4;}
.td_end{border-top:1px solid #e4e4e4; height:auto; padding:5px; }
.wl{text-align: left;}
.vt{vertical-align: top;}
.td_board_left{border-right: 1px solid #e4e4e4;}
.c_w{ color:#fff;}
.filename { background: url(../images/pic_file.png) 0 -25px no-repeat;color: #3ca5c6;max-width: 150px;border: none; padding-left: 20px;margin-right: 10px;margin-bottom: 5px; white-space: nowrap; text-overflow:ellipsis;}
@ -709,6 +713,7 @@ a:hover.about_me{ color:#0781b4;}
.mb5 li{width:200px;word-wrap: break-word;
word-break: normal;
}
#homework_work_test_show{margin-left: 35px;width: 94%;}