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
@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"

@ -17,7 +17,8 @@ class ZipsController < ApplicationController
end
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)
send_file exercises.ex_zip, filename: file_name, type: 'application/zip'

@ -335,10 +335,8 @@ module ApplicationHelper
end
# 导出pdf时转化markdown为html
def to_markdown(text)
def to_markdown(text,origin_url)
return nil if text.blank?
request_url = "http://47.96.87.25:48080"
options = {
:autolink => true,
:no_intra_emphasis => true,
@ -350,8 +348,7 @@ module ApplicationHelper
}
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,options)
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}")
m_t&.include?("src=\"") ? m_t&.gsub("src=\"","src=\"#{origin_url}") : m_t
end
end

@ -3,11 +3,12 @@ class ExerciseUserPdfService
include ApplicationHelper
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
@ex_user = ex_user
@request_url = request_url
@ex_user_user = @ex_user.user
@course = @exercise.course
end

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

@ -68,12 +68,12 @@
</div>
<div class="pbt5">
<% 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">
<span><%= to_markdown(q.question_title) %></span>
<span><%= to_markdown(q.question_title,@request_url) %></span>
</div>
<% else %>
<span class="ques-title"><%= to_markdown(q.question_title) %></span>
<span class="ques-title"><%= to_markdown(q.question_title,@request_url) %></span>
<% end %>
</div>
<div class="pbt5">
@ -81,14 +81,14 @@
<% 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>
<span class="inline-block pull-left choice-text ml10"><%= to_markdown(s.choice_text,@request_url) %></span>
</div>
<% end %>
<% elsif q.question_type == 1 %>
<% 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>
<span class="inline-block pull-left choice-text ml10"><%= to_markdown(s.choice_text,@request_url) %></span>
</div>
<% end %>
<% elsif q.question_type == 2 %>

@ -121,7 +121,7 @@
<div class="pbt10">
<div class="position-relative">
<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">
<%= q.question_type_name %>
</span>
@ -168,12 +168,12 @@
</div>
<div class="pbt5">
<% 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">
<span><%= to_markdown(q.question_title) %></span>
<span><%= to_markdown(q.question_title,@request_url) %></span>
</div>
<% else %>
<span class="ques-title"><%= to_markdown(q.question_title) %></span>
<span class="ques-title"><%= to_markdown(q.question_title,@request_url) %></span>
<% end %>
</div>
</div>
@ -183,7 +183,7 @@
<% check_answer = (user_answer.present? && (s.id == user_answer.first.exercise_choice_id)) ? "choose-answer" : '' %>
<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>
<span class="inline-block pull-left ml10 choice-text"><%= to_markdown(s.choice_text,@request_url) %></span>
</div>
<% end %>
<% elsif q_type == 1 %>
@ -195,7 +195,7 @@
<% else %>
<span class="choose-checkbox pull-left mt8"></span>
<% 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>
<% end %>
<% elsif q_type == 2 %>
@ -335,7 +335,7 @@
<div class="bdc">
<div class="pbt10">
<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 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>

Loading…
Cancel
Save