mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
* Simplify poller by using query string so it works on all pages
* Minify jquery.timeago * Consolidate js into one file to minimize requests for page refresh * Remove bootstrap.js since it doesn't appear to be used
This commit is contained in:
parent
b3ce389024
commit
1869a29503
11 changed files with 44 additions and 274 deletions
|
@ -121,10 +121,6 @@ module Sidekiq
|
|||
slim :index
|
||||
end
|
||||
|
||||
get "/poll" do
|
||||
slim :poll, layout: false
|
||||
end
|
||||
|
||||
get "/queues" do
|
||||
@queues = queues
|
||||
slim :queues
|
||||
|
|
|
@ -35,14 +35,6 @@ class TestWeb < MiniTest::Unit::TestCase
|
|||
refute_match /default/, last_response.body
|
||||
end
|
||||
|
||||
it 'can display poll' do
|
||||
get '/poll'
|
||||
assert_equal 200, last_response.status
|
||||
assert_match /summary/, last_response.body
|
||||
assert_match /workers/, last_response.body
|
||||
refute_match /navbar/, last_response.body
|
||||
end
|
||||
|
||||
it 'can display queues' do
|
||||
assert Sidekiq::Client.push('queue' => :foo, 'class' => WebWorker, 'args' => [1, 3])
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
7
web/assets/javascripts/vendor/bootstrap.js
vendored
7
web/assets/javascripts/vendor/bootstrap.js
vendored
File diff suppressed because one or more lines are too long
3
web/assets/javascripts/vendor/jquery.js
vendored
3
web/assets/javascripts/vendor/jquery.js
vendored
File diff suppressed because one or more lines are too long
148
web/assets/javascripts/vendor/jquery.timeago.js
vendored
148
web/assets/javascripts/vendor/jquery.timeago.js
vendored
|
@ -1,148 +0,0 @@
|
|||
/**
|
||||
* Timeago is a jQuery plugin that makes it easy to support automatically
|
||||
* updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago").
|
||||
*
|
||||
* @name timeago
|
||||
* @version 0.11.1
|
||||
* @requires jQuery v1.2.3+
|
||||
* @author Ryan McGeary
|
||||
* @license MIT License - http://www.opensource.org/licenses/mit-license.php
|
||||
*
|
||||
* For usage and examples, visit:
|
||||
* http://timeago.yarp.com/
|
||||
*
|
||||
* Copyright (c) 2008-2011, Ryan McGeary (ryanonjavascript -[at]- mcgeary [*dot*] org)
|
||||
*/
|
||||
(function($) {
|
||||
$.timeago = function(timestamp) {
|
||||
if (timestamp instanceof Date) {
|
||||
return inWords(timestamp);
|
||||
} else if (typeof timestamp === "string") {
|
||||
return inWords($.timeago.parse(timestamp));
|
||||
} else {
|
||||
return inWords($.timeago.datetime(timestamp));
|
||||
}
|
||||
};
|
||||
var $t = $.timeago;
|
||||
|
||||
$.extend($.timeago, {
|
||||
settings: {
|
||||
refreshMillis: 60000,
|
||||
allowFuture: false,
|
||||
strings: {
|
||||
prefixAgo: null,
|
||||
prefixFromNow: null,
|
||||
suffixAgo: "ago",
|
||||
suffixFromNow: "from now",
|
||||
seconds: "less than a minute",
|
||||
minute: "about a minute",
|
||||
minutes: "%d minutes",
|
||||
hour: "about an hour",
|
||||
hours: "about %d hours",
|
||||
day: "a day",
|
||||
days: "%d days",
|
||||
month: "about a month",
|
||||
months: "%d months",
|
||||
year: "about a year",
|
||||
years: "%d years",
|
||||
wordSeparator: " ",
|
||||
numbers: []
|
||||
}
|
||||
},
|
||||
inWords: function(distanceMillis) {
|
||||
var $l = this.settings.strings;
|
||||
var prefix = $l.prefixAgo;
|
||||
var suffix = $l.suffixAgo;
|
||||
if (this.settings.allowFuture) {
|
||||
if (distanceMillis < 0) {
|
||||
prefix = $l.prefixFromNow;
|
||||
suffix = $l.suffixFromNow;
|
||||
}
|
||||
}
|
||||
|
||||
var seconds = Math.abs(distanceMillis) / 1000;
|
||||
var minutes = seconds / 60;
|
||||
var hours = minutes / 60;
|
||||
var days = hours / 24;
|
||||
var years = days / 365;
|
||||
|
||||
function substitute(stringOrFunction, number) {
|
||||
var string = $.isFunction(stringOrFunction) ? stringOrFunction(number, distanceMillis) : stringOrFunction;
|
||||
var value = ($l.numbers && $l.numbers[number]) || number;
|
||||
return string.replace(/%d/i, value);
|
||||
}
|
||||
|
||||
var words = seconds < 45 && substitute($l.seconds, Math.round(seconds)) ||
|
||||
seconds < 90 && substitute($l.minute, 1) ||
|
||||
minutes < 45 && substitute($l.minutes, Math.round(minutes)) ||
|
||||
minutes < 90 && substitute($l.hour, 1) ||
|
||||
hours < 24 && substitute($l.hours, Math.round(hours)) ||
|
||||
hours < 42 && substitute($l.day, 1) ||
|
||||
days < 30 && substitute($l.days, Math.round(days)) ||
|
||||
days < 45 && substitute($l.month, 1) ||
|
||||
days < 365 && substitute($l.months, Math.round(days / 30)) ||
|
||||
years < 1.5 && substitute($l.year, 1) ||
|
||||
substitute($l.years, Math.round(years));
|
||||
|
||||
var separator = $l.wordSeparator === undefined ? " " : $l.wordSeparator;
|
||||
return $.trim([prefix, words, suffix].join(separator));
|
||||
},
|
||||
parse: function(iso8601) {
|
||||
var s = $.trim(iso8601);
|
||||
s = s.replace(/\.\d\d\d+/,""); // remove milliseconds
|
||||
s = s.replace(/-/,"/").replace(/-/,"/");
|
||||
s = s.replace(/T/," ").replace(/Z/," UTC");
|
||||
s = s.replace(/([\+\-]\d\d)\:?(\d\d)/," $1$2"); // -04:00 -> -0400
|
||||
return new Date(s);
|
||||
},
|
||||
datetime: function(elem) {
|
||||
// jQuery's `is()` doesn't play well with HTML5 in IE
|
||||
var isTime = $(elem).get(0).tagName.toLowerCase() === "time"; // $(elem).is("time");
|
||||
var iso8601 = isTime ? $(elem).attr("datetime") : $(elem).attr("title");
|
||||
return $t.parse(iso8601);
|
||||
}
|
||||
});
|
||||
|
||||
$.fn.timeago = function() {
|
||||
var self = this;
|
||||
self.each(refresh);
|
||||
|
||||
var $s = $t.settings;
|
||||
if ($s.refreshMillis > 0) {
|
||||
setInterval(function() { self.each(refresh); }, $s.refreshMillis);
|
||||
}
|
||||
return self;
|
||||
};
|
||||
|
||||
function refresh() {
|
||||
var data = prepareData(this);
|
||||
if (!isNaN(data.datetime)) {
|
||||
$(this).text(inWords(data.datetime));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
function prepareData(element) {
|
||||
element = $(element);
|
||||
if (!element.data("timeago")) {
|
||||
element.data("timeago", { datetime: $t.datetime(element) });
|
||||
var text = $.trim(element.text());
|
||||
if (text.length > 0) {
|
||||
element.attr("title", text);
|
||||
}
|
||||
}
|
||||
return element.data("timeago");
|
||||
}
|
||||
|
||||
function inWords(date) {
|
||||
return $t.inWords(distance(date));
|
||||
}
|
||||
|
||||
function distance(date) {
|
||||
return (new Date().getTime() - date.getTime());
|
||||
}
|
||||
|
||||
// fix for IE6 suckage
|
||||
document.createElement("abbr");
|
||||
document.createElement("time");
|
||||
}(jQuery));
|
|
@ -216,17 +216,6 @@ header.row .pagination {
|
|||
font-weight: bold;
|
||||
float: right;
|
||||
}
|
||||
.summary_bar .poll-status {
|
||||
height: 58px;
|
||||
text-align: center;
|
||||
}
|
||||
.summary_bar .poll-status .text {
|
||||
font-weight: 300;
|
||||
}
|
||||
.summary_bar .poll-status .time {
|
||||
color: #008800;
|
||||
font-weight: 320;
|
||||
}
|
||||
|
||||
table.table-white {
|
||||
background-color: #fff;
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
table class="queues table table-hover table-bordered table-striped table-white"
|
||||
thead
|
||||
th Queue
|
||||
th Size
|
||||
th Actions
|
||||
- queues.each do |(queue, size)|
|
||||
tr
|
||||
td
|
||||
a href="#{root_path}queues/#{queue}" #{queue}
|
||||
td= number_with_delimiter(size)
|
||||
td width="20%"
|
||||
form action="#{root_path}queues/#{queue}" method="post"
|
||||
input.btn.btn-danger.btn-small type="submit" name="delete" value="Delete" data-confirm="Are you sure you want to delete the #{queue} queue?"
|
|
@ -4,6 +4,11 @@ html
|
|||
link href='#{{root_path}}stylesheets/bootstrap.css' media='screen' rel='stylesheet' type='text/css'
|
||||
link href='#{{root_path}}stylesheets/application.css' media='screen' rel='stylesheet' type='text/css'
|
||||
title= Sidekiq::NAME
|
||||
|
||||
- if params[:poll]
|
||||
javascript:
|
||||
setInterval("window.location.reload(true)", 2000);
|
||||
|
||||
body.admin
|
||||
.navbar.navbar-fixed-top
|
||||
==slim :_nav
|
||||
|
@ -19,7 +24,6 @@ html
|
|||
li
|
||||
p.navbar-text Time: #{Time.now.utc.strftime('%H:%M:%S UTC')}
|
||||
|
||||
|
||||
#page
|
||||
.container
|
||||
.row
|
||||
|
@ -30,15 +34,12 @@ html
|
|||
== slim :_summary
|
||||
.row
|
||||
.span2
|
||||
a#live-poll.btn.btn-block.btn-primary name='poll' href='#{{root_path}}poll' Live Poll
|
||||
.span2.poll-status
|
||||
span.text
|
||||
span.time
|
||||
- if params[:poll]
|
||||
a#live-poll.btn.btn-block.btn-primary.active href='#{{root_path}}#{{current_path}}' Stop Polling
|
||||
- else
|
||||
a#live-poll.btn.btn-block.btn-primary href='#{{root_path}}#{{current_path}}?poll=true' Live Poll
|
||||
|
||||
.span10
|
||||
== yield
|
||||
|
||||
script type="text/javascript" src="#{{root_path}}javascripts/vendor/jquery.js"
|
||||
script type="text/javascript" src="#{{root_path}}javascripts/vendor/jquery.timeago.js"
|
||||
script type="text/javascript" src="#{{root_path}}javascripts/vendor/bootstrap.js"
|
||||
script type="text/javascript" src="#{{root_path}}javascripts/application.js"
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
div
|
||||
== slim :_summary
|
||||
== slim :_workers
|
||||
== slim :_status
|
||||
== slim :_queues
|
|
@ -1,3 +1,15 @@
|
|||
h3 Queues
|
||||
|
||||
== slim :_queues
|
||||
table class="queues table table-hover table-bordered table-striped table-white"
|
||||
thead
|
||||
th Queue
|
||||
th Size
|
||||
th Actions
|
||||
- queues.each do |(queue, size)|
|
||||
tr
|
||||
td
|
||||
a href="#{root_path}queues/#{queue}" #{queue}
|
||||
td= number_with_delimiter(size)
|
||||
td width="20%"
|
||||
form action="#{root_path}queues/#{queue}" method="post"
|
||||
input.btn.btn-danger.btn-small type="submit" name="delete" value="Delete" data-confirm="Are you sure you want to delete the #{queue} queue?"
|
Loading…
Add table
Reference in a new issue