Class: RobotLab::Web::Components::Dashboard

Inherits:
Phlex::HTML
  • Object
show all
Defined in:
lib/robot_lab/web/components/dashboard.rb

Overview

The dashboard: registered robots + the recent-activity feed.

Instance Method Summary collapse

Constructor Details

#initialize(robots:, activity:) ⇒ Dashboard

Returns a new instance of Dashboard.



8
9
10
11
# File 'lib/robot_lab/web/components/dashboard.rb', line 8

def initialize(robots:, activity:)
  @robots = robots
  @activity = activity
end

Instance Method Details

#view_templateObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/robot_lab/web/components/dashboard.rb', line 13

def view_template
  h1 { "Robots" }
  if @robots.empty?
    p { "No robots registered. In your boot script:" }
    pre { %(require "robot_lab/web"\n\nRobotLab::Web.register(my_robot)) }
  else
    ul(class: "robots") do
      @robots.each do |name|
        li { a(href: "/robots/#{name}") { name } }
      end
    end
  end

  h2 { "Recent activity" }
  if @activity.empty?
    p(class: "muted") { "Nothing yet." }
  else
    ul(class: "activity") do
      @activity.each { |entry| li { plain activity_line(entry) } }
    end
  end
end