You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.5 KiB

  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.CanRead(models.UnitTypeReleases),
  40. ctx.Repo.CanRead(models.UnitTypeIssues),
  41. ctx.Repo.CanRead(models.UnitTypePullRequests)); err != nil {
  42. ctx.ServerError("GetActivityStats", err)
  43. return
  44. }
  45. ctx.HTML(200, tplActivity)
  46. }