Class: Admin::AnimalsController

Inherits:
ApplicationController
  • Object
show all
Includes:
PublicActivity::StoreController
Defined in:
app/controllers/admin/animals_controller.rb

Instance Method Summary collapse

Instance Method Details

#add_imageObject


127
128
129
130
131
132
133
134
135
# File 'app/controllers/admin/animals_controller.rb', line 127

def add_image
  @animal = Animal.find(params[:id])
  if @animal.update_attributes(params[:animal])
    flash[:notice] = 'Successfully added image.'
  else
    flash[:error] = @animal.errors.messages.first
  end
  redirect_to admin_animal_path(@animal)
end

#cage_cardObject


102
103
104
105
106
107
108
109
# File 'app/controllers/admin/animals_controller.rb', line 102

def cage_card
  @animal = Animal.includes(:animal_color, :animal_sex, :species, :status, :organization, :spay_neuter, :shelter).find(params[:id])

  respond_with(@animal) do |format|
    format.html {render :action => "cage_card", :layout => "cage_card"}
    format.xml  { render :xml => @animal }
  end
end

#createObject


62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/admin/animals_controller.rb', line 62

def create
  @animal = current_user.organization.animals.new(animal_params)
  if @animal.save
    $statsd.increment 'animal.created'
    flash[:notice] = 'Animal was successfully created.'
  else
    flash[:error] = 'Animal was not successfully created.'
  end
  
  respond_with(@animal, :location => admin_animal_path(@animal))
end

#destroyObject


81
82
83
84
85
86
87
88
# File 'app/controllers/admin/animals_controller.rb', line 81

def destroy
  @animal = Animal.find(params[:id])
  @animal.destroy
  $statsd.increment 'animal.deleted'
  flash[:notice] = 'Successfully destroyed animal.'
  
  respond_with(@animal, :location => admin_animals_path)
end

#duplicateObject


90
91
92
93
94
95
96
97
98
99
100
# File 'app/controllers/admin/animals_controller.rb', line 90

def duplicate
  new_record = Animal.find(params[:id]).dup
  if new_record.save
    $statsd.increment 'animal.duplicated'
    flash[:notice] = 'Successfully duplicated.'
  else
    flash[:error] = 'There was a problem duplicating.'
  end
  
  redirect_to :back
end

#editObject


58
59
60
# File 'app/controllers/admin/animals_controller.rb', line 58

def edit
  redirect_to admin_animal_path(params[:id])
end

#indexObject


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/admin/animals_controller.rb', line 7

def index
  if !params[:archived_view]
    @archived_condition = {archived: false}
  end
  @search = Animal.select('animals.name,
                            animals.microchip,
                            animals.birthday,
                            animals.id,
                            animals.status_id,
                            animals.animal_color_id,
                            animals.animal_sex_id,
                            animals.species_id,
                            animals.spay_neuter_id,
                            animals.updated_at,
                            animals.image,
                            animals.image_file_name,
                            animals.image_updated_at,
                            animals.organization_id,
                            animals.created_at,
                            animals.updated_at').
                  includes(:animal_color, :animal_sex, :species, :status, :organization, :spay_neuter).
                  organization(current_user).
                  where(@archived_condition).
                  search(params[:q])
  @animals = @search.result.paginate(:page => params[:page], :per_page => 10).order("name ASC")
  
  @presenter = Admin::Animals::IndexPresenter.new(current_user)
  
  respond_with(@animals) do |format|
    format.html
    format.csv { render :csv => Animal.includes(:animal_color, :animal_sex, :species, :status, :organization, :spay_neuter, :biter).organization(current_user).all,
                        :filename => 'animals' }
  end
end

#newObject


51
52
53
54
55
56
# File 'app/controllers/admin/animals_controller.rb', line 51

def new
  @animal = Animal.new
  @presenter = Admin::Animals::NewPresenter.new(current_user)
  
  respond_with(@animal)
end

#qr_codeObject


111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'app/controllers/admin/animals_controller.rb', line 111

def qr_code
  @animal = Animal.includes(:animal_color, :animal_sex, :species, :status, :organization, :spay_neuter, :shelter).find(params[:id])

  respond_to do |format|
    format.html {render :action => "qr_code", :layout => "qr_code"}
    format.svg { render :qrcode => "
      #{@animal.name}
      #{@animal.species_name}
      ----
      #{@animal.organization_name} 
      #{view_context.number_to_phone(@animal.organization_phone_number, :area_code => true) unless @animal.organization_phone_number.blank?}
      #{@animal.organization_address unless @animal.organization_address.blank?}
      #{@animal.organization_city unless @animal.organization_city.blank?} #{@animal.organization_state unless @animal.organization_state.blank?} #{@animal.organization_zip_code unless @animal.organization_zip_code.blank?}", :level => :h, :unit => 6 }
  end
end

#showObject


42
43
44
45
46
47
48
49
# File 'app/controllers/admin/animals_controller.rb', line 42

def show
  @animal = Animal.includes(:animal_color, :animal_sex, :species, :status, :organization, :spay_neuter, :shelter, :shots).find(params[:id])
  if @animal.documents.blank?
    @animal.documents.build
  end
  @presenter = Admin::Animals::ShowPresenter.new(current_user, @animal)
  respond_with(@animal)
end

#updateObject


74
75
76
77
78
79
# File 'app/controllers/admin/animals_controller.rb', line 74

def update
  @animal = Animal.find(params[:id])
  @animal.update_attributes(animal_params)
  $statsd.increment 'animal.updated'
  respond_with(@animal, :location => admin_animal_path(@animal)) 
end