Class: Naf::MachinesController

Inherits:
ApplicationController show all
Includes:
ApplicationHelper, TimeHelper
Defined in:
app/controllers/naf/machines_controller.rb

Constant Summary

Constants included from ApplicationHelper

ApplicationHelper::NAF_ALL_VISIBLE_RESOURCES, ApplicationHelper::NAF_CREATE_BLOCKED_RESOURCES, ApplicationHelper::NAF_DESTROY_BLOCKED_RESOURCES, ApplicationHelper::NAF_READ_ONLY_RESOURCES

Instance Method Summary collapse

Methods included from TimeHelper

#time_difference, #time_format

Methods included from ApplicationHelper

#add_color, #http_protocol, #naf_display_job_search_link?, #naf_generate_back_link, #naf_generate_child_resources_link, #naf_generate_create_link, #naf_generate_destroy_link, #naf_generate_edit_link, #naf_generate_index_link, #naf_highlight_tab?, #naf_last_queued_at_link, #naf_link_to_add_fields, #naf_link_to_remove_fields, #naf_make_header, #naf_model_name, #naf_nested_resource_index?, #naf_parent_resource_link, #naf_table_title, #naf_tabs

Instance Method Details

#createObject



47
48
49
50
51
52
53
54
55
# File 'app/controllers/naf/machines_controller.rb', line 47

def create
  @machine = Naf::Machine.new(params[:machine])
  if @machine.save
    redirect_to(@machine,
                notice: "Machine '#{@machine.server_name.blank? ? @machine.server_address : @machine.server_name}' was successfully created.")
  else
    render action: "new"
  end
end

#editObject



57
58
59
# File 'app/controllers/naf/machines_controller.rb', line 57

def edit
  @machine = Naf::Machine.find(params[:id])
end

#indexObject



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
# File 'app/controllers/naf/machines_controller.rb', line 9

def index
  respond_to do |format|
    format.html
    format.json do
      set_page

      if params['show'].present?
        filter = params['show']['deleted']
      else
        filter = false
      end

      machines = []
      machine = []
      @total_records = Naf::Machine.count(:all)
      Logical::Naf::Machine.all(filter).map(&:to_hash).map do |hash|
        hash.map do |key, value|
          value = '' if value.nil?
          machine << value
        end
        machines << machine
        machine =[]
      end
      @machines = machines.paginate(page: @page, per_page: @rows_per_page)

      render layout: 'naf/layouts/jquery_datatables'
    end
  end
end

#last_checked_schedule_atObject



85
86
87
88
89
# File 'app/controllers/naf/machines_controller.rb', line 85

def last_checked_schedule_at
  render json: {
    last_checked_schedule_at: time_format(::Naf::Machine.last_time_schedules_were_checked)
  }
end

#newObject



43
44
45
# File 'app/controllers/naf/machines_controller.rb', line 43

def new
  @machine = Naf::Machine.new
end

#showObject



39
40
41
# File 'app/controllers/naf/machines_controller.rb', line 39

def show
  @machine = Naf::Machine.includes(:machine_affinity_slots).find(params[:id])
end

#updateObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/controllers/naf/machines_controller.rb', line 61

def update
  respond_to do |format|
    @machine = Naf::Machine.find(params[:id])

    if params[:terminate]
      @machine.mark_machine_down(::Naf::Machine.local_machine)
      format.json do
        render json: { success: true }.to_json
      end
    end

    if @machine.update_attributes(params[:machine])
      format.html do
        redirect_to(@machine,
                    notice: "Machine '#{@machine.server_name.blank? ? @machine.server_address : @machine.server_name}' was successfully updated.")
      end
    else
      format.html do
        render action: "edit"
      end
    end
  end
end