lib/sidekiq/expected_failures/web.rb in sidekiq-expected_failures-0.0.1 vs lib/sidekiq/expected_failures/web.rb in sidekiq-expected_failures-0.2.0
- old
+ new
@@ -1,39 +1,23 @@
-require 'sinatra/assetpack'
-
module Sidekiq
module ExpectedFailures
module Web
def self.registered(app)
- web_dir = File.expand_path("../../../../web", __FILE__)
- assets_dir = File.join(web_dir, "assets")
+ web_dir = File.expand_path("../../../../web", __FILE__)
- app.register Sinatra::AssetPack
-
- app.assets do
- serve '/js', from: assets_dir
- js 'expected', ['/js/expected.js']
- js 'bootstrap', ['/js/bootstrap.js']
- end
-
app.helpers do
def link_to_details(job)
data = []
job["args"].each_with_index { |argument, index| data << "data-#{index+1}='#{h argument.inspect}'" }
"<a href='#' #{data.join(' ')} title='#{job["worker"]}'>Details</a>"
end
end
- app.get "/expected_failures/clear/:what" do
- case params[:what]
- when 'old'
- Sidekiq::ExpectedFailures.clear_old
- when 'all'
- Sidekiq::ExpectedFailures.clear_all
- when 'counters'
- Sidekiq::ExpectedFailures.clear_counters
+ app.post "/expected_failures/clear" do
+ if %w(old all counters).include?(params[:what])
+ Sidekiq::ExpectedFailures.send("clear_#{params[:what]}")
end
redirect "#{root_path}expected_failures"
end
@@ -45,9 +29,13 @@
@date = params[:date] || @dates.keys[0]
(@current_page, @total_size, @jobs) = page("expected:#{@date}", params[:page], @count)
@jobs = @jobs.map { |msg| Sidekiq.load_json(msg) }
@counters = Sidekiq::ExpectedFailures.counters
end
+
+ @javascript = %w(expected bootstrap).map do |file|
+ File.read(File.join(web_dir, "assets/#{file}.js"))
+ end.join
erb File.read(File.join(web_dir, "views/expected_failures.erb"))
end
end
end