diff --git a/app/controllers/admins/laboratory_subjects_controller.rb b/app/controllers/admins/laboratory_subjects_controller.rb index c09697c7e..827645839 100644 --- a/app/controllers/admins/laboratory_subjects_controller.rb +++ b/app/controllers/admins/laboratory_subjects_controller.rb @@ -19,9 +19,9 @@ class Admins::LaboratorySubjectsController < Admins::BaseController ActiveRecord::Base.transaction do current_subject = current_laboratory_subject.subject - current_subject.shixuns.each do |shixun| - shixun.destroy! - end + # 实训软删除,并解除与子站的关联 + current_laboratory.laboratory_shixuns.where(shixun_id: current_subject.shixuns).destroy_all + current_subject.shixuns.update_all(status: -1) current_subject.destroy! render_delete_success diff --git a/app/controllers/admins/shixun_recycles_controller.rb b/app/controllers/admins/shixun_recycles_controller.rb new file mode 100644 index 000000000..5a0582d4e --- /dev/null +++ b/app/controllers/admins/shixun_recycles_controller.rb @@ -0,0 +1,22 @@ +class Admins::ShixunRecyclesController < Admins::BaseController + + def index + sort_by = params[:sort_by].presence || 'created_at' + sort_direction = params[:sort_direction].presence || 'desc' + search = params[:search].to_s.strip + shixuns = Shixun.where(status: -1).where("name like ?", "%#{search}%").order("#{sort_by} #{sort_direction}") + @shixuns = paginate shixuns.preload(:user, :laboratory) + end + + def destroy + Shixun.find(params[:id]).destroy! + + render_delete_success + end + + def resume + Shixun.find(params[:id]).update!(status: 0) + render_delete_success + end + +end diff --git a/app/controllers/admins/shixuns_controller.rb b/app/controllers/admins/shixuns_controller.rb index a4aa8a044..e2d2830ad 100644 --- a/app/controllers/admins/shixuns_controller.rb +++ b/app/controllers/admins/shixuns_controller.rb @@ -1,7 +1,7 @@ class Admins::ShixunsController < Admins::BaseController def index - params[:sort_by] = params[:sort_by].presence || 'created_on' + params[:sort_by] = params[:sort_by].presence || 'created_at' params[:sort_direction] = params[:sort_direction].presence || 'desc' shixuns = Admins::ShixunQuery.call(params) @editing_shixuns = shixuns.where(status:0).size @@ -23,7 +23,7 @@ class Admins::ShixunsController < Admins::BaseController end def destroy - Shixun.find(params[:id]).destroy! + Shixun.find(params[:id]).update!(status: -1) render_delete_success end diff --git a/app/models/shixun.rb b/app/models/shixun.rb index e8aa1b186..0f9842739 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -53,6 +53,7 @@ class Shixun < ApplicationRecord has_many :shixun_reviews, -> {order("shixun_reviews.created_at desc")}, :dependent => :destroy has_many :laboratory_shixuns, dependent: :destroy + belongs_to :laboratory, optional: true scope :search_by_name, ->(keyword) { where("name like ? or description like ? ", "%#{keyword}%", "%#{keyword}%") } diff --git a/app/services/users/shixun_service.rb b/app/services/users/shixun_service.rb index aeaac6a2c..9460d3a88 100644 --- a/app/services/users/shixun_service.rb +++ b/app/services/users/shixun_service.rb @@ -41,6 +41,8 @@ class Users::ShixunService def user_policy_filter(relations) # 只有自己或者管理员才有过滤筛选及查看全部状态下实训功能 + Rails.logger.info("self_or_admin?: #{self_or_admin?}") + Rails.logger.info("user: #{user.id}") if self_or_admin? relations = relations.where.not(status: -1) status_filter(relations) diff --git a/app/views/admins/shared/_sidebar.html.erb b/app/views/admins/shared/_sidebar.html.erb index 4e6639393..df344fd1a 100644 --- a/app/views/admins/shared/_sidebar.html.erb +++ b/app/views/admins/shared/_sidebar.html.erb @@ -27,7 +27,8 @@
ID | +实训名称 | +子站源 | +创建者 | +<%= sort_tag('创建于', name: 'created_at', path: admins_shixun_recycles_path) %> | +操作 | + + + <% if shixuns.present? %> + <% shixuns.each do |shixun| %> +
---|---|---|---|---|---|
<%= shixun.identifier %> | +<%= link_to overflow_hidden_span(shixun.name), "/shixuns/#{shixun.identifier}", :target => "_blank", :title => shixun.name %> | +<%= shixun.laboratory&.school&.name %> | +<%= link_to shixun.user.try(:real_name),"/users/#{shixun.user.try(:login)}",target:'_blank' %> | +<%= format_time shixun.created_at %> | ++ <%= delete_link '删除', admins_shixun_recycle_path(shixun, element: ".shixun-recycle-item-#{shixun.id}"), class: 'delete-shixun-recyle-action' %> + <%= link_to('恢复', resume_admins_shixun_recycle_path(shixun), :method => :post, :remote => true, :data => { confirm: "您确定要恢复吗?" } ) %> + | +