Merge branch 'dev_aliyun' of http://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

dev_forum
cxt 5 years ago
commit b131048309

@ -150,9 +150,8 @@ class ChallengesController < ApplicationController
def index
uid_logger("identifier: #{params}")
# 通过调试发现 这里includes(:games)性能会慢10倍
current_myshixun = @shixun.current_myshixun(current_user.id)
@challenges = @shixun.challenges.includes(:games).where("games.user_id" => (current_myshixun ? current_user.id : nil))
@challenges = Challenge.fields_for_list.where(shixun_id: @shixun.id)
@editable = @shixun.status == 0 # before_action有判断权限如果没发布则肯定是管理人员
@user = current_user

@ -1334,7 +1334,6 @@ class ExercisesController < ApplicationController
#导出空白试卷
def export_exercise
@exercise_questions = @exercise.exercise_questions.includes(:exercise_choices).order("question_number ASC")
@request_url = request.base_url
filename = "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.current.strftime('%Y%m%d%H%M%S')}.pdf"
stylesheets = "#{Rails.root}/app/templates/exercise_export/exercise_export.css"
render pdf: 'exercise_export/blank_exercise', filename: filename, stylesheets: stylesheets

@ -128,7 +128,7 @@ class MessagesController < ApplicationController
def destroy
begin
return normal_status(403, "您没有权限进行该操作") unless @message.author == current_user || current_user.teacher_of_course?(@message.board.course)
return normal_status(403, "您没有权限进行该操作") if current_user.course_identity(@message.board.course) >= 5 || @message.author != current_user
@message.destroy!
rescue Exception => e
uid_logger_error(e.message)

@ -179,6 +179,16 @@ class ShixunsController < ApplicationController
ShixunTagRepertoire.create!(:tag_repertoire_id => str.tag_repertoire_id, :shixun_id => @new_shixun.id)
end
# 同步配置
@shixun.shixun_service_configs.each do |config|
ShixunServiceConfig.create!(:shixun_id => @new_shixun.id,
:cpu_limit => config.cpu_limit,
:lower_cpu_limit => config.lower_cpu_limit,
:memory_limit => config.memory_limit,
:request_limit => config.request_limit,
:mirror_repository_id => config.mirror_repository_id)
end
# fork版本库
logger.info("###########fork_repo_path: ######{@repo_path}")
project_fork(@new_shixun, @repo_path, current_user.login)
@ -367,11 +377,6 @@ class ShixunsController < ApplicationController
end
def update
h = {test_set_permission: params[:test_set_permission], code_hidden: params[:code_hidden],
task_pass: params[:task_pass], hide_code: params[:hide_code], forbid_copy: params[:forbid_copy]}
s_params = shixun_params.merge(h)
ActiveRecord::Base.transaction do
begin
@shixun.shixun_mirror_repositories.destroy_all
@ -384,8 +389,8 @@ class ShixunsController < ApplicationController
end
end
@shixun.update_attributes(s_params)
@shixun.shixun_info.update_attributes(description: params[:description], evaluate_script: params[:evaluate_script])
@shixun.update_attributes(shixun_params)
@shixun.shixun_info.update_attributes(shixun_info_params)
@shixun.shixun_schools.delete_all
if params[:scope_partment].present? && params[:user_scope].to_i == 1
arr = []
@ -402,13 +407,8 @@ class ShixunsController < ApplicationController
# 超级管理员和运营人员才能保存 中间层服务器pod信息的配置
if current_user.admin? || current_user.business?
@shixun.shixun_service_configs.destroy_all
params[:mirror_id].each_with_index do |mirror_id, index|
ShixunServiceConfig.create!(:shixun_id => @shixun.id,
:cpu_limit => params[:cpu_limit][index],
:lower_cpu_limit => params[:lower_cpu_limit][index],
:memory_limit => params[:memory_limit][index],
:request_limit => params[:request_limit][index],
:mirror_repository_id => mirror_id)
params[:shixun_service_configs].each do |config|
@shixun.shixun_service_configs.create!(config)
end
end
rescue Exception => e
@ -446,6 +446,7 @@ class ShixunsController < ApplicationController
@choice_small_type = @shixun.small_mirror_id
@main_type = shixun_main_type
@small_type = shixun_small_type
@configs = @shixun.shixun_service_configs
#@mirror_script = MirrorScript.select([:id, :script_type]).find(@shixun.mirror_script_id).attributes if @shixun.mirror_script_id && @shixun.mirror_script_id != 0
# @shixun_main_mirror = @shixun.show_shixun_mirror
# @script_type = @shixun.script_tag.try(:script_type) || "无"
@ -734,7 +735,13 @@ private
def shixun_params
raise("实训名称不能为空") if params[:name].blank?
params.require(:shixun).permit(:name, :trainee, :webssh, :can_copy, :use_scope, :vnc, :test_set_permission,
:task_pass, :repo_name, :multi_webssh, :opening_time, :mirror_script_id)
:task_pass, :repo_name, :multi_webssh, :opening_time, :mirror_script_id, :code_hidden,
:hide_code, :forbid_copy)
end
def shixun_info_params
raise("实训描述不能为空") if params[:description].blank?
raise("评测脚本不能为空") if params[:evaluate_script].blank?
params.require(:shixun_info).permit(:description, :evaluate_script)
end
def find_shixun

@ -17,7 +17,7 @@ class ZipsController < ApplicationController
end
def export_exercises
exercises = ExportExercisesService.new(@exercise,@ex_users,@request_url)
exercises = ExportExercisesService.new(@exercise,@ex_users)
file_name = filename_for_content_disposition(exercises.filename)
send_file exercises.ex_zip, filename: file_name, type: 'application/zip'
@ -41,7 +41,6 @@ class ZipsController < ApplicationController
ActiveRecord::Base.transaction do
begin
@exercise = Exercise.includes(:exercise_users,:exercise_questions).find_by(id:params[:exercise_id])
@request_url = request.base_url
group_id = params[:exercise_group_id]
if @exercise.blank?
normal_status(-1,"试卷不存在")

@ -334,9 +334,11 @@ module ApplicationHelper
raw arr.join('')
end
# 导出pdf时转化markdown为html
def to_markdown(text)
Rails.logger.info("#########################text______________tedxt_________________###{text}")
return nil if text.blank?
request_url = "http://47.96.87.25:48080"
options = {
:autolink => true,
:no_intra_emphasis => true,
@ -347,10 +349,9 @@ module ApplicationHelper
:tables => true
}
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,options)
ss = markdown.render(text)
Rails.logger.info("#########################text______________markdown.render(text)________________###{ss}")
ss
m_t = markdown.render(text)
m_t&.include?("src=\"") ? m_t&.gsub("src=\"","src=\"#{request_url}") : m_t
Rails.logger.info("###########__________request_url_________###################{request_url}")
end
end

@ -1,5 +1,7 @@
class Shixun < ApplicationRecord
# status: 0编辑 1申请发布 2正式发布 3关闭 -1软删除
# hide_code 隐藏代码窗口
# code_hidden: 隐藏代码目录
has_many :challenges, dependent: :destroy
has_many :myshixuns, :dependent => :destroy
has_many :shixun_members, dependent: :destroy

@ -5,10 +5,9 @@ class ExerciseUserPdfService
attr_reader :exercise, :ex_user
def initialize(exercise, ex_user,request_url)
def initialize(exercise, ex_user)
@exercise = exercise
@ex_user = ex_user
@request_url = request_url
@ex_user_user = @ex_user.user
@course = @exercise.course
end

@ -3,10 +3,9 @@ class ExportExercisesService
include StudentWorksHelper
attr_reader :exercise, :ex_users
def initialize(exercise, ex_users,request_url)
def initialize(exercise, ex_users)
@exercise = exercise
@ex_users = ex_users
@request_url = request_url
end
def filename
@ -19,7 +18,7 @@ class ExportExercisesService
pdfs = []
Zip::File.open(zip_file.path, Zip::File::CREATE) do |zip|
ex_users.each do |ex_user|
export = ExerciseUserPdfService.new(exercise, ex_user,@request_url)
export = ExerciseUserPdfService.new(exercise, ex_user)
pdf = export.ex_pdf
pdfs << pdf
begin

@ -44,7 +44,6 @@
<span class="mr15">实训题<span class="mlr5"><%= @exercise_ques_shixun_count %></span>题,
共<span class="mlr5"><%= @exercise_ques_shixun_scores %></span>分</span>
<% end %>
<% if @exercise_ques_count > 0 %>
<span class="pull-right">
共<span class="text-orange mlr5"><%= @exercise_ques_scores %></span>分
@ -59,7 +58,7 @@
<div class="mbt10">
<% @exercise_questions.each do |q| %>
<div class="bdc">
<div class="pbt10">
<div class="pbt5">
<div class="pbt5">
<span class="mr5 text-blue"><%= q.question_number %>、</span>
<span class="text-blue">
@ -68,43 +67,39 @@
<span class="text-gray mlr5">(<%= q&.question_score %>分)</span>
</div>
<div class="pbt5">
<% q_markdown = to_markdown(q.question_title) %>
<% q_title = q_markdown&.include?("src=\"") ? q_markdown&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q_markdown %>
<% if q.question_type == 5 %>
<% q_markdown_name = to_markdown(q.shixun_name) %>
<% q_name = q_markdown_name&.include?("src=\"") ? q_markdown_name&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q_markdown_name %>
<span class="ques-title" id="ques_marked_<%= index %>"><%= q_name %></span>
<span class="ques-title" ><%= to_markdown(q.shixun_name) %></span>
<div class="mt8 text-gray">
<span id="ques_title_<%= index %>"><%= q_markdown %></span>
<span><%= to_markdown(q.question_title) %></span>
</div>
<% else %>
<span class="ques-title" id="ques_title_<%= index %>"><%= q_markdown %></span>
<span class="ques-title"><%= to_markdown(q.question_title) %></span>
<% end %>
</div>
<div class="pbt5">
<% if q.question_type == 0 %>
<% q.exercise_choices.each_with_index do |s,index| %>
<p class="pbt5">
<span class="choose-radio"></span>
<span class="mr15"><%= convert_to_char((index+1).to_s)%></span><%= s.choice_text%>
</p>
<% q.exercise_choices.each do |s| %>
<div class="pbt5 clearfix main-choice">
<span class="choose-radio pull-left mt8"></span>
<span class="inline-block pull-left choice-text ml10"><%= to_markdown(s.choice_text) %></span>
</div>
<% end %>
<% elsif q.question_type == 1 %>
<% q.exercise_choices.each_with_index do |s,index| %>
<p class="pbt5">
<span class="choose-checkbox"></span>
<span class="mr20"><%= convert_to_char((index+1).to_s)%></span><%= s.choice_text%>
</p>
<% q.exercise_choices.each do |s| %>
<div class="pbt5 clearfix main-choice">
<span class="choose-checkbox pull-left mt8"></span>
<span class="inline-block pull-left choice-text ml10"><%= to_markdown(s.choice_text) %></span>
</div>
<% end %>
<% elsif q.question_type == 2 %>
<p class="pbt5">
<% q.exercise_choices.each_with_index do |s,index| %>
<span class="mr15">
<span class="choose-radio"></span>
<span class="mlr5"><%= s.choice_text %></span>
<div class="pbt5 clearfix">
<% q.exercise_choices.each do |s| %>
<span class="mr15 clearfix">
<span class="choose-radio "></span>
<span class="mlr5 inline-block"><%= s.choice_text %></span>
</span>
<% end %>
</p>
</div>
<% elsif q.question_type == 3 %>
<% st_counts = q.exercise_standard_answers.pluck(:exercise_choice_id).uniq %>
<% st_counts.each_with_index do |s,index| %>

@ -44,6 +44,9 @@ p{
.mbt10{
margin: 10px 0;
}
.mt5{
margin-top:5px;
}
.pull-right{
float:right;
}
@ -82,9 +85,15 @@ p{
.ml20{
margin-left:20px;
}
.ml10{
margin-left:10px;
}
.mr3{
margin-right:3px;
}
.mr8{
margin-right:8px;
}
.mr15{
margin-right:15px;
}
@ -248,7 +257,7 @@ table{
text-align:center;
}
table, tr, td, th, tbody, thead, tfoot,textarea{
table, tr, td, th, tbody, thead, tfoot,textarea,.main-choice{
page-break-inside: avoid;
}
table th{
@ -310,5 +319,10 @@ textarea{
zoom:1;
}
.choice-text p{
margin-bottom:0;
}

@ -121,7 +121,7 @@
<div class="pbt10">
<div class="position-relative">
<div class="pbt5">
<span class="mr5 text-blue"><%= q.question_number %>、&nbsp;</span>
<span class="mr5 text-blue"><%= q.question_number %>、&nbsp;</span><%= request.base_url %>
<span class="text-blue">
<%= q.question_type_name %>
</span>
@ -167,41 +167,39 @@
<% end %>
</div>
<div class="pbt5">
<% q_title = q.question_title&.html_safe %>
<% if q_type == 5 %>
<% q_name = q.shixun_name&.html_safe %>
<span class="ques-title"><%= q_name&.include?("src=\"") ? q_name&.gsub("src=\"","src=\"#{@request_url}") : q_name %></span>
<% if q.question_type == 5 %>
<span class="ques-title" ><%= to_markdown(q.shixun_name) %></span>
<div class="mt8 text-gray">
<span><%= q_title&.include?("src=\"") ? q_title&.gsub("src=\"","src=\"#{@request_url}") : q_title %></span>
<span><%= to_markdown(q.question_title) %></span>
</div>
<% else %>
<span class="ques-title"><%= q_title&.include?("src=\"") ? q_title&.gsub("src=\"","src=\"#{@request_url}") : q_title %></span>
<span class="ques-title"><%= to_markdown(q.question_title) %></span>
<% end %>
</div>
</div>
<div class="pbt5">
<% if q_type == 0 %>
<% q.exercise_choices.each_with_index do |s,index| %>
<% q.exercise_choices.each do |s| %>
<% check_answer = (user_answer.present? && (s.id == user_answer.first.exercise_choice_id)) ? "choose-answer" : '' %>
<p class="pbt5">
<span class="choose-radio <%= check_answer %>"></span>
<span class="mr15"><%= convert_to_char((index+1).to_s)%></span><%= s.choice_text%>
</p>
<div class="pbt5 clearfix main-choice">
<span class="choose-radio <%= check_answer %> pull-left mt8"></span>
<span class="inline-block pull-left ml10 choice-text"><%= to_markdown(s.choice_text) %></span>
</div>
<% end %>
<% elsif q_type == 1 %>
<% q.exercise_choices.each_with_index do |s,index| %>
<% q.exercise_choices.each do |s| %>
<% check_answer = (user_answer.present? && (user_answer.pluck(:exercise_choice_id).include?(s.id))) ? true : false %>
<p class="pbt5">
<div class="pbt5 clearfix main-choice">
<% if check_answer %>
<span class="choose-checkbox choose-answer-multi" ></span>
<span class="choose-checkbox choose-answer-multi mt8" ></span>
<% else %>
<span class="choose-checkbox"></span>
<span class="choose-checkbox pull-left mt8"></span>
<% end %>
<span class="mr15"><%= convert_to_char((index+1).to_s)%></span><%= s.choice_text%>
</p>
<span class="inline-block pull-left choice-text ml10"><%= to_markdown(s.choice_text) %></span>
</div>
<% end %>
<% elsif q_type == 2 %>
<p class="pbt5">
<div class="pbt5 clearfix">
<% q.exercise_choices.each do |s| %>
<% if user_answer.present? && (s.id == user_answer.first.exercise_choice_id) %>
<% check_answer = 'choose-answer' %>
@ -213,7 +211,7 @@
<span class="mlr5"><%= s.choice_text %></span>
</span>
<% end %>
</p>
</div>
<% elsif q_type == 3 %>
<% st_counts = q.exercise_standard_answers.pluck(:exercise_choice_id).uniq %>
<% st_counts.each_with_index do |s,index| %>
@ -224,13 +222,13 @@
<% end %>
<p class="pbt10 flex-nowrap">
<span class="pull-left line-34">答案(填空<%= index+1 %></span>
<span class="null-answer"><%= check_answer&.html_safe %></span>
<span class="null-answer"><%= to_markdown(check_answer) %></span>
</p>
<% end %>
<% elsif q_type == 4 %>
<% check_answer = (user_answer.present? ? user_answer.first.answer_text : '--') %>
<p class="flex-nowrap">
<span class="null-answer main-height"><%= check_answer&.html_safe %></span>
<span class="null-answer main-height"><%= to_markdown(check_answer) %></span>
</p>
<% else %>
<div class="mbt10">

@ -1,6 +1,6 @@
# 导航栏公共数据
json.partial! "challenges/top_common_data", shixun_identifier: @shixun.identifier
json.(@challenge, :id, :subject, :task_pass, :difficulty, :score)
json.(@challenge, :id, :subject, :task_pass, :difficulty, :score, :exec_time)
json.tags @challenge.challenge_tags.map(&:name)

@ -22,13 +22,21 @@ json.shixun do
json.hide_code @shixun.hide_code # 隐藏代码窗口
json.code_hidden @shixun.code_hidden # 代码目录隐藏
json.vnc @shixun.vnc
json.exec_time @shixun.exec_time
#json.exec_time @shixun.exec_time
json.webssh @shixun.webssh
json.multi_webssh @shixun.multi_webssh
json.use_scope @shixun.use_scope
json.scope_partment @shixun.schools.map(&:name) # 公开范围
json.opening_time @shixun.opening_time
json.forbid_copy @shixun.forbid_copy
# 实训服务配置
json.shixun_service_configs do
json.array! @configs do |config|
json.name config.mirror_repository&.name
json.(config, :cpu_limit, :lower_cpu_limit, :memory_limit, :request_limit, :mirror_repository_id)
end
end
end

Loading…
Cancel
Save