Skip to content

Heatmap days clickable #13935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Feb 20, 2021
25 changes: 19 additions & 6 deletions models/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,13 @@ func (a *Action) GetIssueContent() string {

// GetFeedsOptions options for retrieving feeds
type GetFeedsOptions struct {
RequestedUser *User // the user we want activity for
RequestedTeam *Team // the team we want activity for
Actor *User // the user viewing the activity
IncludePrivate bool // include private actions
OnlyPerformedBy bool // only actions performed by requested user
IncludeDeleted bool // include deleted actions
RequestedUser *User // the user we want activity for
RequestedTeam *Team // the team we want activity for
Actor *User // the user viewing the activity
IncludePrivate bool // include private actions
OnlyPerformedBy bool // only actions performed by requested user
IncludeDeleted bool // include deleted actions
Date string // the day we want activity for: YYYY-MM-DD
}

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

if opts.Date != "" {
dateLow, err := time.Parse("2006-01-02", opts.Date)
if err != nil {
log.Warn("Unable to parse %s, filter not applied: %v", opts.Date, err)
} else {
dateHigh := dateLow.Add(86399000000000) // 23h59m59s

cond = cond.And(builder.Gte{"created_unix": dateLow.Unix()})
cond = cond.And(builder.Lte{"created_unix": dateHigh.Unix()})
}
}

return cond, nil
}
1 change: 1 addition & 0 deletions routers/user/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ func Dashboard(ctx *context.Context) {
IncludePrivate: true,
OnlyPerformedBy: false,
IncludeDeleted: false,
Date: ctx.Query("date"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're missing this parameter in routers/user/profile.go.

})

if ctx.Written() {
Expand Down
1 change: 1 addition & 0 deletions routers/user/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ func Profile(ctx *context.Context) {
IncludePrivate: showPrivate,
OnlyPerformedBy: true,
IncludeDeleted: false,
Date: ctx.Query("date"),
})
if ctx.Written() {
return
Expand Down
21 changes: 20 additions & 1 deletion web_src/js/components/ActivityHeatmap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
:end-date="endDate"
:values="values"
:range-color="colorRange"
@day-click="handleDayClick($event)"
/>
</div>
</template>
Expand Down Expand Up @@ -48,7 +49,25 @@ export default {
}
return s;
}
}
},
methods: {
handleDayClick(e) {
// Reset filter if same date is clicked
const params = new URLSearchParams(document.location.search);
const queryDate = params.get('date');
// Timezone has to be stripped because toISOString() converts to UTC
const clickedDate = new Date(e.date - (e.date.getTimezoneOffset() * 60000)).toISOString().substring(0, 10);

if (queryDate && queryDate === clickedDate) {
params.delete('date');
} else {
params.set('date', clickedDate);
}

const newSearch = params.toString();
window.location.search = newSearch.length ? `?${newSearch}` : '';
}
},
};
</script>
<style scoped/>