Module: Sidekiq::History::WebExtension

Defined in:
lib/sidekiq/history/web_extension.rb

Constant Summary collapse

ROOT =
File.expand_path('../../../web', __dir__)

Class Method Summary collapse

Class Method Details

.registered(app) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/sidekiq/history/web_extension.rb', line 6

def self.registered(app)
  app.get '/history' do
    @count = (params[:count] || 25).to_i
    (@current_page, @total_size, @messages) = page('history', params[:page], @count, reverse: true)
    @messages = @messages.map { |msg, score| Sidekiq::SortedEntry.new(nil, score, msg) }

    render(:erb, File.read("#{ROOT}/views/history.erb"))
  end

  app.post '/history/remove' do
    Sidekiq::History.reset_history(counter: params['counter'])
    redirect("#{root_path}history")
  end

  app.get '/filter/history' do
    return redirect "#{root_path}history" unless params[:substr]

    @messages = search(HistorySet.new, params[:substr])
    render(:erb, File.read("#{ROOT}/views/history.erb"))
  end

  app.post '/filter/history' do
    return redirect "#{root_path}history" unless params[:substr]

    @messages = search(HistorySet.new, params[:substr])
    render(:erb, File.read("#{ROOT}/views/history.erb"))
  end

  app.settings.locales << File.expand_path('locales', ROOT)
end