add library_apply

dev_aliyun_beta
SylorHuang 6 years ago
parent 2f8d34792e
commit 13c8208565

@ -0,0 +1,21 @@
$(document).on('turbolinks:load', function() {
if ($('body.admins-library-applies-index-page').length > 0) {
var $searchFrom = $('.library-applies-list-form');
$searchFrom.find('select[name="status"]').val('pending');
$searchFrom.on('click', '.search-form-tab', function(){
var $link = $(this);
$searchFrom.find('input[name="keyword"]').val('');
$searchFrom.find('select[name="status"]').val('processed');
if($link.data('value') === 'processed'){
$searchFrom.find('.status-filter').show();
} else {
$searchFrom.find('.status-filter').hide();
$searchFrom.find('select[name="status"]').val('pending');
}
});
}
})

@ -0,0 +1,9 @@
.admins-library-applies-index-page {
.library-applies-list-container {
span {
&.apply-status-agreed { color: #28a745; }
&.apply-status-refused { color: #dc3545; }
&.apply-status-processed { color: #6c757d; }
}
}
}

@ -0,0 +1,26 @@
class Admins::LibraryAppliesController < Admins::BaseController
def index
params[:status] ||= 'pending'
@apply_status = params[:status] || ""
applies = Admins::LibraryApplyQuery.call(params)
@library_applies = paginate applies.preload(library: :user)
end
def agree
Libraries::AgreeApplyService.new(current_library_apply, current_user).call
render_success_js
end
def refuse
Libraries::RefuseApplyService.new(current_library_apply, current_user, reason: params[:reason]).call
render_success_js
end
private
def current_library_apply
@_current_library_apply ||= LibraryApply.find(params[:id])
end
end

@ -16,4 +16,8 @@ class LibraryApply < ApplicationRecord
transitions from: :pending, to: :agreed
end
end
def status_i18n
end
end

@ -0,0 +1,29 @@
class Admins::LibraryApplyQuery < ApplicationQuery
include CustomSortable
attr_reader :params
sort_columns :updated_at, default_by: :updated_at, default_direction: :desc
def initialize(params)
@params = params
end
def call
status =
case params[:status]
when 'processed' then %w(agreed refused)
else params[:status]
end
applies = LibraryApply.where(status: status) if status.present?
# 关键字模糊查询
keyword = params[:keyword].to_s.strip
if keyword.present?
applies = applies.joins(:library)
.where('title LIKE :keyword OR uuid LIKE :keyword', keyword: "%#{keyword}%")
end
custom_sort(applies, params[:sort_by], params[:sort_direction])
end
end

@ -0,0 +1,32 @@
<% define_admin_breadcrumbs do %>
<% add_admin_breadcrumb('教学案例发布') %>
<% end %>
<div class="box search-form-container flex-column mb-0 pb-0 library-applies-list-form">
<ul class="nav nav-tabs w-100 search-form-tabs">
<li class="nav-item">
<%= link_to '待审批', admins_library_applies_path(status: :pending), remote: true, 'data-value': 'pending',
class: "nav-link search-form-tab #{params[:status] == 'pending' ? 'active' : ''}" %>
</li>
<li class="nav-item">
<%= link_to '已审批', admins_library_applies_path(status: :processed), remote: true, 'data-value': 'processed',
class: "nav-link search-form-tab #{params[:status] != 'pending' ? 'active' : ''}" %>
</li>
</ul>
<%= form_tag(admins_library_applies_path(unsafe_params), method: :get, class: 'form-inline search-form justify-content-end mt-3', remote: true) do %>
<div class="form-group status-filter" style="<%= params[:status] != 'pending' ? '' : 'display: none;' %>">
<label for="status">审核状态:</label>
<% status_options = [['全部', 'processed'], ['已同意', 'agreed'], ['已拒绝', 'refused']] %>
<%= select_tag(:status, options_for_select(status_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') %>
<% end %>
</div>
<div class="box library-applies-list-container">
<%= render(partial: 'admins/library_applies/shared/list', locals: { applies: @library_applies }) %>
</div>
<%= render(partial: 'admins/shared/admin_common_refuse_modal') %>

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

@ -0,0 +1,56 @@
<% is_processed = params[:status].to_s != 'pending' %>
<table class="table table-hover text-center library_applies-list-table">
<thead class="thead-light">
<tr>
<th width="8%">头像</th>
<th width="14%">姓名</th>
<th width="26%" class="text-left">教学案例</th>
<th width="26%" class="text-left">案例描述</th>
<th width="16%">时间</th>
<% if is_processed %>
<th width="16%">拒绝原因</th>
<th width="8%">状态</th>
<% else %>
<th width="20%">操作</th>
<% end %>
</tr>
</thead>
<tbody>
<% if applies.present? %>
<% applies.each do |apply| %>
<% user = apply.library.user %>
<% library = apply.library %>
<tr class="library_applies-item library_applies-<%= apply.id %>">
<td>
<%= link_to "/users/#{user.login}", class: 'professional-authentication-avatar', target: '_blank', data: { toggle: 'tooltip', title: '个人主页' } do %>
<img src="/images/<%= url_to_avatar(user) %>" class="rounded-circle" width="40" height="40" />
<% end %>
</td>
<td><%= user.real_name %></td>
<td class="text-left"><%= link_to library.title, library_path(library), :target => "_blank" %></td>
<td class="text-left"><%= overflow_hidden_span library.content[0..50] + "..."%></td>
<td><%= apply.updated_at.strftime('%Y-%m-%d %H:%M') %></td>
<% if is_processed %>
<td class="text-secondary"><%= overflow_hidden_span apply.reason %></td>
<td><span class="apply-status-<%= apply.status %>"><%= t("library_apply.status.#{apply.status}") %></span></td>
<% else %>
<td class="action-container">
<%= agree_link '同意', agree_admins_library_apply_path(apply, element: ".library_applies-#{apply.id}"), 'data-confirm': '确认审核通过?' %>
<%= javascript_void_link('拒绝', class: 'action refuse-action',
data: {
toggle: 'modal', target: '.admin-common-refuse-modal', id: apply.id,
url: refuse_admins_library_apply_path(apply, element: ".library_applies-#{apply.id}")
}) %>
</td>
<% end %>
</tr>
<% end %>
<% else %>
<%= render 'admins/shared/no_data_for_table' %>
<% end %>
</tbody>
</table>
<%= render partial: 'admins/shared/paginate', locals: { objects: applies } %>

@ -42,7 +42,8 @@
<li><%= sidebar_item(admins_identity_authentications_path, '实名认证', icon: 'id-card-o', controller: 'admins-identity_authentications') %></li>
<li><%= sidebar_item(admins_professional_authentications_path, '职业认证', icon: 'drivers-license', controller: 'admins-professional_authentications') %></li>
<li><%= sidebar_item(admins_shixun_authorizations_path, '实训发布', icon: 'object-ungroup', controller: 'admins-shixun_authorizations') %></li>
<li><%= sidebar_item(admins_subject_authorizations_path, '实践课程发布', icon: 'object-group', controller: 'admins-subject_authorizations') %></li>
<li><%= sidebar_item(admins_subject_authorizations_path, '实践课程发布', icon: 'object-group', controller: 'admins-subject_authorizations') %></li>
<li><%= sidebar_item(admins_library_applies_path, '教学案例发布', icon: 'language', controller: 'admins-library_applies') %></li>
<% end %>
</li>

@ -0,0 +1,7 @@
zh-CN:
library_apply:
status:
'pending': '待审批'
'processed': '已审批'
'refused': '已拒绝'
'agreed': '已同意'

@ -762,6 +762,12 @@ Rails.application.routes.draw do
end
end
resources :library_applies, only: [:index] do
member do
post :agree
post :refuse
end
end
resources :identity_authentications, only: [:index] do
member do
post :agree

Loading…
Cancel
Save