| 
									
										
										
										
											2017-03-30 19:42:33 +02:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Settings::ImportsController < ApplicationController | 
					
						
							|  |  |  |   layout 'admin' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   before_action :authenticate_user! | 
					
						
							|  |  |  |   before_action :set_account | 
					
						
							| 
									
										
										
										
											2018-10-25 07:10:01 +09:00
										 |  |  |   before_action :set_body_classes | 
					
						
							| 
									
										
										
										
											2017-03-30 19:42:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def show | 
					
						
							|  |  |  |     @import = Import.new | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def create | 
					
						
							|  |  |  |     @import = Import.new(import_params) | 
					
						
							|  |  |  |     @import.account = @account | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if @import.save | 
					
						
							|  |  |  |       ImportWorker.perform_async(@import.id) | 
					
						
							|  |  |  |       redirect_to settings_import_path, notice: I18n.t('imports.success') | 
					
						
							|  |  |  |     else | 
					
						
							| 
									
										
										
										
											2017-04-19 09:37:42 -04:00
										 |  |  |       render :show | 
					
						
							| 
									
										
										
										
											2017-03-30 19:42:33 +02:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def set_account | 
					
						
							|  |  |  |     @account = current_user.account | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def import_params | 
					
						
							|  |  |  |     params.require(:import).permit(:data, :type) | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2018-10-25 07:10:01 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def set_body_classes | 
					
						
							|  |  |  |     @body_classes = 'admin' | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2017-03-30 19:42:33 +02:00
										 |  |  | end |