summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2017-10-15 02:17:39 +0300
committerGitHub <noreply@github.com>2017-10-15 02:17:39 +0300
commitf42dbdbae59600266d03357f9693c659adc9cab3 (patch)
tree90b42df32a5f064d9055fec37c909aa83c432dcc /routers
parent8863e74f2aa7150605712eb21468b6f1305289f7 (diff)
downloadgitea-f42dbdbae59600266d03357f9693c659adc9cab3.tar.gz
gitea-f42dbdbae59600266d03357f9693c659adc9cab3.zip
Add Activity page to repository (#2674)
* Add Activity page to repository * Add request data for activity * Add issue data for activity * Add user unit right checks * Add releases to activity * Log repository unit loading error
Diffstat (limited to 'routers')
-rw-r--r--routers/repo/activity.go76
-rw-r--r--routers/routes/routes.go5
2 files changed, 81 insertions, 0 deletions
diff --git a/routers/repo/activity.go b/routers/repo/activity.go
new file mode 100644
index 0000000000..564537c1fd
--- /dev/null
+++ b/routers/repo/activity.go
@@ -0,0 +1,76 @@
+// Copyright 2017 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package repo
+
+import (
+ "time"
+
+ "code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/modules/base"
+ "code.gitea.io/gitea/modules/context"
+)
+
+const (
+ tplActivity base.TplName = "repo/activity"
+)
+
+// Activity render the page to show repository latest changes
+func Activity(ctx *context.Context) {
+ ctx.Data["Title"] = ctx.Tr("repo.activity")
+ ctx.Data["PageIsActivity"] = true
+
+ ctx.Data["Period"] = ctx.Params("period")
+
+ timeUntil := time.Now()
+ var timeFrom time.Time
+
+ switch ctx.Data["Period"] {
+ case "daily":
+ timeFrom = timeUntil.Add(-time.Hour * 24)
+ case "halfweekly":
+ timeFrom = timeUntil.Add(-time.Hour * 72)
+ case "weekly":
+ timeFrom = timeUntil.Add(-time.Hour * 168)
+ case "monthly":
+ timeFrom = timeUntil.AddDate(0, -1, 0)
+ default:
+ ctx.Data["Period"] = "weekly"
+ timeFrom = timeUntil.Add(-time.Hour * 168)
+ }
+ ctx.Data["DateFrom"] = timeFrom.Format("January 2, 2006")
+ ctx.Data["DateUntil"] = timeUntil.Format("January 2, 2006")
+ ctx.Data["PeriodText"] = ctx.Tr("repo.activity.period." + ctx.Data["Period"].(string))
+
+ stats := &models.ActivityStats{}
+
+ if ctx.Repo.Repository.UnitEnabled(models.UnitTypeReleases) {
+ if err := models.FillReleasesForActivity(stats, ctx.Repo.Repository.ID, timeFrom); err != nil {
+ ctx.Handle(500, "FillReleasesForActivity", err)
+ return
+ }
+ }
+ if ctx.Repo.Repository.UnitEnabled(models.UnitTypePullRequests) {
+ if err := models.FillPullRequestsForActivity(stats, ctx.Repo.Repository.ID, timeFrom); err != nil {
+ ctx.Handle(500, "FillPullRequestsForActivity", err)
+ return
+ }
+ }
+ if ctx.Repo.Repository.UnitEnabled(models.UnitTypeIssues) {
+ if err := models.FillIssuesForActivity(stats, ctx.Repo.Repository.ID, timeFrom); err != nil {
+ ctx.Handle(500, "FillIssuesForActivity", err)
+ return
+ }
+ }
+ if err := models.FillUnresolvedIssuesForActivity(stats, ctx.Repo.Repository.ID, timeFrom,
+ ctx.Repo.Repository.UnitEnabled(models.UnitTypeIssues),
+ ctx.Repo.Repository.UnitEnabled(models.UnitTypePullRequests)); err != nil {
+ ctx.Handle(500, "FillUnresolvedIssuesForActivity", err)
+ return
+ }
+
+ ctx.Data["Activity"] = stats
+
+ ctx.HTML(200, tplActivity)
+}
diff --git a/routers/routes/routes.go b/routers/routes/routes.go
index 8875fa47bf..e6079445bb 100644
--- a/routers/routes/routes.go
+++ b/routers/routes/routes.go
@@ -613,6 +613,11 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/*", repo.WikiRaw)
}, repo.MustEnableWiki)
+ m.Group("/activity", func() {
+ m.Get("", repo.Activity)
+ m.Get("/:period", repo.Activity)
+ }, context.RepoRef(), repo.MustBeNotBare, context.CheckAnyUnit(models.UnitTypePullRequests, models.UnitTypeIssues, models.UnitTypeReleases))
+
m.Get("/archive/*", repo.MustBeNotBare, context.CheckUnit(models.UnitTypeCode), repo.Download)
m.Group("/pulls/:index", func() {