예제 #1
0
// 加载更多link
func discover_loadMoreLink(ctx *goku.HttpContext) goku.ActionResulter {
	page, err := strconv.Atoi(ctx.Get("page"))
	success, hasmore := false, false
	errorMsgs, html := "", ""
	if err == nil && page > 1 {
		ot := ctx.Get("o")
		if ot == "" {
			ot = "hot"
		}
		dt, _ := strconv.Atoi(ctx.Get("dt"))
		links, _ := models.LinkForHome_GetByPage(ot, dt, page, golink.PAGE_SIZE)
		if links != nil && len(links) > 0 {
			ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx)
			vr := ctx.RenderPartial("loadmorelink", nil)
			vr.Render(ctx, vr.Body)
			html = vr.Body.String()
			hasmore = len(links) >= golink.PAGE_SIZE
		}
		success = true
	} else {
		errorMsgs = "参数错误"
	}
	r := map[string]interface{}{
		"success": success,
		"errors":  errorMsgs,
		"html":    html,
		"hasmore": hasmore,
	}
	return ctx.Json(r)
}
예제 #2
0
func favorite_loadMoreLink(ctx *goku.HttpContext) goku.ActionResulter {
	page, err := strconv.Atoi(ctx.Get("page"))
	success, hasmore := false, false
	errorMsgs, html := "", ""
	if err == nil && page > 1 {
		user := ctx.Data["user"].(*models.User)

		links := models.FavoriteLink_ByUser(user.Id, page, golink.PAGE_SIZE)
		if links != nil && len(links) > 0 {
			ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx)
			vr := ctx.RenderPartial("loadmorelink", nil)
			vr.Render(ctx, vr.Body)
			html = vr.Body.String()
			hasmore = len(links) >= golink.PAGE_SIZE
		}
		success = true
	} else {
		errorMsgs = "参数错误"
	}
	r := map[string]interface{}{
		"success": success,
		"errors":  errorMsgs,
		"html":    html,
		"hasmore": hasmore,
	}
	return ctx.Json(r)
}
예제 #3
0
// 发现 首页
func discover_index(ctx *goku.HttpContext) goku.ActionResulter {
	ot := ctx.Get("o")
	if ot == "" {
		ot = "hot"
	}
	dt, _ := strconv.Atoi(ctx.Get("dt"))
	ctx.ViewData["Order"] = ot
	links, _ := models.LinkForHome_GetByPage(ot, dt, 1, golink.PAGE_SIZE)
	ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx)
	ctx.ViewData["TopTab"] = "discover"
	ctx.ViewData["HasMoreLink"] = len(links) >= golink.PAGE_SIZE
	return ctx.Render("/home/index", nil)
}
예제 #4
0
파일: topic.go 프로젝트: cloudcache/ohlala
			return ctx.Render("error", nil)
		}

		sort := ctx.Get("o") //排序方式
		t := ctx.Get("t")    //时间范围

		ctx.ViewData["Order"] = golink.ORDER_TYPE_HOT
		if _, ok := golink.ORDER_TYPE_MAP[sort]; ok {
			ctx.ViewData["Order"] = sort
		}

		page, pagesize := utils.PagerParams(ctx.Request)
		links, _ := models.Link_ForTopic(topic.Id, page, pagesize, sort, t)
		followers, _ := models.Topic_GetFollowers(topic.Id, 1, 24)

		ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx)
		ctx.ViewData["HasMoreLink"] = len(links) >= golink.PAGE_SIZE
		ctx.ViewData["Followers"] = followers
		return ctx.View(models.Topic_ToVTopic(topic, ctx))

	}). //Filters(filters.NewRequireLoginFilter()). // 暂时不需要登陆吧

	/**
	 * 关注话题
	 */
	Post("follow", func(ctx *goku.HttpContext) goku.ActionResulter {

		topicId, _ := strconv.ParseInt(ctx.RouteData.Params["id"], 10, 64)
		ok, err := models.Topic_Follow(ctx.Data["user"].(*models.User).Id, topicId)
		var errs string
		if err != nil {