课程等级体系导出excel

dev_trainings
daiao 6 years ago
parent 7126019a38
commit 94f1899930

@ -376,7 +376,7 @@ class ApplicationController < ActionController::Base
def require_admin
return unless require_login
if !User.current.admin? && @shixun.status > 1
if !User.current.admin?
render_403
return false
end

@ -32,6 +32,14 @@ class ManagementsController < ApplicationController
# 实训课程等级体系
def subject_level_system
@levels = SubjectLevelSystem.all
respond_to do |format|
format.html
format.xls{
time = Time.now.strftime("%Y%m%d")
filename = "实训课程体系#{time}.xls"
send_data(export_subject_level_system(), :type => 'application/octet-stream', :filename => filename_for_content_disposition(filename))
}
end
end
# 创建课程等级体系
@ -4286,6 +4294,33 @@ end
return sheet.rows
end
def export_subject_level_system
xls_report = StringIO.new
book = Spreadsheet::Workbook.new
sheet1 = book.create_worksheet :name => "实训课程等级体系"
blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10
sheet1.row(0).default_format = blue
count_row = 1
sheet1.row(0).concat(["序号", "等级", "实训课程名称", "实训课程url", "实训名称"])
levels = SubjectLevelSystem.includes(subjects: [stage_shixuns: :shixun]).where(nil)
levels.each_with_index do |level, i|
sheet1[count_row, 0] = i + 1
sheet1[count_row, 1] = level.level
level.subjects.each do |subject|
sheet1[count_row, 2] = subject.name
sheet1[count_row, 3] = "#{subject_path(subject)}"
count_row += 1
subject.shixuns.each do |shixun|
sheet1[count_row, 4] = shixun.name
count_row += 1
end
end
count_row += 1
end
book.write xls_report
xls_report.string
end
def shixun_feedback_xls shixun_ids, beginTime, endTime
xls_report = StringIO.new
book = Spreadsheet::Workbook.new

@ -10,7 +10,7 @@ class ShixunsController < ApplicationController
before_filter :view_allow, :only => [:collaborators, :propaedeutics, :shixun_discuss, :ranking_list]
before_filter :require_manager, :only => [ :settings, :add_script, :publish, :collaborators_delete, :shixun_members_added, :add_collaborators, :update, :destroy]
before_filter :validation_email, :only => [:new]
before_filter :require_admin, :only => [:destroy]
#before_filter :require_manager, :only => [:destroy]
# 移动云ToC模式权限控制
# before_filter :ecloud_auth, :except => [:show, :index]
@ -1117,6 +1117,7 @@ class ShixunsController < ApplicationController
end
def destroy
render_403 if @shixun.status > 1 && !User.current.admin?
ActiveRecord::Base.transaction do
g = Gitlab.client
g.delete_project(@shixun.gpid) if @shixun.try(:gpid).present?

@ -1,3 +1,6 @@
<div class="edu-con-top clearfix xmt10 bor-grey-e mt10">
<a href="<%= subject_level_system_managements_path(:format => "xls") %>" class="fr task-btn task-btn-orange ml5" >导出excel</a>
</div>
<table class="edu-pop-table edu-txt-center" cellpadding="0" cellspacing="0">
<thead>
<th width="10%">等级</th>

Loading…
Cancel
Save