pagination on the history page

This commit is contained in:
rick
2010-08-12 09:38:28 -07:00
parent b118436fa9
commit 45de814154
3 changed files with 37 additions and 12 deletions
+5 -3
View File
@@ -80,9 +80,11 @@ module Precious
end
get '/history/:name' do
@name = params[:name]
wiki = Gollum::Wiki.new($path)
@page = wiki.page(@name)
@name = params[:name]
wiki = Gollum::Wiki.new($path)
@page = wiki.page(@name)
@page_num = [params[:page].to_i, 1].max
@versions = @page.versions :page => @page_num
mustache :history
end
@@ -10,6 +10,7 @@
<th colspan="5">
Select any two versions to <input type="submit" value="Compare" />
</th>
</tr>
{{#versions}}
<tr class="commit">
<td class="checkbox">
@@ -27,6 +28,10 @@
</tr>
{{/versions}}
</table>
<div class="pagination">
{{{previous_link}}}
{{{next_link}}}
</div>
</form>
</div>
</div>
+27 -9
View File
@@ -1,26 +1,44 @@
module Precious
module Views
class History < Layout
attr_reader :page
attr_reader :page, :page_num
def title
"History of #{@page.title}"
end
def versions
i = @page.versions.size + 1
@page.versions.map do |v|
i = @versions.size + 1
@versions.map do |v|
i -= 1
{ :id => v.id,
:id7 => v.id[0..6],
:num => i,
{ :id => v.id,
:id7 => v.id[0..6],
:num => i,
:selected => @page.version.id == v.id,
:author => v.author.name,
:message => v.message,
:date => v.committed_date.strftime("%B %d, %Y"),
:author => v.author.name,
:message => v.message,
:date => v.committed_date.strftime("%B %d, %Y"),
:gravatar => Digest::MD5.hexdigest(v.author.email) }
end
end
def previous_link
label = "&laquo; Previous"
if @page_num == 1
%(<span class="disabled">#{label}</span>)
else
%(<a href="/history/#{@page.name}?page=#{@page_num-1}" hotkey="h">#{label}</a>)
end
end
def next_link
label = "Next &raquo;"
if @versions.size == Gollum::Page.per_page
%(<a href="/history/#{@page.name}?page=#{@page_num+1}" hotkey="l">#{label}</a>)
else
%(<span class="disabled">#{label}</span>)
end
end
end
end
end