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

@ -1334,7 +1334,6 @@ class ExercisesController < ApplicationController
#导出空白试卷 #导出空白试卷
def export_exercise def export_exercise
@exercise_questions = @exercise.exercise_questions.includes(:exercise_choices).order("question_number ASC") @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" 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" stylesheets = "#{Rails.root}/app/templates/exercise_export/exercise_export.css"
render pdf: 'exercise_export/blank_exercise', filename: filename, stylesheets: stylesheets render pdf: 'exercise_export/blank_exercise', filename: filename, stylesheets: stylesheets

@ -128,7 +128,7 @@ class MessagesController < ApplicationController
def destroy def destroy
begin 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! @message.destroy!
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) 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) ShixunTagRepertoire.create!(:tag_repertoire_id => str.tag_repertoire_id, :shixun_id => @new_shixun.id)
end 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版本库 # fork版本库
logger.info("###########fork_repo_path: ######{@repo_path}") logger.info("###########fork_repo_path: ######{@repo_path}")
project_fork(@new_shixun, @repo_path, current_user.login) project_fork(@new_shixun, @repo_path, current_user.login)
@ -367,11 +377,6 @@ class ShixunsController < ApplicationController
end end
def update 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 ActiveRecord::Base.transaction do
begin begin
@shixun.shixun_mirror_repositories.destroy_all @shixun.shixun_mirror_repositories.destroy_all
@ -384,8 +389,8 @@ class ShixunsController < ApplicationController
end end
end end
@shixun.update_attributes(s_params) @shixun.update_attributes(shixun_params)
@shixun.shixun_info.update_attributes(description: params[:description], evaluate_script: params[:evaluate_script]) @shixun.shixun_info.update_attributes(shixun_info_params)
@shixun.shixun_schools.delete_all @shixun.shixun_schools.delete_all
if params[:scope_partment].present? && params[:user_scope].to_i == 1 if params[:scope_partment].present? && params[:user_scope].to_i == 1
arr = [] arr = []
@ -402,13 +407,8 @@ class ShixunsController < ApplicationController
# 超级管理员和运营人员才能保存 中间层服务器pod信息的配置 # 超级管理员和运营人员才能保存 中间层服务器pod信息的配置
if current_user.admin? || current_user.business? if current_user.admin? || current_user.business?
@shixun.shixun_service_configs.destroy_all @shixun.shixun_service_configs.destroy_all
params[:mirror_id].each_with_index do |mirror_id, index| params[:shixun_service_configs].each do |config|
ShixunServiceConfig.create!(:shixun_id => @shixun.id, @shixun.shixun_service_configs.create!(config)
: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)
end end
end end
rescue Exception => e rescue Exception => e
@ -446,6 +446,7 @@ class ShixunsController < ApplicationController
@choice_small_type = @shixun.small_mirror_id @choice_small_type = @shixun.small_mirror_id
@main_type = shixun_main_type @main_type = shixun_main_type
@small_type = shixun_small_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 #@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 # @shixun_main_mirror = @shixun.show_shixun_mirror
# @script_type = @shixun.script_tag.try(:script_type) || "无" # @script_type = @shixun.script_tag.try(:script_type) || "无"
@ -734,7 +735,13 @@ private
def shixun_params def shixun_params
raise("实训名称不能为空") if params[:name].blank? raise("实训名称不能为空") if params[:name].blank?
params.require(:shixun).permit(:name, :trainee, :webssh, :can_copy, :use_scope, :vnc, :test_set_permission, 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 end
def find_shixun def find_shixun

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

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

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

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

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

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

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

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

@ -1,6 +1,6 @@
# 导航栏公共数据 # 导航栏公共数据
json.partial! "challenges/top_common_data", shixun_identifier: @shixun.identifier 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) json.tags @challenge.challenge_tags.map(&:name)

@ -22,13 +22,21 @@ json.shixun do
json.hide_code @shixun.hide_code # 隐藏代码窗口 json.hide_code @shixun.hide_code # 隐藏代码窗口
json.code_hidden @shixun.code_hidden # 代码目录隐藏 json.code_hidden @shixun.code_hidden # 代码目录隐藏
json.vnc @shixun.vnc json.vnc @shixun.vnc
json.exec_time @shixun.exec_time #json.exec_time @shixun.exec_time
json.webssh @shixun.webssh json.webssh @shixun.webssh
json.multi_webssh @shixun.multi_webssh json.multi_webssh @shixun.multi_webssh
json.use_scope @shixun.use_scope json.use_scope @shixun.use_scope
json.scope_partment @shixun.schools.map(&:name) # 公开范围 json.scope_partment @shixun.schools.map(&:name) # 公开范围
json.opening_time @shixun.opening_time json.opening_time @shixun.opening_time
json.forbid_copy @shixun.forbid_copy 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 end

Loading…
Cancel
Save