diff --git a/app/assets/stylesheets/generic/avatar.scss b/app/assets/stylesheets/generic/avatar.scss index b688620673926ce6ddecfc557c0f9fea83d53ade..b88cdd83937b1f307e07b4859eb9f474bc74fbd3 100644 --- a/app/assets/stylesheets/generic/avatar.scss +++ b/app/assets/stylesheets/generic/avatar.scss @@ -15,6 +15,10 @@ &.s24 { margin-right: 4px; } } + &.avatar-tile { + @include border-radius(0px); + } + &.s16 { width: 16px; height: 16px; margin-right: 6px; } &.s24 { width: 24px; height: 24px; margin-right: 8px; } &.s26 { width: 26px; height: 26px; margin-right: 8px; } diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index ff5e31067fb2fd7253663c1f14696b5c3b2786a4..57d8ef09faf423edcec343b8915be526d889e77b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -28,13 +28,10 @@ class UsersController < ApplicationController def calendar visible_projects = ProjectsFinder.new.execute(current_user) - - # Get user repositories and collect timestamps for commits - user_repositories = visible_projects.map(&:repository) - calendar = Gitlab::CommitsCalendar.new(user_repositories, @user) + calendar = Gitlab::CommitsCalendar.new(visible_projects, @user) @timestamps = calendar.timestamps - @starting_year = (Time.now - 1.year).strftime("%Y") - @starting_month = Date.today.strftime("%m").to_i + @starting_year = calendar.starting_year + @starting_month = calendar.starting_month render 'calendar', layout: false end diff --git a/app/models/project_contributions.rb b/app/models/project_contributions.rb new file mode 100644 index 0000000000000000000000000000000000000000..8ab2d814a9489225fd8221502d97316d57c16952 --- /dev/null +++ b/app/models/project_contributions.rb @@ -0,0 +1,23 @@ +class ProjectContributions + attr_reader :project, :user + + def initialize(project, user) + @project, @user = project, user + end + + def commits_log + repository = project.repository + + if !repository.exists? || repository.empty? + return {} + end + + Rails.cache.fetch(cache_key) do + repository.commits_per_day_for_user(user) + end + end + + def cache_key + "#{Date.today.to_s}-commits-log-#{project.id}-#{user.email}" + end +end diff --git a/app/views/groups/show.html.haml b/app/views/groups/show.html.haml index 81f0e1dd2d82ad7adc5a9eedd54e9ce48c8725fc..484bebca2d832e8799d5c0a0f665aa35c57136f9 100644 --- a/app/views/groups/show.html.haml +++ b/app/views/groups/show.html.haml @@ -1,6 +1,6 @@ .dashboard %div - = image_tag group_icon(@group.path), class: "avatar s90" + = image_tag group_icon(@group.path), class: "avatar avatar-tile s90" .clearfix %h2 = @group.name diff --git a/app/views/users/calendar.html.haml b/app/views/users/calendar.html.haml index 727faf2367905cdb261de6bc4afbe1e6068bbd66..13bdc5ed1e77bac38793f073cb82a81d3568303d 100644 --- a/app/views/users/calendar.html.haml +++ b/app/views/users/calendar.html.haml @@ -1,4 +1,4 @@ -%h4 Calendar: +%h4 Calendar #cal-heatmap.calendar :javascript new calendar( diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index 445f43cd5007536c5f77b2e8901846efb6296fc4..b05918b019e3d33c944179abee37e3e4f9077dc9 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -1,7 +1,7 @@ .row .col-md-8 %h3.page-title - = image_tag avatar_icon(@user.email, 90), class: "avatar s90", alt: '' + = image_tag avatar_icon(@user.email, 90), class: "avatar avatar-tile s90", alt: '' = @user.name - if @user == current_user .pull-right @@ -15,7 +15,7 @@ .clearfix - if @groups.any? - %h4 Groups: + %h4 Groups = render 'groups', groups: @groups %hr @@ -24,7 +24,7 @@ %i.fa.fa-spinner.fa-spin %hr %h4 - User Activity: + User Activity - if current_user %span.rss-icon.pull-right diff --git a/lib/gitlab/commits_calendar.rb b/lib/gitlab/commits_calendar.rb index ccc80d080af5b8edea431d6a4a2b2b8688028b17..2f30d238e6bd9591be4ea57a9b86d9c4c119c5c2 100644 --- a/lib/gitlab/commits_calendar.rb +++ b/lib/gitlab/commits_calendar.rb @@ -2,15 +2,15 @@ module Gitlab class CommitsCalendar attr_reader :timestamps - def initialize(repositories, user) + def initialize(projects, user) @timestamps = {} date_timestamps = [] - repositories.select(&:exists?).reject(&:empty?).each do |raw_repository| - commits_log = raw_repository.commits_per_day_for_user(user) - date_timestamps << commits_log + projects.reject(&:forked?).each do |project| + date_timestamps << ProjectContributions.new(project, user).commits_log end + # Sumarrize commits from all projects per days date_timestamps = date_timestamps.inject do |collection, date| collection.merge(date) { |k, old_v, new_v| old_v + new_v } end @@ -21,5 +21,13 @@ module Gitlab @timestamps[timestamp] = commits if timestamp end end + + def starting_year + (Time.now - 1.year).strftime("%Y") + end + + def starting_month + Date.today.strftime("%m").to_i + end end end