parent
27972122a6
commit
1a66348dcf
@ -0,0 +1,60 @@
|
||||
class Admins::ShixunSettingsController < Admins::BaseController
|
||||
|
||||
def index
|
||||
params[:sort_by] = params[:sort_by].presence || 'created_on'
|
||||
params[:sort_direction] = params[:sort_direction].presence || 'desc'
|
||||
shixuns = Admins::ShixunSettingsQuery.call(params)
|
||||
@editing_shixuns = shixuns.where(status:0).size
|
||||
@pending_shixuns = shixuns.where(status:1).size
|
||||
@processed_shixuns = shixuns.where(status:2).size
|
||||
@closed_shixuns = shixuns.where(status:3).size
|
||||
@shixuns_type_check = MirrorRepository.select(:id,:type_name).pluck(:type_name,:id)
|
||||
|
||||
@can_copy = params[:can_copy] || "0"
|
||||
@params_page = params[:page] || 1
|
||||
@shixuns = paginate shixuns.preload(:user,:challenges)
|
||||
|
||||
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(@shixuns), :type => 'application/octet-stream', :filename => filename_for_content_disposition(filename))
|
||||
}
|
||||
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
|
||||
end
|
@ -0,0 +1,48 @@
|
||||
class Admins::ShixunSettingsQuery < ApplicationQuery
|
||||
include CustomSortable
|
||||
|
||||
attr_reader :params
|
||||
|
||||
sort_columns :created_at, default_by: :created_at, default_direction: :desc
|
||||
|
||||
def initialize(params)
|
||||
@params = params
|
||||
end
|
||||
|
||||
def call
|
||||
all_shixuns = Shixun.all
|
||||
status =
|
||||
case params[:status]
|
||||
when "editing" then [0]
|
||||
when "pending" then [1]
|
||||
when "processed" then [2]
|
||||
when "closed" then [3]
|
||||
else
|
||||
[0,1,2,3]
|
||||
end
|
||||
|
||||
all_shixuns = all_shixuns.where(status: status) if status.present?
|
||||
|
||||
if params[:tag].present?
|
||||
all_shixuns = all_shixuns.joins(:mirror_repositories).where("mirror_repositories.id = ?",params[:tag].to_i)
|
||||
end
|
||||
|
||||
# 关键字模糊查询
|
||||
keyword = params[:keyword].to_s.strip
|
||||
if keyword.present?
|
||||
search_type = params[:search_type] || "0"
|
||||
case search_type
|
||||
when "0"
|
||||
all_shixuns = all_shixuns.joins(:user)
|
||||
.where('CONCAT(lastname, firstname) like :keyword', keyword: "%#{keyword}%")
|
||||
when "1"
|
||||
all_shixuns = all_shixuns.where('name like :keyword', keyword: "%#{keyword}%")
|
||||
else
|
||||
all_shixuns = all_shixuns.joins(user: {user_extension: :school}).where('schools.name LIKE ?', "%#{keyword}%")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
custom_sort(all_shixuns, params[:sort_by], params[:sort_direction])
|
||||
end
|
||||
end
|
@ -0,0 +1,66 @@
|
||||
<% define_admin_breadcrumbs do %>
|
||||
<% add_admin_breadcrumb('实训配置', admins_shixun_settings_path) %>
|
||||
<% end %>
|
||||
|
||||
<div class="box search-form-container shixun-settings-list-form">
|
||||
<%= form_tag(admins_shixun_settings_path, method: :get, class: 'form-inline search-form', remote: true) do %>
|
||||
<div class="d-flex flex-column w-100">
|
||||
<div class="d-flex">
|
||||
<div class="form-group mr-2">
|
||||
<label for="status">状态:</label>
|
||||
<% status_options = [['全部', ''], ["编辑中(#{@editing_shixuns})", "editing"], ["待审核(#{@pending_shixuns})", 'pending'], ["已发布(#{@processed_shixuns})", 'processed'],["已关闭(#{@closed_shixuns})",'closed']] %>
|
||||
<%= select_tag(:status, options_for_select(status_options), class: 'form-control') %>
|
||||
</div>
|
||||
<div class="form-group mr-2">
|
||||
<label for="tag-choosed">技术平台:</label>
|
||||
<%= select_tag(:tag, options_for_select(@shixuns_type_check.unshift(["",nil])), class: 'form-control',id:"tag-choosed") %>
|
||||
</div>
|
||||
<div class="form-group mr-2">
|
||||
<label>搜索类型:</label>
|
||||
<% auto_trial_options = [['创建者姓名', 0], ['实训名称', 1], ['学校名称', 2]] %>
|
||||
<%= select_tag(:search_type, options_for_select(auto_trial_options), class: 'form-control') %>
|
||||
</div>
|
||||
<%= text_field_tag(:keyword, params[:keyword], class: 'form-control col-sm-2 ml-3', placeholder: '输入关键字搜索') %>
|
||||
<%= submit_tag('搜索', class: 'btn btn-primary ml-3') %>
|
||||
<%= link_to "清除",admins_shixun_settings_path(status:nil,tag:nil,search_type:nil,keyword:nil),class: "btn btn-default" %>
|
||||
|
||||
<div class="">
|
||||
<a href="<%= admins_shixun_settings_path( :format => "xls") %>" class="btn btn-primary fr" id="shixun_xls">导出</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="d-flex">
|
||||
<span class="fl ml25 shixun_webssh">
|
||||
<%= check_box_tag :can_copy,"1",false, class:"mr5 magic-checkbox", id: "can_copy_filter", onchange: "this.form.submit()"%>
|
||||
<!-- <input type="checkbox" class="mr5 magic-checkbox" name="can_copy" value="1" id="can_copy_filter" onchange="this.form.submit()">-->
|
||||
<label style="top:2px;padding-left:23px;" for="can_copy_filter"><span class="only_view">只看可复制</span></label>
|
||||
</span>
|
||||
<span class="fl ml20 shixun_webssh">
|
||||
<input type="checkbox" class="mr5 magic-checkbox" name="webssh" value="1" id="webssh_filter">
|
||||
<label style="top:2px;padding-left:23px;" for="webssh_filter"><span class="only_view">只看可ssh</span></label>
|
||||
</span>
|
||||
<span class="fl ml20 shixun_webssh">
|
||||
<input type="checkbox" class="mr5 magic-checkbox" name="hidden" value="1" id="hidden_filter">
|
||||
<label style="top:2px;padding-left:23px;" for="hidden_filter"><span class="only_view">只看已隐藏</span></label>
|
||||
</span>
|
||||
<span class="fl ml20 shixun_webssh">
|
||||
<input type="checkbox" class="mr5 magic-checkbox" name="homepage_show" value="1" id="homepage_show_filter">
|
||||
<label style="top:2px;padding-left:23px;" for="homepage_show_filter"><span class="only_view">只看首页显示</span></label>
|
||||
</span>
|
||||
<span class="fl ml20 shixun_webssh">
|
||||
<input type="checkbox" class="mr5 magic-checkbox" name="task_pass" value="1" id="task_pass_filter">
|
||||
<label style="top:2px;padding-left:23px;" for="task_pass_filter"><span class="only_view">只看可跳关</span></label>
|
||||
</span>
|
||||
<span class="fl ml20 shixun_webssh">
|
||||
<input type="checkbox" class="mr5 magic-checkbox" name="code_hidden" value="1" id="code_hidden_filter">
|
||||
<label style="top:2px;padding-left:23px;" for="code_hidden_filter"><span class="only_view">只看已隐藏文件目录</span></label>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="box shixun-settings-list-container">
|
||||
<%= render partial: 'admins/shixun_settings/shared/list', locals: { shixuns: @shixuns } %>
|
||||
</div>
|
||||
|
@ -0,0 +1 @@
|
||||
$(".shixun-settings-list-container").html(<%= j render "admins/shixun_settings/shared/list",locals:{shixuns:@shixuns} %>)
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Loading…
Reference in new issue