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/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 @@
  • <%= sidebar_item(admins_shixun_settings_path, '实训配置', icon: 'cog', controller: 'admins-shixun_settings') %>
  • <%= sidebar_item(admins_mirror_repositories_path, '镜像管理', icon: 'cubes', controller: 'admins-mirror_repositories') %>
  • <%= sidebar_item(admins_myshixuns_path, '学员实训列表', icon: 'server', controller: 'admins-myshixuns') %>
  • - <% end %> +
  • <%= sidebar_item(admins_shixun_recycles_path, '实训回收站', icon: 'recycle', controller: 'admins-myshixuns') %>
  • + <% end %>
  • diff --git a/app/views/admins/shixun_recycles/index.html.erb b/app/views/admins/shixun_recycles/index.html.erb new file mode 100644 index 000000000..eb6947a06 --- /dev/null +++ b/app/views/admins/shixun_recycles/index.html.erb @@ -0,0 +1,15 @@ +<% define_admin_breadcrumbs do %> + <% add_admin_breadcrumb('实训回收站') %> +<% end %> + +
    + <%= form_tag(admins_shixun_recycles_path, method: :get, class: 'form-inline search-form',id:"shixun-recycles-search-form",remote:true) do %> + <%= text_field_tag(:search, params[:search], class: 'form-control col-sm-2 ml-3', placeholder: '输入名称关键字搜索') %> + <%= submit_tag('搜索', class: 'btn btn-primary ml-3','data-disable-with': '搜索中...') %> + <%= link_to "清除",admins_shixun_recycles_path,class: "btn btn-default",id:"shixun-recycles-clear-search",'data-disable-with': '清除中...' %> + <% end %> +
    + +
    + <%= render partial: 'admins/shixun_recycles/shared/list', locals: { shixuns: @shixuns } %> +
    diff --git a/app/views/admins/shixun_recycles/index.js.erb b/app/views/admins/shixun_recycles/index.js.erb new file mode 100644 index 000000000..9255dde34 --- /dev/null +++ b/app/views/admins/shixun_recycles/index.js.erb @@ -0,0 +1 @@ +$(".shixun-recycles-list-container").html("<%= j render partial: "admins/shixun_recycles/shared/list",locals: {shixuns: @shixuns} %>") \ No newline at end of file diff --git a/app/views/admins/shixun_recycles/shared/_list.html.erb b/app/views/admins/shixun_recycles/shared/_list.html.erb new file mode 100644 index 000000000..60d2742e9 --- /dev/null +++ b/app/views/admins/shixun_recycles/shared/_list.html.erb @@ -0,0 +1,31 @@ + + + + + + + + + + + <% if shixuns.present? %> + <% shixuns.each do |shixun| %> + + + + + + + + + <% end %> + <% else %> + <%= render 'admins/shared/no_data_for_table' %> + <% end %> + +
    ID实训名称子站源创建者<%= sort_tag('创建于', name: 'created_at', path: admins_shixun_recycles_path) %>操作
    <%= 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: "您确定要恢复吗?" } ) %> +
    + +<%= render partial: 'admins/shared/paginate', locals: { objects: shixuns } %> \ No newline at end of file diff --git a/app/views/admins/shixuns/shared/_list.html.erb b/app/views/admins/shixuns/shared/_list.html.erb index 7e96eb0fa..7503d8fd2 100644 --- a/app/views/admins/shixuns/shared/_list.html.erb +++ b/app/views/admins/shixuns/shared/_list.html.erb @@ -9,14 +9,14 @@ 选择 状态 创建者 - <%= sort_tag('创建于', name: 'created_on', path: admins_shixuns_path) %> + <%= sort_tag('创建于', name: 'created_at', path: admins_shixuns_path) %> 单测 操作 <% if shixuns.present? %> <% shixuns.each_with_index do |shixun,index| %> - + <%= list_index_no(@params_page.to_i, index) %> <%= shixun.identifier %> <%= link_to overflow_hidden_span(shixun.name), "/shixuns/#{shixun.identifier}", :target => "_blank", :title => shixun.name %> @@ -33,7 +33,7 @@ <%= shixun.challenges.where(:st => 0).size %> <%= shixun.challenges.where(:st => 1).size %> <%= shixun_authentication_status shixun %> - <%= link_to shixun.owner.try(:real_name),"/users/#{shixun.owner.try(:login)}",target:'_blank' %> + <%= link_to shixun.user.try(:real_name),"/users/#{shixun.user.try(:login)}",target:'_blank' %> <%= format_time shixun.created_at %> class="ml-3 mr5 magic-checkbox" id="join_teacher_homepage_<%= shixun.id %>"> @@ -41,7 +41,7 @@ <% if shixun.status == 0 %> - <%= link_to(l(:button_delete), admins_shixun_path(shixun), :method => :delete, :data => { confirm: "您确定要删除吗?" } ) %> + <%= delete_link l(:button_delete), admins_shixun_path(shixun, element: ".shixun-item-#{shixun.id}"), class: 'delete-shixun-action' %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index 4b525eeac..ad4cd56d5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1049,6 +1049,9 @@ Rails.application.routes.draw do resources :shixuns, only: [:index,:destroy] resources :shixun_settings, only: [:index,:update] resources :shixun_feedback_messages, only: [:index] + resources :shixun_recycles, only: [:index, :destroy] do + post :resume, on: :member + end resources :department_applies,only: [:index,:destroy] do collection do post :merge