Skip to content

Commit 343c756

Browse files
LFriede6543techknowlogick
authored
Heatmap days clickable (#13935)
* Heatmap days clickable * Error handling * Unselect filter * better dayclick handler * made linter happy * clickable heatmap for profiles Co-authored-by: 6543 <[email protected]> Co-authored-by: techknowlogick <[email protected]>
1 parent f3e64f6 commit 343c756

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

models/action.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,12 +289,13 @@ func (a *Action) GetIssueContent() string {
289289

290290
// GetFeedsOptions options for retrieving feeds
291291
type GetFeedsOptions struct {
292-
RequestedUser *User // the user we want activity for
293-
RequestedTeam *Team // the team we want activity for
294-
Actor *User // the user viewing the activity
295-
IncludePrivate bool // include private actions
296-
OnlyPerformedBy bool // only actions performed by requested user
297-
IncludeDeleted bool // include deleted actions
292+
RequestedUser *User // the user we want activity for
293+
RequestedTeam *Team // the team we want activity for
294+
Actor *User // the user viewing the activity
295+
IncludePrivate bool // include private actions
296+
OnlyPerformedBy bool // only actions performed by requested user
297+
IncludeDeleted bool // include deleted actions
298+
Date string // the day we want activity for: YYYY-MM-DD
298299
}
299300

300301
// GetFeeds returns actions according to the provided options
@@ -380,5 +381,17 @@ func activityQueryCondition(opts GetFeedsOptions) (builder.Cond, error) {
380381
cond = cond.And(builder.Eq{"is_deleted": false})
381382
}
382383

384+
if opts.Date != "" {
385+
dateLow, err := time.Parse("2006-01-02", opts.Date)
386+
if err != nil {
387+
log.Warn("Unable to parse %s, filter not applied: %v", opts.Date, err)
388+
} else {
389+
dateHigh := dateLow.Add(86399000000000) // 23h59m59s
390+
391+
cond = cond.And(builder.Gte{"created_unix": dateLow.Unix()})
392+
cond = cond.And(builder.Lte{"created_unix": dateHigh.Unix()})
393+
}
394+
}
395+
383396
return cond, nil
384397
}

routers/user/home.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ func Dashboard(ctx *context.Context) {
156156
IncludePrivate: true,
157157
OnlyPerformedBy: false,
158158
IncludeDeleted: false,
159+
Date: ctx.Query("date"),
159160
})
160161

161162
if ctx.Written() {

routers/user/profile.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ func Profile(ctx *context.Context) {
202202
IncludePrivate: showPrivate,
203203
OnlyPerformedBy: true,
204204
IncludeDeleted: false,
205+
Date: ctx.Query("date"),
205206
})
206207
if ctx.Written() {
207208
return

web_src/js/components/ActivityHeatmap.vue

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
:end-date="endDate"
1111
:values="values"
1212
:range-color="colorRange"
13+
@day-click="handleDayClick($event)"
1314
/>
1415
</div>
1516
</template>
@@ -48,7 +49,25 @@ export default {
4849
}
4950
return s;
5051
}
51-
}
52+
},
53+
methods: {
54+
handleDayClick(e) {
55+
// Reset filter if same date is clicked
56+
const params = new URLSearchParams(document.location.search);
57+
const queryDate = params.get('date');
58+
// Timezone has to be stripped because toISOString() converts to UTC
59+
const clickedDate = new Date(e.date - (e.date.getTimezoneOffset() * 60000)).toISOString().substring(0, 10);
60+
61+
if (queryDate && queryDate === clickedDate) {
62+
params.delete('date');
63+
} else {
64+
params.set('date', clickedDate);
65+
}
66+
67+
const newSearch = params.toString();
68+
window.location.search = newSearch.length ? `?${newSearch}` : '';
69+
}
70+
},
5271
};
5372
</script>
5473
<style scoped/>

0 commit comments

Comments
 (0)