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

dev_forum
cxt 5 years ago
commit cf3b9ce1c8

@ -1333,6 +1333,7 @@ class ExercisesController < ApplicationController
#导出空白试卷 #导出空白试卷
def export_exercise def export_exercise
@request_url = request.base_url
@exercise_questions = @exercise.exercise_questions.includes(:exercise_choices).order("question_number ASC") @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" 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"

@ -17,7 +17,8 @@ class ZipsController < ApplicationController
end end
def export_exercises def export_exercises
exercises = ExportExercisesService.new(@exercise,@ex_users) @request_url = request.base_url
exercises = ExportExercisesService.new(@exercise,@ex_users,@request_url)
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'

@ -335,10 +335,8 @@ module ApplicationHelper
end end
# 导出pdf时转化markdown为html # 导出pdf时转化markdown为html
def to_markdown(text) def to_markdown(text,origin_url)
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,
@ -350,8 +348,7 @@ module ApplicationHelper
} }
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,options) markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,options)
m_t = markdown.render(text) m_t = markdown.render(text)
m_t&.include?("src=\"") ? m_t&.gsub("src=\"","src=\"#{request_url}") : m_t m_t&.include?("src=\"") ? m_t&.gsub("src=\"","src=\"#{origin_url}") : m_t
Rails.logger.info("###########__________request_url_________###################{request_url}")
end end
end end

@ -3,11 +3,12 @@ class ExerciseUserPdfService
include ApplicationHelper include ApplicationHelper
include StudentWorksHelper include StudentWorksHelper
attr_reader :exercise, :ex_user attr_reader :exercise, :ex_user, :request_url
def initialize(exercise, ex_user) def initialize(exercise, ex_user,request_url)
@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

@ -1,11 +1,12 @@
class ExportExercisesService class ExportExercisesService
include ExercisesHelper include ExercisesHelper
include StudentWorksHelper include StudentWorksHelper
attr_reader :exercise, :ex_users attr_reader :exercise, :ex_users, :request_url
def initialize(exercise, ex_users) def initialize(exercise, ex_users, request_url)
@exercise = exercise @exercise = exercise
@ex_users = ex_users @ex_users = ex_users
@request_url = request_url
end end
def filename def filename
@ -18,7 +19,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) export = ExerciseUserPdfService.new(exercise, ex_user,@request_url)
pdf = export.ex_pdf pdf = export.ex_pdf
pdfs << pdf pdfs << pdf
begin begin

@ -68,12 +68,12 @@
</div> </div>
<div class="pbt5"> <div class="pbt5">
<% if q.question_type == 5 %> <% if q.question_type == 5 %>
<span class="ques-title" ><%= to_markdown(q.shixun_name) %></span> <span class="ques-title" ><%= to_markdown(q.shixun_name,@request_url) %></span>
<div class="mt8 text-gray"> <div class="mt8 text-gray">
<span><%= to_markdown(q.question_title) %></span> <span><%= to_markdown(q.question_title,@request_url) %></span>
</div> </div>
<% else %> <% else %>
<span class="ques-title"><%= to_markdown(q.question_title) %></span> <span class="ques-title"><%= to_markdown(q.question_title,@request_url) %></span>
<% end %> <% end %>
</div> </div>
<div class="pbt5"> <div class="pbt5">
@ -81,14 +81,14 @@
<% q.exercise_choices.each do |s| %> <% q.exercise_choices.each do |s| %>
<div class="pbt5 clearfix main-choice"> <div class="pbt5 clearfix main-choice">
<span class="choose-radio pull-left mt8"></span> <span class="choose-radio pull-left mt8"></span>
<span class="inline-block pull-left choice-text ml10"><%= to_markdown(s.choice_text) %></span> <span class="inline-block pull-left choice-text ml10"><%= to_markdown(s.choice_text,@request_url) %></span>
</div> </div>
<% end %> <% end %>
<% elsif q.question_type == 1 %> <% elsif q.question_type == 1 %>
<% q.exercise_choices.each do |s| %> <% q.exercise_choices.each do |s| %>
<div class="pbt5 clearfix main-choice"> <div class="pbt5 clearfix main-choice">
<span class="choose-checkbox pull-left mt8"></span> <span class="choose-checkbox pull-left mt8"></span>
<span class="inline-block pull-left choice-text ml10"><%= to_markdown(s.choice_text) %></span> <span class="inline-block pull-left choice-text ml10"><%= to_markdown(s.choice_text,@request_url) %></span>
</div> </div>
<% end %> <% end %>
<% elsif q.question_type == 2 %> <% elsif q.question_type == 2 %>

@ -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><%= request.base_url %> <span class="mr5 text-blue"><%= q.question_number %>、&nbsp;</span>
<span class="text-blue"> <span class="text-blue">
<%= q.question_type_name %> <%= q.question_type_name %>
</span> </span>
@ -168,12 +168,12 @@
</div> </div>
<div class="pbt5"> <div class="pbt5">
<% if q.question_type == 5 %> <% if q.question_type == 5 %>
<span class="ques-title" ><%= to_markdown(q.shixun_name) %></span> <span class="ques-title" ><%= to_markdown(q.shixun_name,@request_url) %></span>
<div class="mt8 text-gray"> <div class="mt8 text-gray">
<span><%= to_markdown(q.question_title) %></span> <span><%= to_markdown(q.question_title,@request_url) %></span>
</div> </div>
<% else %> <% else %>
<span class="ques-title"><%= to_markdown(q.question_title) %></span> <span class="ques-title"><%= to_markdown(q.question_title,@request_url) %></span>
<% end %> <% end %>
</div> </div>
</div> </div>
@ -183,7 +183,7 @@
<% 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" : '' %>
<div class="pbt5 clearfix main-choice"> <div class="pbt5 clearfix main-choice">
<span class="choose-radio <%= check_answer %> pull-left mt8"></span> <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> <span class="inline-block pull-left ml10 choice-text"><%= to_markdown(s.choice_text,@request_url) %></span>
</div> </div>
<% end %> <% end %>
<% elsif q_type == 1 %> <% elsif q_type == 1 %>
@ -195,7 +195,7 @@
<% else %> <% else %>
<span class="choose-checkbox pull-left mt8"></span> <span class="choose-checkbox pull-left mt8"></span>
<% end %> <% end %>
<span class="inline-block pull-left choice-text ml10"><%= to_markdown(s.choice_text) %></span> <span class="inline-block pull-left choice-text ml10"><%= to_markdown(s.choice_text,@request_url) %></span>
</div> </div>
<% end %> <% end %>
<% elsif q_type == 2 %> <% elsif q_type == 2 %>
@ -335,7 +335,7 @@
<div class="bdc"> <div class="bdc">
<div class="pbt10"> <div class="pbt10">
<div class="inline-block pull-left"> <div class="inline-block pull-left">
<span><img src="/images/avatars/User/<%= ques_user.id %>" class="avatar-32"/></span> <span><img src="<%= @request_url %>/images/avatars/User/<%= ques_user.id %>" class="avatar-32"/></span>
</div> </div>
<div class="ml38"> <div class="ml38">
<p class="mb10"><span class="pr"><%= ques_user.real_name %></span><span class="plr15 text-gray"><%= ques_comment.first.updated_at.strftime('%Y-%m-%d %H:%M') %></span></p> <p class="mb10"><span class="pr"><%= ques_user.real_name %></span><span class="plr15 text-gray"><%= ques_comment.first.updated_at.strftime('%Y-%m-%d %H:%M') %></span></p>

Loading…
Cancel
Save