Class: ImportsController

Inherits:
ArtfullyOseController show all
Defined in:
app/controllers/imports_controller.rb

Instance Method Summary collapse

Instance Method Details

#approveObject



10
11
12
13
14
15
16
# File 'app/controllers/imports_controller.rb', line 10

def approve
  @import = organization.imports.find(params[:id])
  @import.approve!

  flash[:notice] = "Your file has been entered in the import queue. This process may take some time.  Reload this page to see progress or check back in a few minutes."
  redirect_to imports_path
end

#createObject



41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/imports_controller.rb', line 41

def create
  @import = Import.build(@type)
  @import.user = current_user
  @import.organization = organization

  if @import.save
    redirect_to import_path(@import)
  else
    render :new
  end
end

#destroyObject



53
54
55
56
57
# File 'app/controllers/imports_controller.rb', line 53

def destroy
  @import = organization.imports.find(params[:id])
  @import.destroy
  redirect_to imports_path
end

#indexObject



6
7
8
# File 'app/controllers/imports_controller.rb', line 6

def index
  @imports = organization.imports.order('created_at desc').all
end

#newObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/imports_controller.rb', line 25

def new
  if params[:bucket].present? && params[:key].present?      
    @import = Import.build(@type)
    @import.organization  = organization
    @import.s3_bucket     = params[:bucket]
    @import.s3_key        = params[:key]
    @import.s3_etag       = params[:etag]
    @import.status        = "caching"
    @import.user_id       = current_user.id
    @import.caching!
    redirect_to import_path(@import)
  else
    @import = Import.build(@type)
  end
end

#showObject



18
19
20
21
22
23
# File 'app/controllers/imports_controller.rb', line 18

def show
  @import = organization.imports.find(params[:id])
  @parsed_rows = @import.parsed_rows.paginate(:page => params[:page], :per_page => 50)
  
  @people = Person.where(:import_id => @import.id).paginate(:page => params[:page], :per_page => 50) unless @import.id.nil?
end

#templateObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/imports_controller.rb', line 59

def template   
  case @type
  when "events"
    fields = ParsedRow::EVENT_FIELDS
  when "people"
    fields = ParsedRow::PEOPLE_FIELDS
  when "donations"
    fields = ParsedRow::DONATION_FIELDS
  end
  
  columns = fields.map { |field, names| names.first }
  csv_string = CSV.generate { |csv| csv << columns }
  send_data csv_string, :filename => "Artfully-Import-Template.csv", :type => "text/csv", :disposition => "attachment"
end