rosa-build/app/admin/node_instructions.rb

92 lines
2.3 KiB
Ruby
Raw Normal View History

2014-04-14 22:32:25 +01:00
ActiveAdmin.register NodeInstruction do
menu priority: 3
controller do
def scoped_collection
NodeInstruction.includes(:user)
end
end
filter :user_uname, as: :string
filter :status, as: :select, collection: NodeInstruction::STATUSES
filter :updated_at
index do
column :id
column :user
column(:status, sortable: :status) do |ni|
status_tag(ni.status, status_color(ni))
end
column :updated_at
actions
2014-04-14 22:32:25 +01:00
end
form do |f|
f.inputs do
f.input :user, as: :select, include_blank: false, collection: User.system.map { |u| [u.uname, u.id] }
f.input :status, as: :select, include_blank: false, collection: NodeInstruction::STATUSES
f.input :instruction, as: :text
end
f.actions
end
show do
attributes_table do
row :id
row :user
row(:status, sortable: :status) do |ni|
status_tag(ni.status, status_color(ni))
end
row :created_at
row :updated_at
row :instruction
2014-04-17 23:18:00 +01:00
row(:output) do |ni|
ni.output.to_s.lines.join('<br/>').html_safe
end
2014-04-14 22:32:25 +01:00
end
end
sidebar 'Actions', only: :show do
2014-04-15 22:26:12 +01:00
%w(disable ready restart restart_failed).each do |state|
2014-04-14 22:32:25 +01:00
div do
link_to state.humanize, force_admin_node_instruction_path(resource, state: state), method: :patch
end if resource.send("can_#{state}?")
end
end
2014-04-17 20:08:22 +01:00
sidebar 'Actions', only: :index do
locked = NodeInstruction.all_locked?
span(class: "status_tag #{locked ? 'red' : 'green'}") do
if locked
link_to 'Unlock instructions', unlock_all_admin_node_instructions_path, method: :post
else
link_to 'Lock instructions', lock_all_admin_node_instructions_path, method: :post
end
2014-04-14 22:32:25 +01:00
end
2014-04-17 20:08:22 +01:00
end
collection_action :lock_all, method: :post do
NodeInstruction.lock_all
flash[:notice] = 'Locked successfully'
2014-04-17 20:08:22 +01:00
redirect_to admin_node_instructions_path
end
collection_action :unlock_all, method: :post do
NodeInstruction.unlock_all
flash[:notice] = 'Unlocked successfully'
2014-04-17 20:08:22 +01:00
redirect_to admin_node_instructions_path
end
member_action :force, method: :patch do
resource.send(params[:state])
flash[:notice] = 'Updated successfully'
2014-04-14 22:32:25 +01:00
redirect_to admin_node_instruction_path(resource)
end
end