子站实践课程的删除做成软删除,并增加实训回收站列表

dev_forge
cxt 5 years ago
parent 20ce52c4a1
commit fea6353350

@ -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

@ -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

@ -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

@ -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}%") }

@ -27,6 +27,7 @@
<li><%= sidebar_item(admins_shixun_settings_path, '实训配置', icon: 'cog', controller: 'admins-shixun_settings') %></li>
<li><%= sidebar_item(admins_mirror_repositories_path, '镜像管理', icon: 'cubes', controller: 'admins-mirror_repositories') %></li>
<li><%= sidebar_item(admins_myshixuns_path, '学员实训列表', icon: 'server', controller: 'admins-myshixuns') %></li>
<li><%= sidebar_item(admins_shixun_recycles_path, '实训回收站', icon: 'recycle', controller: 'admins-myshixuns') %></li>
<% end %>
</li>

@ -0,0 +1,15 @@
<% define_admin_breadcrumbs do %>
<% add_admin_breadcrumb('实训回收站') %>
<% end %>
<div class="box search-form-container shixun-recycles-list-form">
<%= 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 %>
</div>
<div class="box admin-list-container shixun-recycles-list-container">
<%= render partial: 'admins/shixun_recycles/shared/list', locals: { shixuns: @shixuns } %>
</div>

@ -0,0 +1 @@
$(".shixun-recycles-list-container").html("<%= j render partial: "admins/shixun_recycles/shared/list",locals: {shixuns: @shixuns} %>")

@ -0,0 +1,31 @@
<table class="table table-hover text-center shixuns-list-table">
<thead class="thead-light">
<th width="8%">ID</th>
<th width="32%" class="text-left">实训名称</th>
<th width="20%">子站源</th>
<th width="10%">创建者</th>
<th width="20%"><%= sort_tag('创建于', name: 'created_at', path: admins_shixun_recycles_path) %></th>
<th width="10%">操作</th>
</thead>
<tbody>
<% if shixuns.present? %>
<% shixuns.each do |shixun| %>
<tr id="shixun_recycle_item_<%= shixun.id %>">
<td><%= shixun.identifier %></td>
<td class="text-left"><span><%= link_to overflow_hidden_span(shixun.name), "/shixuns/#{shixun.identifier}", :target => "_blank", :title => shixun.name %></span></td>
<td><%= shixun.laboratory&.school&.name %></td>
<td><%= link_to shixun.user.try(:real_name),"/users/#{shixun.user.try(:login)}",target:'_blank' %></td>
<td><%= format_time shixun.created_at %></td>
<td class="operate">
<%= 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: "您确定要恢复吗?" } ) %>
</td>
</tr>
<% end %>
<% else %>
<%= render 'admins/shared/no_data_for_table' %>
<% end %>
</tbody>
</table>
<%= render partial: 'admins/shared/paginate', locals: { objects: shixuns } %>

@ -9,14 +9,14 @@
<th width="5%">选择</th>
<th width="6%">状态</th>
<th width="7%">创建者</th>
<th width="13%"><%= sort_tag('创建于', name: 'created_on', path: admins_shixuns_path) %></th>
<th width="13%"><%= sort_tag('创建于', name: 'created_at', path: admins_shixuns_path) %></th>
<th width="5%">单测</th>
<th width="6%">操作</th>
</thead>
<tbody>
<% if shixuns.present? %>
<% shixuns.each_with_index do |shixun,index| %>
<tr>
<tr id="shixun_item_<%= shixun.id %>">
<td><%= list_index_no(@params_page.to_i, index) %></td>
<td><%= shixun.identifier %></td>
<td class="text-left"><span><%= link_to overflow_hidden_span(shixun.name), "/shixuns/#{shixun.identifier}", :target => "_blank", :title => shixun.name %></span></td>
@ -33,7 +33,7 @@
<td><%= shixun.challenges.where(:st => 0).size %></td>
<td><%= shixun.challenges.where(:st => 1).size %></td>
<td class="shixuns-status-<%= shixun.status %>"><%= shixun_authentication_status shixun %></td>
<td><%= link_to shixun.owner.try(:real_name),"/users/#{shixun.owner.try(:login)}",target:'_blank' %></td>
<td><%= link_to shixun.user.try(:real_name),"/users/#{shixun.user.try(:login)}",target:'_blank' %></td>
<td><%= format_time shixun.created_at %></td>
<td class="homepage_teacher">
<input type="checkbox" name="sigle_show" value="<%= shixun.id %>" <%= shixun.sigle_training ? "checked" : "" %> class="ml-3 mr5 magic-checkbox" id="join_teacher_homepage_<%= shixun.id %>">
@ -41,7 +41,7 @@
</td>
<td class="operate">
<% 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 %>
</td>
</tr>

@ -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

Loading…
Cancel
Save