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
+2
View File
@@ -83,6 +83,8 @@ module Precious
@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>
+21 -3
View File
@@ -1,15 +1,15 @@
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],
@@ -21,6 +21,24 @@ module Precious
: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