Skip to content

Commit

Permalink
- Add 'first' and 'last' links
Browse files Browse the repository at this point in the history
  • Loading branch information
jls committed Nov 21, 2010
1 parent 27d3c68 commit 6714ab1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/logstash/web/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,21 @@ class LogStash::Web::Server < Sinatra::Base
next_params = params.clone
next_params["offset"] = [offset + count, @total - count].min
@next_href = "?" + next_params.collect { |k,v| [URI.escape(k.to_s), URI.escape(v.to_s)].join("=") }.join("&")
last_params = next_params.clone
last_params["offset"] = @total - offset
@last_href = "?" + last_params.collect { |k,v| [URI.escape(k.to_s), URI.escape(v.to_s)].join("=") }.join("&")
end

if offset > 0
prev_params = params.clone
prev_params["offset"] = [offset - count, 0].max
@prev_href = "?" + prev_params.collect { |k,v| [URI.escape(k.to_s), URI.escape(v.to_s)].join("=") }.join("&")

if prev_params["offset"] > 0
first_params = prev_params.clone
first_params["offset"] = 0
@first_href = "?" + first_params.collect { |k,v| [URI.escape(k.to_s), URI.escape(v.to_s)].join("=") }.join("&")
end
end

body haml :"search/ajax", :layout => !request.xhr?
Expand Down
7 changes: 7 additions & 0 deletions lib/logstash/web/views/search/ajax.haml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
%strong
Results #{@result_start} - #{@result_end} of #{@total}
|
- if @first_href
%a.pager{ :href => @first_href } first
|
- if @prev_href
%a.pager{ :href => @prev_href }
prev
Expand All @@ -22,6 +25,10 @@
- if @next_href
%a.pager{ :href => @next_href }
next
- if @last_href
|
%a.pager{ :href => @last_href }
last
- if @hits.length == 0
- if !params[:q]
No query given. How about <a href="?q=*" class="querychanger">this?</a>
Expand Down

0 comments on commit 6714ab1

Please sign in to comment.