|
|
|
class Admins::ShixunSettingsController < Admins::BaseController
|
|
|
|
|
|
|
|
def index
|
|
|
|
params[:sort_by] = params[:sort_by].presence || 'created_on'
|
|
|
|
params[:sort_direction] = params[:sort_direction].presence || 'desc'
|
|
|
|
|
|
|
|
shixun_settings = Admins::ShixunSettingsQuery.call(params)
|
|
|
|
@editing_shixuns = shixun_settings.where(status:0).size
|
|
|
|
@pending_shixuns = shixun_settings.where(status:1).size
|
|
|
|
@processed_shixuns = shixun_settings.where(status:2).size
|
|
|
|
@closed_shixuns = shixun_settings.where(status:3).size
|
|
|
|
@shixuns_type_check = MirrorRepository.select(:id,:type_name).pluck(:type_name,:id)
|
|
|
|
@shixun_tags = TagRepertoire.order("name asc").select(:id,:name).pluck(:name,:id)
|
|
|
|
@params_page = params[:page] || 1
|
|
|
|
@shixun_settings = paginate shixun_settings.preload(:user,:tag_repertoires)
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
|
|
|
format.html
|
|
|
|
format.xls{
|
|
|
|
filename = "实训详情_#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}.xls"
|
|
|
|
send_data(shixun_list_xls(shixun_settings), :type => 'application/octet-stream', :filename => filename_for_content_disposition(filename))
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@shixun = Shixun.find_by(id:params[:id])
|
|
|
|
@page_no = params[:page_no] || "1"
|
|
|
|
@shixun_tags = TagRepertoire.order("name asc").select(:id,:name).pluck(:name,:id)
|
|
|
|
tag_ids = params[:tag_repertoires]
|
|
|
|
if tag_ids.present?
|
|
|
|
@shixun&.shixun_tag_repertoires.delete_all
|
|
|
|
tag_repertoire_ids = @shixun&.tag_repertoires&.pluck(:id)
|
|
|
|
tag_ids.each do |id|
|
|
|
|
unless tag_repertoire_ids.include?(id)
|
|
|
|
tag_repertoire = @shixun.shixun_tag_repertoires.new(shixun_id:@shixun.id,tag_repertoire_id:id)
|
|
|
|
tag_repertoire.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
|
|
|
format.json{
|
|
|
|
render json: {status: 0}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if @shixun.update_attributes(setting_params)
|
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
|
|
|
format.json{
|
|
|
|
render json: {status: 0}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
else
|
|
|
|
redirect_to admins_shixun_settings_path
|
|
|
|
flash[:danger] = "更新失败"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def shixun_list_xls shixuns
|
|
|
|
xls_report = StringIO.new
|
|
|
|
book = Spreadsheet::Workbook.new
|
|
|
|
sheet1 = book.create_worksheet :name => "sheet"
|
|
|
|
blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10
|
|
|
|
sheet1.row(0).default_format = blue
|
|
|
|
sheet1.row(0).concat(["实训ID","实训名称","技术平台", "Fork源", "实践任务","选择题任务","挑战人数", "通关人数", "状态","创建者", "单位", "职业", "关卡序号","关卡名称","技能标签"])
|
|
|
|
count_row = 1
|
|
|
|
shixuns.find_each do |shixun|
|
|
|
|
sheet1[count_row, 0] = shixun.identifier
|
|
|
|
sheet1[count_row, 1] = shixun.name
|
|
|
|
sheet1[count_row, 2] = shixun.shixun_main_name
|
|
|
|
sheet1[count_row, 3] = shixun.fork_identifier
|
|
|
|
sheet1[count_row, 4] = shixun.challenges.practice_type.count
|
|
|
|
sheet1[count_row, 5] = shixun.challenges.choose_type.count
|
|
|
|
sheet1[count_row, 6] = shixun.myshixuns.count
|
|
|
|
sheet1[count_row, 7] = shixun.myshixuns.finished.count
|
|
|
|
sheet1[count_row, 8] = shixun.shixun_status
|
|
|
|
sheet1[count_row, 9] = shixun.owner.show_real_name
|
|
|
|
sheet1[count_row, 10] = shixun.owner.school_name
|
|
|
|
sheet1[count_row, 11] = shixun.owner.identity
|
|
|
|
shixun.challenges.each do |challenge|
|
|
|
|
sheet1[count_row, 12] = "第#{challenge.position}关"
|
|
|
|
sheet1[count_row, 13] = challenge.subject
|
|
|
|
sheet1[count_row, 14] = challenge.tags_show
|
|
|
|
count_row += 1
|
|
|
|
end
|
|
|
|
count_row += 1
|
|
|
|
end
|
|
|
|
book.write xls_report
|
|
|
|
xls_report.string
|
|
|
|
end
|
|
|
|
|
|
|
|
def setting_params
|
|
|
|
params.permit(:use_scope,:excute_time,:close,:status,:can_copy,:webssh,:hidden,:homepage_show,:task_pass,:code_hidden,:id,tag_repertoires:[])
|
|
|
|
end
|
|
|
|
end
|