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/courses_controller.rb b/app/controllers/courses_controller.rb index e0844ab4c..cef2a1785 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -776,7 +776,7 @@ class CoursesController < ApplicationController name = attachment.disk_filename if name.split(".").last == "xls" begin - attachment_folder = Rails.configuration.educoder['attachment_folder'] + attachment_folder = edu_setting('attachment_folder') full_path = "#{attachment_folder}/#{path}/#{name}" xls = Roo::Spreadsheet.open(full_path, extension: :xls) worksheet = xls.sheet(0) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 2377f411b..3c364b979 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1333,8 +1333,8 @@ class ExercisesController < ApplicationController #导出空白试卷 def export_exercise - @exercise_questions = @exercise.exercise_questions.includes(:exercise_choices).order("question_number ASC") @request_url = request.base_url + @exercise_questions = @exercise.exercise_questions.includes(:exercise_choices).order("question_number ASC") 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/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index f242f3438..545fbce85 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -12,7 +12,7 @@ class HomeworkCommonsController < ApplicationController :code_review_detail, :show_comment, :settings, :works_list, :update_settings, :reference_answer, :publish_groups, :end_groups, :alter_name, :update_explanation] before_action :user_course_identity - before_action :homework_publish, only: [:show, :works_list, :code_review_results, :show_comment, :settings, :reference_answer] + before_action :homework_publish, only: [:show, :works_list, :code_review_results, :show_comment, :settings, :reference_answer, :update_student_score] before_action :teacher_allowed, only: [:new, :edit, :create, :update, :shixuns, :subjects, :create_shixun_homework, :publish_homework, :end_homework, :set_public, :choose_category, :move_to_category, :choose_category, :create_subject_homework, :multi_destroy, :group_list, :homework_code_repeat, @@ -237,6 +237,7 @@ class HomeworkCommonsController < ApplicationController end def update_score + tip_exception("作业还未发布,暂不能计算成绩") if @homework.publish_time.nil? || @homework.publish_time > Time.now begin if @homework.unified_setting student_works = @homework.student_works diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 5631d03a7..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) diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 77a41d065..c20546701 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -17,6 +17,7 @@ class ZipsController < ApplicationController end def export_exercises + @request_url = request.base_url exercises = ExportExercisesService.new(@exercise,@ex_users,@request_url) file_name = filename_for_content_disposition(exercises.filename) @@ -41,7 +42,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 fd5a8b233..fd72b5651 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -334,9 +334,8 @@ module ApplicationHelper raw arr.join('') end - def to_markdown(text) - request_url = request.base_url - + # 导出pdf时,转化markdown为html + def to_markdown(text,origin_url) return nil if text.blank? options = { :autolink => true, @@ -349,9 +348,7 @@ module ApplicationHelper } markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,options) m_t = markdown.render(text) - ss = m_t&.include?("src=\"") ? m_t&.gsub("src=\"","src=\"#{request_url}") : m_t - Rails.logger.info("############_____________ss________________##################{ss}") - ss + m_t&.include?("src=\"") ? m_t&.gsub("src=\"","src=\"#{origin_url}") : m_t end end diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index 9b96cd70c..44ee1e769 100644 --- a/app/services/exercise_user_pdf_service.rb +++ b/app/services/exercise_user_pdf_service.rb @@ -3,7 +3,7 @@ class ExerciseUserPdfService include ApplicationHelper include StudentWorksHelper - attr_reader :exercise, :ex_user + attr_reader :exercise, :ex_user, :request_url def initialize(exercise, ex_user,request_url) @exercise = exercise diff --git a/app/services/export_exercises_service.rb b/app/services/export_exercises_service.rb index 48bfc9519..f83323d7e 100644 --- a/app/services/export_exercises_service.rb +++ b/app/services/export_exercises_service.rb @@ -1,9 +1,9 @@ class ExportExercisesService include ExercisesHelper include StudentWorksHelper - attr_reader :exercise, :ex_users + attr_reader :exercise, :ex_users, :request_url - def initialize(exercise, ex_users,request_url) + def initialize(exercise, ex_users, request_url) @exercise = exercise @ex_users = ex_users @request_url = request_url diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 9ee1d40f7..153ba1514 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,45 +67,39 @@ (<%= q&.question_score %>分)
- 电脑的电路图 - udasker_picture - <% q_markdown = to_markdown(q.question_title) %> <% if q.question_type == 5 %> - <% q_markdown_name = to_markdown(q.shixun_name) %> - <%= q_markdown_name %> + <%= to_markdown(q.shixun_name,@request_url) %>
- <%= q_markdown %> + <%= to_markdown(q.question_title,@request_url) %>
<% else %> - <%= q_markdown %> + <%= to_markdown(q.question_title,@request_url) %> <% end %>
<% if q.question_type == 0 %> - <% q.exercise_choices.each_with_index do |s,index| %> -

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

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

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

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

- <% q.exercise_choices.each_with_index do |s,index| %> - - - <%= to_markdown(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..bb3723373 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -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,@request_url) %>
- <%= q_title&.include?("src=\"") ? q_title&.gsub("src=\"","src=\"#{@request_url}") : q_title %> + <%= to_markdown(q.question_title,@request_url) %>
<% else %> - <%= q_title&.include?("src=\"") ? q_title&.gsub("src=\"","src=\"#{@request_url}") : q_title %> + <%= to_markdown(q.question_title,@request_url) %> <% 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,@request_url) %> +
<% 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,@request_url) %> +
<% 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 %>
@@ -337,7 +335,7 @@
- +

<%= ques_user.real_name %><%= ques_comment.first.updated_at.strftime('%Y-%m-%d %H:%M') %>

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 ed7d93039..e81498058 100644 --- a/app/views/shixuns/settings.json.jbuilder +++ b/app/views/shixuns/settings.json.jbuilder @@ -22,7 +22,7 @@ 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