Commit 1c27ab50 authored by Jacob Schatz's avatar Jacob Schatz

Merge branch 'fix-reduce-contributions-calendar-payload' into 'master'

Replace contributions calendar timezone payload with dates

## What does this MR do?
Fixes a ~regression bug introduced in !5784 whereby the calendar squares would not render due to a timezone mismatch between the server timezone and the browser (user) timezone. I am now returning the dates instead of the timezone from the backend. There's a good chance we will still have a calendar off by one error (which is an existing issue #1943) but passing dates should make sure that the calendar activity squares render correctly across timezones.

## Are there points in the code the reviewer needs to double check?
Double check that this displays the correct calendar squares when the GitLab instance is hosted in a different timezone than the user viewing it

## Why was this MR needed?
Fixes ~regression issue 😞 

## Screenshots (if relevant)
Before:
![Screen_Shot_2016-09-13_at_9.47.06_PM](/uploads/d8b41b9b43320f021452e39f29b0e194/Screen_Shot_2016-09-13_at_9.47.06_PM.png)

After:
![Screen_Shot_2016-09-13_at_9.46.11_PM](/uploads/e09a3b35eef77ee1cf73b924c3815d3a/Screen_Shot_2016-09-13_at_9.46.11_PM.png)

## Does this MR meet the acceptance criteria?

- [x] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added
- Tests
  - [x] All builds are passing
- [x] Conform by the [merge request performance guides](http://docs.gitlab.com/ce/development/merge_request_performance_guidelines.html)
- [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [x] Branch has no merge conflicts with `master` (if you do - rebase it please)
- [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)

## What are the relevant issue numbers?
Closes #21921

See merge request !6336
parents 1c2aa4f8 a147b43d
......@@ -30,6 +30,7 @@ v 8.12.0 (unreleased)
- Fix file permissions change when updating a file on the Gitlab UI !5979
- Change merge_error column from string to text type
- Reduce contributions calendar data payload (ClemMakesApps)
- Replace contributions calendar timezone payload with dates (ClemMakesApps)
- Add `web_url` field to issue, merge request, and snippet API objects (Ben Boeckel)
- Enable pipeline events by default !6278
- Move parsing of sidekiq ps into helper !6245 (pascalbetz)
......
......@@ -29,7 +29,7 @@
date.setDate(date.getDate() + i);
var day = date.getDay();
var count = timestamps[date.getTime() * 0.001];
var count = timestamps[dateFormat(date, 'yyyy-mm-dd')];
// Create a new group array if this is the first day of the week
// or if is first object
......
......@@ -73,7 +73,7 @@ class UsersController < ApplicationController
def calendar
calendar = contributions_calendar
@timestamps = calendar.timestamps
@activity_dates = calendar.activity_dates
render 'calendar', layout: false
end
......
......@@ -4,6 +4,6 @@
Summary of issues, merge requests, and push events
:javascript
new Calendar(
#{@timestamps.to_json},
#{@activity_dates.to_json},
'#{user_calendar_activities_path}'
);
\ No newline at end of file
module Gitlab
class ContributionsCalendar
attr_reader :timestamps, :projects, :user
attr_reader :activity_dates, :projects, :user
def initialize(projects, user)
@projects = projects
@user = user
end
def timestamps
return @timestamps if @timestamps.present?
def activity_dates
return @activity_dates if @activity_dates.present?
@timestamps = {}
@activity_dates = {}
date_from = 1.year.ago
events = Event.reorder(nil).contributions.where(author_id: user.id).
......@@ -19,18 +19,17 @@ module Gitlab
select('date(created_at) as date, count(id) as total_amount').
map(&:attributes)
dates = (1.year.ago.to_date..Date.today).to_a
activity_dates = (1.year.ago.to_date..Date.today).to_a
dates.each do |date|
date_id = date.to_time.to_i.to_s
activity_dates.each do |date|
day_events = events.find { |day_events| day_events["date"] == date }
if day_events
@timestamps[date_id] = day_events["total_amount"]
@activity_dates[date] = day_events["total_amount"]
end
end
@timestamps
@activity_dates
end
def events_by_date(date)
......
require 'spec_helper'
feature 'Contributions Calendar', js: true, feature: true do
include WaitForAjax
let(:contributed_project) { create(:project, :public) }
before do
login_as :user
issue_params = { title: 'Bug in old browser' }
Issues::CreateService.new(contributed_project, @user, issue_params).execute
# Push code contribution
push_params = {
project: contributed_project,
action: Event::PUSHED,
author_id: @user.id,
data: { commit_count: 3 }
}
Event.create(push_params)
visit @user.username
wait_for_ajax
end
it 'displays calendar', js: true do
expect(page).to have_css('.js-contrib-calendar')
end
it 'displays calendar activity log', js: true do
expect(find('.content_list .event-note')).to have_content "Bug in old browser"
end
it 'displays calendar activity square color', js: true do
expect(page).to have_selector('.user-contrib-cell[fill=\'#acd5f2\']', count: 1)
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment