Class: Karafka::Web::Ui::Base

Inherits:
Roda
  • Object
show all
Includes:
Helpers::ApplicationHelper, Helpers::PathsHelper, Helpers::TailwindHelper, Helpers::TimeHelper, Helpers::TopicsHelper
Defined in:
lib/karafka/web/ui/base.rb

Overview

Base Roda application

Direct Known Subclasses

Pro::Ui::App, App, Routes::Ux

Constant Summary collapse

CONTEXT_DETAILS =

Details that need to be evaluated in the context of OSS or Pro web UI. If those would be evaluated in the base, they would not be initialized as expected

lambda do
  plugin(
    :public,
    root: Karafka::Web.gem_root.join('lib/karafka/web/ui/public'),
    # Cache all static files for the end user for as long as possible
    # We can do it because we ship per version assets so they invalidate with gem bumps
    headers: { 'Cache-Control' => 'max-age=31536000, immutable' },
    gzip: true,
    brotli: true
  )
  plugin :render_each
  plugin :partials
  # The secret here will be reconfigured after Web UI configuration setup
  # This is why we assign here a random value as it will have to be changed by the end
  # user to make the Web UI work.
  plugin :sessions, key: '_karafka_session', secret: SecureRandom.hex(64)
  plugin :route_csrf
end

Constants included from Helpers::TailwindHelper

Helpers::TailwindHelper::TYPES

Constants included from Helpers::TopicsHelper

Helpers::TopicsHelper::DEFAULT_LIMIT

Instance Method Summary collapse

Methods included from Helpers::TailwindHelper

#badge, #link_button, #tailwind_types

Methods included from Helpers::TopicsHelper

#topics_assignment_label, #topics_assignment_text, #topics_partition_identifier

Methods included from Helpers::TimeHelper

#human_readable_time, #poll_state_with_change_time_label, #relative_time, #time_with_label

Methods included from Helpers::ApplicationHelper

#deep_merge, #flat_hash, #format_memory, #icon, #kafka_state_badge, #lag_trend_badge, #lag_with_label, #lso_risk_state_badge, #lso_risk_state_bg, #nav_class, #normalized_metric, #number_with_delimiter, #object_value_to_s, #offset_with_label, #sort_link, #status_badge, #tags, #truncate, #view_title

Methods included from Helpers::PathsHelper

#action?, #asset_path, #consumer_path, #consumers_path, #explorer_messages_path, #explorer_path, #explorer_topics_path, #flatten_params, #root_path, #scheduled_messages_explorer_path, #topics_path

Instance Method Details

#build(consumer_class) ⇒ Object

Builds a consumer instance with all needed details

Parameters:

  • consumer_class (Class)


174
175
176
177
178
# File 'lib/karafka/web/ui/base.rb', line 174

def build(consumer_class)
  Controllers::Requests::ExecutionWrapper.new(
    consumer_class.new(params, session)
  )
end

#paramsKarafka::Web::Ui::Controllers::Requests::Params

Returns curated params.

Returns:



194
195
196
# File 'lib/karafka/web/ui/base.rb', line 194

def params
  Controllers::Requests::Params.new(request.params)
end

#render_response(response) ⇒ Object

Sets appropriate template variables based on the response object and renders the expected view

Parameters:

  • response (Karafka::Web::Ui::Controllers::Responses::Data)

    response data object



183
184
185
186
187
188
189
190
191
# File 'lib/karafka/web/ui/base.rb', line 183

def render_response(response)
  response.attributes.each do |key, value|
    instance_variable_set(
      "@#{key}", value
    )
  end

  view(response.path)
end