parent
e17c0ef42a
commit
080d18ce30
@ -0,0 +1,14 @@
|
||||
class Admins::MyshixunsController < Admins::BaseController
|
||||
def index
|
||||
params[:sort_by] = params[:sort_by].presence || 'created_at'
|
||||
params[:sort_direction] = params[:sort_direction].presence || 'desc'
|
||||
|
||||
myshixuns = Admins::MyshixunQuery.call(params)
|
||||
|
||||
@myshixuns = paginate myshixuns.includes(:last_executable_task, :last_task, shixun: :user, user: { user_extension: :school })
|
||||
|
||||
myshixun_ids = @myshixuns.map(&:id)
|
||||
@finish_game_count = Game.where(myshixun_id: myshixun_ids, status: 2).group(:myshixun_id).count
|
||||
@total_score = Game.where(myshixun_id: myshixun_ids, status: 2).where('final_score > 0').group(:myshixun_id).sum(:final_score)
|
||||
end
|
||||
end
|
@ -0,0 +1,26 @@
|
||||
class Admins::MyshixunQuery < 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
|
||||
objs = Myshixun.all
|
||||
|
||||
keyword = params[:keyword].to_s.strip
|
||||
if keyword.present?
|
||||
like_sql = 'users.login LIKE :keyword OR CONCAT(users.lastname, users.firstname) LIKE :keyword OR '\
|
||||
'schools.name LIKE :keyword OR shixuns.name LIKE :keyword OR CONCAT(teacher.lastname, teacher.firstname) Like :keyword'
|
||||
objs = objs.joins(:shixun, user: { user_extension: :school })
|
||||
.joins('JOIN users teacher ON teacher.id = shixuns.user_id')
|
||||
.where(like_sql, keyword: "%#{keyword}%")
|
||||
end
|
||||
|
||||
custom_sort(objs, params[:sort_by], params[:sort_direction])
|
||||
end
|
||||
end
|
@ -0,0 +1,14 @@
|
||||
<% define_admin_breadcrumbs do %>
|
||||
<% add_admin_breadcrumb('学员实训列表') %>
|
||||
<% end %>
|
||||
|
||||
<div class="box search-form-container myshixun-list-form">
|
||||
<%= form_tag(admins_myshixuns_path, method: :get, class: 'form-inline search-form', remote: true) do %>
|
||||
<%= text_field_tag(:keyword, params[:keyword], class: 'form-control col-md-4 ml-3', placeholder: '学员UID/姓名/学校/实训名称/老师姓名检索') %>
|
||||
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="box myshixun-list-container">
|
||||
<%= render(partial: 'admins/myshixuns/shared/list', locals: { myshixuns: @myshixuns, finish_game_count: @finish_game_count, total_score: @total_score }) %>
|
||||
</div>
|
@ -0,0 +1 @@
|
||||
$('.myshixun-list-container').html("<%= j( render(partial: 'admins/myshixuns/shared/list', locals: { myshixuns: @myshixuns, finish_game_count: @finish_game_count, total_score: @total_score }) ) %>");
|
@ -0,0 +1,49 @@
|
||||
<table class="table table-hover text-center myshixun-list-table">
|
||||
<thead class="thead-light">
|
||||
<tr>
|
||||
<th width="6%">ID</th>
|
||||
<th width="10%">标识</th>
|
||||
<th width="22%" class="text-left">实训名称</th>
|
||||
<th width="10%">实训老师</th>
|
||||
<th width="6%">完成</th>
|
||||
<th width="6%">经验值</th>
|
||||
<th width="10%">学员姓名</th>
|
||||
<th width="16%" class="text-left">学员单位</th>
|
||||
<th width="14%"><%= sort_tag('开启时间', name: 'created_at', path: admins_myshixuns_path) %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% if myshixuns.present? %>
|
||||
<% myshixuns.each do |myshixun| %>
|
||||
<tr class="myshixun-item-<%= myshixun.id %>">
|
||||
<td><%= myshixun.id %></td>
|
||||
<td>
|
||||
<% current_task = myshixun.last_executable_task || myshixun.last_task %>
|
||||
<%= link_to "/myshixuns/#{myshixun.identifier}/stages/#{current_task.identifier}", target: '_blank' do %>
|
||||
<%= myshixun.identifier %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td class="text-left">
|
||||
<%= link_to "/shixuns/#{myshixun.shixun.identifier}", target: '_blank' do %>
|
||||
<%= overflow_hidden_span myshixun.shixun.name, width: 280 %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td><%= myshixun.shixun.user.real_name %></td>
|
||||
<td><%= finish_game_count.fetch(myshixun.id, 0) %>/<%= myshixun.shixun.challenges_count %></td>
|
||||
<td><%= total_score.fetch(myshixun.id, 0) %></td>
|
||||
<td>
|
||||
<%= link_to "/users/#{myshixun.user.login}", target: '_blank' do %>
|
||||
<%= overflow_hidden_span myshixun.user.real_name, width: 80 %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td class="text-left"><%= overflow_hidden_span myshixun.user&.school_name, width: 150 %></td>
|
||||
<td><%= myshixun.created_at&.strftime('%Y-%m-%d %H:%M') %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= render 'admins/shared/no_data_for_table' %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%= render partial: 'admins/shared/paginate', locals: { objects: myshixuns } %>
|
Loading…
Reference in new issue