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



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

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

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

#destroyObject



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

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



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

def edit
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



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

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



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

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
# File 'app/controllers/foreman_datacenter/racks_controller.rb', line 18

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

#updateObject



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

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

#update_associated_objectsObject



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

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