mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
Source files keep their SPDX-License-Identifier and Hanzo copyright line; the Gitea, Gogs and LFS Test Server copyrights they used to repeat now live once in NOTICE, alongside LICENSE. The header lint accepts any copyright line above the SPDX line, so it no longer demands an upstream one. Co-authored-by: Hanzo Dev <[email protected]>
67 lines
1.8 KiB
Go
67 lines
1.8 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package user
|
|
|
|
import (
|
|
"net/http"
|
|
"net/url"
|
|
|
|
activities_model "github.com/hanzoai/git/models/activities"
|
|
"github.com/hanzoai/git/modules/setting"
|
|
"github.com/hanzoai/git/services/context"
|
|
)
|
|
|
|
func prepareHeatmapURL(ctx *context.Context) {
|
|
ctx.Data["EnableHeatmap"] = setting.Service.EnableUserHeatmap
|
|
if !setting.Service.EnableUserHeatmap {
|
|
return
|
|
}
|
|
|
|
if ctx.Org.Organization == nil {
|
|
// for individual user
|
|
ctx.Data["HeatmapURL"] = ctx.Doer.HomeLink() + "/-/heatmap"
|
|
return
|
|
}
|
|
|
|
// for org or team
|
|
heatmapURL := ctx.Org.Organization.OrganisationLink() + "/dashboard/-/heatmap"
|
|
if ctx.Org.Team != nil {
|
|
heatmapURL += "/" + url.PathEscape(ctx.Org.Team.LowerName)
|
|
}
|
|
ctx.Data["HeatmapURL"] = heatmapURL
|
|
}
|
|
|
|
func writeHeatmapJSON(ctx *context.Context, hdata []*activities_model.UserHeatmapData) {
|
|
data := make([][2]int64, len(hdata))
|
|
var total int64
|
|
for i, v := range hdata {
|
|
data[i] = [2]int64{int64(v.Timestamp), v.Contributions}
|
|
total += v.Contributions
|
|
}
|
|
ctx.JSON(http.StatusOK, map[string]any{
|
|
"heatmapData": data,
|
|
"totalContributions": total,
|
|
})
|
|
}
|
|
|
|
// DashboardHeatmap returns heatmap data as JSON, for the individual user, organization or team dashboard.
|
|
func DashboardHeatmap(ctx *context.Context) {
|
|
if !setting.Service.EnableUserHeatmap {
|
|
ctx.NotFound(nil)
|
|
return
|
|
}
|
|
var data []*activities_model.UserHeatmapData
|
|
var err error
|
|
if ctx.Org.Organization == nil {
|
|
data, err = activities_model.GetUserHeatmapDataByUser(ctx, ctx.ContextUser, ctx.Doer)
|
|
} else {
|
|
data, err = activities_model.GetUserHeatmapDataByOrgTeam(ctx, ctx.Org.Organization, ctx.Org.Team, ctx.Doer)
|
|
}
|
|
if err != nil {
|
|
ctx.ServerError("GetUserHeatmapData", err)
|
|
return
|
|
}
|
|
writeHeatmapJSON(ctx, data)
|
|
}
|