2015-03-22 02:48:08 -04:00
|
|
|
module Gitlab
|
|
|
|
class ContributionsCalendar
|
|
|
|
attr_reader :timestamps, :projects, :user
|
|
|
|
|
|
|
|
def initialize(projects, user)
|
|
|
|
@projects = projects
|
|
|
|
@user = user
|
|
|
|
end
|
|
|
|
|
|
|
|
def timestamps
|
|
|
|
return @timestamps if @timestamps.present?
|
|
|
|
|
|
|
|
@timestamps = {}
|
|
|
|
date_from = 1.year.ago
|
|
|
|
|
2015-03-22 17:52:44 -04:00
|
|
|
events = Event.reorder(nil).contributions.where(author_id: user.id).
|
2015-03-22 17:35:27 -04:00
|
|
|
where("created_at > ?", date_from).where(project_id: projects).
|
|
|
|
group('date(created_at)').
|
2015-04-24 06:27:52 -04:00
|
|
|
select('date(created_at) as date, count(id) as total_amount').
|
2015-03-22 17:52:44 -04:00
|
|
|
map(&:attributes)
|
2015-03-22 02:48:08 -04:00
|
|
|
|
|
|
|
dates = (1.year.ago.to_date..(Date.today + 1.day)).to_a
|
|
|
|
|
|
|
|
dates.each do |date|
|
|
|
|
date_id = date.to_time.to_i.to_s
|
|
|
|
@timestamps[date_id] = 0
|
2015-03-22 17:35:27 -04:00
|
|
|
day_events = events.find { |day_events| day_events["date"] == date }
|
2015-03-22 02:48:08 -04:00
|
|
|
|
2015-03-22 17:35:27 -04:00
|
|
|
if day_events
|
|
|
|
@timestamps[date_id] = day_events["total_amount"]
|
2015-03-22 02:48:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@timestamps
|
|
|
|
end
|
|
|
|
|
|
|
|
def events_by_date(date)
|
2015-03-22 16:55:00 -04:00
|
|
|
events = Event.contributions.where(author_id: user.id).
|
2015-03-22 02:48:08 -04:00
|
|
|
where("created_at > ? AND created_at < ?", date.beginning_of_day, date.end_of_day).
|
|
|
|
where(project_id: projects)
|
|
|
|
|
|
|
|
events.select do |event|
|
|
|
|
event.push? || event.issue? || event.merge_request?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def starting_year
|
2016-01-01 22:11:34 -05:00
|
|
|
1.year.ago.year
|
2015-03-22 02:48:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def starting_month
|
2016-01-01 22:11:34 -05:00
|
|
|
Date.today.month
|
2015-03-22 02:48:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|