Commit a15e9f02 authored by Clement Ho's avatar Clement Ho

Reduce contributions calendar data payload

parent cd6157d5
......@@ -2,6 +2,7 @@ Please view this file on the master branch, on stable branches it's out of date.
v 8.12.0 (unreleased)
- Change merge_error column from string to text type
- Reduce contributions calendar data payload (ClemMakesApps)
- Add `web_url` field to issue, merge request, and snippet API objects (Ben Boeckel)
- Optimistic locking for Issues and Merge Requests (title and description overriding prevention)
- Add `wiki_page_events` to project hook APIs (Ben Boeckel)
......
......@@ -67,6 +67,14 @@
$.timeago.settings.strings = tmpLocale;
};
w.gl.utils.getDayDifference = function(a, b) {
var millisecondsPerDay = 1000 * 60 * 60 * 24;
var date1 = Date.UTC(a.getFullYear(), a.getMonth(), a.getDate());
var date2 = Date.UTC(b.getFullYear(), b.getMonth(), b.getDate());
return Math.floor((date2 - date1) / millisecondsPerDay);
}
})(window);
}).call(this);
......@@ -3,7 +3,6 @@
this.Calendar = (function() {
function Calendar(timestamps, calendar_activities_path) {
var group, i;
this.calendar_activities_path = calendar_activities_path;
this.clickDay = bind(this.clickDay, this);
this.currentSelectedDate = '';
......@@ -13,26 +12,36 @@
this.monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
this.months = [];
this.timestampsTmp = [];
i = 0;
group = 0;
_.each(timestamps, (function(_this) {
return function(count, date) {
var day, innerArray, newDate;
newDate = new Date(parseInt(date) * 1000);
day = newDate.getDay();
var group = 0;
var today = new Date()
today.setHours(0, 0, 0, 0, 0);
var oneYearAgo = new Date(today);
oneYearAgo.setFullYear(today.getFullYear() - 1);
var days = gl.utils.getDayDifference(oneYearAgo, today);
for(var i = 0; i <= days; i++) {
var date = new Date(oneYearAgo);
date.setDate(date.getDate() + i);
var day = date.getDay();
var count = timestamps[date.getTime() * 0.001];
if ((day === 0 && i !== 0) || i === 0) {
_this.timestampsTmp.push([]);
this.timestampsTmp.push([]);
group++;
}
innerArray = _this.timestampsTmp[group - 1];
var innerArray = this.timestampsTmp[group - 1];
innerArray.push({
count: count,
date: newDate,
count: count || 0,
date: date,
day: day
});
return i++;
};
})(this));
}
this.colorKey = this.initColorKey();
this.color = this.initColor();
this.renderSvg(group);
......
......@@ -23,7 +23,6 @@ module Gitlab
dates.each do |date|
date_id = date.to_time.to_i.to_s
@timestamps[date_id] = 0
day_events = events.find { |day_events| day_events["date"] == date }
if day_events
......
......@@ -29,3 +29,22 @@ describe 'Date time utils', ->
it 'should return Saturday', ->
day = gl.utils.getDayName(new Date('07/23/2016'))
expect(day).toBe('Saturday')
describe 'get day difference', ->
it 'should return 7', ->
firstDay = new Date('07/01/2016')
secondDay = new Date('07/08/2016')
difference = gl.utils.getDayDifference(firstDay, secondDay)
expect(difference).toBe(7)
it 'should return 31', ->
firstDay = new Date('07/01/2016')
secondDay = new Date('08/01/2016')
difference = gl.utils.getDayDifference(firstDay, secondDay)
expect(difference).toBe(31)
it 'should return 365', ->
firstDay = new Date('07/02/2015')
secondDay = new Date('07/01/2016')
difference = gl.utils.getDayDifference(firstDay, secondDay)
expect(difference).toBe(365)
\ No newline at end of file
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