2011-10-30 23:02:41 +00:00
|
|
|
module Locomotive
|
2011-07-04 13:25:02 +00:00
|
|
|
class ImportController < BaseController
|
2010-09-28 22:08:11 +00:00
|
|
|
|
|
|
|
sections 'settings', 'site'
|
|
|
|
|
2011-06-26 23:02:48 +00:00
|
|
|
skip_load_and_authorize_resource
|
|
|
|
|
|
|
|
before_filter :authorize_import
|
|
|
|
|
2010-09-28 22:08:11 +00:00
|
|
|
def show
|
2011-12-08 15:47:17 +00:00
|
|
|
@import = Locomotive::Import::Model.current(current_site)
|
|
|
|
respond_with @import
|
2010-09-28 22:08:11 +00:00
|
|
|
end
|
|
|
|
|
2011-11-20 10:59:12 +00:00
|
|
|
def new
|
2011-12-08 15:47:17 +00:00
|
|
|
@import = Locomotive::Import::Model.new
|
|
|
|
respond_with @import
|
2011-11-20 10:59:12 +00:00
|
|
|
end
|
2010-09-28 22:08:11 +00:00
|
|
|
|
|
|
|
def create
|
2011-12-08 15:47:17 +00:00
|
|
|
@import = Locomotive::Import::Model.create(params[:import].merge(:site => current_site))
|
|
|
|
respond_with @import, :location => Locomotive.config.delayed_job ? import_url : new_import_url
|
2010-09-28 22:08:11 +00:00
|
|
|
end
|
|
|
|
|
2011-06-26 23:02:48 +00:00
|
|
|
protected
|
|
|
|
|
|
|
|
def authorize_import
|
2011-06-27 15:27:07 +00:00
|
|
|
authorize! :import, Site
|
2011-06-26 23:02:48 +00:00
|
|
|
end
|
|
|
|
|
2010-09-28 22:08:11 +00:00
|
|
|
end
|
2011-11-20 10:59:12 +00:00
|
|
|
end
|
2011-12-08 15:47:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
# begin
|
|
|
|
# Locomotive::Import::Job.run!(params[:zipfile], current_site, {
|
|
|
|
# :samples => Boolean.set(params[:samples]),
|
|
|
|
# :reset => Boolean.set(params[:reset])
|
|
|
|
# })
|
|
|
|
#
|
|
|
|
# flash[:notice] = t("fash.locomotive.import.create.#{Locomotive.config.delayed_job ? 'notice' : 'done'}")
|
|
|
|
#
|
|
|
|
# redirect_to Locomotive.config.delayed_job ? import_url : new_import_url
|
|
|
|
# rescue Exception => e
|
|
|
|
# logger.error "[Locomotive import] #{e.message} / #{e.backtrace}"
|
|
|
|
#
|
|
|
|
# @error = e.message
|
|
|
|
# flash[:alert] = t('fash.locomotive.import.create.alert')
|
|
|
|
#
|
|
|
|
# render 'new'
|
|
|
|
# end
|
|
|
|
|
|
|
|
# def show
|
|
|
|
# @job = Delayed::Job.where({ :job_type => 'import', :site_id => current_site.id }).last
|
|
|
|
#
|
|
|
|
# respond_to do |format|
|
|
|
|
# format.html do
|
|
|
|
# redirect_to new_import_url if @job.nil?
|
|
|
|
# end
|
|
|
|
# format.json { render :json => {
|
|
|
|
# :step => @job.nil? ? 'done' : @job.step,
|
|
|
|
# :failed => @job && @job.last_error.present?
|
|
|
|
# } }
|
|
|
|
# end
|
|
|
|
# end
|