Fork to maintain patches against the official gitea for https://code.ceondo.com https://github.com/go-gitea/gitea

activity.go 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package repo
  5. import (
  6. "time"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/base"
  9. "code.gitea.io/gitea/modules/context"
  10. )
  11. const (
  12. tplActivity base.TplName = "repo/activity"
  13. )
  14. // Activity render the page to show repository latest changes
  15. func Activity(ctx *context.Context) {
  16. ctx.Data["Title"] = ctx.Tr("repo.activity")
  17. ctx.Data["PageIsActivity"] = true
  18. ctx.Data["Period"] = ctx.Params("period")
  19. timeUntil := time.Now()
  20. var timeFrom time.Time
  21. switch ctx.Data["Period"] {
  22. case "daily":
  23. timeFrom = timeUntil.Add(-time.Hour * 24)
  24. case "halfweekly":
  25. timeFrom = timeUntil.Add(-time.Hour * 72)
  26. case "weekly":
  27. timeFrom = timeUntil.Add(-time.Hour * 168)
  28. case "monthly":
  29. timeFrom = timeUntil.AddDate(0, -1, 0)
  30. default:
  31. ctx.Data["Period"] = "weekly"
  32. timeFrom = timeUntil.Add(-time.Hour * 168)
  33. }
  34. ctx.Data["DateFrom"] = timeFrom.Format("January 2, 2006")
  35. ctx.Data["DateUntil"] = timeUntil.Format("January 2, 2006")
  36. ctx.Data["PeriodText"] = ctx.Tr("repo.activity.period." + ctx.Data["Period"].(string))
  37. var err error
  38. if ctx.Data["Activity"], err = models.GetActivityStats(ctx.Repo.Repository.ID, timeFrom,
  39. ctx.Repo.Repository.UnitEnabled(models.UnitTypeReleases),
  40. ctx.Repo.Repository.UnitEnabled(models.UnitTypeIssues),
  41. ctx.Repo.Repository.UnitEnabled(models.UnitTypePullRequests)); err != nil {
  42. ctx.Handle(500, "GetActivityStats", err)
  43. return
  44. }
  45. ctx.HTML(200, tplActivity)
  46. }