openidec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit bdfa1a6f83e2f29e419f9cacc5f5d48b4883fe01
parent c099411db97d297c09fe157905699c558afd9c49
Author: Peter Kosyh <p.kosyh@gmail.com>
Date:   Thu,  3 Sep 2020 10:17:53 +0300

pager

Diffstat:
Mii-node/tpl/topics.tpl | 5+++--
Mii-node/web.go | 17+++++++++++------
2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/ii-node/tpl/topics.tpl b/ii-node/tpl/topics.tpl @@ -1,5 +1,5 @@ {{template "header.tpl"}} - +<a href="/{{.Echo}}/1">1</a><a href="/{{.Echo}}/{{.Pages}}">{{.Pages}}</a> <table class="topiclist"> <tr> <th>Topics</th> @@ -8,11 +8,12 @@ </tr> {{range .Topics }} <tr> -<td><a href="{{.Head.MsgId}}">{{.Head.Subj}}</a></td> +<td><a href="/{{.Head.MsgId}}">{{.Head.Subj}}</a></td> <td>{{.Count}}</td> <td>{{.Date}}</td> </tr> {{ end }} </table> + {{template "footer.tpl"}} diff --git a/ii-node/web.go b/ii-node/web.go @@ -16,6 +16,7 @@ type WebContext struct { Topics []Topic Msg []ii.Msg Render func(string) template.HTML + Echo string Page int Pages int } @@ -103,7 +104,7 @@ func www_topics(www WWW, w http.ResponseWriter, r *http.Request, echo string, pa return topics[i].Last.Off > topics[j].Last.Off }) tcount := len(topics) - start := page * tcount / PAGE_SIZE + start := (page - 1)* PAGE_SIZE nr := PAGE_SIZE for i := start; i < tcount && nr > 0; i ++ { t := topics[i] @@ -118,8 +119,9 @@ func www_topics(www WWW, w http.ResponseWriter, r *http.Request, echo string, pa nr -- } ii.Trace.Printf("Stop to generate topics") - ctx.Page = start + ctx.Page = page ctx.Pages = tcount / PAGE_SIZE + ctx.Echo = echo if tcount % PAGE_SIZE != 0 { ctx.Pages ++ } @@ -161,15 +163,18 @@ func Web(www WWW, w http.ResponseWriter, r *http.Request) error { if path == "" { return www_index(www, w, r) } + if ii.IsMsgId(path) { + return www_topic(www, w, r, path) + } if ii.IsEcho(args[0]) { - var page int + page := 1 if len(args) > 1 { fmt.Sscanf(args[1], "%d", &page) } + if page <= 0 { + page = 1 + } return www_topics(www, w, r, args[0], page) } - if ii.IsMsgId(path) { - return www_topic(www, w, r, path) - } return nil }