1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Merge pull request #1284 from aackerman/sidekiq-web-query-params

Allow polling and paging parameters to work together in Sidekiq web ui
This commit is contained in:
Mike Perham 2013-10-25 22:13:43 -07:00
commit 4a77fd6e2b
3 changed files with 17 additions and 7 deletions

View file

@ -76,7 +76,7 @@ module Sidekiq
def location def location
Sidekiq.redis { |conn| conn.client.location } Sidekiq.redis { |conn| conn.client.location }
end end
def redis_connection def redis_connection
Sidekiq.redis { |conn| conn.client.id } Sidekiq.redis { |conn| conn.client.id }
end end
@ -110,6 +110,16 @@ module Sidekiq
[score.to_f, jid] [score.to_f, jid]
end end
SAFE_QPARAMS = %w(page poll)
# Merge options with current params, filter safe params, and stringify to query string
def qparams(options)
options = options.stringify_keys
params.merge(options).map { |key, value|
SAFE_QPARAMS.include?(key) ? "#{key}=#{value}" : next
}.join("&")
end
def truncate(text, truncate_after_chars = 2000) def truncate(text, truncate_after_chars = 2000)
truncate_after_chars && text.size > truncate_after_chars ? "#{text[0..truncate_after_chars]}..." : text truncate_after_chars && text.size > truncate_after_chars ? "#{text[0..truncate_after_chars]}..." : text
end end

View file

@ -1,23 +1,23 @@
<% if @total_size > @count %> <% if @total_size > @count %>
<ul class="pagination pull-right"> <ul class="pagination pull-right">
<li class="<%= 'disabled' if @current_page == 1 %>"> <li class="<%= 'disabled' if @current_page == 1 %>">
<a href="<%= url %>?page=1">«</a> <a href="<%= url %>?page=1">&laquo;</a>
</li> </li>
<% if @current_page > 1 %> <% if @current_page > 1 %>
<li> <li>
<a href="<%= url %>?page=<%= @current_page - 1 %>"><%= @current_page - 1 %></a> <a href="<%= url %>?<%= qparams(page: @current_page - 1) %>"><%= @current_page - 1 %></a>
</li> </li>
<% end %> <% end %>
<li class="disabled"> <li class="disabled">
<a href="<%= url %>?page=<%= @current_page %>"><%= @current_page %></a> <a href="<%= url %>?<%= qparams(page: @current_page) %>"><%= @current_page %></a>
</li> </li>
<% if @total_size > @current_page * @count %> <% if @total_size > @current_page * @count %>
<li> <li>
<a href="<%= url %>?page=<%= @current_page + 1 %>"><%= @current_page + 1 %></a> <a href="<%= url %>?<%= qparams(page: @current_page + 1) %>"><%= @current_page + 1 %></a>
</li> </li>
<% end %> <% end %>
<li class="<%= 'disabled' if @total_size <= @current_page * @count %>"> <li class="<%= 'disabled' if @total_size <= @current_page * @count %>">
<a href="<%= url %>?page=<%= (@total_size.to_f / @count).ceil %>">»</a> <a href="<%= url %>?<%= qparams(page: (@total_size.to_f / @count).ceil) %>">&raquo;</a>
</li> </li>
</ul> </ul>
<% end %> <% end %>

View file

@ -7,6 +7,6 @@
<% if params[:poll] %> <% if params[:poll] %>
<a id="live-poll" class="btn btn-primary active" href="<%= root_path %><%= current_path %>"><%= t('StopPolling') %></a> <a id="live-poll" class="btn btn-primary active" href="<%= root_path %><%= current_path %>"><%= t('StopPolling') %></a>
<% else %> <% else %>
<a id="live-poll" class="btn btn-primary" href="<%= root_path %><%= current_path %>?poll=true"><%= t('LivePoll') %></a> <a id="live-poll" class="btn btn-primary" href="<%= root_path %><%= current_path %>?<%= qparams(poll: true) %>"><%= t('LivePoll') %></a>
<% end %> <% end %>
<% end %> <% end %>