// png = path and query // In the CMS you can access it from uni.P + "?" + uni.Req.URL.RawQuery. func DoPaging(db *mgo.Database, collection string, query map[string]interface{}, page_num_key string, get map[string][]string, pnq string, limit int) PagingInfo { var current_page int num_str, has := get[page_num_key] if !has { current_page = 1 } else { val, err := strconv.ParseInt(num_str[0], 10, 32) if err == nil { current_page = int(val) } else { current_page = 1 } } all_results, _ := db.C(collection).Find(query).Count() // TODO: think about the error here. nav, _ := paging.P(current_page, all_results/limit+1, 3, pnq) skip := (current_page - 1) * limit return PagingInfo{ Result: nav, Skip: skip, Current_page: current_page, Limit: limit, All_results: all_results, Paramkey: page_num_key, Url: pnq, } }
func pager(uni *context.Uni, pagestr string, count, limit int) []paging.Pelem { if len(pagestr) == 0 { pagestr = "1" } if limit == 0 { return nil } p := uni.Path + "?" + uni.Req.URL.RawQuery page, err := strconv.Atoi(pagestr) if err != nil { return nil // Not blowing up here. } if page == 0 { return nil } page_count := count/limit + 1 nav, _ := paging.P(page, page_count, 3, p) return nav }
func pager(ctx iface.Context, pagestr string, count, limit int) []paging.Pelem { if len(pagestr) == 0 { pagestr = "1" } if limit == 0 { return nil } p := ctx.NonPortable().Resource() + "?" + ctx.NonPortable().RawParams() page, err := strconv.Atoi(pagestr) if err != nil { return nil // Not blowing up here. } if page == 0 { return nil } page_count := count/limit + 1 nav, _ := paging.P(page, page_count, 3, p) return nav }