Class: Cosmo::Web::Controllers::Streams

Inherits:
Application show all
Defined in:
lib/cosmo/web/controllers/streams.rb

Constant Summary

Constants included from Renderer

Renderer::ASSETS_ROOT, Renderer::VIEWS_ROOT

Instance Method Summary collapse

Methods inherited from Application

#content_for, #hx_request?, #initialize, #params, #path, #render

Methods included from Renderer

#no_content, #not_found, #ok, #redirect_to, #serve, #url_for

Constructor Details

This class inherits a constructor from Cosmo::Web::Controllers::Application

Instance Method Details

#_infoObject



47
48
49
50
51
# File 'lib/cosmo/web/controllers/streams.rb', line 47

def _info
  name = Rack::Utils.unescape(@request.params["name"])
  stream = API::Stream.new(name)
  ok render("streams/_info", stream.info.merge(name:, paused: stream.paused?))
end

#_tableObject



42
43
44
45
# File 'lib/cosmo/web/controllers/streams.rb', line 42

def _table
  streams = API::Stream.all.map { row_locals(_1) }
  ok render("streams/_table", { streams: streams })
end

#indexObject



9
10
11
12
13
14
# File 'lib/cosmo/web/controllers/streams.rb', line 9

def index
  return _table if hx_request?

  content_for :title, "Streams"
  ok render("streams/index", layout: true)
end

#infoObject



16
17
18
19
20
21
22
# File 'lib/cosmo/web/controllers/streams.rb', line 16

def info
  name = Rack::Utils.unescape(@request.params["name"])
  return _info if hx_request?

  content_for :title, "Streams"
  ok render("streams/info", { name: name }, layout: true)
end

#pauseObject



24
25
26
27
28
29
30
31
# File 'lib/cosmo/web/controllers/streams.rb', line 24

def pause
  name = Rack::Utils.unescape(@request.params["name"])
  stream = API::Stream.new(name)
  stream.pause!
  return ok render("streams/_pause_banner", banner_locals(stream)) if @request.params["banner"]

  ok render("streams/_stream_row", { stream: row_locals(stream) })
end

#unpauseObject



33
34
35
36
37
38
39
40
# File 'lib/cosmo/web/controllers/streams.rb', line 33

def unpause
  name = Rack::Utils.unescape(@request.params["name"])
  stream = API::Stream.new(name)
  stream.unpause!
  return ok render("streams/_pause_banner", banner_locals(stream)) if @request.params["banner"]

  ok render("streams/_stream_row", { stream: row_locals(stream) })
end