From 4374223f7dff0eefe865d9f030c83076d2443929 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Mon, 26 Aug 2019 15:41:31 +0800 Subject: [PATCH] admins: shixun publish and subject publish feature --- .../admins/shixun_authorizations/index.js | 18 ++++++ .../admins/subject_authorizations/index.js | 18 ++++++ ...tics.scss => daily_school_statistics.scss} | 0 ...ons.scss => identity_authentications.scss} | 0 ...scss => professional_authentications.scss} | 0 ...statistics.scss => school_statistics.scss} | 0 .../admins/shixun_authorizations.scss | 9 +++ .../admins/subject_authorizations.scss | 9 +++ .../shixun_authorizations_controller.rb | 48 ++++++++++++++ .../subject_authorizations_controller.rb | 49 ++++++++++++++ .../concerns/admins/error_rescue_handler.rb | 2 +- .../concerns/admins/render_helper.rb | 2 +- app/models/apply_action.rb | 8 +++ .../shixun_auths/agree_apply_service.rb | 43 +++++++++++++ .../shixun_auths/refuse_apply_service.rb | 35 ++++++++++ .../subject_auths/agree_apply_service.rb | 30 +++++++++ .../subject_auths/refuse_apply_service.rb | 35 ++++++++++ app/views/admins/shared/_sidebar.html.erb | 2 + app/views/admins/shared/error.js.erb | 5 +- .../shixun_authorizations/index.html.erb | 32 ++++++++++ .../admins/shixun_authorizations/index.js.erb | 1 + .../shared/_list.html.erb | 60 +++++++++++++++++ .../subject_authorizations/index.html.erb | 33 ++++++++++ .../subject_authorizations/index.js.erb | 1 + .../shared/_list.html.erb | 64 +++++++++++++++++++ config/locales/apply_actions/zh-CN.yml | 7 ++ config/routes.rb | 12 ++++ 27 files changed, 520 insertions(+), 3 deletions(-) create mode 100644 app/assets/javascripts/admins/shixun_authorizations/index.js create mode 100644 app/assets/javascripts/admins/subject_authorizations/index.js rename app/assets/stylesheets/admins/{daily-school-statistics.scss => daily_school_statistics.scss} (100%) rename app/assets/stylesheets/admins/{identity-authentications.scss => identity_authentications.scss} (100%) rename app/assets/stylesheets/admins/{professional-authentications.scss => professional_authentications.scss} (100%) rename app/assets/stylesheets/admins/{school-statistics.scss => school_statistics.scss} (100%) create mode 100644 app/assets/stylesheets/admins/shixun_authorizations.scss create mode 100644 app/assets/stylesheets/admins/subject_authorizations.scss create mode 100644 app/controllers/admins/shixun_authorizations_controller.rb create mode 100644 app/controllers/admins/subject_authorizations_controller.rb create mode 100644 app/services/admins/shixun_auths/agree_apply_service.rb create mode 100644 app/services/admins/shixun_auths/refuse_apply_service.rb create mode 100644 app/services/admins/subject_auths/agree_apply_service.rb create mode 100644 app/services/admins/subject_auths/refuse_apply_service.rb create mode 100644 app/views/admins/shixun_authorizations/index.html.erb create mode 100644 app/views/admins/shixun_authorizations/index.js.erb create mode 100644 app/views/admins/shixun_authorizations/shared/_list.html.erb create mode 100644 app/views/admins/subject_authorizations/index.html.erb create mode 100644 app/views/admins/subject_authorizations/index.js.erb create mode 100644 app/views/admins/subject_authorizations/shared/_list.html.erb create mode 100644 config/locales/apply_actions/zh-CN.yml diff --git a/app/assets/javascripts/admins/shixun_authorizations/index.js b/app/assets/javascripts/admins/shixun_authorizations/index.js new file mode 100644 index 000000000..ba7b23821 --- /dev/null +++ b/app/assets/javascripts/admins/shixun_authorizations/index.js @@ -0,0 +1,18 @@ +$(document).on('turbolinks:load', function() { + if ($('body.admins-shixun-authorizations-index-page').length > 0) { + var $searchFrom = $('.shixun-authorization-list-form'); + + $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(); + } + }); + } +}) \ No newline at end of file diff --git a/app/assets/javascripts/admins/subject_authorizations/index.js b/app/assets/javascripts/admins/subject_authorizations/index.js new file mode 100644 index 000000000..d80f0850c --- /dev/null +++ b/app/assets/javascripts/admins/subject_authorizations/index.js @@ -0,0 +1,18 @@ +$(document).on('turbolinks:load', function() { + if ($('body.admins-subject-authorizations-index-page').length > 0) { + var $searchFrom = $('.subject-authorization-list-form'); + + $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(); + } + }); + } +}) \ No newline at end of file diff --git a/app/assets/stylesheets/admins/daily-school-statistics.scss b/app/assets/stylesheets/admins/daily_school_statistics.scss similarity index 100% rename from app/assets/stylesheets/admins/daily-school-statistics.scss rename to app/assets/stylesheets/admins/daily_school_statistics.scss diff --git a/app/assets/stylesheets/admins/identity-authentications.scss b/app/assets/stylesheets/admins/identity_authentications.scss similarity index 100% rename from app/assets/stylesheets/admins/identity-authentications.scss rename to app/assets/stylesheets/admins/identity_authentications.scss diff --git a/app/assets/stylesheets/admins/professional-authentications.scss b/app/assets/stylesheets/admins/professional_authentications.scss similarity index 100% rename from app/assets/stylesheets/admins/professional-authentications.scss rename to app/assets/stylesheets/admins/professional_authentications.scss diff --git a/app/assets/stylesheets/admins/school-statistics.scss b/app/assets/stylesheets/admins/school_statistics.scss similarity index 100% rename from app/assets/stylesheets/admins/school-statistics.scss rename to app/assets/stylesheets/admins/school_statistics.scss diff --git a/app/assets/stylesheets/admins/shixun_authorizations.scss b/app/assets/stylesheets/admins/shixun_authorizations.scss new file mode 100644 index 000000000..05bcbc2bb --- /dev/null +++ b/app/assets/stylesheets/admins/shixun_authorizations.scss @@ -0,0 +1,9 @@ +.admins-shixun-authorizations-index-page { + .shixun-authorization-list-container { + span { + &.apply-status-1 { color: #28a745; } + &.apply-status-2 { color: #dc3545; } + &.apply-status-3 { color: #6c757d; } + } + } +} \ No newline at end of file diff --git a/app/assets/stylesheets/admins/subject_authorizations.scss b/app/assets/stylesheets/admins/subject_authorizations.scss new file mode 100644 index 000000000..f16c30151 --- /dev/null +++ b/app/assets/stylesheets/admins/subject_authorizations.scss @@ -0,0 +1,9 @@ +.admins-subject-authorizations-index-page { + .subject-authorization-list-container { + span { + &.apply-status-1 { color: #28a745; } + &.apply-status-2 { color: #dc3545; } + &.apply-status-3 { color: #6c757d; } + } + } +} \ No newline at end of file diff --git a/app/controllers/admins/shixun_authorizations_controller.rb b/app/controllers/admins/shixun_authorizations_controller.rb new file mode 100644 index 000000000..31bd5faf7 --- /dev/null +++ b/app/controllers/admins/shixun_authorizations_controller.rb @@ -0,0 +1,48 @@ +class Admins::ShixunAuthorizationsController < Admins::BaseController + def index + params[:status] ||= 'pending' + + applies = ApplyAction.where(container_type: 'ApplyShixun') + + status = + case params[:status] + when 'pending' then 0 + when 'processed' then [1, 2] + when 'agreed' then 1 + when 'refused' then 2 + else 0 + end + applies = applies.where(status: status) if status.present? + + # 关键字模糊查询 + keyword = params[:keyword].to_s.strip + if keyword.present? + applies = applies.joins('JOIN shixuns ON shixuns.id = apply_actions.container_id') + .where('shixuns.name LIKE :keyword', keyword: "%#{keyword}%") + end + + applies = applies.order(updated_at: :desc) + + @applies = paginate applies.includes(user: :user_extension) + + shixun_ids = @applies.map(&:container_id) + @shixun_map = Shixun.where(id: shixun_ids).each_with_object({}) { |s, h| h[s.id] = s } + end + + def agree + Admins::ShixunAuths::AgreeApplyService.call(current_apply, current_user) + render_success_js + end + + def refuse + Admins::ShixunAuths::RefuseApplyService.call(current_apply, current_user, params) + + render_success_js + end + + private + + def current_apply + @_current_apply ||= ApplyAction.where(container_type: 'ApplyShixun').find(params[:id]) + end +end \ No newline at end of file diff --git a/app/controllers/admins/subject_authorizations_controller.rb b/app/controllers/admins/subject_authorizations_controller.rb new file mode 100644 index 000000000..3d3733fa4 --- /dev/null +++ b/app/controllers/admins/subject_authorizations_controller.rb @@ -0,0 +1,49 @@ +class Admins::SubjectAuthorizationsController < Admins::BaseController + def index + params[:status] ||= 'pending' + + applies = ApplyAction.where(container_type: 'ApplySubject') + + status = + case params[:status] + when 'pending' then 0 + when 'processed' then [1, 2] + when 'agreed' then 1 + when 'refused' then 2 + else 0 + end + applies = applies.where(status: status) if status.present? + + # 关键字模糊查询 + keyword = params[:keyword].to_s.strip + if keyword.present? + applies = applies.joins('JOIN subjects ON subjects.id = apply_actions.container_id') + .where('subjects.name LIKE :keyword', keyword: "%#{keyword}%") + end + + applies = applies.order(updated_at: :desc) + + @applies = paginate applies.includes(user: :user_extension) + + subject_ids = @applies.map(&:container_id) + @subject_map = Subject.where(id: subject_ids).each_with_object({}) { |s, h| h[s.id] = s } + @challenge_count_map = Challenge.joins(shixun: :stage_shixuns).where(st: 0, stage_shixuns: { subject_id: subject_ids}).group('subject_id').count + end + + def agree + Admins::SubjectAuths::AgreeApplyService.call(current_apply, current_user) + render_success_js + end + + def refuse + Admins::SubjectAuths::RefuseApplyService.call(current_apply, current_user, params) + + render_success_js + end + + private + + def current_apply + @_current_apply ||= ApplyAction.where(container_type: 'ApplySubject').find(params[:id]) + end +end \ No newline at end of file diff --git a/app/controllers/concerns/admins/error_rescue_handler.rb b/app/controllers/concerns/admins/error_rescue_handler.rb index b1e29d5ce..ceb810f36 100644 --- a/app/controllers/concerns/admins/error_rescue_handler.rb +++ b/app/controllers/concerns/admins/error_rescue_handler.rb @@ -2,7 +2,7 @@ module Admins::ErrorRescueHandler extend ActiveSupport::Concern included do - rescue_from Exception, Educoder::TipException do |e| + rescue_from Exception do |e| raise e if Rails.env.development? Util.logger_error e diff --git a/app/controllers/concerns/admins/render_helper.rb b/app/controllers/concerns/admins/render_helper.rb index 3651f892b..0ccc16a09 100644 --- a/app/controllers/concerns/admins/render_helper.rb +++ b/app/controllers/concerns/admins/render_helper.rb @@ -28,7 +28,7 @@ module Admins::RenderHelper def internal_server_error respond_to do |format| format.html { render 'admins/shared/500' } - format.js { render_js_error(message) } + format.js { render_js_error('系统错误') } format.json { render status: 500, json: { message: '系统错误' } } end end diff --git a/app/models/apply_action.rb b/app/models/apply_action.rb index 2d31f394d..54bdaa396 100644 --- a/app/models/apply_action.rb +++ b/app/models/apply_action.rb @@ -1,8 +1,16 @@ # 申请消息 class ApplyAction < ApplicationRecord + belongs_to :user + has_many :tidings, :as => :container, :dependent => :destroy after_create :send_tiding + def status_text + I18n.t!("apply_action.status.#{status}") + rescue I18n::MissingTranslationData + nil + end + def send_tiding if container_type == 'TrialAuthorization' && status == 1 tidings.create(user_id: user_id, trigger_user_id: 0, status: 1, viewed: 0, tiding_type: 'System', diff --git a/app/services/admins/shixun_auths/agree_apply_service.rb b/app/services/admins/shixun_auths/agree_apply_service.rb new file mode 100644 index 000000000..4734e03bb --- /dev/null +++ b/app/services/admins/shixun_auths/agree_apply_service.rb @@ -0,0 +1,43 @@ +class Admins::ShixunAuths::AgreeApplyService < ApplicationService + attr_reader :apply, :user, :shixun + + def initialize(apply, user) + @apply = apply + @user = user + @shixun = Shixun.find(apply.container_id) + end + + def call + ActiveRecord::Base.transaction do + apply.update!(status: 1, dealer_id: user.id) + shixun.update!(status: 2, publish_time: Time.now) + + # 奖励金币、经验 + reward_grade_and_experience! + + deal_tiding! + end + end + + private + + def reward_grade_and_experience! + score = shixun.all_score + shixun_creator = shixun.user + + RewardGradeService.call(shixun_creator, container_id: shixun.id, container_type: 'shixunPublish', score: score) + + Experience.create!(user_id: shixun_creator.id, container_id: shixun.id, container_type: 'shixunPublish', score: score) + shixun_creator.update_column(:experience, shixun_creator.experience.to_i + score) + end + + def deal_tiding! + apply.tidings.where(tiding_type: 'Apply', status: 0).update_all(status: 1) + + Tiding.create!(user_id: apply.user_id, trigger_user_id: 0, + container_id: apply.id, container_type: 'ApplyAction', + parent_container_id: apply.container_id, parent_container_type: apply.container_type, + belong_container_id: apply.container_id, belong_container_type: 'Shixun', + status: 1, tiding_type: 'System') + end +end \ No newline at end of file diff --git a/app/services/admins/shixun_auths/refuse_apply_service.rb b/app/services/admins/shixun_auths/refuse_apply_service.rb new file mode 100644 index 000000000..49416a2b0 --- /dev/null +++ b/app/services/admins/shixun_auths/refuse_apply_service.rb @@ -0,0 +1,35 @@ +class Admins::ShixunAuths::RefuseApplyService < ApplicationService + attr_reader :apply, :user, :shixun, :params + + def initialize(apply, user, params) + @apply = apply + @user = user + @shixun = Shixun.find(apply.container_id) + @params = params + end + + def call + ActiveRecord::Base.transaction do + shixun.update!(status: 0) + apply.update!(status: 2, reason: reason, dealer_id: user.id) + + deal_tiding! + end + end + + private + + def reason + params[:reason].to_s.strip + end + + def deal_tiding! + apply.tidings.where(tiding_type: 'Apply', status: 0).update_all(status: 1) + + Tiding.create!(user_id: apply.user_id, trigger_user_id: 0, + container_id: apply.id, container_type: 'ApplyAction', + parent_container_id: apply.container_id, parent_container_type: apply.container_type, + belong_container_id: apply.container_id, belong_container_type: 'Shixun', + status: 2, tiding_type: 'System') + end +end \ No newline at end of file diff --git a/app/services/admins/subject_auths/agree_apply_service.rb b/app/services/admins/subject_auths/agree_apply_service.rb new file mode 100644 index 000000000..465e3e903 --- /dev/null +++ b/app/services/admins/subject_auths/agree_apply_service.rb @@ -0,0 +1,30 @@ +class Admins::SubjectAuths::AgreeApplyService < ApplicationService + attr_reader :apply, :user, :subject + + def initialize(apply, user) + @apply = apply + @user = user + @subject = Subject.find(apply.container_id) + end + + def call + ActiveRecord::Base.transaction do + apply.update!(status: 1, dealer_id: user.id) + subject.update!(status: 2, publish_time: Time.now) + + deal_tiding! + end + end + + private + + def deal_tiding! + apply.tidings.where(tiding_type: 'Apply', status: 0).update_all(status: 1) + + Tiding.create!(user_id: apply.user_id, trigger_user_id: 0, + container_id: apply.id, container_type: 'ApplyAction', + parent_container_id: apply.container_id, parent_container_type: apply.container_type, + belong_container_id: apply.container_id, belong_container_type: 'Subject', + status: 1, tiding_type: 'System') + end +end \ No newline at end of file diff --git a/app/services/admins/subject_auths/refuse_apply_service.rb b/app/services/admins/subject_auths/refuse_apply_service.rb new file mode 100644 index 000000000..f51d55185 --- /dev/null +++ b/app/services/admins/subject_auths/refuse_apply_service.rb @@ -0,0 +1,35 @@ +class Admins::SubjectAuths::RefuseApplyService < ApplicationService + attr_reader :apply, :user, :subject, :params + + def initialize(apply, user, params) + @apply = apply + @user = user + @subject = Subject.find(apply.container_id) + @params = params + end + + def call + ActiveRecord::Base.transaction do + subject.update!(status: 0) + apply.update!(status: 2, reason: reason, dealer_id: user.id) + + deal_tiding! + end + end + + private + + def reason + params[:reason].to_s.strip + end + + def deal_tiding! + apply.tidings.where(tiding_type: 'Apply', status: 0).update_all(status: 1) + + Tiding.create!(user_id: apply.user_id, trigger_user_id: 0, + container_id: apply.id, container_type: 'ApplyAction', + parent_container_id: apply.container_id, parent_container_type: apply.container_type, + belong_container_id: apply.container_id, belong_container_type: 'Subject', + status: 2, tiding_type: 'System') + end +end \ 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 2be899ebd..ab30e8bd3 100644 --- a/app/views/admins/shared/_sidebar.html.erb +++ b/app/views/admins/shared/_sidebar.html.erb @@ -41,6 +41,8 @@ <%= sidebar_item_group('#apply-review-submenu', '审核', icon: 'gavel') do %>
  • <%= 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') %>
  • <% end %> diff --git a/app/views/admins/shared/error.js.erb b/app/views/admins/shared/error.js.erb index ebb78aec6..261796d0b 100644 --- a/app/views/admins/shared/error.js.erb +++ b/app/views/admins/shared/error.js.erb @@ -4,4 +4,7 @@ setTimeout(function() { if ($('.admin-alert-container button.close').length > 0) { $('.admin-alert-container button.close').trigger('click'); } -}, 2000) \ No newline at end of file +}, 5000) +$(".admin-body-container").animate({ + scrollTop: 0 +}, 200); \ No newline at end of file diff --git a/app/views/admins/shixun_authorizations/index.html.erb b/app/views/admins/shixun_authorizations/index.html.erb new file mode 100644 index 000000000..743f2e1b2 --- /dev/null +++ b/app/views/admins/shixun_authorizations/index.html.erb @@ -0,0 +1,32 @@ +<% define_admin_breadcrumbs do %> + <% add_admin_breadcrumb('实训发布') %> +<% end %> + +
    + + + <%= form_tag(admins_shixun_authorizations_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/shixun_authorizations/shared/list', locals: { applies: @applies, shixun_map: @shixun_map }) %> +
    + +<%= render(partial: 'admins/shared/admin_common_refuse_modal') %> \ No newline at end of file diff --git a/app/views/admins/shixun_authorizations/index.js.erb b/app/views/admins/shixun_authorizations/index.js.erb new file mode 100644 index 000000000..caa8bb389 --- /dev/null +++ b/app/views/admins/shixun_authorizations/index.js.erb @@ -0,0 +1 @@ +$('.shixun-authorization-list-container').html("<%= j( render partial: 'admins/shixun_authorizations/shared/list', locals: { applies: @applies, shixun_map: @shixun_map } ) %>"); \ No newline at end of file diff --git a/app/views/admins/shixun_authorizations/shared/_list.html.erb b/app/views/admins/shixun_authorizations/shared/_list.html.erb new file mode 100644 index 000000000..ce3b4ca43 --- /dev/null +++ b/app/views/admins/shixun_authorizations/shared/_list.html.erb @@ -0,0 +1,60 @@ +<% is_processed = params[:status].to_s != 'pending' %> + + + + + + + + + + <% if is_processed %> + + + <% else %> + + <% end %> + + + + <% if applies.present? %> + <% applies.each do |apply| %> + <% user = apply.user %> + <% shixun = shixun_map[apply.container_id] %> + + + + + + + + <% if is_processed %> + + + <% else %> + + <% end %> + + <% end %> + <% else %> + <%= render 'admins/shared/no_data_for_table' %> + <% end %> + +
    头像创建者实训名称任务数时间拒绝原因状态操作
    + <%= link_to "/users/#{user.login}", class: 'shixun-authorization-avatar', target: '_blank', data: { toggle: 'tooltip', title: '个人主页' } do %> + + <% end %> + <%= user.real_name %> + <%= link_to "/shixuns/#{shixun.identifier}", target: '_blank' do %> + <%= overflow_hidden_span shixun.name, width: 300 %> + <% end %> + <%= shixun.challenges_count %><%= apply.updated_at.strftime('%Y-%m-%d %H:%M') %><%= overflow_hidden_span apply.reason, width: 140 %><%= apply.status_text %> + <%= agree_link '同意', agree_admins_shixun_authorization_path(apply, element: ".shixun-authorization-#{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_shixun_authorization_path(apply, element: ".shixun-authorization-#{apply.id}") + }) %> +
    + +<%= render partial: 'admins/shared/paginate', locals: { objects: applies } %> \ No newline at end of file diff --git a/app/views/admins/subject_authorizations/index.html.erb b/app/views/admins/subject_authorizations/index.html.erb new file mode 100644 index 000000000..3d5539663 --- /dev/null +++ b/app/views/admins/subject_authorizations/index.html.erb @@ -0,0 +1,33 @@ +<% define_admin_breadcrumbs do %> + <% add_admin_breadcrumb('实践课程发布') %> +<% end %> + +
    + + + <%= form_tag(admins_subject_authorizations_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/subject_authorizations/shared/list', + locals: { applies: @applies, subject_map: @subject_map, challenge_count_map: @challenge_count_map }) %> +
    + +<%= render(partial: 'admins/shared/admin_common_refuse_modal') %> \ No newline at end of file diff --git a/app/views/admins/subject_authorizations/index.js.erb b/app/views/admins/subject_authorizations/index.js.erb new file mode 100644 index 000000000..a21809041 --- /dev/null +++ b/app/views/admins/subject_authorizations/index.js.erb @@ -0,0 +1 @@ +$('.subject-authorization-list-container').html("<%= j( render partial: 'admins/subject_authorizations/shared/list', locals: { applies: @applies, subject_map: @subject_map, challenge_count_map: @challenge_count_map } ) %>"); \ No newline at end of file diff --git a/app/views/admins/subject_authorizations/shared/_list.html.erb b/app/views/admins/subject_authorizations/shared/_list.html.erb new file mode 100644 index 000000000..7b8da800d --- /dev/null +++ b/app/views/admins/subject_authorizations/shared/_list.html.erb @@ -0,0 +1,64 @@ +<% is_processed = params[:status].to_s != 'pending' %> + + + + + + + + + + + + <% if is_processed %> + + + <% else %> + + <% end %> + + + + <% if applies.present? %> + <% applies.each do |apply| %> + <% user = apply.user %> + <% subject = subject_map[apply.container_id] %> + + + + + + + + + + <% if is_processed %> + + + <% else %> + + <% end %> + + <% end %> + <% else %> + <%= render 'admins/shared/no_data_for_table' %> + <% end %> + +
    头像创建者实践课程名称阶段数实训数关卡数时间拒绝原因状态操作
    + <%= link_to "/users/#{user.login}", class: 'subject-authorization-avatar', target: '_blank', data: { toggle: 'tooltip', title: '个人主页' } do %> + + <% end %> + <%= user.real_name %> + <%= link_to "/paths/#{subject.id}", target: '_blank' do %> + <%= overflow_hidden_span subject.name, width: 300 %> + <% end %> + <%= subject.stages_count %><%= subject.shixuns_count %><%= challenge_count_map.fetch(subject.id, 0) %><%= apply.updated_at.strftime('%Y-%m-%d %H:%M') %><%= overflow_hidden_span apply.reason, width: 140 %><%= apply.status_text %> + <%= agree_link '同意', agree_admins_subject_authorization_path(apply, element: ".subject-authorization-#{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_subject_authorization_path(apply, element: ".subject-authorization-#{apply.id}") + }) %> +
    + +<%= render partial: 'admins/shared/paginate', locals: { objects: applies } %> \ No newline at end of file diff --git a/config/locales/apply_actions/zh-CN.yml b/config/locales/apply_actions/zh-CN.yml new file mode 100644 index 000000000..933ef6223 --- /dev/null +++ b/config/locales/apply_actions/zh-CN.yml @@ -0,0 +1,7 @@ +zh-CN: + apply_action: + status: + '0': '待处理' + '1': '已同意' + '2': '已拒绝' + '3': '已撤销' \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 4fc660a45..7e2cf72f3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -774,6 +774,18 @@ Rails.application.routes.draw do post :refuse end end + resources :shixun_authorizations, only: [:index] do + member do + post :agree + post :refuse + end + end + resources :subject_authorizations, only: [:index] do + member do + post :agree + post :refuse + end + end end #git 认证回调