orgs search
This commit is contained in:
parent
9a92a8c58c
commit
9aef00ce06
|
@ -2,7 +2,11 @@ class Admins::OrganizationsController < Admins::BaseController
|
|||
before_action :finder_org, except: [:index]
|
||||
|
||||
def index
|
||||
@orgs = paginate Organization.all
|
||||
params[:sort_by] = params[:sort_by].presence || 'created_on'
|
||||
params[:sort_direction] = params[:sort_direction].presence || 'desc'
|
||||
|
||||
orgs = Admins::OrganizationQuery.call(params)
|
||||
@orgs = paginate orgs
|
||||
end
|
||||
|
||||
def show
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
class Admins::OrganizationQuery < ApplicationQuery
|
||||
include CustomSortable
|
||||
attr_reader :params
|
||||
sort_columns :created_on, :last_login_on, :experience, :grade, default_by: :created_on, default_direction: :desc
|
||||
|
||||
def initialize(params)
|
||||
@params = params
|
||||
end
|
||||
|
||||
def call
|
||||
orgs = Organization.all
|
||||
# 关键字检索
|
||||
keyword = params[:keyword].to_s.strip.presence
|
||||
if keyword
|
||||
sql = 'nickname LIKE :keyword OR login LIKE :keyword'
|
||||
orgs = orgs.where(sql, keyword: "%#{keyword}%")
|
||||
end
|
||||
|
||||
custom_sort(orgs, params[:sort_by], params[:sort_direction])
|
||||
end
|
||||
end
|
|
@ -1,6 +1,15 @@
|
|||
<% define_admin_breadcrumbs do %>
|
||||
<% add_admin_breadcrumb('组织管理', admins_organizations_path) %>
|
||||
<% end %>
|
||||
<div class="box search-form-container user-list-form">
|
||||
<%= form_tag(admins_organizations_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: 'login/昵称') %>
|
||||
|
||||
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="box admin-list-container organizations-list-container">
|
||||
<%= render partial: 'admins/organizations/shared/org_list', locals: { organizations: @orgs } %>
|
||||
|
|
|
@ -1 +1 @@
|
|||
$('.users-list-container').html("<%= j( render partial: 'admins/organizations/shared/org_list', locals: { organizations: @orgs } ) %>");
|
||||
$('.organizations-list-container').html("<%= j( render partial: 'admins/organizations/shared/org_list', locals: { organizations: @orgs } ) %>");
|
|
@ -2,6 +2,7 @@
|
|||
<thead class="thead-light">
|
||||
<tr>
|
||||
<th width="4%">序号</th>
|
||||
<th width="4%">ID</th>
|
||||
<th width="8%" class="text-left">login</th>
|
||||
<th width="8%" class="text-left">昵称</th>
|
||||
<th width="10%"><%= sort_tag('创建于', name: 'created_on', path: admins_organizations_path) %></th>
|
||||
|
@ -15,6 +16,7 @@
|
|||
<% organizations.each_with_index do |org, index| %>
|
||||
<tr class="org-item-<%= org.id %>">
|
||||
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
|
||||
<td><%= org.id %></td>
|
||||
<td class="text-left">
|
||||
<%= link_to "/#{org.login}", target: '_blank' do %>
|
||||
<%= overflow_hidden_span org.login, width: 100 %>
|
||||
|
|
Loading…
Reference in New Issue