diff --git a/app/assets/javascripts/admins/library_applies/index.js b/app/assets/javascripts/admins/library_applies/index.js new file mode 100644 index 000000000..ce890d4fb --- /dev/null +++ b/app/assets/javascripts/admins/library_applies/index.js @@ -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'); + } + }); + + } +}) \ No newline at end of file diff --git a/app/assets/stylesheets/admins/library_applies.scss b/app/assets/stylesheets/admins/library_applies.scss new file mode 100644 index 000000000..23b7ce30a --- /dev/null +++ b/app/assets/stylesheets/admins/library_applies.scss @@ -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; } + } + } +} \ No newline at end of file diff --git a/app/controllers/admins/library_applies_controller.rb b/app/controllers/admins/library_applies_controller.rb new file mode 100644 index 000000000..f038021cd --- /dev/null +++ b/app/controllers/admins/library_applies_controller.rb @@ -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 \ No newline at end of file diff --git a/app/models/library_apply.rb b/app/models/library_apply.rb index 0a7ec8aec..85944169b 100644 --- a/app/models/library_apply.rb +++ b/app/models/library_apply.rb @@ -16,4 +16,8 @@ class LibraryApply < ApplicationRecord transitions from: :pending, to: :agreed end end + + def status_i18n + + end end \ No newline at end of file diff --git a/app/queries/admins/library_apply_query.rb b/app/queries/admins/library_apply_query.rb new file mode 100644 index 000000000..9fdc2d067 --- /dev/null +++ b/app/queries/admins/library_apply_query.rb @@ -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 \ No newline at end of file diff --git a/app/views/admins/library_applies/index.html.erb b/app/views/admins/library_applies/index.html.erb new file mode 100644 index 000000000..55a7e9e09 --- /dev/null +++ b/app/views/admins/library_applies/index.html.erb @@ -0,0 +1,32 @@ +<% define_admin_breadcrumbs do %> + <% add_admin_breadcrumb('教学案例发布') %> +<% end %> + +
+ + + <%= form_tag(admins_library_applies_path(unsafe_params), method: :get, class: 'form-inline search-form justify-content-end mt-3', remote: true) do %> +
+ + <% status_options = [['全部', 'processed'], ['已同意', 'agreed'], ['已拒绝', 'refused']] %> + <%= select_tag(:status, options_for_select(status_options) ,class: 'form-control') %> +
+ <%= text_field_tag(:keyword, params[:keyword], class: 'form-control col-sm-2 ml-3', placeholder: '编号/名称检索') %> + <%= submit_tag('搜索', class: 'btn btn-primary ml-3') %> + <% end %> +
+ +
+ <%= render(partial: 'admins/library_applies/shared/list', locals: { applies: @library_applies }) %> +
+ +<%= render(partial: 'admins/shared/admin_common_refuse_modal') %> \ No newline at end of file diff --git a/app/views/admins/library_applies/index.js.erb b/app/views/admins/library_applies/index.js.erb new file mode 100644 index 000000000..6f4c3e712 --- /dev/null +++ b/app/views/admins/library_applies/index.js.erb @@ -0,0 +1 @@ +$('.library-applies-list-container').html("<%= j( render partial: 'admins/library_applies/shared/list', locals: { applies: @library_applies } ) %>"); \ No newline at end of file diff --git a/app/views/admins/library_applies/shared/_list.html.erb b/app/views/admins/library_applies/shared/_list.html.erb new file mode 100644 index 000000000..4aa853ca6 --- /dev/null +++ b/app/views/admins/library_applies/shared/_list.html.erb @@ -0,0 +1,56 @@ +<% is_processed = params[:status].to_s != 'pending' %> + + + + + + + + + + <% if is_processed %> + + + <% else %> + + <% end %> + + + + <% if applies.present? %> + <% applies.each do |apply| %> + <% user = apply.library.user %> + <% library = apply.library %> + + + + + + + + <% if is_processed %> + + + <% else %> + + <% end %> + + <% end %> + <% else %> + <%= render 'admins/shared/no_data_for_table' %> + <% end %> + +
头像姓名教学案例案例描述时间拒绝原因状态操作
+ <%= link_to "/users/#{user.login}", class: 'professional-authentication-avatar', target: '_blank', data: { toggle: 'tooltip', title: '个人主页' } do %> + + <% end %> + <%= user.real_name %><%= link_to library.title, library_path(library), :target => "_blank" %><%= overflow_hidden_span library.content[0..50] + "..."%><%= apply.updated_at.strftime('%Y-%m-%d %H:%M') %><%= overflow_hidden_span apply.reason %><%= t("library_apply.status.#{apply.status}") %> + <%= 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}") + }) %> +
+ +<%= render partial: 'admins/shared/paginate', locals: { objects: applies } %> \ No newline at end of file diff --git a/app/views/admins/shared/_sidebar.html.erb b/app/views/admins/shared/_sidebar.html.erb index ab30e8bd3..8135c647c 100644 --- a/app/views/admins/shared/_sidebar.html.erb +++ b/app/views/admins/shared/_sidebar.html.erb @@ -42,7 +42,8 @@
  • <%= sidebar_item(admins_identity_authentications_path, '实名认证', icon: 'id-card-o', controller: 'admins-identity_authentications') %>
  • <%= sidebar_item(admins_professional_authentications_path, '职业认证', icon: 'drivers-license', controller: 'admins-professional_authentications') %>
  • <%= sidebar_item(admins_shixun_authorizations_path, '实训发布', icon: 'object-ungroup', controller: 'admins-shixun_authorizations') %>
  • -
  • <%= sidebar_item(admins_subject_authorizations_path, '实践课程发布', icon: 'object-group', controller: 'admins-subject_authorizations') %>
  • +
  • <%= sidebar_item(admins_subject_authorizations_path, '实践课程发布', icon: 'object-group', controller: 'admins-subject_authorizations') %>
  • +
  • <%= sidebar_item(admins_library_applies_path, '教学案例发布', icon: 'language', controller: 'admins-library_applies') %>
  • <% end %> diff --git a/config/locales/library_applies/zh-CN.yml b/config/locales/library_applies/zh-CN.yml new file mode 100644 index 000000000..0d2cf6c9d --- /dev/null +++ b/config/locales/library_applies/zh-CN.yml @@ -0,0 +1,7 @@ +zh-CN: + library_apply: + status: + 'pending': '待审批' + 'processed': '已审批' + 'refused': '已拒绝' + 'agreed': '已同意' \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 7e2cf72f3..0c048c84c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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