2015-03-22 06:48:08 +00: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 21:52:44 +00:00
|
|
|
events = Event.reorder(nil).contributions.where(author_id: user.id).
|
2015-03-22 21:35:27 +00:00
|
|
|
where("created_at > ?", date_from).where(project_id: projects).
|
|
|
|
group('date(created_at)').
|
2015-04-24 10:27:52 +00:00
|
|
|
select('date(created_at) as date, count(id) as total_amount').
|
2015-03-22 21:52:44 +00:00
|
|
|
map(&:attributes)
|
2015-03-22 06:48:08 +00:00
|
|
|
|
2016-04-27 10:07:46 +00:00
|
|
|
dates = (1.year.ago.to_date..Date.today).to_a
|
2015-03-22 06:48:08 +00:00
|
|
|
|
|
|
|
dates.each do |date|
|
|
|
|
date_id = date.to_time.to_i.to_s
|
2015-03-22 21:35:27 +00:00
|
|
|
day_events = events.find { |day_events| day_events["date"] == date }
|
2015-03-22 06:48:08 +00:00
|
|
|
|
2015-03-22 21:35:27 +00:00
|
|
|
if day_events
|
|
|
|
@timestamps[date_id] = day_events["total_amount"]
|
2015-03-22 06:48:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@timestamps
|
|
|
|
end
|
|
|
|
|
|
|
|
def events_by_date(date)
|
2015-03-22 20:55:00 +00:00
|
|
|
events = Event.contributions.where(author_id: user.id).
|
2015-03-22 06:48:08 +00: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-02 03:11:34 +00:00
|
|
|
1.year.ago.year
|
2015-03-22 06:48:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def starting_month
|
2016-01-02 03:11:34 +00:00
|
|
|
Date.today.month
|
2015-03-22 06:48:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|