diff --git a/app/controllers/admins/laboratory_shixuns_controller.rb b/app/controllers/admins/laboratory_shixuns_controller.rb index f5c7d5ef3..d190573f1 100644 --- a/app/controllers/admins/laboratory_shixuns_controller.rb +++ b/app/controllers/admins/laboratory_shixuns_controller.rb @@ -19,6 +19,13 @@ class Admins::LaboratoryShixunsController < Admins::BaseController render_ok end + def destroy + return render_js_error('不能删除自建实训', type: :notify) if current_laboratory_shixun.ownership? + current_laboratory_shixun.destroy! + + render_delete_success + end + def homepage current_laboratory_shixun.update!(homepage: true) render_ok diff --git a/app/controllers/admins/laboratory_subjects_controller.rb b/app/controllers/admins/laboratory_subjects_controller.rb index d6dc4af9d..60572110c 100644 --- a/app/controllers/admins/laboratory_subjects_controller.rb +++ b/app/controllers/admins/laboratory_subjects_controller.rb @@ -21,6 +21,15 @@ class Admins::LaboratorySubjectsController < Admins::BaseController render_ok end + def destroy + return render_js_error('不能删除自建课程', type: :notify) if current_laboratory_subject.ownership? + + current_laboratory_subject.destroy! + + render_delete_success + end + + def homepage current_laboratory_subject.update!(homepage: true) render_ok diff --git a/app/controllers/cooperative/base_controller.rb b/app/controllers/cooperative/base_controller.rb index 556cd7aa9..5ab08582d 100644 --- a/app/controllers/cooperative/base_controller.rb +++ b/app/controllers/cooperative/base_controller.rb @@ -16,7 +16,7 @@ class Cooperative::BaseController < ApplicationController private def current_laboratory - @_current_laboratory ||= Laboratory.find_by_subdomain(request.subdomain) + @_current_laboratory ||= Laboratory.find_by_subdomain('hut' || request.subdomain) end def current_setting_or_default(name) diff --git a/app/controllers/cooperative/laboratory_shixuns_controller.rb b/app/controllers/cooperative/laboratory_shixuns_controller.rb index e428416da..2aa8a0bf6 100644 --- a/app/controllers/cooperative/laboratory_shixuns_controller.rb +++ b/app/controllers/cooperative/laboratory_shixuns_controller.rb @@ -15,6 +15,13 @@ class Cooperative::LaboratoryShixunsController < Cooperative::BaseController end + def destroy + return render_js_error('不能删除自建实训', type: :notify) if current_laboratory_shixun.ownership? + current_laboratory_shixun.destroy! + + render_delete_success + end + def homepage current_laboratory_shixun.update!(homepage: true) render_ok diff --git a/app/controllers/cooperative/laboratory_subjects_controller.rb b/app/controllers/cooperative/laboratory_subjects_controller.rb index 77088c223..0243d542a 100644 --- a/app/controllers/cooperative/laboratory_subjects_controller.rb +++ b/app/controllers/cooperative/laboratory_subjects_controller.rb @@ -18,6 +18,13 @@ class Cooperative::LaboratorySubjectsController < Cooperative::BaseController current_laboratory_subject.subject.update!(update_params) end + def destroy + return render_js_error('不能删除自建实践课程', type: :notify) if current_laboratory_subject.ownership? + current_laboratory_subject.destroy! + + render_delete_success + end + def homepage current_laboratory_subject.update!(homepage: true) render_ok diff --git a/app/views/admins/laboratory_shixuns/shared/_td.html.erb b/app/views/admins/laboratory_shixuns/shared/_td.html.erb index 84cfeb450..dbdf0df75 100644 --- a/app/views/admins/laboratory_shixuns/shared/_td.html.erb +++ b/app/views/admins/laboratory_shixuns/shared/_td.html.erb @@ -25,4 +25,8 @@ <%= link_to('去修改', admins_shixun_settings_path(id: laboratory_shixun.shixun_id)) %> <%= javascript_void_link('首页展示', class: 'action homepage-show-action', data: { id: laboratory_shixun.id }, style: laboratory_shixun.homepage? ? 'display:none' : '') %> <%= javascript_void_link('取消首页展示', class: 'action homepage-hide-action', data: { id: laboratory_shixun.id }, style: laboratory_shixun.homepage? ? '' : 'display:none') %> + + <% unless laboratory_shixun.ownership? %> + <%= delete_link '删除', admins_laboratory_laboratory_shixun_path(current_laboratory, laboratory_shixun, element: ".laboratory-shixun-item-#{laboratory_shixun.id}") %> + <% end %> \ No newline at end of file diff --git a/app/views/admins/laboratory_subjects/shared/_list.html.erb b/app/views/admins/laboratory_subjects/shared/_list.html.erb index 8194e3dfb..55f67dea8 100644 --- a/app/views/admins/laboratory_subjects/shared/_list.html.erb +++ b/app/views/admins/laboratory_subjects/shared/_list.html.erb @@ -36,6 +36,10 @@ <%= link_to('去修改', admins_subjects_path(id: laboratory_subject.subject_id)) %> <%= javascript_void_link('首页展示', class: 'action homepage-show-action', data: { id: laboratory_subject.id }, style: laboratory_subject.homepage? ? 'display:none' : '') %> <%= javascript_void_link('取消首页展示', class: 'action homepage-hide-action', data: { id: laboratory_subject.id }, style: laboratory_subject.homepage? ? '' : 'display:none') %> + + <% unless laboratory_subject.ownership? %> + <%= delete_link '删除', admins_laboratory_laboratory_subject_path(current_laboratory, laboratory_subject, element: ".laboratory-subject-item-#{laboratory_subject.id}") %> + <% end %> <% end %> diff --git a/app/views/cooperative/laboratory_shixuns/shared/_td.html.erb b/app/views/cooperative/laboratory_shixuns/shared/_td.html.erb index e7f87057d..d57a05c2e 100644 --- a/app/views/cooperative/laboratory_shixuns/shared/_td.html.erb +++ b/app/views/cooperative/laboratory_shixuns/shared/_td.html.erb @@ -29,4 +29,8 @@ <% end %> <%= javascript_void_link('首页展示', class: 'action homepage-show-action', data: { id: laboratory_shixun.id }, style: laboratory_shixun.homepage? ? 'display:none' : '') %> <%= javascript_void_link('取消首页展示', class: 'action homepage-hide-action', data: { id: laboratory_shixun.id }, style: laboratory_shixun.homepage? ? '' : 'display:none') %> + + <% unless laboratory_shixun.ownership? %> + <%= delete_link '删除', cooperative_laboratory_shixun_path(laboratory_shixun, element: ".laboratory-shixun-item-#{laboratory_shixun.id}") %> + <% end %> \ No newline at end of file diff --git a/app/views/cooperative/laboratory_subjects/shared/_td.html.erb b/app/views/cooperative/laboratory_subjects/shared/_td.html.erb index 301bbd6a7..029fdabce 100644 --- a/app/views/cooperative/laboratory_subjects/shared/_td.html.erb +++ b/app/views/cooperative/laboratory_subjects/shared/_td.html.erb @@ -25,4 +25,8 @@ <%= javascript_void_link('首页展示', class: 'action homepage-show-action', data: { id: laboratory_subject.id }, style: laboratory_subject.homepage? ? 'display:none' : '') %> <%= javascript_void_link('取消首页展示', class: 'action homepage-hide-action', data: { id: laboratory_subject.id }, style: laboratory_subject.homepage? ? '' : 'display:none') %> + + <% unless laboratory_subject.ownership? %> + <%= delete_link '删除', cooperative_laboratory_subject_path(laboratory_subject, element: ".laboratory-subject-item-#{laboratory_subject.id}") %> + <% end %> \ No newline at end of file diff --git a/app/views/home/index.json.jbuilder b/app/views/home/index.json.jbuilder index 5bbd1b799..8edbcb339 100644 --- a/app/views/home/index.json.jbuilder +++ b/app/views/home/index.json.jbuilder @@ -3,11 +3,11 @@ json.images_url @images_url json.reps @rep_list json.shixuns do - json.partial! 'shixuns/shixun', locals: {shixuns: @shixuns.present? ? @shixuns : @main_shixuns} + json.partial! 'shixuns/shixun', locals: {shixuns: @shixuns} end json.subjects do - json.partial! 'subjects/subject', locals: {subjects: @subjects.present? ? @subjects : @main_subjects} + json.partial! 'subjects/subject', locals: {subjects: @subjects} end if current_laboratory.main_site? diff --git a/app/views/users/get_user_info.json.jbuilder b/app/views/users/get_user_info.json.jbuilder index 94f3f76a9..e80c8c215 100644 --- a/app/views/users/get_user_info.json.jbuilder +++ b/app/views/users/get_user_info.json.jbuilder @@ -13,6 +13,7 @@ json.phone @user.phone json.email @user.mail json.profile_completed @user.profile_completed? json.professional_certification @user.professional_certification +json.main_site current_laboratory.main_site? if @course json.course_identity @course_identity json.course_name @course.name diff --git a/config/routes.rb b/config/routes.rb index 0c8f61d3c..6add0d256 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1049,13 +1049,13 @@ Rails.application.routes.draw do post :drag, on: :collection end - resources :laboratory_shixuns, only: [:index, :create] do + resources :laboratory_shixuns, only: [:index, :create, :destroy] do member do post :homepage post :cancel_homepage end end - resources :laboratory_subjects, only: [:index, :create] do + resources :laboratory_subjects, only: [:index, :create, :destroy] do member do post :homepage post :cancel_homepage @@ -1132,13 +1132,13 @@ Rails.application.routes.draw do resources :carousels, only: [:index, :create, :update, :destroy] do post :drag, on: :collection end - resources :laboratory_shixuns, only: [:index, :edit, :update] do + resources :laboratory_shixuns, only: [:index, :edit, :update, :destroy] do member do post :homepage post :cancel_homepage end end - resources :laboratory_subjects, only: [:index, :edit, :update] do + resources :laboratory_subjects, only: [:index, :edit, :update, :destroy] do member do post :homepage post :cancel_homepage