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

dev_forum
jingquan huang 5 years ago
commit 569042a602

@ -138,7 +138,7 @@ class ChallengesController < ApplicationController
# tab 0,nil 过关任务, 1 评测设置, 2 参考答案 # tab 0,nil 过关任务, 1 评测设置, 2 参考答案
def edit def edit
@tab = params[:tab].to_i @tab = params[:tab].to_i
@power = current_user.manager_of_shixun?(@shixun) && @shixun.status == 0 @power = @shixun.status == 0
challenge_num = Challenge.where(:shixun_id => @shixun).count challenge_num = Challenge.where(:shixun_id => @shixun).count
@position = @challenge.position @position = @challenge.position
@chooses = @challenge.challenge_chooses @chooses = @challenge.challenge_chooses
@ -159,8 +159,8 @@ class ChallengesController < ApplicationController
def show def show
@tab = params[:tab].nil? ? 1 : params[:tab].to_i @tab = params[:tab].nil? ? 1 : params[:tab].to_i
challenge_num = Challenge.where(shixun_id: @shixun).count challenge_num = @shixun.challenges_count
@power = current_user.manager_of_shixun?(@shixun) && @shixun.status == 0 @power = @shixun.status == 0 # 之前验证走过了是不是管理员,因此这里只用判断是否发布
@position = @challenge.position @position = @challenge.position
if @position < challenge_num if @position < challenge_num
@next_challenge = Challenge.where(:shixun_id => @shixun, :position => @position + 1).first @next_challenge = Challenge.where(:shixun_id => @shixun, :position => @position + 1).first
@ -278,9 +278,6 @@ class ChallengesController < ApplicationController
def find_shixun def find_shixun
@shixun = Shixun.find_by_identifier(params[:shixun_identifier]) @shixun = Shixun.find_by_identifier(params[:shixun_identifier])
if !current_user.shixun_permission(@shixun)
tip_exception(403, "..")
end
end end
# 通用接口 # 通用接口

@ -101,7 +101,7 @@ class ExercisesController < ApplicationController
@page = params[:page] || 1 @page = params[:page] || 1
@limit = params[:limit] || 15 @limit = params[:limit] || 15
@exercises = @exercises.page(@page).per(@limit) @exercises = @exercises.page(@page).per(@limit)
@exercises = @exercises.includes(:exercise_users,:exercise_questions,:exercise_group_settings) @exercises = @exercises&.includes(:exercise_users,:exercise_questions,:exercise_group_settings)
else else
@exercises = [] @exercises = []
end end
@ -188,7 +188,7 @@ class ExercisesController < ApplicationController
else else
@is_teacher_or = 0 #为学生 @is_teacher_or = 0 #为学生
end end
@exercise_questions = @exercise.exercise_questions.order("question_number ASC") @exercise_questions = @exercise.exercise_questions&.includes(:exercise_choices,:exercise_shixun_challenges,:exercise_standard_answers).order("question_number ASC")
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)
tip_exception("试卷创建失败!") tip_exception("试卷创建失败!")
@ -1334,6 +1334,7 @@ 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
@ -1418,7 +1419,7 @@ class ExercisesController < ApplicationController
:best_counts => best_counts, :best_counts => best_counts,
} }
@exercise_questions = @exercise.exercise_questions @exercise_questions = @exercise.exercise_questions&.includes(:exercise_choices,:exercise_answers,:exercise_standard_answers,:exercise_shixun_challenges,:exercise_shixun_answers)
@paging_type = "percent" @paging_type = "percent"
# 按题型排序 # 按题型排序

@ -16,12 +16,17 @@ class FilesController < ApplicationController
sort = params[:sort] || 0 # 0: 降序1: 升序 sort = params[:sort] || 0 # 0: 降序1: 升序
sort_type = params[:sort_type] || 'created_on' # created_on时间排序 downloads下载次数排序; quotes: 引用次数排序 sort_type = params[:sort_type] || 'created_on' # created_on时间排序 downloads下载次数排序; quotes: 引用次数排序
course_second_category_id = params[:course_second_category_id] || 0 # 0: 为主目录, 其他为次目录id course_second_category_id = params[:course_second_category_id] || 0 # 0: 为主目录, 其他为次目录id
@user = current_user || nil @user = current_user
@attachments = @course.attachments.by_course_second_category_id(course_second_category_id) @attachments = @course.attachments.by_course_second_category_id(course_second_category_id)
.includes(attachment_group_settings: :course_group, author: [:user_extension, :course_members]) .includes(attachment_group_settings: :course_group, author: [:user_extension, :course_members])
.ordered(sort: sort.to_i, sort_type: sort_type.strip) .ordered(sort: sort.to_i, sort_type: sort_type.strip)
get_category(@course, course_second_category_id) get_category(@course, course_second_category_id)
@total_count = @attachments.size
@public_count = @attachments.publiced.size
@private_count = @total_count - @public_count
@attachments = @attachments.by_keywords(params[:search])
@attachments = @attachments =
case @user.course_identity(@course) case @user.course_identity(@course)
when 5 when 5
@ -32,12 +37,6 @@ class FilesController < ApplicationController
@attachments @attachments
end end
@total_count = @attachments.size
@public_count = @attachments.publiced.size
@private_count = @total_count - @public_count
@attachments = @attachments.by_keywords(params[:search])
@attachments = @attachments.page(@page).per(@page_size) @attachments = @attachments.page(@page).per(@page_size)
end end

@ -426,12 +426,12 @@ class GamesController < ApplicationController
game_code = GameCode.where(:game_id => @game.try(:id), :path => path).first game_code = GameCode.where(:game_id => @game.try(:id), :path => path).first
if game_code.present? if game_code.present?
content = game_code.try(:new_code) content = game_code.try(:new_code)
@content = if @myshixun.mirror_name.select{|a| a.include?("MachineLearning") || a.include?("Python")}.present? && content.present? # @content = if @myshixun.mirror_name.select{|a| a.include?("MachineLearning") || a.include?("Python")}.present? && content.present?
content.gsub(/\t/, ' ') # content.gsub(/\t/, ' ')
else # else
content # content
end # end
update_file_content(@content, @myshixun.repo_path, path, current_user.mail, current_user.full_name, "game passed reset") update_file_content(content, @myshixun.repo_path, path, current_user.mail, current_user.full_name, "game passed reset")
else else
tip_exception("代码重置失败,代码为空") tip_exception("代码重置失败,代码为空")
end end

@ -90,7 +90,7 @@ class PollsController < ApplicationController
@limit = params[:limit] || 15 @limit = params[:limit] || 15
@polls = @polls.page(@page).per(@limit) @polls = @polls.page(@page).per(@limit)
@polls = @polls.includes(:poll_users,:poll_questions,:poll_group_settings) @polls = @polls&.includes(:poll_users,:poll_questions,:poll_group_settings)
else else
@polls = [] @polls = []
@ -183,7 +183,7 @@ class PollsController < ApplicationController
else else
@is_teacher_or = 0 @is_teacher_or = 0
end end
@poll_questions = @poll.poll_questions.order("question_number ASC") @poll_questions = @poll.poll_questions&.includes(:poll_answers).order("question_number ASC")
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)
tip_exception("没有权限") tip_exception("没有权限")
@ -1148,7 +1148,7 @@ class PollsController < ApplicationController
end end
def get_questions_count def get_questions_count
@poll_questions = @poll.poll_questions.order("question_number ASC") @poll_questions = @poll.poll_questions&.includes(:poll_answers,:poll_votes).order("question_number ASC")
@poll_questions_count = @poll_questions.count # 全部的题目数 @poll_questions_count = @poll_questions.count # 全部的题目数
@poll_question_singles = @poll_questions.ques_count(1).all.count # 单选题 @poll_question_singles = @poll_questions.ques_count(1).all.count # 单选题
@poll_question_doubles = @poll_questions.ques_count(2).all.count # 多选题 @poll_question_doubles = @poll_questions.ques_count(2).all.count # 多选题

@ -17,7 +17,7 @@ class ZipsController < ApplicationController
end end
def export_exercises def export_exercises
exercises = ExportExercisesService.new(@exercise,@ex_users) 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'
@ -41,6 +41,7 @@ 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,"试卷不存在")
@ -48,19 +49,20 @@ class ZipsController < ApplicationController
@course = @exercise.course @course = @exercise.course
default_ex_users = @exercise.all_exercise_users(current_user.id).exercise_user_committed default_ex_users = @exercise.all_exercise_users(current_user.id).exercise_user_committed
default_ex_users_size = default_ex_users.size
@ex_users = default_ex_users #仅导出已提交的,截止后则是全部为提交的。 @ex_users = default_ex_users #仅导出已提交的,截止后则是全部为提交的。
#可以分班选择 #可以分班选择
if group_id.present? if group_id.present?
exercise_students = @course.students.course_find_by_ids("course_group_id",group_id) # 试卷所分班的全部人数 exercise_students = @course.students.where(course_group_id: group_id) # 试卷所分班的全部人数
user_ids = exercise_students.pluck(:user_id).reject(&:blank?) user_ids = exercise_students.pluck(:user_id).reject(&:blank?).uniq
@ex_users = @ex_users.exercise_commit_users(user_ids) @ex_users = @ex_users.where(user_id: user_ids)
end end
# @ex_users = @ex_users.first(200)
default_ex_users_size = @ex_users.size
if default_ex_users_size == 0 if default_ex_users_size == 0
normal_status(-1,"导出失败,暂时没有已提交的学生") normal_status(-1,"导出失败,暂时没有已提交的学生")
elsif default_ex_users_size > 200 elsif default_ex_users_size > 100
normal_status(-1,"导出数量超过200,请分班导出或联系网站管理员导出") normal_status(-1,"导出数量超过100,请分班导出或联系网站管理员导出")
end end
end end
rescue Exception => e rescue Exception => e

@ -110,7 +110,7 @@ module PollsHelper
poll_user_name = user.nickname poll_user_name = user.nickname
end end
course_member = course_members.find_by(user_id:user.id) course_member = course_members.find_by(user_id:user.id)
course_group_id = course_members.present? ? course_member.course_group_id : nil course_group_id = course_member.present? ? course_member.course_group_id : nil
if course_group_id == 0 if course_group_id == 0
course_group_name = "未分班" course_group_name = "未分班"
else else

@ -5,9 +5,10 @@ class ExerciseUserPdfService
attr_reader :exercise, :ex_user attr_reader :exercise, :ex_user
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
@ -37,10 +38,10 @@ class ExerciseUserPdfService
kit = PDFKit.new(html) kit = PDFKit.new(html)
base_css = %w(app/templates/exercise_export/exercise_export.css) base_css = %w(app/templates/exercise_export/exercise_export.css)
base_css.each { |css| kit.stylesheets << Rails.root.join(css) } base_css.each { |css| kit.stylesheets << Rails.root.join(css) }
#-----正式需删掉 # #-----正式需删掉
# aa = File.open(Rails.root.join("public/123.html"),"w+") # aa = File.open(Rails.root.join("public/123.html"),"w+")
# aa.syswrite(kit.source) # aa.syswrite(kit.source)
#正式需删掉------- # #正式需删掉-------
file = Tempfile.new(filename) file = Tempfile.new(filename)
kit.to_pdf(file.path) kit.to_pdf(file.path)
file file

@ -3,9 +3,10 @@ class ExportExercisesService
include StudentWorksHelper include StudentWorksHelper
attr_reader :exercise, :ex_users attr_reader :exercise, :ex_users
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,13 +68,15 @@
<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_title = q.question_title&.html_safe %>
<% if q.question_type == 5 %> <% if q.question_type == 5 %>
<span class="ques-title"><%= q.shixun_name.present? ? q.shixun_name&.html_safe : "" %></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.question_title.present? ? q.question_title&.html_safe : "" %></span> <span><%= q_title&.include?("src=\"") ? q_title&.gsub("src=\"","src=\"#{@request_url}") : q_title %></span>
</div> </div>
<% else %> <% else %>
<span class="ques-title"><%= q.question_title.present? ? q.question_title&.html_safe : "" %></span> <span class="ques-title"><%= q_title&.include?("src=\"") ? q_title&.gsub("src=\"","src=\"#{@request_url}") : q_title %></span>
<% end %> <% end %>
</div> </div>
<div class="pbt5"> <div class="pbt5">

@ -167,15 +167,15 @@
<% end %> <% end %>
</div> </div>
<div class="pbt5"> <div class="pbt5">
<% q_title = q.question_title&.html_safe %>
<% if q_type == 5 %> <% if q_type == 5 %>
<span class="ques-title"><%= q.shixun_name&.html_safe %></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.question_title&.html_safe %></span> <span><%= q_title&.include?("src=\"") ? q_title&.gsub("src=\"","src=\"#{@request_url}") : q_title %></span>
</div> </div>
<% elsif q_type == 4 %>
<span class="ques-title"><%= q.question_title&.html_safe %></span>
<% else %> <% else %>
<span class="ques-title"><%= q.question_title&.html_safe %></span> <span class="ques-title"><%= q_title&.include?("src=\"") ? q_title&.gsub("src=\"","src=\"#{@request_url}") : q_title %></span>
<% end %> <% end %>
</div> </div>
</div> </div>

Loading…
Cancel
Save