diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 856afeb01..33963a192 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -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 diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 2377f411b..8b65d7c70 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -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 diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index bad54b88e..f684b27f3 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -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) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index f079aed1e..f7172021c 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -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 diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 77a41d065..4de85ec64 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -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,"试卷不存在") diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index cb2f487cb..6ddbdce0c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 18d5c5fae..c4345f90a 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -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 diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index 9b96cd70c..be048c4c2 100644 --- a/app/services/exercise_user_pdf_service.rb +++ b/app/services/exercise_user_pdf_service.rb @@ -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 diff --git a/app/services/export_exercises_service.rb b/app/services/export_exercises_service.rb index 48bfc9519..12b5501f9 100644 --- a/app/services/export_exercises_service.rb +++ b/app/services/export_exercises_service.rb @@ -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 diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 63b7fb8bc..1dde00e56 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -44,7 +44,6 @@ 实训题<%= @exercise_ques_shixun_count %>题, 共<%= @exercise_ques_shixun_scores %> <% end %> - <% if @exercise_ques_count > 0 %> <%= @exercise_ques_scores %>分 @@ -59,7 +58,7 @@
<% @exercise_questions.each do |q| %>
-
+
<%= q.question_number %>、 @@ -68,43 +67,39 @@ (<%= q&.question_score %>分)
- <% 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 %> - <%= q_name %> + <%= to_markdown(q.shixun_name) %>
- <%= q_markdown %> + <%= to_markdown(q.question_title) %>
<% else %> - <%= q_markdown %> + <%= to_markdown(q.question_title) %> <% end %>
<% if q.question_type == 0 %> - <% q.exercise_choices.each_with_index do |s,index| %> -

- - <%= convert_to_char((index+1).to_s)%><%= s.choice_text%> -

+ <% q.exercise_choices.each do |s| %> +
+ + <%= to_markdown(s.choice_text) %> +
<% end %> <% elsif q.question_type == 1 %> - <% q.exercise_choices.each_with_index do |s,index| %> -

- - <%= convert_to_char((index+1).to_s)%><%= s.choice_text%> -

+ <% q.exercise_choices.each do |s| %> +
+ + <%= to_markdown(s.choice_text) %> +
<% end %> <% elsif q.question_type == 2 %> -

- <% q.exercise_choices.each_with_index do |s,index| %> - - - <%= s.choice_text %> +

+ <% q.exercise_choices.each do |s| %> + + + <%= s.choice_text %> <% end %> -

+
<% elsif q.question_type == 3 %> <% st_counts = q.exercise_standard_answers.pluck(:exercise_choice_id).uniq %> <% st_counts.each_with_index do |s,index| %> diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index 9190e9251..f0eeb0f4c 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -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; +} + + diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 5770c5921..f523246a0 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -121,7 +121,7 @@
- <%= q.question_number %>、  + <%= q.question_number %>、 <%= request.base_url %> <%= q.question_type_name %> @@ -167,41 +167,39 @@ <% end %>
- <% q_title = q.question_title&.html_safe %> - <% if q_type == 5 %> - <% q_name = q.shixun_name&.html_safe %> - <%= q_name&.include?("src=\"") ? q_name&.gsub("src=\"","src=\"#{@request_url}") : q_name %> + <% if q.question_type == 5 %> + <%= to_markdown(q.shixun_name) %>
- <%= q_title&.include?("src=\"") ? q_title&.gsub("src=\"","src=\"#{@request_url}") : q_title %> + <%= to_markdown(q.question_title) %>
<% else %> - <%= q_title&.include?("src=\"") ? q_title&.gsub("src=\"","src=\"#{@request_url}") : q_title %> + <%= to_markdown(q.question_title) %> <% end %>
<% 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" : '' %> -

- - <%= convert_to_char((index+1).to_s)%><%= s.choice_text%> -

+
+ + <%= to_markdown(s.choice_text) %> +
<% 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 %> -

+

<% if check_answer %> - + <% else %> - + <% end %> - <%= convert_to_char((index+1).to_s)%><%= s.choice_text%> -

+ <%= to_markdown(s.choice_text) %> +
<% end %> <% elsif q_type == 2 %> -

+

<% 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 @@ <%= s.choice_text %> <% end %> -

+
<% 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 %>

答案(填空<%= index+1 %>): - <%= check_answer&.html_safe %> + <%= to_markdown(check_answer) %>

<% end %> <% elsif q_type == 4 %> <% check_answer = (user_answer.present? ? user_answer.first.answer_text : '--') %>

- <%= check_answer&.html_safe %> + <%= to_markdown(check_answer) %>

<% else %>
diff --git a/app/views/challenges/show.json.jbuilder b/app/views/challenges/show.json.jbuilder index 332879eac..cffe77ebb 100644 --- a/app/views/challenges/show.json.jbuilder +++ b/app/views/challenges/show.json.jbuilder @@ -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) diff --git a/app/views/shixuns/settings.json.jbuilder b/app/views/shixuns/settings.json.jbuilder index e97331388..e81498058 100644 --- a/app/views/shixuns/settings.json.jbuilder +++ b/app/views/shixuns/settings.json.jbuilder @@ -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