|  |  | @ -1,15 +1,17 @@ | 
			
		
	
		
		
			
				
					
					|  |  |  | class Admins::CarouselsController < Admins::BaseController |  |  |  | class Admins::CarouselsController < Admins::BaseController | 
			
		
	
		
		
			
				
					
					|  |  |  |   before_action :convert_file!, only: [:create] |  |  |  |   before_action :convert_file!, only: [:create] | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   helper_method :current_laboratory | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   def index |  |  |  |   def index | 
			
		
	
		
		
			
				
					
					|  |  |  |     @images = PortalImage.order(position: :asc) |  |  |  |     @images = current_laboratory.portal_images.order(position: :asc) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |   end |  |  |  |   end | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   def create |  |  |  |   def create | 
			
		
	
		
		
			
				
					
					|  |  |  |     position = PortalImage.count + 1 |  |  |  |     position = current_laboratory.portal_images.count + 1 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     ActiveRecord::Base.transaction do |  |  |  |     ActiveRecord::Base.transaction do | 
			
		
	
		
		
			
				
					
					|  |  |  |       image = PortalImage.create!(create_params.merge(position: position)) |  |  |  |       image = current_laboratory.portal_images.create!(create_params.merge(position: position)) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |       file_path = Util::FileManage.disk_filename('PortalImage', image.id) |  |  |  |       file_path = Util::FileManage.disk_filename('PortalImage', image.id) | 
			
		
	
		
		
			
				
					
					|  |  |  |       File.delete(file_path) if File.exist?(file_path) # 删除之前的文件 |  |  |  |       File.delete(file_path) if File.exist?(file_path) # 删除之前的文件 | 
			
		
	
	
		
		
			
				
					|  |  | @ -17,7 +19,7 @@ class Admins::CarouselsController < Admins::BaseController | 
			
		
	
		
		
			
				
					
					|  |  |  |     end |  |  |  |     end | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     flash[:success] = '保存成功' |  |  |  |     flash[:success] = '保存成功' | 
			
		
	
		
		
			
				
					
					|  |  |  |     redirect_to admins_carousels_path |  |  |  |     redirect_to admins_laboratory_carousels_path(current_laboratory) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |   end |  |  |  |   end | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   def update |  |  |  |   def update | 
			
		
	
	
		
		
			
				
					|  |  | @ -29,7 +31,7 @@ class Admins::CarouselsController < Admins::BaseController | 
			
		
	
		
		
			
				
					
					|  |  |  |     ActiveRecord::Base.transaction do |  |  |  |     ActiveRecord::Base.transaction do | 
			
		
	
		
		
			
				
					
					|  |  |  |       current_image.destroy! |  |  |  |       current_image.destroy! | 
			
		
	
		
		
			
				
					
					|  |  |  |       # 前移 |  |  |  |       # 前移 | 
			
		
	
		
		
			
				
					
					|  |  |  |       PortalImage.where('position > ?', current_image.position) |  |  |  |       current_laboratory.portal_images.where('position > ?', current_image.position) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         .update_all('position = position - 1') |  |  |  |         .update_all('position = position - 1') | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |       file_path = Util::FileManage.disk_filename('PortalImage', current_image.id) |  |  |  |       file_path = Util::FileManage.disk_filename('PortalImage', current_image.id) | 
			
		
	
	
		
		
			
				
					|  |  | @ -39,10 +41,10 @@ class Admins::CarouselsController < Admins::BaseController | 
			
		
	
		
		
			
				
					
					|  |  |  |   end |  |  |  |   end | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   def drag |  |  |  |   def drag | 
			
		
	
		
		
			
				
					
					|  |  |  |     move  = PortalImage.find_by(id: params[:move_id]) |  |  |  |     move  = current_laboratory.portal_images.find_by(id: params[:move_id]) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     after = PortalImage.find_by(id: params[:after_id]) |  |  |  |     after = current_laboratory.portal_images.find_by(id: params[:after_id]) | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     Admins::DragPortalImageService.call(move, after) |  |  |  |     Admins::DragPortalImageService.call(current_laboratory, move, after) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     render_ok |  |  |  |     render_ok | 
			
		
	
		
		
			
				
					
					|  |  |  |   rescue Admins::DragPortalImageService::Error => e |  |  |  |   rescue Admins::DragPortalImageService::Error => e | 
			
		
	
		
		
			
				
					
					|  |  |  |     render_error(e.message) |  |  |  |     render_error(e.message) | 
			
		
	
	
		
		
			
				
					|  |  | @ -50,8 +52,12 @@ class Admins::CarouselsController < Admins::BaseController | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   private |  |  |  |   private | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   def current_laboratory | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     @_current_laboratory ||= Laboratory.find(params[:laboratory_id]) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   end | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   def current_image |  |  |  |   def current_image | 
			
		
	
		
		
			
				
					
					|  |  |  |     @_current_image ||= PortalImage.find(params[:id]) |  |  |  |     @_current_image ||= current_laboratory.portal_images.find(params[:id]) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |   end |  |  |  |   end | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   def create_params |  |  |  |   def create_params | 
			
		
	
	
		
		
			
				
					|  |  | 
 |