Class: ForemanDatacenter::RacksController

Inherits:
ApplicationController show all
Includes:
Foreman::Controller::AutoCompleteSearch, Controller::Parameters::Rack
Defined in:
app/controllers/foreman_datacenter/racks_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#action_permission, #controller_permission, #find_resource, #not_found, #resource_class, #resource_class_for, #resource_finder, #resource_name, #resource_scope, #scope_for

Instance Method Details

#createObject



30
31
32
33
34
35
36
37
38
# File 'app/controllers/foreman_datacenter/racks_controller.rb', line 30

def create
  @rack = ForemanDatacenter::Rack.new(rack_params)

  if @rack.save
    process_success object: @rack
  else
    process_error object: @rack
  end
end

#destroyObject



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/foreman_datacenter/racks_controller.rb', line 48

def destroy
  unless params['object_only']
    @rack.devices.each { |d| d.destroy }
  else
    @rack.devices.delete_all(:nullify)
  end

  if @rack.destroy
    process_success success_redirect: racks_path
  else
    process_error object: @rack
  end
end

#editObject



27
28
# File 'app/controllers/foreman_datacenter/racks_controller.rb', line 27

def edit
end

#export_to_csvObject



68
69
70
71
72
73
# File 'app/controllers/foreman_datacenter/racks_controller.rb', line 68

def export_to_csv
  data = @rack.format_for_csv
  file = File.open("#{@rack.name}.csv", "r")
  send_file(file)
  file.close
end

#indexObject



8
9
10
# File 'app/controllers/foreman_datacenter/racks_controller.rb', line 8

def index
  @racks = resource_base_search_and_page.includes(:site, :rack_group)
end

#moveObject



62
63
64
65
66
# File 'app/controllers/foreman_datacenter/racks_controller.rb', line 62

def move
  @racks = resource_base_search_and_page
  @devices = @rack.devices
  process_error object: @rack, error_msg: 'Current Rack haven\'t any Devices.' if @devices.empty?
end

#newObject



23
24
25
# File 'app/controllers/foreman_datacenter/racks_controller.rb', line 23

def new
  @rack = ForemanDatacenter::Rack.new
end

#rack_groupsObject

action for async selecting rack_group in rack _form



13
14
15
16
# File 'app/controllers/foreman_datacenter/racks_controller.rb', line 13

def rack_groups
  @rack_groups = ForemanDatacenter::RackGroup.where(site_id: params[:site_id]).all
  render partial: 'rack_groups'
end

#showObject



18
19
20
21
# File 'app/controllers/foreman_datacenter/racks_controller.rb', line 18

def show
  @rack = resource_base.includes(devices: [:device_role]).find(params[:id])
  @order = params[:order] || "desc"
end

#updateObject



40
41
42
43
44
45
46
# File 'app/controllers/foreman_datacenter/racks_controller.rb', line 40

def update
  if @rack.update(rack_params)
    process_success object: @rack
  else
    process_error object: @rack
  end
end

#update_associated_objectsObject



75
76
77
78
79
80
81
82
83
84
# File 'app/controllers/foreman_datacenter/racks_controller.rb', line 75

def update_associated_objects
  begin
    @rack = ForemanDatacenter::Rack.find(request.env['HTTP_REFERER'].split('/')[-2])
    @devices = @rack.devices
    @devices.update_all(rack_id: params[:rack_id])
    process_success success_redirect: racks_path, success_msg: 'Associated objects successfully moved.'
  rescue => e
    process_error object: @rack, error_msg: "#{e}"
  end
end