This commit is contained in:
sw 2015-09-06 09:31:33 +08:00
commit cc9c84b333
14 changed files with 102 additions and 66 deletions

View File

@ -12,8 +12,11 @@ class StudentWorkController < ApplicationController
### ###
def program_test def program_test
resultObj = {status: 0, results: [], error_msg: '', time: Time.now} 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 student_work = find_or_save_student_work
unless student_work unless student_work
resultObj[:status] = 100 resultObj[:status] = 100
else else
@ -39,6 +42,27 @@ class StudentWorkController < ApplicationController
end end
end end
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
resultObj[:status] = result["status"].to_i
resultObj[:time] = Time.now.strftime('%Y-%m-%d %T')
resultObj[:index] = 0
end
end
render :json => resultObj render :json => resultObj
end end
@ -142,6 +166,10 @@ class StudentWorkController < ApplicationController
end end
def new def new
if @homework.homework_type==2
redirect_to new_user_commit_homework_users_path(homework_id: @homework.id)
return
end
@user = User.current @user = User.current
@student_work = @homework.student_works.where("user_id = ?",User.current.id).first @student_work = @homework.student_works.where("user_id = ?",User.current.id).first
if @student_work.nil? if @student_work.nil?

View File

@ -106,18 +106,18 @@ class UsersController < ApplicationController
return return
end end
# 当前用户查看消息,则设置消息为已读 # 当前用户查看消息,则设置消息为已读
if params[:viewed] == "all" #if params[:viewed] == "all"
course_querys = @user.course_messages # course_querys = @user.course_messages
forge_querys = @user.forge_messages # forge_querys = @user.forge_messages
user_querys = @user.user_feedback_messages # user_querys = @user.user_feedback_messages
forum_querys = @user.memo_messages # forum_querys = @user.memo_messages
if User.current.id == @user.id # if User.current.id == @user.id
course_querys.update_all(:viewed => true) # course_querys.update_all(:viewed => true)
forge_querys.update_all(:viewed => true) # forge_querys.update_all(:viewed => true)
user_querys.update_all(:viewed => true) # user_querys.update_all(:viewed => true)
forum_querys.update_all(:viewed => true) # forum_querys.update_all(:viewed => true)
end # end
end #end
# @new_message_count = forge_querys.count + forum_querys.count + course_querys.count + user_querys.count # @new_message_count = forge_querys.count + forum_querys.count + course_querys.count + user_querys.count
case params[:type] case params[:type]
when nil when nil
@ -347,6 +347,7 @@ class UsersController < ApplicationController
def new_user_commit_homework def new_user_commit_homework
@user = User.current @user = User.current
@homework = HomeworkCommon.find(params[:homework_id]) @homework = HomeworkCommon.find(params[:homework_id])
@is_test = params[:is_test] == 'true'
@student_work = @homework.student_works.where(user_id: User.current.id).first @student_work = @homework.student_works.where(user_id: User.current.id).first
if @student_work.nil? if @student_work.nil?
@student_work = StudentWork.new @student_work = StudentWork.new
@ -359,7 +360,7 @@ class UsersController < ApplicationController
def user_commit_homework def user_commit_homework
flash[:notice] = l(:notice_successful_create) flash[:notice] = l(:notice_successful_create)
redirect_to user_homeworks_user_path(User.current) redirect_to student_work_index_url(:homework => params[:homework])
end end
def user_new_homework def user_new_homework

View File

@ -2347,7 +2347,7 @@ module ApplicationHelper
if homework.homework_type == 1 && homework.homework_detail_manual && homework.homework_detail_manual.comment_status != 1 #匿评作业,且作业状态不是在开启匿评之前 if homework.homework_type == 1 && homework.homework_detail_manual && homework.homework_detail_manual.comment_status != 1 #匿评作业,且作业状态不是在开启匿评之前
link_to "修改作品", "", :class => 'c_blue', :title => "开启匿评后不可修改作品" link_to "修改作品", "", :class => 'c_blue', :title => "开启匿评后不可修改作品"
elsif homework.homework_type == 2 #编程作业不能修改作品 elsif homework.homework_type == 2 #编程作业不能修改作品
link_to "作品已交", "",:class => 'c_blue',:title => "编程作业不可修改作品" link_to "作品已交", student_work_index_path(:homework => homework.id),:class => 'c_blue',:title => "编程作业不可修改作品"
else else
link_to "修改作品", edit_student_work_path(work.id),:class => 'c_blue' link_to "修改作品", edit_student_work_path(work.id),:class => 'c_blue'
end end

View File

@ -492,6 +492,7 @@ class Query < ActiveRecord::Base
def project_statement def project_statement
project_clauses = [] project_clauses = []
unless project.descendants.blank?
if project && !project.descendants.active.empty? if project && !project.descendants.active.empty?
ids = [project.id] ids = [project.id]
if has_filter?("subproject_id") if has_filter?("subproject_id")
@ -512,6 +513,7 @@ class Query < ActiveRecord::Base
elsif project elsif project
project_clauses << "#{Project.table_name}.id = %d" % project.id project_clauses << "#{Project.table_name}.id = %d" % project.id
end end
end
project_clauses.any? ? project_clauses.join(' AND ') : nil project_clauses.any? ? project_clauses.join(' AND ') : nil
end end

View File

@ -85,7 +85,7 @@
<% activity= activity.parent ? activity.parent : activity%> <% activity= activity.parent ? activity.parent : activity%>
<% replies_all_i = 0 %> <% replies_all_i = 0 %>
<% if count > 0 %> <% if count > 0 %>
<div class="homepagePostReplyContainer" id="reply_div_<%= user_activity_id %>"> <div class="" id="reply_div_<%= user_activity_id %>">
<ul> <ul>
<% activity.children.reorder("created_on desc").each do |reply|%> <% activity.children.reorder("created_on desc").each do |reply|%>
<% replies_all_i=replies_all_i+1 %> <% replies_all_i=replies_all_i+1 %>

View File

@ -57,7 +57,7 @@
<% replies_all_i = 0 %> <% replies_all_i = 0 %>
<% if count > 0 %> <% if count > 0 %>
<div class="homepagePostReplyContainer" id="reply_div_<%= user_activity_id %>"> <div class="" id="reply_div_<%= user_activity_id %>">
<ul> <ul>
<% activity.comments.reorder("created_on desc").each do |comment| %> <% activity.comments.reorder("created_on desc").each do |comment| %>
<% replies_all_i = replies_all_i + 1 %> <% replies_all_i = replies_all_i + 1 %>

View File

@ -94,7 +94,7 @@
<% replies_all_i = 0 %> <% replies_all_i = 0 %>
<% if count > 0 %> <% if count > 0 %>
<div class="homepagePostReplyContainer" id="reply_div_<%= user_activity_id %>"> <div class="" id="reply_div_<%= user_activity_id %>">
<ul> <ul>
<% activity.journals.reorder("created_on desc").each do |reply| %> <% activity.journals.reorder("created_on desc").each do |reply| %>
<% replies_all_i=replies_all_i + 1 %> <% replies_all_i=replies_all_i + 1 %>

View File

@ -71,7 +71,7 @@
<% activity= activity.parent_id.nil? ? activity : activity.parent %> <% activity= activity.parent_id.nil? ? activity : activity.parent %>
<% replies_all_i = 0 %> <% replies_all_i = 0 %>
<% if count > 0 %> <% if count > 0 %>
<div class="homepagePostReplyContainer" id="reply_div_<%= user_activity_id %>"> <div class="" id="reply_div_<%= user_activity_id %>">
<ul> <ul>
<% activity.children.reorder("created_on desc").each do |reply| %> <% activity.children.reorder("created_on desc").each do |reply| %>
<% replies_all_i=replies_all_i+1 %> <% replies_all_i=replies_all_i+1 %>

View File

@ -9,7 +9,7 @@
span.ke-icon-emoticons:hover{background-position:-79px -671px;width:50px;height:26px;} span.ke-icon-emoticons:hover{background-position:-79px -671px;width:50px;height:26px;}
div.ke-toolbar .ke-outline{border:none;} div.ke-toolbar .ke-outline{border:none;}
.ke-inline-block{display: none;} .ke-inline-block{display: none;}
.ke-container{height: 40px !important;} .ke-container{height: 30px !important;}
</style> </style>
<% user_activities.each do |user_activity| <% user_activities.each do |user_activity|
if user_activities %> if user_activities %>

View File

@ -19,6 +19,11 @@
<div class="homepagePostSubmit"> <div class="homepagePostSubmit">
<%= user_for_homework_common homework_common,is_teacher %> <%= user_for_homework_common homework_common,is_teacher %>
</div> </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), class: 'c_blue' %>
</div>
<% end %>
<div class="homepagePostDeadline"> <div class="homepagePostDeadline">
<%= l(:label_end_time)%><%= homework_common.end_time%> <%= l(:label_end_time)%><%= homework_common.end_time%>
</div> </div>

View File

@ -41,19 +41,17 @@
<div class="homepageRight"> <div class="homepageRight">
<div class="HomeWork"> <div class="HomeWork">
<div class="RightBanner"> <div class="RightBanner">
<div class="NewsBannerName">提交作品</div> <div class="NewsBannerName"><%= @is_test ? '模拟答题' : '提交作品' %></div>
</div> </div>
<div class="HomeWorkBox"> <div class="HomeWorkBox">
<div class=""> <div class="">
<div class="homepagePostTitle fl"><%= @homework.name %></div><span class="fr c_grey">截止时间:<%= @homework.end_time %></span> <div class="homepagePostTitle fl"><%= @homework.name %></div><span class="fr c_grey">截止时间:<%= @homework.end_time %></span>
<div class="cl"></div> <div class="cl"></div>
<a href="javascript:void(0);" class="c_blue"><%= @homework.user.show_name %></a> <a href="javascript:void(0);" class="c_blue"><%= @homework.user.show_name %></a>
<p class="HomeWorkP"><%= @homework.description %> <br /> <p class="HomeWorkP"><%= @homework.description.html_safe %> <br />
输入 2 1 1 4 4 2 3 6 5 <br />
输出 15<br />
</p> </p>
</div> </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><!---HomeWorkBox end -->
<div class="HomeWorkCon"> <div class="HomeWorkCon">
<%= form_for(@student_work, <%= form_for(@student_work,
@ -64,7 +62,7 @@
:homework => @homework.id :homework => @homework.id
}, },
:method => :post) do |f|%> :method => :post) do |f|%>
<input type="hidden" name="is_test" value="<%=@is_test%>">
<div class="mt15"> <div class="mt15">
<span>请使用 <%= @homework.language_name %> 语言编写</span> <span>请使用 <%= @homework.language_name %> 语言编写</span>
</div> </div>
@ -76,13 +74,18 @@
</div> </div>
<div class="mt10"> <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> <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> <a href="javascript:void(0);" class="BlueCirBtn fr" id="commit-program-work-btn">提交代码</a>
<% end %>
<div class="cl"></div> <div class="cl"></div>
</div> </div>
<% end %> <% end %>
</div><!----HomeWorkCon end--> </div><!----HomeWorkCon end-->
</div><!----HomeWork end--> </div><!----HomeWork end-->
<div class="cl"></div>
<div class="ProResult mt10"> <div class="ProResult mt10">
<% @student_work.student_work_tests.each_with_index do |test, index| %> <% @student_work.student_work_tests.each_with_index do |test, index| %>
<div class="ProResultTop"> <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> <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

@ -29,14 +29,7 @@
</div> </div>
<div class="resources mt10" id="users_setting"> <div class="resources mt10" id="users_setting">
<div> <div>
<% if params[:type].nil? %>
<div class="newsReadSetting">
有&nbsp;<span class="c_red"><%= User.current.count_new_message %></span>&nbsp;条未读
<% unless User.current.count_new_message == 0 %>
<a href="javascript:void(0);" class="ml15"><%= link_to "全部设为已读", user_message_path(User.current, :viewed => 'all') %></a>
<% end %>
</div>
<% end %>
<% if @message_alls.count >0 %> <% if @message_alls.count >0 %>
<%# 课程消息 %> <%# 课程消息 %>
<% unless @message_alls.nil? %> <% unless @message_alls.nil? %>

View File

@ -26,6 +26,7 @@ $(function(){
var student_work_id = $('#test-program-btn').attr('data-student-work-id'); var student_work_id = $('#test-program-btn').attr('data-student-work-id');
var src = $('#program-src').val(); var src = $('#program-src').val();
var title = $('#program-title').val(); var title = $('#program-title').val();
var is_test = $('input[name=is_test]').val();
if(!valid_form()){ if(!valid_form()){
return; return;
@ -33,10 +34,13 @@ $(function(){
$.post( $.post(
'/student_work/program_test', '/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){ function(data,status){
tested = true; tested = true;
console.log(data); console.log(data);
if(data.index <=0){
data.index = $('.ProResultTop').length+1;
}
if (typeof cb == 'function') {cb(); return;} if (typeof cb == 'function') {cb(); return;}
@ -44,7 +48,7 @@ $(function(){
var html=bt('t:result-list',data); var html=bt('t:result-list',data);
$('.ProResult').prepend(html); $('.ProResult').prepend(html);
if (data.status==0) { if (data.status==0 && is_test != 'true') {
var r=confirm("答题正确,是否立刻提交?"); var r=confirm("答题正确,是否立刻提交?");
if (r) { if (r) {
$(".HomeWorkCon form").submit(); $(".HomeWorkCon form").submit();