summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-03-18 13:05:07 +0000
committerDouwe Maan <douwe@gitlab.com>2015-03-18 13:05:07 +0000
commit1f21dfaeabe9e515b821139a22809fb03fccbcd9 (patch)
treedb2794e1f760a05bc659e2269f05e9415b9aae50 /app
parent5c4d6606c7efc1eec0c636477c3ed51b75ca7f08 (diff)
parent9e5738b0072f8715d52801f3469be9f3742beb97 (diff)
downloadgitlab-ce-1f21dfaeabe9e515b821139a22809fb03fccbcd9.tar.gz
Merge branch 'commit_calendar_activity' into 'master'
Extend commit calendar to actually show what commits were made on a date ## What does this MR do? This MR extends the commit calendar so it acutally shows what commits were made on a date and in which project. It is based on the optimizations @dzaporozhets made for the calendar. ## Are there points in the code the reviewer needs to double check? The UI and how the links are generated i guess. That feels hacky at the moment :/ ## Screenshot: ![commit_calendar_extend_display](https://gitlab.com/uploads/gitlab-org/gitlab-ce/5bf1631660/commit_calendar_extend_display.png) I assume that i have to refactor this a bit more to make it a cleaner implementation, so please give me feedback on what needs to be changed :) See merge request !326
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/calendar.js.coffee17
-rw-r--r--app/assets/stylesheets/generic/calendar.scss62
-rw-r--r--app/controllers/users_controller.rb19
-rw-r--r--app/models/project_contributions.rb9
-rw-r--r--app/models/repository.rb14
-rw-r--r--app/views/users/calendar.html.haml3
-rw-r--r--app/views/users/calendar_activities.html.haml33
-rw-r--r--app/views/users/show.html.haml1
8 files changed, 131 insertions, 27 deletions
diff --git a/app/assets/javascripts/calendar.js.coffee b/app/assets/javascripts/calendar.js.coffee
index 19ea4ccc4cf..2891a48e249 100644
--- a/app/assets/javascripts/calendar.js.coffee
+++ b/app/assets/javascripts/calendar.js.coffee
@@ -4,7 +4,7 @@ class @calendar
day: "numeric"
year: "numeric"
- constructor: (timestamps, starting_year, starting_month) ->
+ constructor: (timestamps, starting_year, starting_month, calendar_activities_path) ->
cal = new CalHeatMap()
cal.init
itemName: ["commit"]
@@ -26,5 +26,16 @@ class @calendar
]
legendCellPadding: 3
onClick: (date, count) ->
- return
- return
+ formated_date = date.getFullYear() + "-" + (date.getMonth()+1) + "-" + date.getDate()
+ $(".calendar_commit_activity").fadeOut 400
+ $.ajax
+ url: calendar_activities_path
+ data:
+ date: formated_date
+ cache: false
+ dataType: "html"
+ success: (data) ->
+ $(".user-calendar-activities").html data
+ $(".calendar_commit_activity").find(".js-toggle-content").hide()
+ $(".calendar_commit_activity").fadeIn 400
+
diff --git a/app/assets/stylesheets/generic/calendar.scss b/app/assets/stylesheets/generic/calendar.scss
index 9483b26164e..e2ab7fc51a5 100644
--- a/app/assets/stylesheets/generic/calendar.scss
+++ b/app/assets/stylesheets/generic/calendar.scss
@@ -1,29 +1,45 @@
-.calendar_onclick_placeholder {
- padding: 0 0 2px 0;
-}
-
-.calendar_commit_activity {
- padding: 5px 0 0;
-}
-
-.calendar_onclick_second {
- font-size: 14px;
- display: block;
-}
-
-.calendar_onclick_hr {
- padding: 0;
- margin: 10px 0;
-}
+.user-calendar-activities {
+
+ .calendar_commit_activity {
+ padding: 5px 0 0;
+ }
+
+ .calendar_onclick_hr {
+ padding: 0;
+ margin: 10px 0;
+ }
+
+ .calendar_commit_date {
+ color: #999;
+ }
+
+ .calendar_activity_summary {
+ font-size: 14px;
+ }
-.calendar_commit_date {
- color: #999;
-}
+ .str-truncated {
+ max-width: 70%;
+ }
-.calendar_activity_summary {
- font-size: 14px;
+ .text-expander {
+ background: #eee;
+ color: #555;
+ padding: 0 5px;
+ cursor: pointer;
+ margin-left: 4px;
+ &:hover {
+ background-color: #ddd;
+ }
+ }
+
+ .commit-row-message {
+ color: #333;
+ &:hover {
+ color: #444;
+ text-decoration: underline;
+ }
+ }
}
-
/**
* This overwrites the default values of the cal-heatmap gem
*/
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 8a13394dbac..68130eb128c 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -32,6 +32,7 @@ class UsersController < ApplicationController
def calendar
projects = Project.where(id: authorized_projects_ids & @user.contributed_projects_ids)
+
calendar = Gitlab::CommitsCalendar.new(projects, @user)
@timestamps = calendar.timestamps
@starting_year = calendar.starting_year
@@ -40,6 +41,24 @@ class UsersController < ApplicationController
render 'calendar', layout: false
end
+ def calendar_activities
+ projects = Project.where(id: authorized_projects_ids & @user.contributed_projects_ids)
+
+ date = Date.parse(params[:date]) rescue nil
+ if date
+ @calendar_activities = Gitlab::CommitsCalendar.get_commits_for_date(projects, @user, date)
+ else
+ @calendar_activities = {}
+ end
+
+ # get the total number of unique commits
+ @commit_count = @calendar_activities.values.flatten.map(&:id).uniq.count
+
+ @calendar_date = date
+
+ render 'calendar_activities', layout: false
+ end
+
def determine_layout
if current_user
'navless'
diff --git a/app/models/project_contributions.rb b/app/models/project_contributions.rb
index 8ab2d814a94..bfe9928b158 100644
--- a/app/models/project_contributions.rb
+++ b/app/models/project_contributions.rb
@@ -17,6 +17,15 @@ class ProjectContributions
end
end
+ def user_commits_on_date(date)
+ repository = @project.repository
+
+ if !repository.exists? || repository.empty?
+ return []
+ end
+ commits = repository.commits_by_user_on_date_log(@user, date)
+ end
+
def cache_key
"#{Date.today.to_s}-commits-log-#{project.id}-#{user.email}"
end
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 47758b8ad68..7addbca8fb1 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -157,6 +157,20 @@ class Repository
end
end
+ def commits_by_user_on_date_log(user, date)
+ # format the date string for git
+ start_date = date.strftime("%Y-%m-%d 00:00:00")
+ end_date = date.strftime("%Y-%m-%d 23:59:59")
+
+ author_emails = '(' + user.all_emails.map{ |e| Regexp.escape(e) }.join('|') + ')'
+ args = %W(git log -E --author=#{author_emails} --after=#{start_date.to_s} --until=#{end_date.to_s} --branches --pretty=format:%h)
+ commits = Gitlab::Popen.popen(args, path_to_repo).first.split("\n")
+
+ commits.map! do |commit_id|
+ commit(commit_id)
+ end
+ end
+
def commits_per_day_for_user(user)
timestamps_by_user_log(user).
group_by { |commit_date| commit_date }.
diff --git a/app/views/users/calendar.html.haml b/app/views/users/calendar.html.haml
index 1d1c974da24..d113ceeb753 100644
--- a/app/views/users/calendar.html.haml
+++ b/app/views/users/calendar.html.haml
@@ -4,5 +4,6 @@
new calendar(
#{@timestamps.to_json},
#{@starting_year},
- #{@starting_month}
+ #{@starting_month},
+ '#{user_calendar_activities_path}'
);
diff --git a/app/views/users/calendar_activities.html.haml b/app/views/users/calendar_activities.html.haml
new file mode 100644
index 00000000000..7c0cecfadb5
--- /dev/null
+++ b/app/views/users/calendar_activities.html.haml
@@ -0,0 +1,33 @@
+.calendar_commit_activity
+ %hr
+ %h4
+ Commit Activity
+ %strong
+ - if @commit_count == 0
+ no
+ - else
+ = @commit_count
+ %span.calendar_commit_date
+ unique
+ = 'commit'.pluralize(@commit_count)
+ on
+ = @calendar_date.strftime("%b %d, %Y") rescue ''
+ -unless @commit_count == 0
+ %hr
+ - @calendar_activities.each do |project, commits|
+ - next if commits.empty?
+ %div.js-toggle-container
+ %strong
+ = pluralize(commits.count, 'commit')
+ in project
+ = link_to project.name_with_namespace, project_path(project)
+ %a.text-expander.js-toggle-button &hellip;
+ %hr
+ %div.js-toggle-content
+ - commits.each do |commit|
+ %span.monospace
+ = commit.committed_date.strftime("%H:%M")
+ = link_to commit.short_id, namespace_project_commit_path(project.namespace, project, commit), class: "commit_short_id"
+ = link_to commit.message, namespace_project_commit_path(project.namespace, project, commit), class: "commit-row-message str-truncated"
+ %br
+ %hr
diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml
index abd6b229782..6d6beb58711 100644
--- a/app/views/users/show.html.haml
+++ b/app/views/users/show.html.haml
@@ -25,6 +25,7 @@
.user-calendar
%h4.center.light
%i.fa.fa-spinner.fa-spin
+ .user-calendar-activities
%hr
%h4
User Activity