Пример #1
1
func Explore(ctx *middleware.Context) {
	ctx.Data["Title"] = ctx.Tr("explore")
	ctx.Data["PageIsExploreRepositories"] = true

	page := ctx.QueryInt("page")
	if page <= 1 {
		page = 1
	}

	ctx.Data["Page"] = paginater.New(int(models.CountRepositories()), setting.ExplorePagingNum, page, 5)

	repos, err := models.GetRecentUpdatedRepositories(page)
	if err != nil {
		ctx.Handle(500, "GetRecentUpdatedRepositories", err)
		return
	}
	for _, repo := range repos {
		if err = repo.GetOwner(); err != nil {
			ctx.Handle(500, "GetOwner", fmt.Errorf("%d: %v", repo.ID, err))
			return
		}
	}
	ctx.Data["Repos"] = repos

	ctx.HTML(200, EXPLORE_REPOS)
}
Пример #2
0
func Home(ctx *middleware.Context) {
	if ctx.IsSigned {
		user.Dashboard(ctx)
		return
	}

	// Check auto-login.
	userName := ctx.GetCookie(base.CookieUserName)
	if len(userName) != 0 {
		ctx.Redirect("/user/login")
		return
	}

	// Show recent updated repositoires for new visiters.
	repos, err := models.GetRecentUpdatedRepositories()
	if err != nil {
		ctx.Handle(500, "dashboard.Home(GetRecentUpdatedRepositories)", err)
		return
	}

	for _, repo := range repos {
		repo.Owner, err = models.GetUserById(repo.OwnerId)
		if err != nil {
			ctx.Handle(500, "dashboard.Home(GetUserById)", err)
			return
		}
	}
	ctx.Data["Repos"] = repos
	ctx.Data["PageIsHome"] = true
	ctx.HTML(200, "home")
}
Пример #3
0
func Explore(ctx *middleware.Context) {
	ctx.Data["Title"] = ctx.Tr("explore")
	ctx.Data["PageIsExploreRepositories"] = true

	repos, err := models.GetRecentUpdatedRepositories(20)
	if err != nil {
		ctx.Handle(500, "GetRecentUpdatedRepositories", err)
		return
	}
	for _, repo := range repos {
		if err = repo.GetOwner(); err != nil {
			ctx.Handle(500, "GetOwner", fmt.Errorf("%d: %v", repo.Id, err))
			return
		}
	}
	ctx.Data["Repos"] = repos

	ctx.HTML(200, EXPLORE_REPOS)
}
Пример #4
0
func Home(ctx *middleware.Context) {
	if ctx.IsSigned {
		user.Dashboard(ctx)
		return
	}

	// Check auto-login.
	userName := ctx.GetCookie(base.CookieUserName)
	if len(userName) != 0 {
		ctx.Redirect("/user/login")
		return
	}

	repos, _ := models.GetRecentUpdatedRepositories()
	for _, repo := range repos {
		repo.Owner, _ = models.GetUserById(repo.OwnerId)
	}
	ctx.Data["Repos"] = repos
	ctx.Data["PageIsHome"] = true
	ctx.HTML(200, "home")
}