Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun
commit
289766cbd8
@ -0,0 +1,4 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
if ($('body.admins-schools-index-page').length > 0) {
|
||||
}
|
||||
});
|
@ -0,0 +1,3 @@
|
||||
.admins-schools-index-page {
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
class Admins::SchoolsController < Admins::BaseController
|
||||
def index
|
||||
params[:sort_by] ||= 'created_at'
|
||||
params[:sort_direction] ||= 'desc'
|
||||
|
||||
schools = Admins::SchoolQuery.call(params)
|
||||
|
||||
@schools = paginate schools
|
||||
|
||||
school_ids = @schools.map(&:id)
|
||||
@department_count = Department.where(school_id: school_ids).group(:school_id).count
|
||||
end
|
||||
|
||||
def destroy
|
||||
users = User.joins(:user_extension).where(user_extensions: { school_id: current_school.id })
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
users.update_all(profile_completed: false)
|
||||
current_school.destroy!
|
||||
end
|
||||
|
||||
render_delete_success
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def current_school
|
||||
@_current_school ||= School.find(params[:id])
|
||||
end
|
||||
end
|
@ -0,0 +1,23 @@
|
||||
class Admins::SchoolQuery < ApplicationQuery
|
||||
include CustomSortable
|
||||
|
||||
attr_reader :params
|
||||
|
||||
sort_columns :users_count, :created_at, default_by: :created_at, default_direction: :desc
|
||||
|
||||
def initialize(params)
|
||||
@params = params
|
||||
end
|
||||
|
||||
def call
|
||||
schools = School.all
|
||||
|
||||
keyword = strip_param(:keyword)
|
||||
schools = schools.where('schools.name LIKE ?', "%#{keyword}%") if keyword
|
||||
|
||||
schools = schools.joins(:user_extensions).group(:id)
|
||||
schools = schools.select('schools.*, COUNT(*) AS users_count')
|
||||
|
||||
custom_sort schools, params[:sort_by], params[:sort_direction]
|
||||
end
|
||||
end
|
@ -0,0 +1,16 @@
|
||||
<% define_admin_breadcrumbs do %>
|
||||
<% add_admin_breadcrumb('单位列表') %>
|
||||
<% end %>
|
||||
|
||||
<div class="box search-form-container school-list-form">
|
||||
<%= form_tag(admins_schools_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %>
|
||||
<%= text_field_tag(:keyword, params[:keyword], class: 'form-control col-sm-2 ml-3', placeholder: '部门名称检索') %>
|
||||
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
|
||||
<% end %>
|
||||
|
||||
<%#= javascript_void_link '新建单位', class: 'btn btn-primary', data: { toggle: 'modal', target: '.admin-create-school-modal' } %>
|
||||
</div>
|
||||
|
||||
<div class="box school-list-container">
|
||||
<%= render partial: 'admins/schools/shared/list', locals: { schools: @schools } %>
|
||||
</div>
|
@ -0,0 +1 @@
|
||||
$('.school-list-container').html("<%= j(render partial: 'admins/schools/shared/list', locals: { schools: @schools }) %>");
|
@ -0,0 +1,48 @@
|
||||
<table class="table table-hover text-center school-list-table">
|
||||
<thead class="thead-light">
|
||||
<tr>
|
||||
<th width="6%">ID</th>
|
||||
<th width="6%">LOGO</th>
|
||||
<th width="8%">标识码</th>
|
||||
<th width="14%" class="text-left">单位名称</th>
|
||||
<th width="6%">地区</th>
|
||||
<th width="6%">城市</th>
|
||||
<th width="16%">详细地址</th>
|
||||
<th width="6%"><%= sort_tag('用户数', name: 'users_count', path: admins_schools_path) %></th>
|
||||
<th width="6%">部门数</th>
|
||||
<th width="12%"><%= sort_tag('创建时间', name: 'created_at', path: admins_schools_path) %></th>
|
||||
<th width="14%">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% if schools.present? %>
|
||||
<% schools.each do |school| %>
|
||||
<tr class="school-item-<%= school.id %>">
|
||||
<td><%= school.id %></td>
|
||||
<td>
|
||||
<% if Util::FileManage.exists?(school) %>
|
||||
<%= image_tag(Util::FileManage.source_disk_file_url(school).to_s + "?#{Time.now.to_i}", width: 40, height: 40, class: 'preview-image') %>
|
||||
<% else %>
|
||||
<%= content_tag(:span, '--', class: 'text-secondary') %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td><%= display_text school.identifier %></td>
|
||||
<td class="text-left"><%= school.name %></td>
|
||||
<td><%= school.province %></td>
|
||||
<td><%= school.city %></td>
|
||||
<td class="text-left"><%= school.address %></td>
|
||||
<td><%= school.users_count %></td>
|
||||
<td><%= @department_count.fetch(school.id, 0) %></td>
|
||||
<td><%= school.created_at&.strftime('%Y-%m-%d %H:%M') %></td>
|
||||
<td>
|
||||
<%= delete_link '删除', admins_school_path(school, element: ".school-item-#{school.id}"), class: 'delete-school-action' %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= render 'admins/shared/no_data_for_table' %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%= render partial: 'admins/shared/paginate', locals: { objects: schools } %>
|
Loading…
Reference in new issue