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 %> + +
头像 | +姓名 | +教学案例 | +案例描述 | +时间 | + <% if is_processed %> +拒绝原因 | +状态 | + <% else %> +操作 | + <% end %> +
---|---|---|---|---|---|---|---|
+ <%= link_to "/users/#{user.login}", class: 'professional-authentication-avatar', target: '_blank', data: { toggle: 'tooltip', title: '个人主页' } do %>
+ |
+ <%= 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') %> | + + <% if is_processed %> +<%= overflow_hidden_span apply.reason %> | +<%= t("library_apply.status.#{apply.status}") %> | + <% else %> ++ <%= 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}") + }) %> + | + <% end %> +