debian-mirror-gitlab/lib/gitlab/contributions_calendar.rb

54 lines
1.3 KiB
Ruby
Raw Normal View History

2015-04-26 12:48:37 +05:30
module Gitlab
class ContributionsCalendar
2016-09-29 09:46:39 +05:30
attr_reader :activity_dates, :projects, :user
2015-04-26 12:48:37 +05:30
def initialize(projects, user)
@projects = projects
@user = user
end
2016-09-29 09:46:39 +05:30
def activity_dates
return @activity_dates if @activity_dates.present?
2015-04-26 12:48:37 +05:30
2016-09-29 09:46:39 +05:30
@activity_dates = {}
2015-04-26 12:48:37 +05:30
date_from = 1.year.ago
events = Event.reorder(nil).contributions.where(author_id: user.id).
where("created_at > ?", date_from).where(project_id: projects).
group('date(created_at)').
2015-09-11 14:41:01 +05:30
select('date(created_at) as date, count(id) as total_amount').
2015-04-26 12:48:37 +05:30
map(&:attributes)
2016-09-29 09:46:39 +05:30
activity_dates = (1.year.ago.to_date..Date.today).to_a
2015-04-26 12:48:37 +05:30
2016-09-29 09:46:39 +05:30
activity_dates.each do |date|
2015-04-26 12:48:37 +05:30
day_events = events.find { |day_events| day_events["date"] == date }
if day_events
2016-09-29 09:46:39 +05:30
@activity_dates[date] = day_events["total_amount"]
2015-04-26 12:48:37 +05:30
end
end
2016-09-29 09:46:39 +05:30
@activity_dates
2015-04-26 12:48:37 +05:30
end
def events_by_date(date)
events = Event.contributions.where(author_id: user.id).
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
1.year.ago.year
2015-04-26 12:48:37 +05:30
end
def starting_month
Date.today.month
2015-04-26 12:48:37 +05:30
end
end
end