Class: ForemanDatacenter::RackGroupsController

Inherits:
ApplicationController show all
Includes:
Foreman::Controller::AutoCompleteSearch, Controller::Parameters::RackGroup
Defined in:
app/controllers/foreman_datacenter/rack_groups_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



22
23
24
25
26
27
28
29
30
# File 'app/controllers/foreman_datacenter/rack_groups_controller.rb', line 22

def create
  @rack_group = ForemanDatacenter::RackGroup.new(rack_group_params)

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

#destroyObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/foreman_datacenter/rack_groups_controller.rb', line 40

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

  if @rack_group.destroy
    process_success success_redirect: "/datacenter/rack_groups"
  else
    process_error object: @rack_group
  end
end

#editObject



19
20
# File 'app/controllers/foreman_datacenter/rack_groups_controller.rb', line 19

def edit
end

#indexObject



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

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

#moveObject



55
56
57
58
59
# File 'app/controllers/foreman_datacenter/rack_groups_controller.rb', line 55

def move
  @rack_groups = resource_base_search_and_page
  @racks = @rack_group.racks
  process_error object: @rack_group, error_msg: 'Current Rack Group haven\'t any Racks.' if @racks.empty?
end

#newObject



15
16
17
# File 'app/controllers/foreman_datacenter/rack_groups_controller.rb', line 15

def new
  @rack_group = ForemanDatacenter::RackGroup.new
end

#racksObject



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

def racks
  @racks = @rack_group.racks.includes(devices: [:device_role])
  process_error redirect: rack_groups_path(@rack_group), error_msg: 'Current Rack Group haven\'t any Racks.' if @racks.empty?
end

#showObject



12
13
# File 'app/controllers/foreman_datacenter/rack_groups_controller.rb', line 12

def show
end

#updateObject



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

def update
  if @rack_group.update(rack_group_params)
    process_success object: @rack_group
  else
    process_error object: @rack_group
  end
end

#update_associated_objectsObject



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

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