-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added basic heatmap data * Added extra case for sqlite * Built basic heatmap into user profile * Get contribution data from api & styling * Fixed lint & added extra group by statements for all database types * generated swagger spec * generated swagger spec * generated swagger spec * fixed swagger spec * fmt * Added tests * Added setting to enable/disable user heatmap * Added locale for loading text * Removed UseTiDB * Updated librejs & moment.js * Fixed import order * Fixed heatmap in postgresql * Update docs/content/doc/advanced/config-cheat-sheet.en-us.md Co-Authored-By: kolaente <[email protected]> * Added copyright header * Fixed a bug to show the heatmap for the actual user instead of the currently logged in * Added integration test for heatmaps * Added a heatmap on the dashboard * Fixed timestamp parsing * Hide heatmap on mobile * optimized postgresql group by query * Improved sqlite group by statement
- Loading branch information
Showing
27 changed files
with
649 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2018 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 models | ||
|
||
package integrations | ||
|
||
import ( | ||
"code.gitea.io/gitea/models" | ||
"fmt" | ||
"github.com/stretchr/testify/assert" | ||
"net/http" | ||
"testing" | ||
) | ||
|
||
func TestUserHeatmap(t *testing.T) { | ||
prepareTestEnv(t) | ||
adminUsername := "user1" | ||
normalUsername := "user2" | ||
session := loginUser(t, adminUsername) | ||
|
||
urlStr := fmt.Sprintf("/api/v1/users/%s/heatmap", normalUsername) | ||
req := NewRequest(t, "GET", urlStr) | ||
resp := session.MakeRequest(t, req, http.StatusOK) | ||
var heatmap []*models.UserHeatmapData | ||
DecodeJSON(t, resp, &heatmap) | ||
var dummyheatmap []*models.UserHeatmapData | ||
dummyheatmap = append(dummyheatmap, &models.UserHeatmapData{Timestamp: 1540080000, Contributions: 1}) | ||
|
||
assert.Equal(t, dummyheatmap, heatmap) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
act_user_id: 2 | ||
repo_id: 2 | ||
is_private: true | ||
created_unix: 1540139562 | ||
|
||
- | ||
id: 2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2018 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 models | ||
|
||
package models | ||
|
||
import ( | ||
"code.gitea.io/gitea/modules/setting" | ||
"code.gitea.io/gitea/modules/util" | ||
) | ||
|
||
// UserHeatmapData represents the data needed to create a heatmap | ||
type UserHeatmapData struct { | ||
Timestamp util.TimeStamp `json:"timestamp"` | ||
Contributions int64 `json:"contributions"` | ||
} | ||
|
||
// GetUserHeatmapDataByUser returns an array of UserHeatmapData | ||
func GetUserHeatmapDataByUser(user *User) (hdata []*UserHeatmapData, err error) { | ||
var groupBy string | ||
switch { | ||
case setting.UseSQLite3: | ||
groupBy = "strftime('%s', strftime('%Y-%m-%d', created_unix, 'unixepoch'))" | ||
case setting.UseMySQL: | ||
groupBy = "UNIX_TIMESTAMP(DATE_FORMAT(FROM_UNIXTIME(created_unix), '%Y%m%d'))" | ||
case setting.UsePostgreSQL: | ||
groupBy = "extract(epoch from date_trunc('day', to_timestamp(created_unix)))" | ||
case setting.UseMSSQL: | ||
groupBy = "dateadd(DAY,0, datediff(day,0, dateadd(s, created_unix, '19700101')))" | ||
} | ||
|
||
err = x.Select(groupBy+" as timestamp, count(user_id) as contributions"). | ||
Table("action"). | ||
Where("user_id = ?", user.ID). | ||
And("created_unix > ?", (util.TimeStampNow() - 31536000)). | ||
GroupBy("timestamp"). | ||
OrderBy("timestamp"). | ||
Find(&hdata) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2018 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 models | ||
|
||
package models | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestGetUserHeatmapDataByUser(t *testing.T) { | ||
// Prepare | ||
assert.NoError(t, PrepareTestDatabase()) | ||
|
||
// Insert some action | ||
user := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) | ||
|
||
// get the action for comparison | ||
actions, err := GetFeeds(GetFeedsOptions{ | ||
RequestedUser: user, | ||
RequestingUserID: user.ID, | ||
IncludePrivate: true, | ||
OnlyPerformedBy: false, | ||
IncludeDeleted: true, | ||
}) | ||
assert.NoError(t, err) | ||
|
||
// Get the heatmap and compare | ||
heatmap, err := GetUserHeatmapDataByUser(user) | ||
assert.NoError(t, err) | ||
assert.Equal(t, len(actions), len(heatmap)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,10 @@ | |
.ui.repository.list { | ||
margin-top: 25px; | ||
} | ||
|
||
#loading-heatmap{ | ||
margin-bottom: 1em; | ||
} | ||
} | ||
|
||
&.followers { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
public/vendor/plugins/calendar-heatmap/calendar-heatmap.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
text.month-name, | ||
text.calendar-heatmap-legend-text, | ||
text.day-initial { | ||
font-size: 10px; | ||
fill: inherit; | ||
font-family: Helvetica, arial, 'Open Sans', sans-serif; | ||
} | ||
rect.day-cell:hover { | ||
stroke: #555555; | ||
stroke-width: 1px; | ||
} | ||
.day-cell-tooltip { | ||
position: absolute; | ||
z-index: 9999; | ||
padding: 5px 9px; | ||
color: #bbbbbb; | ||
font-size: 12px; | ||
background: rgba(0, 0, 0, 0.85); | ||
border-radius: 3px; | ||
text-align: center; | ||
} | ||
.day-cell-tooltip > span { | ||
font-family: Helvetica, arial, 'Open Sans', sans-serif | ||
} | ||
.calendar-heatmap { | ||
box-sizing: initial; | ||
} |
Oops, something went wrong.