module RocketJobMissionControl class ServersDatatable < AbstractDatatable delegate :server_icon, :server_path, :stop_server_path, :resume_server_path, :pause_server_path, :server_card_class, to: :@view def initialize(view, query) query.display_columns = %w[name heartbeat.workers started_at heartbeat.updated_at] query.search_columns = [:name] super(view, query) end private def map(server) { '0' => name_with_icon(server), '1' => h(threads(server)), '2' => h(started_ago(server)), '3' => h(time_since_heartbeat(server)), '4' => action_links_html(server), 'DT_RowClass' => "card callout #{server_card_class(server)}" } end def name_with_icon(server) <<-EOS #{server.name} EOS end def threads(server) "#{server.try!(:heartbeat).try!(:workers).to_i}/#{server.max_workers}" end def started_ago(server) "#{RocketJob.seconds_as_duration(Time.now - (server.started_at || Time.now))} ago" end def time_since_heartbeat(server) "#{RocketJob.seconds_as_duration(Time.now - (server.try!(:heartbeat).try!(:updated_at) || Time.now))} ago" end def action_links_html(server) actions = '