2017-04-19 18:19:27 +08:00
|
|
|
package controllers
|
|
|
|
|
2017-04-30 22:13:12 +08:00
|
|
|
import (
|
|
|
|
"github.com/astaxie/beego"
|
2017-06-14 09:23:29 +08:00
|
|
|
"github.com/lifei6671/mindoc/models"
|
|
|
|
"github.com/lifei6671/mindoc/utils"
|
2017-05-31 10:15:04 +08:00
|
|
|
"math"
|
2017-04-30 22:13:12 +08:00
|
|
|
)
|
|
|
|
|
2017-04-19 18:19:27 +08:00
|
|
|
type HomeController struct {
|
|
|
|
BaseController
|
|
|
|
}
|
|
|
|
|
2017-04-30 22:13:12 +08:00
|
|
|
func (c *HomeController) Index() {
|
|
|
|
c.Prepare()
|
|
|
|
c.TplName = "home/index.tpl"
|
|
|
|
//如果没有开启匿名访问,则跳转到登录页面
|
|
|
|
if !c.EnableAnonymous && c.Member == nil {
|
|
|
|
c.Redirect(beego.URLFor("AccountController.Login"),302)
|
|
|
|
}
|
|
|
|
pageIndex,_ := c.GetInt("page",1)
|
|
|
|
pageSize := 18
|
|
|
|
|
|
|
|
member_id := 0
|
|
|
|
|
|
|
|
if c.Member != nil {
|
|
|
|
member_id = c.Member.MemberId
|
|
|
|
}
|
|
|
|
books,totalCount,err := models.NewBook().FindForHomeToPager(pageIndex,pageSize,member_id)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
beego.Error(err)
|
|
|
|
c.Abort("500")
|
|
|
|
}
|
|
|
|
if totalCount > 0 {
|
|
|
|
html := utils.GetPagerHtml(c.Ctx.Request.RequestURI, pageIndex, pageSize, totalCount)
|
|
|
|
|
|
|
|
c.Data["PageHtml"] = html
|
|
|
|
}else {
|
|
|
|
c.Data["PageHtml"] = ""
|
|
|
|
}
|
2017-05-31 10:15:04 +08:00
|
|
|
c.Data["TotalPages"] = int(math.Ceil(float64(totalCount) / float64(pageSize)))
|
2017-04-30 22:13:12 +08:00
|
|
|
|
|
|
|
c.Data["Lists"] = books
|
|
|
|
|
2017-07-07 16:20:55 +08:00
|
|
|
labels ,totalCount,err := models.NewLabel().FindToPager(1,10)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
c.Data["Labels"] = make([]*models.Label,0)
|
|
|
|
}else{
|
|
|
|
c.Data["Labels"] = labels
|
|
|
|
}
|
2017-04-19 18:19:27 +08:00
|
|
|
}
|