require_relative "base"
module DashboardRouter
include Rooibos::Router
Command = Rooibos::Command
Model = DashboardBase::Dashboard
Init = DashboardBase::Init
View = DashboardBase::View
route :stats, to: StatsPanel
route :network, to: NetworkPanel
route :shell_modal, to: CustomShellModal
MODAL_INACTIVE = -> (_msg, model) { !CustomShellModal.active?(model.shell_modal) }
action :quit, -> { Command.exit }
receive_events :ctrl_c, :quit
forward -> (msg, _) { Rooibos::Message::System::Batch === msg && %i[system_info disk_usage].include?(msg.envelope) },
to: :stats
forward -> (msg, _) { Rooibos::Message::System::Batch === msg && %i[ping uptime].include?(msg.envelope) },
to: :network
forward_instances_of Rooibos::Message::System::Stream, to: :shell_modal
only when: -> (_msg, model) { CustomShellModal.active?(model.shell_modal) } do
otherwise route_to: :shell_modal
end
only when: MODAL_INACTIVE do
receive_events :q, :quit
forward_events :s, to: :stats, as: :fetch_system_info
forward_events :d, to: :stats, as: :fetch_disk_usage
forward_events :p, to: :network, as: :fetch_ping
forward_events :u, to: :network, as: :fetch_uptime
receive_events :c, -> (_, model) {
model.with(shell_modal: CustomShellModal.open)
}
end
Update = from_router
end