Implements local pager. Fixes footer once and for all.

This commit is contained in:
Dominik Picheta 2012-09-30 13:19:03 +01:00
commit 96da91fa3e
4 changed files with 50 additions and 16 deletions

View file

@ -24,7 +24,10 @@
# for row in Rows(db, query, $((c.pageNum-1) * ThreadsPerPage), $ThreadsPerPage): # for row in Rows(db, query, $((c.pageNum-1) * ThreadsPerPage), $ThreadsPerPage):
# inc(count) # inc(count)
<tr> <tr>
<td class="topic">${UrlButton(c, XMLencode(%name), c.genThreadUrl(threadid = %threadid))}</td> <td class="topic">
${UrlButton(c, XMLencode(%name), c.genThreadUrl(threadid = %threadid))}
${genPagenumLocalNav(c, (%threadid).parseInt)}
</td>
#let authorName = getValue(db, sql("select name from person where id = " & #let authorName = getValue(db, sql("select name from person where id = " &
# "(select author from post where id = " & # "(select author from post where id = " &
# "(select min(id) from post where thread = ?))"), %threadId) # "(select min(id) from post where thread = ?))"), %threadId)

View file

@ -525,6 +525,44 @@ proc genPagenumNav(c: var TForumData, stats: TForumStats): string =
result = htmlgen.`div`(id = "pagenumbers", result) result = htmlgen.`div`(id = "pagenumbers", result)
proc gatherTotalPostsByID(c: var TForumData, thrid: int): int =
## Gets the total post count of a thread.
result = GetValue(db, sql"select count(*) from post where thread = ?", $thrid).parseInt
proc gatherTotalPosts(c: var TForumData) =
if c.totalPosts > 0: return
# Gather some data.
const totalPostsQuery =
sql"select count(*) from post p, person u where u.id = p.author and p.thread = ?"
c.totalPosts = getValue(db, totalPostsQuery, $c.threadId).parseInt
proc getPagesInThread(c: var TForumData): int =
c.gatherTotalPosts() # Get total post count
result = ceil(c.totalPosts / postsPerPage).int-1
proc getPagesInThreadByID(c: var TForumData, thrid: int): int =
result = ceil(c.gatherTotalPostsByID(thrid) / postsPerPage).int
proc genPagenumLocalNav(c: var TForumData, thrid: int): string =
result = ""
const maxPostPages = 6 # Maximum links to pages shown.
const hmpp = maxPostPages div 2
# 1 2 3 ... 10 11 12
var currentThrURL = "/t/" & $thrid & "/"
let totalPagesInThread = c.getPagesInThreadByID(thrid)
if totalPagesInThread <= 1: return
var i = 1
while i <= totalPagesInThread:
result.add(a(href=c.req.makeUri(currentThrURL & $i), $i))
if i == hmpp and totalPagesInThread-i > hmpp:
result.add(span("..."))
# skip to the last 3
i = totalPagesInThread-(hmpp-1)
else:
inc(i)
result = htmlgen.`div`(class = "localnums", result)
include "forms.tmpl" include "forms.tmpl"
include "main.tmpl" include "main.tmpl"
@ -544,13 +582,6 @@ template createTFD(): stmt =
if request.cookies.len > 0: if request.cookies.len > 0:
checkLoggedIn(c) checkLoggedIn(c)
proc gatherData(c: var TForumData) =
if c.totalPosts > 0: return
# Gather some data.
const totalPostsQuery =
sql"select count(*) from post p, person u where u.id = p.author and p.thread = ?"
c.totalPosts = getValue(db, totalPostsQuery, $c.threadId).parseInt
get "/": get "/":
createTFD() createTFD()
c.isThreadsList = true c.isThreadsList = true
@ -567,7 +598,7 @@ get "/t/@threadid/?@page?/?":
parseInt(@"postid", c.postId, -1..1000_000) parseInt(@"postid", c.postId, -1..1000_000)
var count = 0 var count = 0
cond validThreadId(c) cond validThreadId(c)
gatherData(c) gatherTotalPosts(c)
if (@"action").len > 0: if (@"action").len > 0:
case @"action" case @"action"
of "reply": of "reply":
@ -623,10 +654,6 @@ template readIDs(): stmt =
if (@"postid").len > 0: if (@"postid").len > 0:
parseInt(@"postid", c.postId, -1..1000_000) parseInt(@"postid", c.postId, -1..1000_000)
proc getTotalPosts(c: var TForumData): int =
c.gatherData() # Get total post count
result = ceil(c.totalPosts / postsPerPage).int-1
template finishLogin(): stmt = template finishLogin(): stmt =
setCookie("sid", c.userpass, daysForward(7)) setCookie("sid", c.userpass, daysForward(7))
redirect(uri("/")) redirect(uri("/"))
@ -665,11 +692,11 @@ post "/doreply":
createTFD() createTFD()
readIDs() readIDs()
if reply(c): if reply(c):
redirect(c.genThreadUrl(pageNum = $(c.getTotalPosts+1)) & "#" & $c.postId) redirect(c.genThreadUrl(pageNum = $(c.getPagesInThread+1)) & "#" & $c.postId)
else: else:
var count = 0 var count = 0
if c.isPreview: if c.isPreview:
c.pageNum = c.getTotalPosts+1 c.pageNum = c.getPagesInThread+1
body = genPostsList(c, $c.threadId, count) body = genPostsList(c, $c.threadId, count)
handleError("doreply", "Reply", false) handleError("doreply", "Reply", false)

View file

@ -50,7 +50,7 @@
#if c.isThreadsList: #if c.isThreadsList:
${c.genListOnline(stats)} ${c.genListOnline(stats)}
#end if #end if
<div id="footerPush"></div>
</div> </div>
<div id="footer"> <div id="footer">
<span>Written in <a href="http://nimrod-code.org/">Nimrod</a> using <a href="https://github.com/dom96/jester">Jester</a></span> <span>Written in <a href="http://nimrod-code.org/">Nimrod</a> using <a href="https://github.com/dom96/jester">Jester</a></span>

View file

@ -152,6 +152,10 @@ div#header a:hover, #nimbtn a:hover {
margin-bottom: 5pt; margin-bottom: 5pt;
} }
#footerPush {
height: 21pt;
}
#footer { #footer {
background-color: #5D5D5D; background-color: #5D5D5D;
background: -moz-linear-gradient(top, #5D5D5D, #4D4D4D); background: -moz-linear-gradient(top, #5D5D5D, #4D4D4D);