diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 89f67ddf4..e40475d51 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -55,12 +55,11 @@ class StudentWorkController < ApplicationController render :json => resultObj end - $test_result = {} - $test_status = {} +#由于负载问题 不要使用全局变量 #根据传入的tIndex确定是第几次测试 def program_test_ex is_test = params[:is_test] == 'true' - resultObj = {status: 0, results: [], error_msg: '', time: Time.now.strftime('%Y-%m-%d %T'),tseq:1,tcount:1} #保存每测试一次返回的结果 + resultObj = {status: 0, results: [], error_msg: '', time: Time.now.strftime('%Y-%m-%d %T'),tseq:1,tcount:1,testid:1} #保存每测试一次返回的结果 student_work = find_or_save_student_work(is_test) @@ -81,7 +80,7 @@ class StudentWorkController < ApplicationController #-1 默认值 0全部正确并结束 2 超时 -2 编译错误 resultObj[:status] = -1 - resultObj[:results] = result["results"][0] #本次测试结果 + resultObj[:results] = result["results"].first #本次测试结果 resultObj[:error_msg] = result["error_msg"] #编译错误时的信息 if result["status"].to_i == -2 #编译错误 @@ -94,24 +93,6 @@ class StudentWorkController < ApplicationController resultObj[:status] = 200 else - #索引 - work_id = student_work.id - - #测试第一个时初始化下全局变量 - if index == 1 - $test_result[work_id] = [] #保存本次测试的结果 输入输出 - $test_status[work_id] = 0 #保存本次测试的结果 正确还是错误 - end - - if result["status"].to_i == -2 - $test_result[work_id] = [result["error_msg"]] - $test_status[work_id] = -2 - else - #存下每次的结果 只有每次都为0才全部正确 - $test_status[work_id] = result["status"] != 0 ? result["status"]:$test_status[work_id] - $test_result[work_id][index - 1] = resultObj[:results] - end - student_work.name = params[:title] student_work.description = params[:src] @@ -121,20 +102,31 @@ class StudentWorkController < ApplicationController student_work.late_penalty = 0 end + #每次都要把数据存到数据库中 + status = resultObj[:status] + if index == 1 + student_work_test = student_work.student_work_tests.build(status: resultObj[:status], + results: [resultObj[:results]],src: params[:src]) + student_work_test.save! + resultObj[:testid] = student_work_test.id + else + 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 $test_status[work_id] == 0 + if status == 0 resultObj[:status] = 0 end - - student_work_test = student_work.student_work_tests.build(status: $test_status[work_id], - results: $test_result[work_id],src: params[:src]) - student_work.save resultObj[:time] = student_work_test.created_at.to_s(:db) resultObj[:index] = student_work.student_work_tests.count - - $test_result[work_id] = nil - $test_status[work_id] = nil end #渲染返回结果 diff --git a/app/models/principal.rb b/app/models/principal.rb index 2c8465538..0c87ec0c6 100644 --- a/app/models/principal.rb +++ b/app/models/principal.rb @@ -44,7 +44,7 @@ class Principal < ActiveRecord::Base else pattern = "%#{q}%".gsub("/","//").gsub("_","/_") # sql = %w(login firstname lastname mail).map {|column| "LOWER(#{table_name}.#{column}) LIKE LOWER(:p)"}.join(" OR ") - sql= "LOWER(concat(lastname,firstname)) LIKE LOWER(:p) or LOWER(login) LIKE LOWER(:p) or LOWER(mail) LIKE LOWER(:p) escape '/'" + sql= "LOWER(concat(lastname,firstname)) LIKE LOWER(:p) escape '/' or LOWER(login) LIKE LOWER(:p) escape '/' or LOWER(mail) LIKE LOWER(:p) escape '/'" params = {:p => pattern} if q =~ /^(.+)\s+(.+)$/ a, b = "#{$1}%", "#{$2}%" diff --git a/app/views/courses/_recommendation.html.erb b/app/views/courses/_recommendation.html.erb index 63803a5b9..1db2edf57 100644 --- a/app/views/courses/_recommendation.html.erb +++ b/app/views/courses/_recommendation.html.erb @@ -7,8 +7,8 @@

<%=link_to e_course.name, course_path(e_course.id), :class => "hidden fl w170" %>

- <% if course_file_num > 0 %> - <%= l(:project_module_attachments) %>(<%= link_to course_file_num, course_files_path(e_course), :class => "linkBlue2" %>) + <% if visable_attachemnts_incourse(e_course).count > 0 %> + <%= l(:project_module_attachments) %>(<%= link_to visable_attachemnts_incourse(e_course).count, course_files_path(e_course), :class => "linkBlue2" %>) <% end %> <% if e_course.homework_commons.where("publish_time <= '#{Date.today}'").count > 0 %> <%= l(:label_homework_commont) %>(<%= link_to e_course.homework_commons.where("publish_time <= '#{Date.today}'").count, homework_common_index_path(:course=>e_course.id), :class => "linkBlue2" %>) diff --git a/app/views/layouts/_project_info.html.erb b/app/views/layouts/_project_info.html.erb index 06d6304d2..d94cbdcc7 100644 --- a/app/views/layouts/_project_info.html.erb +++ b/app/views/layouts/_project_info.html.erb @@ -1,6 +1,6 @@ <% is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) %> -<% teacher_num = 0 %> -<% student_num = 0 %> +<% teacher_num = TeacherAndAssistantCount(@course) %> +<% student_num = studentCount(@course) %>

- <%= render :partial => 'courses/recommendation', :locals => {:course => @course, :course_file_num => course_file_num} %> + <%= render :partial => 'courses/recommendation', :locals => {:course => @course} %>
访问计数 <%= @course.visits.to_i %>
diff --git a/app/views/org_document_comments/edit.html.erb b/app/views/org_document_comments/edit.html.erb index 3ad388bd2..5997482fb 100644 --- a/app/views/org_document_comments/edit.html.erb +++ b/app/views/org_document_comments/edit.html.erb @@ -12,10 +12,12 @@ if($("#document_title").val().trim() == "") { $("#doc_title_hint").html("标题不能为空").show(); + return false; } else { $("#doc_title_hint").hide(); + return true; } } diff --git a/app/views/org_document_comments/new.html.erb b/app/views/org_document_comments/new.html.erb index 24dd7dcfe..cf4ffddcf 100644 --- a/app/views/org_document_comments/new.html.erb +++ b/app/views/org_document_comments/new.html.erb @@ -38,7 +38,7 @@
<%= form_tag organization_org_document_comments_path(:organization_id => @organization.id, :field_id => params[:field_id]), :id => 'new_org_document_form' do |f| %>
- +
diff --git a/app/views/organizations/_show_org_document.html.erb b/app/views/organizations/_show_org_document.html.erb index cf68d71f5..fdd6772e7 100644 --- a/app/views/organizations/_show_org_document.html.erb +++ b/app/views/organizations/_show_org_document.html.erb @@ -10,7 +10,7 @@ TO  <%= link_to document.organization.name, organization_path(document.organization), :class => "newsBlue" %> | <%= document.org_subfield_id.nil? ? "组织文章" :"#{OrgSubfield.find(document.org_subfield_id).name}" %> - <% if @organization.home_id == document.id %> + <% if document.organization.home_id == document.id %> 已设为首页 <% end %>
diff --git a/app/views/users/_resources_list.html.erb b/app/views/users/_resources_list.html.erb index a545038f1..c2b37f0e6 100644 --- a/app/views/users/_resources_list.html.erb +++ b/app/views/users/_resources_list.html.erb @@ -26,349 +26,14 @@ <% end %> <% end %> - diff --git a/app/views/users/_user_resource_info.html.erb b/app/views/users/_user_resource_info.html.erb index bea78130a..bf36e4b38 100644 --- a/app/views/users/_user_resource_info.html.erb +++ b/app/views/users/_user_resource_info.html.erb @@ -37,12 +37,350 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/public/javascripts/homework.js b/public/javascripts/homework.js index 3bca1606c..5b7f1b046 100644 --- a/public/javascripts/homework.js +++ b/public/javascripts/homework.js @@ -57,10 +57,12 @@ $(function(){ ); */ //先测试一次并返回测试集个数及结果再判断是否需要继续进行测试 - var test_post = function(i){ + var test_post = function(i, testid){ $.post( '/student_work/program_test_ex', - {homework: homework_id, student_work_id: student_work_id, src: src, title: title, is_test: is_test,tIndex:i}, + {homework: homework_id, student_work_id: student_work_id, + src: src, title: title, is_test: is_test,tIndex:i, + testid: testid}, function(data,status){ var tSeq = data.tseq; var tCount = data.tcount; @@ -90,7 +92,7 @@ $(function(){ return; } - test_post(i+1); + test_post(i+1, data.testid); } ).fail(function(xhr, status){ if(status == 'timeout'){ @@ -100,9 +102,10 @@ $(function(){ } return; }); + }; - test_post(1); + test_post(1, 0); }; $('#test-program-btn').on('click', test_program);