Merge branch 'develop' into dev_aliyun

dev_home
p31729568 5 years ago
commit 7c721e5915

@ -16,7 +16,7 @@ $(document).on('turbolinks:load', function() {
minimumInputLength: 1,
ajax: {
delay: 500,
url: '/cooperative/users',
url: '/cooperative/users/for_select',
dataType: 'json',
data: function(params){
return { name: params.term };

@ -1,7 +1,13 @@
class Cooperative::UsersController < Cooperative::BaseController
def index
params[:sort_by] = params[:sort_by].presence || 'created_on'
params[:sort_direction] = params[:sort_direction].presence || 'desc'
default_sort('created_on', 'desc')
users = Admins::UserQuery.call(search_params.merge(laboratory_id: current_laboratory.id))
@users = paginate users.includes(user_extension: :school)
end
def for_select
default_sort('created_on', 'desc')
users = Admins::UserQuery.call(search_params)
@users = paginate users.includes(user_extension: :school)
@ -10,6 +16,6 @@ class Cooperative::UsersController < Cooperative::BaseController
private
def search_params
params.permit(:name, :sort_by, :sort_direction)
params.permit(:identity, :name, :keyword, :school_name, :sort_by, :sort_direction)
end
end

@ -7,7 +7,7 @@ class LibrariesController < ApplicationController
helper_method :current_library, :library_manageable?
def index
libraries = Library.all
libraries = current_laboratory.libraries
libraries =
if User.current&.logged? && params[:type] == 'mine'

@ -5,7 +5,7 @@ class CourseActivity < ApplicationRecord
belongs_to :exercise
belongs_to :poll
after_create :add_course_lead
# after_create :add_course_lead
# 发布新课导语
# 导语要放置在课程创建信息之后

@ -16,6 +16,7 @@ class Laboratory < ApplicationRecord
has_many :courses, dependent: :destroy
has_many :competitions, dependent: :destroy
has_many :libraries, dependent: :destroy
validates :identifier, uniqueness: { case_sensitive: false }, allow_nil: true

@ -3,6 +3,7 @@ class Library < ApplicationRecord
belongs_to :user
belongs_to :cover, class_name: 'Attachment', foreign_key: :cover_id, optional: true
belongs_to :laboratory, optional: true
has_many :library_applies, dependent: :delete_all
has_many :library_library_tags, dependent: :delete_all
@ -34,6 +35,13 @@ class Library < ApplicationRecord
end
end
before_save :set_laboratory
private def set_laboratory
return unless new_record?
self.laboratory = Laboratory.current if laboratory_id.blank?
end
def increment_visited_count!(num = 1)
increment_column!(:visited_count, num)
end

@ -13,6 +13,7 @@ module Searchable::Course
def search_data
{
laboratory_id: laboratory_id,
name: name,
author_name: teacher&.real_name
}

@ -30,6 +30,8 @@ class User < ApplicationRecord
LOGIN_CHARS = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z).freeze
belongs_to :laboratory, optional: true
has_one :user_extension, dependent: :destroy
has_many :open_users, dependent: :destroy
has_one :wechat_open_user, class_name: 'OpenUsers::Wechat'
@ -155,7 +157,7 @@ class User < ApplicationRecord
delegate :gender, :department_id, :school_id, :location, :location_city, :technical_title, to: :user_extension, allow_nil: true
before_save :update_hashed_password
before_save :update_hashed_password, :set_laboratory
after_create do
SyncTrustieJob.perform_later("user", 1) if allow_sync_to_trustie?
end
@ -704,6 +706,12 @@ class User < ApplicationRecord
raise('密码长度不能超过16位')
end
end
def set_laboratory
return unless new_record?
self.laboratory = Laboratory.current if laboratory_id.blank?
end
end

@ -6,7 +6,17 @@ class UserExtension < ApplicationRecord
belongs_to :school, optional: true
belongs_to :department, optional: true
before_save :set_laboratory_school
def identity_text
I18n.t("user.identity.#{identity}")
end
private
def set_laboratory_school
return unless new_record?
self.school_id = Laboratory.current.school_id if school_id.blank? && !Laboratory.current.main_site?
end
end

@ -12,6 +12,9 @@ class Admins::UserQuery < ApplicationQuery
def call
users = User.where(type: 'User')
# 云上实验室
users = users.where(laboratory_id: params[:laboratory_id]) if params[:laboratory_id].present?
# 状态
status = params[:status]
users = users.where(status: status) if status.present?

@ -8,34 +8,47 @@ class SearchService < ApplicationService
end
def call
Searchkick.search(keyword, search_options)
# return [] if keyword.blank?
modal_name.search(keyword, search_options)
end
private
def modal_name
@_modal_name ||=
case params[:type].to_s.strip
when 'shixun' then Shixun
when 'course' then Course
when 'subject' then Subject
when 'memo' then Memo
else Shixun
end
end
def search_options
model_options = {
index_name: index_names,
model_includes: model_includes
includes: modal_name.searchable_includes
}
model_options.merge(where: { status: 2 }) if index_names == [Shixun]
model_options.merge(default_options)
end
model_options.deep_merge!(where: { status: 2 }) if modal_name == Shixun
model_options.deep_merge!(extra_options)
def index_names
@_index_names ||=
case params[:type].to_s.strip
when 'shixun' then [Shixun]
when 'course' then [Course]
when 'subject' then [Subject]
when 'memo' then [Memo]
else [Shixun, Course, Subject, Memo]
end
model_options.deep_merge!(default_options)
model_options
end
def model_includes
index_names.each_with_object({}) do |klass, obj|
obj[klass] = klass.searchable_includes
def extra_options
case params[:type].to_s.strip
when 'shixun' then
shixun_ids = Laboratory.current.shixuns.pluck(:id)
Laboratory.current.main_site? ? {} : { where: { id: shixun_ids } }
when 'subject' then
subject_ids = Laboratory.current.subjects.pluck(:id)
Laboratory.current.main_site? ? {} : { where: { id: subject_ids } }
when 'course' then
{ where: { laboratory_id: Laboratory.current.id } }
else
{}
end
end
end

@ -17,6 +17,7 @@
<li><%= sidebar_item(edit_cooperative_laboratory_setting_path, '网站设置', icon: 'cogs', controller: 'cooperative-laboratory_settings') %></li>
<li><%= sidebar_item(cooperative_carousels_path, '轮播图设置', icon: 'image', controller: 'cooperative-carousels') %></li>
<li><%= sidebar_item(cooperative_laboratory_users_path, '管理员列表', icon: 'user', controller: 'cooperative-laboratory_users') %></li>
<li><%= sidebar_item(cooperative_users_path, '用户列表', icon: 'users', controller: 'cooperative-users') %></li>
<li><%= sidebar_item(cooperative_laboratory_shixuns_path, '实训项目', icon: 'window-restore', controller: 'cooperative-laboratory_shixuns') %></li>
<li><%= sidebar_item(cooperative_laboratory_subjects_path, '实践课程', icon: 'th-list', controller: 'cooperative-laboratory_subjects') %></li>
<li><%= sidebar_item('/', '返回主页', icon: 'sign-out', controller: 'root') %></li>

@ -0,0 +1,6 @@
json.count @users.total_count
json.users do
json.array! @users.each do |user|
json.extract! user, :id, :login, :real_name, :identity, :school_name, :hidden_phone
end
end

@ -0,0 +1,21 @@
<% define_breadcrumbs do %>
<% add_breadcrumb('用户列表') %>
<% end %>
<div class="box search-form-container user-list-form">
<%= form_tag(cooperative_users_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %>
<div class="form-group mr-2">
<label for="identity">职业:</label>
<% identity_options = [['全部', ''], ['教师', 0], ['学生', 1], ['专业人士', 2]] %>
<%= select_tag(:identity, options_for_select(identity_options), class: 'form-control') %>
</div>
<%= text_field_tag(:keyword, params[:keyword], class: 'form-control col-sm-2 ml-3', placeholder: 'ID/姓名/邮箱/手机号检索') %>
<%= text_field_tag(:school_name, params[:school_name], class: 'form-control col-sm-2', placeholder: '学校/单位检索') %>
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
<% end %>
</div>
<div class="box cooperative-list-container user-list-container">
<%= render partial: 'cooperative/users/shared/list', locals: { users: @users } %>
</div>

@ -0,0 +1 @@
$('.user-list-container').html("<%= j(render partial: 'cooperative/users/shared/list', locals: { users: @users }) %>");

@ -0,0 +1,40 @@
<table class="table table-hover user-list-table">
<thead class="thead-light">
<tr>
<th width="10%" class="text-left">真实姓名</th>
<th width="16%">邮件地址</th>
<th width="10%">手机号码</th>
<th width="18%">单位</th>
<th width="10%">角色</th>
<th width="14%"><%= sort_tag('创建于', name: 'created_on', path: cooperative_users_path) %></th>
<th width="14%"><%= sort_tag('最后登录', name: 'last_login_on', path: cooperative_users_path) %></th>
<th width="6%"><%= sort_tag('经验值', name: 'experience', path: cooperative_users_path) %></th>
<th width="6%"><%= sort_tag('金币', name: 'grade', path: cooperative_users_path) %></th>
</tr>
</thead>
<tbody>
<% if users.present? %>
<% users.each do |user| %>
<tr class="user-item-<%= user.id %>">
<td class="text-left">
<%= link_to "/users/#{user.login}", target: '_blank' do %>
<%= overflow_hidden_span user.real_name, width: 100 %>
<% end %>
</td>
<td><%= overflow_hidden_span display_text(user.mail), width: 150 %></td>
<td><%= overflow_hidden_span display_text(user.phone), width: 100 %></td>
<td><%= overflow_hidden_span display_text(user.school_name), width: 150 %></td>
<td><%= user.identity %></td>
<td><%= display_text(user.created_on&.strftime('%Y-%m-%d %H:%M')) %></td>
<td><%= display_text(user.last_login_on&.strftime('%Y-%m-%d %H:%M')) %></td>
<td><%= user.experience.to_i %></td>
<td class="grade-content"><%= user.grade.to_i %></td>
</tr>
<% end %>
<% else %>
<%= render 'admins/shared/no_data_for_table' %>
<% end %>
</tbody>
</table>
<%= render partial: 'cooperative/shared/paginate', locals: { objects: users } %>

@ -1135,7 +1135,9 @@ Rails.application.routes.draw do
# get '/', to: 'dashboards#show'
get '/', to: 'laboratory_settings#edit'
resources :files, only: [:create]
resources :users, only: [:index]
resources :users, only: [:index] do
get :for_select, on: :collection
end
resources :laboratory_users, only: [:index, :create, :destroy]
resource :laboratory_setting, only: [:edit, :update]
resources :carousels, only: [:index, :create, :update, :destroy] do

@ -0,0 +1,5 @@
class AddLaboratoryIdToUsers < ActiveRecord::Migration[5.2]
def change
add_reference :users, :laboratory
end
end

@ -0,0 +1,5 @@
class AddLaboratoryIdToLibraries < ActiveRecord::Migration[5.2]
def change
add_reference :libraries, :laboratory
end
end

@ -0,0 +1,7 @@
class TransferLaboratoryData < ActiveRecord::Migration[5.2]
def change
Course.where(laboratory_id: nil).update_all(laboratory_id: 1)
Competition.where(laboratory_id: nil).update_all(laboratory_id: 1)
Library.where(laboratory_id: nil).update_all(laboratory_id: 1)
end
end

File diff suppressed because one or more lines are too long

@ -136218,7 +136218,7 @@ $(document).on('turbolinks:load', function() {
minimumInputLength: 1,
ajax: {
delay: 500,
url: '/cooperative/users',
url: '/cooperative/users/for_select',
dataType: 'json',
data: function(params){
return { name: params.term };
Loading…
Cancel
Save