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

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",
    env_key: "karafka.session",
    secret: SecureRandom.hex(64)
  )
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::SortingHelper

#sort_link

Methods included from Helpers::PartitionsHelper

#lag_with_label, #lso_risk_state_badge, #lso_risk_state_bg, #normalized_metric, #offset_with_label, #partition_in_sync_brokers, #partition_replica_brokers

Methods included from Helpers::FormattingHelper

#format_memory, #number_with_delimiter, #object_value_to_s, #truncate

Methods included from Helpers::BadgesHelper

#kafka_state_badge, #lag_trend_badge, #status_badge, #tags

Methods included from Helpers::ApplicationHelper

#deep_merge, #empty_state, #icon, #nav_class, #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)


196
197
198
199
200
# File 'lib/karafka/web/ui/base.rb', line 196

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

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

Returns curated params.

Returns:



216
217
218
# File 'lib/karafka/web/ui/base.rb', line 216

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



205
206
207
208
209
210
211
212
213
# File 'lib/karafka/web/ui/base.rb', line 205

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

  view(response.path)
end