Merge branch 'szzh' of http://repository.trustie.net/xianbo/trustie2 into szzh
This commit is contained in:
commit
59bbfeb0b5
|
@ -115,23 +115,16 @@ class HomeworkCommonController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
# uri = URI('http://test.gitlab.trustie.net/api/questions.json')
|
||||
# req = Net::HTTP::Post.new(uri, initheader = {'Content-Type' =>'application/json'})
|
||||
# req.body = question.to_json
|
||||
# res = Net::HTTP.start(uri.hostname, uri.port) do |http|
|
||||
# http.request(req)
|
||||
# uri = URI('http://192.168.80.21:8080/api/questions.json')
|
||||
# body = question.to_json
|
||||
# res = Net::HTTP.new(uri.host, uri.port).start do |client|
|
||||
# request = Net::HTTP::Post.new(uri.path)
|
||||
# request.body = body
|
||||
# request["Content-Type"] = "application/json"
|
||||
# client.request(request)
|
||||
# end
|
||||
|
||||
uri = URI('http://192.168.80.21:8080/api/questions.json')
|
||||
body = question.to_json
|
||||
res = Net::HTTP.new(uri.host, uri.port).start do |client|
|
||||
request = Net::HTTP::Post.new(uri.path)
|
||||
request.body = body
|
||||
request["Content-Type"] = "application/json"
|
||||
client.request(request)
|
||||
end
|
||||
result = JSON.parse(res.body)
|
||||
homework_detail_programing.question_id = result["id"] if result["status"] && result["status"] == 0
|
||||
# result = JSON.parse(res.body)
|
||||
# homework_detail_programing.question_id = result["id"] if result["status"] && result["status"] == 0
|
||||
|
||||
homework.homework_detail_programing = homework_detail_programing
|
||||
else
|
||||
|
@ -254,15 +247,15 @@ class HomeworkCommonController < ApplicationController
|
|||
question[:input] << test.input
|
||||
question[:output] << test.output
|
||||
end
|
||||
uri = URI("http://192.168.80.21:8080/api/questions/#{@homework_detail_programing.question_id}.json")
|
||||
body = question.to_json
|
||||
res = Net::HTTP.new(uri.host, uri.port).start do |client|
|
||||
request = Net::HTTP::Put.new(uri.path)
|
||||
request.body = body
|
||||
request["Content-Type"] = "application/json"
|
||||
client.request(request)
|
||||
end
|
||||
result = JSON.parse(res.body)
|
||||
# uri = URI("http://192.168.80.21:8080/api/questions/#{@homework_detail_programing.question_id}.json")
|
||||
# body = question.to_json
|
||||
# res = Net::HTTP.new(uri.host, uri.port).start do |client|
|
||||
# request = Net::HTTP::Put.new(uri.path)
|
||||
# request.body = body
|
||||
# request["Content-Type"] = "application/json"
|
||||
# client.request(request)
|
||||
# end
|
||||
# result = JSON.parse(res.body)
|
||||
end
|
||||
|
||||
@homework.save_attachments(params[:attachments])
|
||||
|
@ -406,4 +399,4 @@ class HomeworkCommonController < ApplicationController
|
|||
student_works += student_works
|
||||
student_works[index + 1 .. index + n]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,13 +3,45 @@ class StudentWorkController < ApplicationController
|
|||
include StudentWorkHelper
|
||||
require 'bigdecimal'
|
||||
require "base64"
|
||||
before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list]
|
||||
before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :program_test]
|
||||
before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work]
|
||||
before_filter :member_of_course, :only => [:index, :new, :create, :show, :add_score, :praise_student_work]
|
||||
before_filter :author_of_work, :only => [:edit, :update, :destroy]
|
||||
before_filter :teacher_of_course, :only => [:student_work_absence_penalty, :absence_penalty_list, :evaluation_list]
|
||||
protect_from_forgery :except => :set_program_score
|
||||
|
||||
###
|
||||
def program_test
|
||||
resultObj = {status: 0, results: [], error_msg: '', time: Time.now}
|
||||
student_work = find_or_save_student_work
|
||||
unless student_work
|
||||
resultObj[:status] = 100
|
||||
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
|
||||
student_work_test = student_work.student_work_tests.build(status: result["status"], results: results,
|
||||
src: params[:src])
|
||||
unless student_work.save
|
||||
resultObj[:status] = 200
|
||||
else
|
||||
resultObj[:status] = result["status"].to_i
|
||||
resultObj[:time] = student_work_test.created_at.to_s(:db)
|
||||
resultObj[:index] = student_work.student_work_tests.count
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
render :json => resultObj
|
||||
end
|
||||
|
||||
def index
|
||||
#设置作业对应的forge_messages表的viewed字段
|
||||
query_student_work = @homework.course_messages
|
||||
|
@ -102,20 +134,16 @@ class StudentWorkController < ApplicationController
|
|||
end
|
||||
|
||||
def new
|
||||
student_work = @homework.student_works.where("user_id = ?",User.current.id).first
|
||||
if student_work.nil?
|
||||
@stundet_work = StudentWork.new
|
||||
respond_to do |format|
|
||||
format.html
|
||||
end
|
||||
else
|
||||
render_403
|
||||
@student_work = @homework.student_works.where("user_id = ?",User.current.id).first
|
||||
if @student_work.nil?
|
||||
@student_work = StudentWork.new
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
if params[:student_work]
|
||||
stundet_work = StudentWork.new
|
||||
stundet_work = StudentWork.find(params[:student_work_id]) if params[:student_work_id]
|
||||
stundet_work ||= StudentWork.new
|
||||
stundet_work.name = params[:student_work][:name]
|
||||
stundet_work.description = params[:student_work][:description]
|
||||
stundet_work.project_id = params[:student_work][:project_id]
|
||||
|
@ -128,23 +156,9 @@ class StudentWorkController < ApplicationController
|
|||
stundet_work.late_penalty = 0
|
||||
end
|
||||
render_attachment_warning_if_needed(stundet_work)
|
||||
|
||||
if stundet_work.save
|
||||
if @homework.homework_type == 2 && @homework.homework_detail_programing #编程作业,学生提交作品后计算系统得分
|
||||
url = "http://192.168.80.21:8080/api/questions/#{@homework.homework_detail_programing.question_id}/solutions.json"
|
||||
solutions = {
|
||||
student_work_id:stundet_work.id,
|
||||
src:Base64.encode64(stundet_work.description),
|
||||
language:@homework.homework_detail_programing.language
|
||||
}
|
||||
uri = URI(url)
|
||||
body = solutions.to_json
|
||||
res = Net::HTTP.new(uri.host, uri.port).start do |client|
|
||||
request = Net::HTTP::Post.new(uri.path)
|
||||
request.body = body
|
||||
request["Content-Type"] = "application/json"
|
||||
client.request(request)
|
||||
end
|
||||
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
|
@ -584,4 +598,44 @@ class StudentWorkController < ApplicationController
|
|||
book.write xls_report
|
||||
xls_report.string
|
||||
end
|
||||
|
||||
def find_or_save_student_work
|
||||
student_work = @homework.student_works.where(user_id: User.current.id).first
|
||||
if student_work.nil?
|
||||
@homework.student_works.build(
|
||||
name: params[:title],
|
||||
description: params[:src],
|
||||
user_id: User.current.id
|
||||
)
|
||||
unless @homework.save
|
||||
else
|
||||
student_work = @homework.student_works.where(user_id: User.current.id).first
|
||||
end
|
||||
end
|
||||
student_work
|
||||
end
|
||||
|
||||
|
||||
def test_realtime(student_work, src)
|
||||
url = "#{Redmine::Configuration['judge_server']}api/realtime_test.json"
|
||||
|
||||
factor = []
|
||||
@homework.homework_tests.each do |test|
|
||||
factor << {input: test.input, output: test.output}
|
||||
end
|
||||
solutions = {
|
||||
src:src,
|
||||
language:@homework.homework_detail_programing.language,
|
||||
factor: factor
|
||||
}
|
||||
uri = URI(url)
|
||||
body = solutions.to_json
|
||||
res = Net::HTTP.new(uri.host, uri.port).start do |client|
|
||||
request = Net::HTTP::Post.new(uri.path)
|
||||
request.body = body
|
||||
request["Content-Type"] = "application/json"
|
||||
client.request(request)
|
||||
end
|
||||
JSON.parse(res.body)
|
||||
end
|
||||
end
|
|
@ -347,6 +347,24 @@ class UsersController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def new_user_commit_homework
|
||||
@user = User.current
|
||||
@homework = HomeworkCommon.find(params[:homework_id])
|
||||
@student_work = @homework.student_works.where(user_id: User.current.id).first
|
||||
if @student_work.nil?
|
||||
@student_work = StudentWork.new
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html {render :layout => 'new_base_user'}
|
||||
end
|
||||
end
|
||||
|
||||
def user_commit_homework
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to user_homeworks_user_path(User.current)
|
||||
end
|
||||
|
||||
def user_new_homework
|
||||
if params[:homework_common]
|
||||
homework = HomeworkCommon.new
|
||||
|
@ -354,7 +372,7 @@ class UsersController < ApplicationController
|
|||
homework.description = params[:homework_common][:description]
|
||||
homework.end_time = params[:homework_common][:end_time] || Time.now
|
||||
homework.publish_time = Time.now
|
||||
homework.homework_type = 1
|
||||
homework.homework_type = params[:homework_type].to_i || 1
|
||||
homework.late_penalty = 2
|
||||
homework.user_id = User.current.id
|
||||
homework.course_id = params[:course_id]
|
||||
|
@ -363,17 +381,36 @@ class UsersController < ApplicationController
|
|||
render_attachment_warning_if_needed(homework)
|
||||
|
||||
#匿评作业相关属性
|
||||
homework_detail_manual = HomeworkDetailManual.new
|
||||
homework_detail_manual.ta_proportion = params[:ta_proportion] || 0.6
|
||||
homework_detail_manual.comment_status = 1
|
||||
homework_detail_manual.evaluation_start = Time.now
|
||||
homework_detail_manual.evaluation_end = Time.now
|
||||
homework_detail_manual.evaluation_num = params[:evaluation_num] || 3
|
||||
homework_detail_manual.absence_penalty = 2
|
||||
homework.homework_detail_manual = homework_detail_manual
|
||||
if homework.homework_type == 1
|
||||
homework_detail_manual = HomeworkDetailManual.new
|
||||
homework_detail_manual.ta_proportion = params[:ta_proportion] || 0.6
|
||||
homework_detail_manual.comment_status = 1
|
||||
homework_detail_manual.evaluation_start = Time.now
|
||||
homework_detail_manual.evaluation_end = Time.now
|
||||
homework_detail_manual.evaluation_num = params[:evaluation_num] || 3
|
||||
homework_detail_manual.absence_penalty = 2
|
||||
homework.homework_detail_manual = homework_detail_manual
|
||||
else
|
||||
homework_detail_programing = HomeworkDetailPrograming.new
|
||||
homework.homework_detail_programing = homework_detail_programing
|
||||
homework_detail_programing.ta_proportion = params[:ta_proportion] || 0.6
|
||||
homework_detail_programing.language = params[:program][:language].to_i
|
||||
|
||||
inputs = params[:program][:input]
|
||||
if Array === inputs
|
||||
inputs.each_with_index do |val, i|
|
||||
homework.homework_tests << HomeworkTest.new(
|
||||
input: val,
|
||||
output: params[:program][:output][i]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if homework.save
|
||||
homework_detail_manual.save if homework_detail_manual
|
||||
homework_detail_programing.save if homework_detail_programing
|
||||
redirect_to user_homeworks_user_path(User.current.id)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -56,4 +56,6 @@ class HomeworkCommon < ActiveRecord::Base
|
|||
Mailer.run.homework_added(self)
|
||||
end
|
||||
|
||||
delegate :language_name, :to => :homework_detail_programing
|
||||
|
||||
end
|
||||
|
|
|
@ -2,4 +2,8 @@ class HomeworkDetailPrograming < ActiveRecord::Base
|
|||
attr_accessible :language, :standard_code, :homework_common_id
|
||||
|
||||
belongs_to :homework_common
|
||||
|
||||
def language_name
|
||||
%W(c c++).at(self.language.to_i - 1)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,5 +2,4 @@ class HomeworkTest < ActiveRecord::Base
|
|||
attr_accessible :input, :output, :homework_common_id,:result,:error_msg
|
||||
|
||||
belongs_to :homework_common
|
||||
has_many :student_work_test
|
||||
end
|
||||
|
|
|
@ -7,7 +7,7 @@ class StudentWork < ActiveRecord::Base
|
|||
has_many :student_works_evaluation_distributions, :dependent => :destroy
|
||||
has_many :student_works_scores, :dependent => :destroy
|
||||
belongs_to :project
|
||||
has_many :student_work_test
|
||||
has_many :student_work_tests, order: 'id desc'
|
||||
|
||||
before_destroy :delete_praise
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
# encoding: utf-8
|
||||
class StudentWorkTest < ActiveRecord::Base
|
||||
attr_accessible :student_work_id, :homework_test_id, :result, :error_msg
|
||||
|
||||
belongs_to :homework_test
|
||||
attr_accessible :student_work_id, :results, :status, :src
|
||||
belongs_to :student_work
|
||||
|
||||
serialize :results, Array
|
||||
|
||||
def status_to_s
|
||||
case self.result.to_i
|
||||
case self.status.to_i
|
||||
when -1
|
||||
'编译出错'
|
||||
when -2
|
||||
|
@ -33,10 +33,11 @@ class StudentWorkTest < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def test_score
|
||||
if self.result.to_i == 0
|
||||
if self.status.to_i == 0
|
||||
format("%.1f",100.0 / self.student_work.homework_common.homework_tests.count)
|
||||
else
|
||||
0
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
$("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'users/course_news', :locals => {:activity => @news,:user_activity_id =>@user_activity_id}) %>");
|
||||
|
||||
init_KindEditor_data(<%= @user_activity_id%>);
|
||||
init_KindEditor_data('<%= @user_activity_id%>');
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
<div class="homepageRight">
|
||||
<div class="HomeWork">
|
||||
<div class="RightBanner">
|
||||
<div class="NewsBannerName">发布作业</div>
|
||||
</div>
|
||||
<div class="HomeWorkCon">
|
||||
<div class="mt15">
|
||||
<textarea class="InputBox W700 " placeholder="请输入作业标题" name="homework_common[name]" id="homework_name" maxlength="255" onkeyup="regex_homework_name();" value="<%= homework.name%>"></textarea>
|
||||
</div>
|
||||
<div class=" mt10">
|
||||
<a href="javascript:void(0);" class="BlueCirBtn fl mr10">导入作业</a>
|
||||
<input type="text" name="homework_common[end_time]" id="homework_end_time" class="InputBox fl W120 date-input" readonly="readonly" value="<%= homework.end_time%>" placeholder="截止日期"></input>
|
||||
<div class="fl DateBorder mr10"><a href="javascript:void(0);" class="pic_date"></a></div>
|
||||
<input type="text" name="homework_common[publish_time]" id="homework_publish_time" class="InputBox fl W120 date-input" readonly="readonly" value="<%= homework.publish_time%>" placeholder="发布日期"></input>
|
||||
<div class="fl DateBorder"><a href="javascript:void(0);" class="pic_date"></a></div>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
<div class="mt10">
|
||||
<% if edit_mode %>
|
||||
<%= f.kindeditor :description,:editor_id => 'homework_description_editor',:owner_id => homework.id,:owner_type =>OwnerTypeHelper::HOMEWORKCOMMON %>
|
||||
<% else %>
|
||||
<%= hidden_field_tag :asset_id,params[:asset_id],:required => false,:style => 'display:none' %>
|
||||
<%= f.kindeditor :description,:editor_id => 'homework_description_editor' %>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="mt10">
|
||||
<textarea class="InputBox W700 SearchIcon" placeholder="发送到课程" style="margin-top: 0px; margin-bottom: 0px; height: 29px;"></textarea>
|
||||
</div>
|
||||
<div class="mt5">
|
||||
<a href="javascript:void(0);" class="AnnexBtn fl mt3">上传附件</a>
|
||||
<a href="javascript:void(0);" class="FilesBtn fl mr15 mt3">资源库</a>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
|
||||
<div class="mt10">
|
||||
<a href="javascript:void(0);" class=" fl DropBtn">高级功能</a>
|
||||
<div class="DropLine"></div>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
<div class="advanced_option" style="display:none;">
|
||||
<div class="mt10">
|
||||
<select class="InputBox W120" required="true">
|
||||
<option value="语言选择">语言选择</option>
|
||||
<option value="C语言">C语言</option>
|
||||
<option value="C++">C++</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="mt10">
|
||||
<textarea class="InputBox W320 fl mr10" placeholder="测试输入" required></textarea><textarea class="InputBox W320 fl mr5" placeholder="测试输出" required></textarea>
|
||||
<a href="javascript:void(0);" class=" fl icon_add" title="增加测试组"></a>
|
||||
<a href="javascript:void(0);" class=" fl icon_remove" title="删除测试组"></a>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt10">
|
||||
<a href="javascript:void(0);" onClick="submit_homework('new_homework_common');" class="BlueCirBtnMini fr">发布</a>
|
||||
<span class="fr mr10 mt3">或</span><%= link_to '取消',homework_common_index_path(:course => @course.id),:class => 'fr mr10 mt3'%>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div><!----HomeWork end-->
|
||||
|
||||
</div>
|
||||
|
||||
<script id="t:test-answer-list" type="text/html">
|
||||
<div class="mt10">
|
||||
<textarea class="InputBox W320 fl mr10" placeholder="测试输入" required></textarea><textarea class="InputBox W320 fl mr5" placeholder="测试输出" required></textarea>
|
||||
<a href="javascript:void(0);" class=" fl icon_add" title="增加测试组"></a>
|
||||
<a href="javascript:void(0);" class=" fl icon_remove" title="删除测试组"></a>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
</script>
|
||||
|
|
@ -1,17 +1,16 @@
|
|||
<%= javascript_include_tag "/assets/kindeditor/kindeditor" %>
|
||||
<% content_for :header_tags do %>
|
||||
<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %>
|
||||
<%= javascript_include_tag 'homework','baiduTemplate' %>
|
||||
<% end %>
|
||||
|
||||
<%= error_messages_for 'homework_common' %>
|
||||
<div class="project_r_h">
|
||||
<h2 class="project_h2">
|
||||
<%= l(:label_course_homework_new)%>
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
<div class="hwork_new">
|
||||
<%= labelled_form_for @homework,:url => {:controller => 'homework_common',:action => 'create'} do |f| %>
|
||||
<%= hidden_field_tag "course",@course.id%>
|
||||
<%= render :partial => 'homework_common/homework_detail_manual_form', :locals => { :homework => @homework,:f => f,:edit_mode => false } %>
|
||||
<a href="javascript:void(0)" class="blue_btn fl mr10" onClick="submit_homework('new_homework_common');" >提交</a>
|
||||
<%#= link_to "上一步", new_homework_common_path(:course => @course.id), :class => "orange_btn_homework fl"%>
|
||||
<%= link_to '取消',homework_common_index_path(:course => @course.id),:class => 'grey_btn fl'%>
|
||||
<%= render :partial => 'homework_common/new_homework_detail_manual_form', :locals => { :homework => @homework,:f => f,:edit_mode => false } %>
|
||||
<% end%>
|
||||
</div><!--hwork_new end-->
|
||||
|
||||
|
||||
<div class="cl"></div>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<%= javascript_include_tag "/assets/kindeditor/kindeditor" %>
|
||||
<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %>
|
||||
<%= error_messages_for 'homework_common' %>
|
||||
<div class="project_r_h">
|
||||
<h2 class="project_h2">
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
<% content_for :header_tags do %>
|
||||
<%= javascript_include_tag 'homework','baiduTemplate' %>
|
||||
<% end %>
|
||||
|
||||
<% if @homework.homework_type == 1 %>
|
||||
<script type="text/javascript">
|
||||
<%if @homework.homework_type == 1 && @homework.homework_detail_manual.comment_status != 1%>
|
||||
$(function(){
|
||||
|
@ -18,7 +23,7 @@
|
|||
<div class="Newwork">
|
||||
<div class="hwork_ctt">
|
||||
<div class="hwork_dis" id="tbc_01">
|
||||
<%= form_for(@stundet_work,
|
||||
<%= form_for(@student_work,
|
||||
:html => { :multipart => true },
|
||||
:url => {:controller => 'student_work',
|
||||
:action => 'create',
|
||||
|
@ -80,4 +85,122 @@
|
|||
</div>
|
||||
</div>
|
||||
</div><!--新建作业结束-->
|
||||
<div class="cl"></div>
|
||||
<div class="cl"></div>
|
||||
|
||||
<% else %>
|
||||
|
||||
|
||||
<!-- 模板1开始,可以使用script(type设置为text/html)来存放模板片段,并且用id标示 -->
|
||||
<script id="t:result-list" type="text/html">
|
||||
<div class="ProResultTop">
|
||||
<p class="c_blue fl">第<!=index!>次测试</p><span class="fr c_grey"><!= time !></span>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
|
||||
<! if(status == -2){!>
|
||||
<div class="ProResultCon "><!= error_msg !></div>
|
||||
<!}else{!>
|
||||
<div class="ProResultTable " >
|
||||
<ul class="ProResultUl " >
|
||||
<! for(var i =0; i <results.length; ++i){ !>
|
||||
<li ><span class="w60 T_C">测试<!=i+1!></span>
|
||||
<! if(results[i]["status"]!=0){ !>
|
||||
<span class="w150 c_red">测试错误!</span>
|
||||
<span class="w60">您的输出:</span>
|
||||
<span class="W200"><!=results[i]["result"]!></span>
|
||||
<span class="w60">正确输出:</span>
|
||||
<span class="W200"><!=results[i]["output"]!></span>
|
||||
<div class="cl"></div>
|
||||
</li>
|
||||
<!}else{!>
|
||||
<span class="w150 c_green">测试正确!</span>
|
||||
<div class="cl"></div>
|
||||
</li>
|
||||
<!}!>
|
||||
<!}!>
|
||||
</ul>
|
||||
</div>
|
||||
<! } !>
|
||||
|
||||
</script>
|
||||
<!-- 模板1结束 -->
|
||||
|
||||
<div class="homepageRight">
|
||||
<div class="HomeWork">
|
||||
<div class="RightBanner">
|
||||
<div class="NewsBannerName">提交作品</div>
|
||||
</div>
|
||||
<div class="HomeWorkBox">
|
||||
<div class="">
|
||||
<div class="homepagePostTitle fl"><%= @homework.name %></div><span class="fr c_grey">截止时间:<%= @homework.end_time %></span>
|
||||
<div class="cl"></div>
|
||||
<a href="javascript:void(0);" class="c_blue"><%= @homework.user.show_name %></a>
|
||||
<p class="HomeWorkP"><%= @homework.description %> <br />
|
||||
输入 2 1 1 4 4 2 3 6 5 <br />
|
||||
输出 15<br />
|
||||
</p>
|
||||
</div>
|
||||
<p class="c_grey mt15">注:迟交扣<span class="c_red">2</span>分,缺评一个作品扣<span class="c_red">2</span>分</p>
|
||||
</div><!---HomeWorkBox end -->
|
||||
<div class="HomeWorkCon">
|
||||
<%= form_for(@student_work,
|
||||
:html => { :multipart => true },
|
||||
:url => {:controller => 'student_work',
|
||||
:action => 'create',
|
||||
:student_work_id => @student_work.id,
|
||||
:homework => @homework.id
|
||||
},
|
||||
:method => :post) do |f|%>
|
||||
|
||||
<div class="mt15">
|
||||
<span>请使用 <%= @homework.language_name %> 语言编写</span>
|
||||
</div>
|
||||
<div class="mt10">
|
||||
<%= f.text_area :name, id: 'program-title', class:"InputBox W700", placeholder:"请概括你的代码的功能" %>
|
||||
</div>
|
||||
<div class="mt10">
|
||||
<%= f.text_area :description, id: 'program-src', class:" W700 H150", placeholder:"请贴入你的代码", rows: 10 %>
|
||||
</div>
|
||||
<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 fr" id="commit-program-work-btn">提交代码</a>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div><!----HomeWorkCon end-->
|
||||
</div><!----HomeWork end-->
|
||||
<div class="ProResult mt10">
|
||||
<% @student_work.student_work_tests.each_with_index do |test, index| %>
|
||||
<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>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
<% if test.status.to_i == -2 %>
|
||||
<div class="ProResultCon "><%= test.results.first %></div>
|
||||
<% else %>
|
||||
<div class="ProResultTable " >
|
||||
<ul class="ProResultUl " >
|
||||
<% test.results.each_with_index do |x, i| %>
|
||||
<li ><span class="w60 T_C">测试<%=i+1%></span>
|
||||
<% if x["status"].to_i != 0 %>
|
||||
<span class="w150 c_red">测试错误!</span>
|
||||
<span class="w60">您的输出:</span>
|
||||
<span class="W200"><%=x["result"]%></span>
|
||||
<span class="w60">正确输出:</span>
|
||||
<span class="W200"><%=x["output"]%></span>
|
||||
<div class="cl"></div>
|
||||
</li>
|
||||
<% else %>
|
||||
<span class="w150 c_green">测试正确!</span>
|
||||
<div class="cl"></div>
|
||||
</li>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div><!----ProResult end-->
|
||||
</div><!--homepageRight end-->
|
||||
|
||||
<% end %>
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
<%= javascript_include_tag "/assets/kindeditor/kindeditor" %>
|
||||
<% content_for :header_tags do %>
|
||||
<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %>
|
||||
<%= javascript_include_tag 'homework','baiduTemplate' %>
|
||||
<% end %>
|
||||
|
||||
<div class="HomeWorkCon">
|
||||
<div>
|
||||
<input type="text" name="homework_common[name]" id="homework_name" class="InputBox w712" maxlength="255" onfocus="$('#homework_editor').show()" onkeyup="regex_homework_name();" placeholder="请输入作业标题" value="<%= homework.name%>" >
|
||||
|
@ -35,11 +39,48 @@
|
|||
<%= render :partial => 'users/user_homework_attachment', :locals => {:container => homework} %>
|
||||
</div>
|
||||
|
||||
<div class="mt5 fr">
|
||||
<a href="javascript:void(0);" class="BlueCirBtnMini fr" onclick=" submit_homework('new_homework_common');">发送</a>
|
||||
<span class="fr mr10 mt3">或</span>
|
||||
<a href="javascript:void(0);" class=" fr mr10 mt3" onclick="reset_homework();">取消</a>
|
||||
</div>
|
||||
<div class="mt5">
|
||||
<a href="javascript:void(0);" class="BlueCirBtnMini fr" onclick=" submit_comm_homework('new_homework_common');">发送</a>
|
||||
<span class="fr mr10 mt3">或</span>
|
||||
<a href="javascript:void(0);" class=" fr mr10 mt3" onclick="reset_homework();">取消</a>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
|
||||
|
||||
|
||||
<div class="mt10">
|
||||
<a href="javascript:void(0);" class=" fl DropBtn">编程选项</a>
|
||||
<div class="DropLine"></div>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
|
||||
<div class="advanced_option" style="display:none;">
|
||||
<div class="mt10">
|
||||
<select class="InputBox W120" required="true" name="program[language]">
|
||||
<option value="1" selected>C语言</option>
|
||||
<option value="2">C++</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="mt10">
|
||||
<textarea class="InputBox W320 fl mr10" placeholder="测试输入" required name="program[input][]"></textarea><textarea class="InputBox W320 fl mr5" placeholder="测试输出" required name="program[output][]"></textarea>
|
||||
<a href="javascript:void(0);" class=" fl icon_add" title="增加测试组"></a>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input type="hidden" name="homework_type" value="1">
|
||||
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
|
||||
|
||||
<script id="t:test-answer-list" type="text/html">
|
||||
<div class="mt10">
|
||||
<textarea class="InputBox W320 fl mr10" placeholder="测试输入" required name="program[input][]"></textarea><textarea class="InputBox W320 fl mr5" placeholder="测试输出" required name="program[output][]"></textarea>
|
||||
<a href="javascript:void(0);" class=" fl icon_add" title="增加测试组"></a>
|
||||
<a href="javascript:void(0);" class=" fl icon_remove" title="删除测试组"></a>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
|
|
|
@ -0,0 +1,117 @@
|
|||
<% content_for :header_tags do %>
|
||||
<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %>
|
||||
<%= javascript_include_tag 'homework','baiduTemplate' %>
|
||||
<% end %>
|
||||
|
||||
<!-- 模板1开始,可以使用script(type设置为text/html)来存放模板片段,并且用id标示 -->
|
||||
<script id="t:result-list" type="text/html">
|
||||
<div class="ProResultTop">
|
||||
<p class="c_blue fl">第<!=index!>次测试</p><span class="fr c_grey"><!= time !></span>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
|
||||
<! if(status == -2){!>
|
||||
<div class="ProResultCon "><!= error_msg !></div>
|
||||
<!}else{!>
|
||||
<div class="ProResultTable " >
|
||||
<ul class="ProResultUl " >
|
||||
<! for(var i =0; i <results.length; ++i){ !>
|
||||
<li ><span class="w60 T_C">测试<!=i+1!></span>
|
||||
<! if(results[i]["status"]!=0){ !>
|
||||
<span class="w150 c_red">测试错误!</span>
|
||||
<span class="w60">您的输出:</span>
|
||||
<span class="W200"><!=results[i]["result"]!></span>
|
||||
<span class="w60">正确输出:</span>
|
||||
<span class="W200"><!=results[i]["output"]!></span>
|
||||
<div class="cl"></div>
|
||||
</li>
|
||||
<!}else{!>
|
||||
<span class="w150 c_green">测试正确!</span>
|
||||
<div class="cl"></div>
|
||||
</li>
|
||||
<!}!>
|
||||
<!}!>
|
||||
</ul>
|
||||
</div>
|
||||
<! } !>
|
||||
|
||||
</script>
|
||||
<!-- 模板1结束 -->
|
||||
|
||||
<div class="homepageRight">
|
||||
<div class="HomeWork">
|
||||
<div class="RightBanner">
|
||||
<div class="NewsBannerName">提交作品</div>
|
||||
</div>
|
||||
<div class="HomeWorkBox">
|
||||
<div class="">
|
||||
<div class="homepagePostTitle fl"><%= @homework.name %></div><span class="fr c_grey">截止时间:<%= @homework.end_time %></span>
|
||||
<div class="cl"></div>
|
||||
<a href="javascript:void(0);" class="c_blue"><%= @homework.user.show_name %></a>
|
||||
<p class="HomeWorkP"><%= @homework.description %> <br />
|
||||
输入 2 1 1 4 4 2 3 6 5 <br />
|
||||
输出 15<br />
|
||||
</p>
|
||||
</div>
|
||||
<p class="c_grey mt15">注:迟交扣<span class="c_red">2</span>分,缺评一个作品扣<span class="c_red">2</span>分</p>
|
||||
</div><!---HomeWorkBox end -->
|
||||
<div class="HomeWorkCon">
|
||||
<%= form_for(@student_work,
|
||||
:html => { :multipart => true },
|
||||
:url => {:controller => 'users',
|
||||
:action => 'user_commit_homework',
|
||||
:student_work_id => @student_work.id,
|
||||
:homework => @homework.id
|
||||
},
|
||||
:method => :post) do |f|%>
|
||||
|
||||
<div class="mt15">
|
||||
<span>请使用 <%= @homework.language_name %> 语言编写</span>
|
||||
</div>
|
||||
<div class="mt10">
|
||||
<%= f.text_area :name, id: 'program-title', class:"InputBox W700", placeholder:"请概括你的代码的功能" %>
|
||||
</div>
|
||||
<div class="mt10">
|
||||
<%= f.text_area :description, id: 'program-src', class:" W700 H150", placeholder:"请贴入你的代码", rows: 10 %>
|
||||
</div>
|
||||
<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 fr" id="commit-program-work-btn">提交代码</a>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div><!----HomeWorkCon end-->
|
||||
</div><!----HomeWork end-->
|
||||
<div class="ProResult mt10">
|
||||
<% @student_work.student_work_tests.each_with_index do |test, index| %>
|
||||
<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>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
<% if test.status.to_i == -2 %>
|
||||
<div class="ProResultCon "><%= test.results.first %></div>
|
||||
<% else %>
|
||||
<div class="ProResultTable " >
|
||||
<ul class="ProResultUl " >
|
||||
<% test.results.each_with_index do |x, i| %>
|
||||
<li ><span class="w60 T_C">测试<%=i+1%></span>
|
||||
<% if x["status"].to_i != 0 %>
|
||||
<span class="w150 c_red">测试错误!</span>
|
||||
<span class="w60">您的输出:</span>
|
||||
<span class="W200"><%=x["result"]%></span>
|
||||
<span class="w60">正确输出:</span>
|
||||
<span class="W200"><%=x["output"]%></span>
|
||||
<div class="cl"></div>
|
||||
</li>
|
||||
<% else %>
|
||||
<span class="w150 c_green">测试正确!</span>
|
||||
<div class="cl"></div>
|
||||
</li>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div><!----ProResult end-->
|
||||
</div><!--homepageRight end-->
|
|
@ -0,0 +1,114 @@
|
|||
|
||||
|
||||
<!-- 模板1开始,可以使用script(type设置为text/html)来存放模板片段,并且用id标示 -->
|
||||
<script id="t:result-list" type="text/html">
|
||||
<div class="ProResultTop">
|
||||
<p class="c_blue fl">第<!=index!>次测试</p><span class="fr c_grey"><!= time !></span>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
|
||||
<! if(status == -2){!>
|
||||
<div class="ProResultCon "><!= error_msg !></div>
|
||||
<!}else{!>
|
||||
<div class="ProResultTable " >
|
||||
<ul class="ProResultUl " >
|
||||
<! for(var i =0; i <results.length; ++i){ !>
|
||||
<li ><span class="w60 T_C">测试<!=i+1!></span>
|
||||
<! if(results[i]["status"]!=0){ !>
|
||||
<span class="w150 c_red">测试错误!</span>
|
||||
<span class="w60">您的输出:</span>
|
||||
<span class="W200"><!=results[i]["result"]!></span>
|
||||
<span class="w60">正确输出:</span>
|
||||
<span class="W200"><!=results[i]["output"]!></span>
|
||||
<div class="cl"></div>
|
||||
</li>
|
||||
<!}else{!>
|
||||
<span class="w150 c_green">测试正确!</span>
|
||||
<div class="cl"></div>
|
||||
</li>
|
||||
<!}!>
|
||||
<!}!>
|
||||
</ul>
|
||||
</div>
|
||||
<! } !>
|
||||
|
||||
</script>
|
||||
<!-- 模板1结束 -->
|
||||
|
||||
<div class="homepageRight">
|
||||
<div class="HomeWork">
|
||||
<div class="RightBanner">
|
||||
<div class="NewsBannerName">提交作品</div>
|
||||
</div>
|
||||
<div class="HomeWorkBox">
|
||||
<div class="">
|
||||
<div class="homepagePostTitle fl"><%= @homework.name %></div><span class="fr c_grey">截止时间:<%= @homework.end_time %></span>
|
||||
<div class="cl"></div>
|
||||
<a href="javascript:void(0);" class="c_blue"><%= @homework.user.show_name %></a>
|
||||
<p class="HomeWorkP"><%= @homework.description %> <br />
|
||||
输入 2 1 1 4 4 2 3 6 5 <br />
|
||||
输出 15<br />
|
||||
</p>
|
||||
</div>
|
||||
<p class="c_grey mt15">注:迟交扣<span class="c_red">2</span>分,缺评一个作品扣<span class="c_red">2</span>分</p>
|
||||
</div><!---HomeWorkBox end -->
|
||||
<div class="HomeWorkCon">
|
||||
<%= form_for(@student_work,
|
||||
:html => { :multipart => true },
|
||||
:url => {:controller => 'student_work',
|
||||
:action => 'create',
|
||||
:student_work_id => @student_work.id,
|
||||
:homework => @homework.id
|
||||
},
|
||||
:method => :post) do |f|%>
|
||||
|
||||
<div class="mt15">
|
||||
<span>请使用 <%= @homework.language_name %> 语言编写</span>
|
||||
</div>
|
||||
<div class="mt10">
|
||||
<%= f.text_area :name, id: 'program-title', class:"InputBox W700", placeholder:"请概括你的代码的功能" %>
|
||||
</div>
|
||||
<div class="mt10">
|
||||
<%= f.text_area :description, id: 'program-src', class:" W700 H150", placeholder:"请贴入你的代码", rows: 10 %>
|
||||
</div>
|
||||
<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 fr" id="commit-program-work-btn">提交代码</a>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div><!----HomeWorkCon end-->
|
||||
</div><!----HomeWork end-->
|
||||
<div class="ProResult mt10">
|
||||
<% @student_work.student_work_tests.each_with_index do |test, index| %>
|
||||
<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>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
<% if test.status.to_i == -2 %>
|
||||
<div class="ProResultCon "><%= test.results.first %></div>
|
||||
<% else %>
|
||||
<div class="ProResultTable " >
|
||||
<ul class="ProResultUl " >
|
||||
<% test.results.each_with_index do |x, i| %>
|
||||
<li ><span class="w60 T_C">测试<%=i+1%></span>
|
||||
<% if x["status"].to_i != 0 %>
|
||||
<span class="w150 c_red">测试错误!</span>
|
||||
<span class="w60">您的输出:</span>
|
||||
<span class="W200"><%=x["result"]%></span>
|
||||
<span class="w60">正确输出:</span>
|
||||
<span class="W200"><%=x["output"]%></span>
|
||||
<div class="cl"></div>
|
||||
</li>
|
||||
<% else %>
|
||||
<span class="w150 c_green">测试正确!</span>
|
||||
<div class="cl"></div>
|
||||
</li>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div><!----ProResult end-->
|
||||
</div><!--homepageRight end-->
|
|
@ -199,9 +199,12 @@ default:
|
|||
|
||||
repository_root_path: '/tmp/htdocs'
|
||||
|
||||
judge_server: 'http://judge.trustie.net/'
|
||||
|
||||
# specific configuration options for production environment
|
||||
# that overrides the default ones
|
||||
production:
|
||||
judge_server: 'http://192.168.80.21:8080/'
|
||||
repository_root_path: '/home/pdl/redmine-2.3.2-0/apache2/htdocs'
|
||||
cookie_domain: ".trustie.net"
|
||||
rmagick_font_path: /usr/share/fonts/ipa-mincho/ipam.ttf
|
||||
|
|
|
@ -120,6 +120,7 @@ RedmineApp::Application.routes.draw do
|
|||
get 'absence_penalty_list'
|
||||
get 'evaluation_list'
|
||||
post 'set_program_score'
|
||||
post 'program_test'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -310,8 +311,11 @@ RedmineApp::Application.routes.draw do
|
|||
collection do
|
||||
match "tag_saveEx" , :via => [:get, :post]
|
||||
post "user_new_homework"
|
||||
get 'new_user_commit_homework'
|
||||
post "user_commit_homework"
|
||||
post 'user_select_homework'
|
||||
end
|
||||
|
||||
member do
|
||||
match 'user_projects_index', :to => 'users#user_projects_index', :via => :get
|
||||
match 'user_projects', :to => 'users#user_projects', :via => :get
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
class ChangeStudentWorkTests < ActiveRecord::Migration
|
||||
|
||||
def change
|
||||
change_table :student_work_tests do |t|
|
||||
t.remove :error_msg
|
||||
t.remove :result
|
||||
t.remove :homework_test_id
|
||||
t.integer :status, default: 9
|
||||
t.text :results
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
class AddSrcToStudentWorkTests < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :student_work_tests, :src, :text
|
||||
end
|
||||
end
|
|
@ -99,13 +99,13 @@ function initFilters(){
|
|||
$('#filters-table td.field input[type=checkbox]').each(function(){
|
||||
toggleFilter($(this).val());
|
||||
});
|
||||
$('#filters-table td.field input[type=checkbox]').live('click',function(){
|
||||
$('#filters-table td.field input[type=checkbox]').on('click',function(){
|
||||
toggleFilter($(this).val());
|
||||
});
|
||||
$('#filters-table .toggle-multiselect').live('click',function(){
|
||||
$('#filters-table .toggle-multiselect').on('click',function(){
|
||||
toggleMultiSelect($(this).siblings('select'));
|
||||
});
|
||||
$('#filters-table input[type=text]').live('keypress', function(e){
|
||||
$('#filters-table input[type=text]').on('keypress', function(e){
|
||||
if (e.keyCode == 13) submit_query_form("query_form");
|
||||
});
|
||||
}
|
||||
|
|
|
@ -0,0 +1,216 @@
|
|||
/**
|
||||
* baiduTemplate简单好用的Javascript模板引擎 1.0.6 版本
|
||||
* http://baidufe.github.com/BaiduTemplate
|
||||
* 开源协议:BSD License
|
||||
* 浏览器环境占用命名空间 baidu.template ,nodejs环境直接安装 npm install baidutemplate
|
||||
* @param str{String} dom结点ID,或者模板string
|
||||
* @param data{Object} 需要渲染的json对象,可以为空。当data为{}时,仍然返回html。
|
||||
* @return 如果无data,直接返回编译后的函数;如果有data,返回html。
|
||||
* @author wangxiao
|
||||
* @email 1988wangxiao@gmail.com
|
||||
*/
|
||||
|
||||
;(function(window){
|
||||
|
||||
//取得浏览器环境的baidu命名空间,非浏览器环境符合commonjs规范exports出去
|
||||
//修正在nodejs环境下,采用baidu.template变量名
|
||||
var baidu = typeof module === 'undefined' ? (window.baidu = window.baidu || {}) : module.exports;
|
||||
|
||||
//模板函数(放置于baidu.template命名空间下)
|
||||
baidu.template = function(str, data){
|
||||
|
||||
//检查是否有该id的元素存在,如果有元素则获取元素的innerHTML/value,否则认为字符串为模板
|
||||
var fn = (function(){
|
||||
|
||||
//判断如果没有document,则为非浏览器环境
|
||||
if(!window.document){
|
||||
return bt._compile(str);
|
||||
};
|
||||
|
||||
//HTML5规定ID可以由任何不包含空格字符的字符串组成
|
||||
var element = document.getElementById(str);
|
||||
if (element) {
|
||||
|
||||
//取到对应id的dom,缓存其编译后的HTML模板函数
|
||||
if (bt.cache[str]) {
|
||||
return bt.cache[str];
|
||||
};
|
||||
|
||||
//textarea或input则取value,其它情况取innerHTML
|
||||
var html = /^(textarea|input)$/i.test(element.nodeName) ? element.value : element.innerHTML;
|
||||
return bt._compile(html);
|
||||
|
||||
}else{
|
||||
|
||||
//是模板字符串,则生成一个函数
|
||||
//如果直接传入字符串作为模板,则可能变化过多,因此不考虑缓存
|
||||
return bt._compile(str);
|
||||
};
|
||||
|
||||
})();
|
||||
|
||||
//有数据则返回HTML字符串,没有数据则返回函数 支持data={}的情况
|
||||
var result = bt._isObject(data) ? fn( data ) : fn;
|
||||
fn = null;
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
//取得命名空间 baidu.template
|
||||
var bt = baidu.template;
|
||||
|
||||
//标记当前版本
|
||||
bt.versions = bt.versions || [];
|
||||
bt.versions.push('1.0.6');
|
||||
|
||||
//缓存 将对应id模板生成的函数缓存下来。
|
||||
bt.cache = {};
|
||||
|
||||
//自定义分隔符,可以含有正则中的字符,可以是HTML注释开头 <! !>
|
||||
bt.LEFT_DELIMITER = bt.LEFT_DELIMITER||'<%';
|
||||
bt.RIGHT_DELIMITER = bt.RIGHT_DELIMITER||'%>';
|
||||
|
||||
//自定义默认是否转义,默认为默认自动转义
|
||||
bt.ESCAPE = true;
|
||||
|
||||
//HTML转义
|
||||
bt._encodeHTML = function (source) {
|
||||
return String(source)
|
||||
.replace(/&/g,'&')
|
||||
.replace(/</g,'<')
|
||||
.replace(/>/g,'>')
|
||||
.replace(/\\/g,'\')
|
||||
.replace(/"/g,'"')
|
||||
.replace(/'/g,''');
|
||||
};
|
||||
|
||||
//转义影响正则的字符
|
||||
bt._encodeReg = function (source) {
|
||||
return String(source).replace(/([.*+?^=!:${}()|[\]/\\])/g,'\\$1');
|
||||
};
|
||||
|
||||
//转义UI UI变量使用在HTML页面标签onclick等事件函数参数中
|
||||
bt._encodeEventHTML = function (source) {
|
||||
return String(source)
|
||||
.replace(/&/g,'&')
|
||||
.replace(/</g,'<')
|
||||
.replace(/>/g,'>')
|
||||
.replace(/"/g,'"')
|
||||
.replace(/'/g,''')
|
||||
.replace(/\\\\/g,'\\')
|
||||
.replace(/\\\//g,'\/')
|
||||
.replace(/\\n/g,'\n')
|
||||
.replace(/\\r/g,'\r');
|
||||
};
|
||||
|
||||
//将字符串拼接生成函数,即编译过程(compile)
|
||||
bt._compile = function(str){
|
||||
var funBody = "var _template_fun_array=[];\nvar fn=(function(__data__){\nvar _template_varName='';\nfor(name in __data__){\n_template_varName+=('var '+name+'=__data__[\"'+name+'\"];');\n};\neval(_template_varName);\n_template_fun_array.push('"+bt._analysisStr(str)+"');\n_template_varName=null;\n})(_template_object);\nfn = null;\nreturn _template_fun_array.join('');\n";
|
||||
return new Function("_template_object",funBody);
|
||||
};
|
||||
|
||||
//判断是否是Object类型
|
||||
bt._isObject = function (source) {
|
||||
return 'function' === typeof source || !!(source && 'object' === typeof source);
|
||||
};
|
||||
|
||||
//解析模板字符串
|
||||
bt._analysisStr = function(str){
|
||||
|
||||
//取得分隔符
|
||||
var _left_ = bt.LEFT_DELIMITER;
|
||||
var _right_ = bt.RIGHT_DELIMITER;
|
||||
|
||||
//对分隔符进行转义,支持正则中的元字符,可以是HTML注释 <! !>
|
||||
var _left = bt._encodeReg(_left_);
|
||||
var _right = bt._encodeReg(_right_);
|
||||
|
||||
str = String(str)
|
||||
|
||||
//去掉分隔符中js注释
|
||||
.replace(new RegExp("("+_left+"[^"+_right+"]*)//.*\n","g"), "$1")
|
||||
|
||||
//去掉注释内容 <%* 这里可以任意的注释 *%>
|
||||
//默认支持HTML注释,将HTML注释匹配掉的原因是用户有可能用 <! !>来做分割符
|
||||
.replace(new RegExp("<!--.*?-->", "g"),"")
|
||||
.replace(new RegExp(_left+"\\*.*?\\*"+_right, "g"),"")
|
||||
|
||||
//把所有换行去掉 \r回车符 \t制表符 \n换行符
|
||||
.replace(new RegExp("[\\r\\t\\n]","g"), "")
|
||||
|
||||
//用来处理非分隔符内部的内容中含有 斜杠 \ 单引号 ‘ ,处理办法为HTML转义
|
||||
.replace(new RegExp(_left+"(?:(?!"+_right+")[\\s\\S])*"+_right+"|((?:(?!"+_left+")[\\s\\S])+)","g"),function (item, $1) {
|
||||
var str = '';
|
||||
if($1){
|
||||
|
||||
//将 斜杠 单引 HTML转义
|
||||
str = $1.replace(/\\/g,"\").replace(/'/g,''');
|
||||
while(/<[^<]*?'[^<]*?>/g.test(str)){
|
||||
|
||||
//将标签内的单引号转义为\r 结合最后一步,替换为\'
|
||||
str = str.replace(/(<[^<]*?)'([^<]*?>)/g,'$1\r$2')
|
||||
};
|
||||
}else{
|
||||
str = item;
|
||||
}
|
||||
return str ;
|
||||
});
|
||||
|
||||
|
||||
str = str
|
||||
//定义变量,如果没有分号,需要容错 <%var val='test'%>
|
||||
.replace(new RegExp("("+_left+"[\\s]*?var[\\s]*?.*?[\\s]*?[^;])[\\s]*?"+_right,"g"),"$1;"+_right_)
|
||||
|
||||
//对变量后面的分号做容错(包括转义模式 如<%:h=value%>) <%=value;%> 排除掉函数的情况 <%fun1();%> 排除定义变量情况 <%var val='test';%>
|
||||
.replace(new RegExp("("+_left+":?[hvu]?[\\s]*?=[\\s]*?[^;|"+_right+"]*?);[\\s]*?"+_right,"g"),"$1"+_right_)
|
||||
|
||||
//按照 <% 分割为一个个数组,再用 \t 和在一起,相当于将 <% 替换为 \t
|
||||
//将模板按照<%分为一段一段的,再在每段的结尾加入 \t,即用 \t 将每个模板片段前面分隔开
|
||||
.split(_left_).join("\t");
|
||||
|
||||
//支持用户配置默认是否自动转义
|
||||
if(bt.ESCAPE){
|
||||
str = str
|
||||
|
||||
//找到 \t=任意一个字符%> 替换为 ‘,任意字符,'
|
||||
//即替换简单变量 \t=data%> 替换为 ',data,'
|
||||
//默认HTML转义 也支持HTML转义写法<%:h=value%>
|
||||
.replace(new RegExp("\\t=(.*?)"+_right,"g"),"',typeof($1) === 'undefined'?'':baidu.template._encodeHTML($1),'");
|
||||
}else{
|
||||
str = str
|
||||
|
||||
//默认不转义HTML转义
|
||||
.replace(new RegExp("\\t=(.*?)"+_right,"g"),"',typeof($1) === 'undefined'?'':$1,'");
|
||||
};
|
||||
|
||||
str = str
|
||||
|
||||
//支持HTML转义写法<%:h=value%>
|
||||
.replace(new RegExp("\\t:h=(.*?)"+_right,"g"),"',typeof($1) === 'undefined'?'':baidu.template._encodeHTML($1),'")
|
||||
|
||||
//支持不转义写法 <%:=value%>和<%-value%>
|
||||
.replace(new RegExp("\\t(?::=|-)(.*?)"+_right,"g"),"',typeof($1)==='undefined'?'':$1,'")
|
||||
|
||||
//支持url转义 <%:u=value%>
|
||||
.replace(new RegExp("\\t:u=(.*?)"+_right,"g"),"',typeof($1)==='undefined'?'':encodeURIComponent($1),'")
|
||||
|
||||
//支持UI 变量使用在HTML页面标签onclick等事件函数参数中 <%:v=value%>
|
||||
.replace(new RegExp("\\t:v=(.*?)"+_right,"g"),"',typeof($1)==='undefined'?'':baidu.template._encodeEventHTML($1),'")
|
||||
|
||||
//将字符串按照 \t 分成为数组,在用'); 将其合并,即替换掉结尾的 \t 为 ');
|
||||
//在if,for等语句前面加上 '); ,形成 ');if ');for 的形式
|
||||
.split("\t").join("');")
|
||||
|
||||
//将 %> 替换为_template_fun_array.push('
|
||||
//即去掉结尾符,生成函数中的push方法
|
||||
//如:if(list.length=5){%><h2>',list[4],'</h2>');}
|
||||
//会被替换为 if(list.length=5){_template_fun_array.push('<h2>',list[4],'</h2>');}
|
||||
.split(_right_).join("_template_fun_array.push('")
|
||||
|
||||
//将 \r 替换为 \
|
||||
.split("\r").join("\\'");
|
||||
|
||||
return str;
|
||||
};
|
||||
|
||||
})(window);
|
|
@ -0,0 +1,133 @@
|
|||
$(function(){
|
||||
//提交作业
|
||||
|
||||
var bt=baidu.template;
|
||||
bt.LEFT_DELIMITER='<!';
|
||||
bt.RIGHT_DELIMITER='!>';
|
||||
|
||||
var tested = false;
|
||||
var valid_form = function() {
|
||||
var src = $('#program-src').val();
|
||||
var title = $('#program-title').val();
|
||||
|
||||
if (!src) {
|
||||
alert('请输入正确的代码');
|
||||
return false;
|
||||
}
|
||||
if (!title) {
|
||||
alert('请输入标题');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
var test_program = function(cb){
|
||||
var homework_id = $('#test-program-btn').attr('data-homework-id');
|
||||
var student_work_id = $('#test-program-btn').attr('data-student-work-id');
|
||||
var src = $('#program-src').val();
|
||||
var title = $('#program-title').val();
|
||||
|
||||
if(!valid_form()){
|
||||
return;
|
||||
}
|
||||
|
||||
$.post(
|
||||
'/student_work/program_test',
|
||||
{homework: homework_id, student_work_id: student_work_id, src: src, title: title},
|
||||
function(data,status){
|
||||
tested = true;
|
||||
console.log(data);
|
||||
|
||||
if (typeof cb == 'function') {cb(); return;}
|
||||
|
||||
|
||||
var html=bt('t:result-list',data);
|
||||
$('.ProResult').prepend(html);
|
||||
|
||||
if (data.status==0) {
|
||||
var r=confirm("答题正确,是否立刻提交?");
|
||||
if (r) {
|
||||
$(".HomeWorkCon form").submit();
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
$('#test-program-btn').on('click', test_program);
|
||||
|
||||
|
||||
$('#commit-program-work-btn').on('click', function(){
|
||||
if(!valid_form()){
|
||||
return;
|
||||
}
|
||||
if($('.ProResult .ProResultTop').length<=0){
|
||||
var r=confirm("测试后才能提交,是否立刻测试?");
|
||||
if (r) {
|
||||
test_program();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!tested) {
|
||||
test_program(function(){
|
||||
$(".HomeWorkCon form").submit();
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
$(".HomeWorkCon form").submit();
|
||||
});
|
||||
|
||||
$('form.edit_student_work').on('keydown', '#program-src', function(){
|
||||
tested = false;
|
||||
});
|
||||
|
||||
|
||||
//发布作业
|
||||
var isProgramHomework = function(){
|
||||
return !$(".advanced_option").is(":hidden");
|
||||
}
|
||||
|
||||
var submit_comm_homework = function(id){
|
||||
var valid = true;
|
||||
if (isProgramHomework()) {
|
||||
$.each($('.advanced_option textarea.InputBox'), function(i, val){
|
||||
if ($(val).val().length<=0) {
|
||||
$(val).focus();
|
||||
valid = false;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
if (valid) {
|
||||
$('input[name=homework_type]').val(2);
|
||||
};
|
||||
}
|
||||
if (valid) {
|
||||
submit_homework(id);
|
||||
}
|
||||
}
|
||||
window.submit_comm_homework = submit_comm_homework;
|
||||
|
||||
var datepickerOptions={dateFormat:'yy-mm-dd',firstDay:0,showWeek:true,showOtherMonths:true,selectOtherMonths:true};
|
||||
|
||||
$('input.date-input').datepicker(datepickerOptions);
|
||||
|
||||
$('a.pic_date').on('click', function(){
|
||||
$(this).parent().prev().first().focus();
|
||||
})
|
||||
|
||||
|
||||
$('a.DropBtn').on('click', function(){
|
||||
$(".advanced_option").toggle();
|
||||
});
|
||||
|
||||
$(".HomeWork").on('click', 'a.icon_add', function(){
|
||||
var html = bt('t:test-answer-list', null);
|
||||
$(this).parent('.mt10').after(html);
|
||||
|
||||
});
|
||||
$(".HomeWork").on('click', 'a.icon_remove', function(){
|
||||
$(this).parent('.mt10').remove();
|
||||
});
|
||||
});
|
|
@ -131,13 +131,13 @@
|
|||
});
|
||||
//鼠标经过列表项事件
|
||||
//鼠标经过
|
||||
$(".mailHover").live("mouseover", function(){
|
||||
$(".mailHover").on("mouseover", function(){
|
||||
index = Number($(this).attr("id").split("_")[1]);
|
||||
liveValue = $("#mailList_"+index).text();
|
||||
x.children("." + cf).removeClass(cf).addClass(cl);
|
||||
$(this).addClass(cf).removeClass(cl);
|
||||
});
|
||||
$(".mailHover").live("click", function(){
|
||||
$(".mailHover").on("click", function(){
|
||||
$("#mail").val($(this).html());
|
||||
});
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -4,10 +4,10 @@ $(function(){
|
|||
$("#users_setting").css("min-height",$("#LSide").height()-100);
|
||||
|
||||
//头像相关
|
||||
$("#homepage_portrait_image").live("mouseover",function(){
|
||||
$("#homepage_portrait_image").on("mouseover",function(){
|
||||
$("#edit_user_file_btn").show();
|
||||
$("#watch_user_btn").show();
|
||||
}).live("mouseout",function(){
|
||||
}).on("mouseout",function(){
|
||||
$("#edit_user_file_btn").hide();
|
||||
$("#watch_user_btn").hide();
|
||||
});
|
||||
|
|
|
@ -453,7 +453,7 @@ $(function(){
|
|||
cookiesave(personalized_expand_key,JSON.stringify(personalized_map));
|
||||
target.toggle(timeout);
|
||||
}
|
||||
$("*[nhtype='toggle4cookie']").live('click',function(){
|
||||
$("*[nhtype='toggle4cookie']").on('click',function(){
|
||||
personalized_click($(this),500);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//个人动态
|
||||
$(function(){
|
||||
KindEditor.ready(function(K){
|
||||
$("a[nhname='reply_btn']").live('click',function(){
|
||||
$("a[nhname='reply_btn']").on('click',function(){
|
||||
var params = {};
|
||||
params.kindutil = K;
|
||||
params.container = $(this).parent().parent('div');
|
||||
|
@ -35,7 +35,7 @@ $(function(){
|
|||
},300);
|
||||
});
|
||||
|
||||
$("a[nhname='sub_reply_btn']").live('click',function(){
|
||||
$("a[nhname='sub_reply_btn']").on('click',function(){
|
||||
var params = {};
|
||||
params.kindutil = K;
|
||||
params.container = $(this).parent().parent('div');
|
||||
|
|
|
@ -719,3 +719,51 @@ a:hover.about_me{ color:#0781b4;}
|
|||
|
||||
|
||||
|
||||
/*20150820课程作业 LB*/
|
||||
.HomeWork {width:708px; background-color:#ffffff; padding:10px 20px 20px 20px; border:1px solid #dddddd;}
|
||||
.RightBanner {width:708px; height:34px; border-bottom:1px solid #e9e9e9;}
|
||||
select.InputBox,input.InputBox,textarea.InputBox{ border:1px solid #d9d9d9; color:#888888; height:28px; line-height:28px; padding-left:5px; font-size:14px;}
|
||||
a.BlueCirBtn{ display:block;width:75px; height:28px; background-color:#ffffff; line-height:28px; vertical-align:middle; text-align:center; border:1px solid #15bccf; color:#15bccf; -moz-border-radius:5px; -webkit-border-radius:5px; border-radius:5px;}
|
||||
a:hover.BlueCirBtn{ background:#15bccf; color:#fff;}
|
||||
.W440{ width:440px;}
|
||||
.W120{ width:110px;}
|
||||
.W700{ width:700px;max-width: 700px;min-width: 700px;}
|
||||
.w708{width: 708px;}
|
||||
a.AnnexBtn{ background: url(../images/homepage_icon2.png) 0px -343px no-repeat; width:70px; height:20px; display:block; padding-left:20px; color:#888888;}
|
||||
a:hover.AnnexBtn{background: url(../images/homepage_icon2.png) -90px -343px no-repeat; color:#15bccf;}
|
||||
a.FilesBtn{ background: url(../images/homepage_icon2.png) 0px -373px no-repeat; width:70px; height:20px; display:block; padding-left:20px; color:#888888;}
|
||||
a:hover.FilesBtn{background: url(../images/homepage_icon2.png) -89px -372px no-repeat; color:#15bccf;}
|
||||
a.BlueCirBtnMini{ display:block;width:40px; height:22px; background-color:#ffffff; line-height:24px; vertical-align:middle; text-align:center; border:1px solid #15bccf; color:#15bccf; -moz-border-radius:5px; -webkit-border-radius:5px; border-radius:5px;}
|
||||
a:hover.BlueCirBtnMini{ background:#15bccf; color:#fff;}
|
||||
a.DropBtn{background: url(../images/homepage_icon2.png) -125px -339px no-repeat; width:85px; height:20px; display:block; color:#888888; font-size:14px;}
|
||||
a:hover.DropBtn{background: url(../images/homepage_icon2.png) -125px -370px no-repeat;}
|
||||
.DropLine{border-top:1px solid #d9d9d9; float:left; width:623px; height:10px; margin-top:10px;}
|
||||
/*20150820编程作业 LB*/
|
||||
.W320{ width:320px;}
|
||||
.icon_add{ background:url(images/icons.png) 0px -310px no-repeat; width:16px; height:27px; display:block;float:left; margin-right:5px;}
|
||||
a:hover.icon_add{background:url(images/icons.png) -20px -310px no-repeat;}
|
||||
.icon_remove{background:url(images/icons.png) 0px -338px no-repeat; width:16px; height:27px; display:block;float:left;}
|
||||
a:hover.icon_remove{background:url(images/icons.png) -20px -338px no-repeat;}
|
||||
/*20150820提交作业 LB*/
|
||||
.HomeWorkBox{ background:#f6f6f6; padding:10px; margin:10px 0;}
|
||||
.c_grey{ color:#888888;}
|
||||
.c_dark_grey{color:#a9a9a9 !important;}
|
||||
.HomeWorkP{ width:690px; font-size:14px;}
|
||||
.H150{ height:150px;}
|
||||
.ProResult{width:748px; background-color:#fff; border:1px solid #dddddd;border-bottom:none; }
|
||||
.ProResultTop{ height:38px; line-height:38px; border-bottom:1px solid #dddddd; background:#f2f2f2; padding:0 10px;}
|
||||
.ProResultCon{ padding:10px; color:#888888; line-height:24px; border-bottom:1px solid #dddddd; }
|
||||
.W50{ width:50px;}
|
||||
.W200{ width:200px;}
|
||||
.ProResultTable{ color:#888888;}
|
||||
.T_C{ text-align:center;}
|
||||
.SearchIcon{background:url(../images/homepage_icon2.png) 676px -393px no-repeat; }
|
||||
.SearchIcon:hover{background:url(../images/homepage_icon2.png) 676px -419px no-repeat; }
|
||||
a.link_file{ background:url(../images/pic_file.png) 0 2px no-repeat; padding-left:20px; }
|
||||
a:hover.link_file{ background:url(../images/pic_file.png) 0 -25px no-repeat; color:#3ca5c6;}
|
||||
a.remove-upload {background: url(../images/delete.png) no-repeat 1px 50%;width: 1px;display: inline-block;padding-left: 16px;}
|
||||
a.FilesName{ max-width:540px;overflow:hidden; white-space:nowrap; text-overflow:ellipsis; display:block;}
|
||||
a.FilesName02{ max-width:665px;overflow:hidden; white-space:nowrap; text-overflow:ellipsis; display:block;}
|
||||
.ProResultUl span { display:block; float:left;}
|
||||
.ProResultUl li{ line-height:35px; border-bottom:1px solid #dddddd; }
|
||||
.DateBorder{border:1px solid #d9d9d9; border-left:none; padding:7px 6px 6px 6px;}
|
|
@ -952,13 +952,3 @@ blockquote {
|
|||
background-size: 100% 100%;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue