diff --git a/app/assets/javascripts/admins/shixun_settings/index.js b/app/assets/javascripts/admins/shixun_settings/index.js index 8b3eee505..ece7b3233 100644 --- a/app/assets/javascripts/admins/shixun_settings/index.js +++ b/app/assets/javascripts/admins/shixun_settings/index.js @@ -12,6 +12,11 @@ $(document).on('turbolinks:load', function() { window.location.href = "/admins/shixun_settings.xls?" + searchForm.serialize(); }); + // 基础数据导出 + searchContainer.on('click', "#shixun-settings-base-export", function () { + window.location.href = "/admins/shixun_settings.xls?base_data=1" + searchForm.serialize(); + }); + $(".shixun-settings-list-container").on("change", '.shixun-setting-form', function () { var s_id = $(this).attr("data-id"); var s_value = $(this).val(); diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index 756a5e241..a401fc379 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -53,3 +53,8 @@ input.form-control { position: absolute; } +.export-base-absolute{ + right:100px; + position: absolute; +} + diff --git a/app/controllers/admins/shixun_settings_controller.rb b/app/controllers/admins/shixun_settings_controller.rb index 216c9d909..bd54018cd 100644 --- a/app/controllers/admins/shixun_settings_controller.rb +++ b/app/controllers/admins/shixun_settings_controller.rb @@ -28,7 +28,13 @@ class Admins::ShixunSettingsController < Admins::BaseController 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)) + export_url = + if params[:base_data].present? + shixun_base_list_xls(shixun_settings) + else + shixun_list_xls(shixun_settings) + end + send_data(export_url, :type => 'application/octet-stream', :filename => filename_for_content_disposition(filename)) } end @@ -91,6 +97,34 @@ class Admins::ShixunSettingsController < Admins::BaseController xls_report.string end + def shixun_base_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.includes(:mirror_repositories, :challenges, user: [user_extension: :school]).find_each do |shixun| + sheet1[count_row, 0] = shixun.identifier + sheet1[count_row, 1] = shixun.name + sheet1[count_row, 2] = shixun.mirror_repositories.select{|mr| mr.main_type == "1"}.first&.type_name + sheet1[count_row, 3] = shixun.fork_from + sheet1[count_row, 4] = shixun.shixun_status + sheet1[count_row, 5] = shixun.user.show_real_name + sheet1[count_row, 6] = shixun.user.school_name + sheet1[count_row, 7] = shixun.user.identity + shixun.challenges.each do |challenge| + sheet1[count_row, 8] = "第#{challenge.position}关" + sheet1[count_row, 9] = challenge.subject + 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,:page_no, :id,tag_repertoires:[]) end diff --git a/app/views/admins/shixun_settings/index.html.erb b/app/views/admins/shixun_settings/index.html.erb index 2687de67b..7aab73f64 100644 --- a/app/views/admins/shixun_settings/index.html.erb +++ b/app/views/admins/shixun_settings/index.html.erb @@ -24,6 +24,7 @@ <%= submit_tag('搜索', class: 'btn btn-primary ml-3','data-disable-with': '搜索中...') %> <%= link_to "清除",admins_shixun_settings_path,class: "btn btn-default",'data-disable-with': '清除中...' %>
+ 导出基础数据 导出