Skip to content
Snippets Groups Projects
Commit 1f0e1656 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Load contribution calendar via AJAX

parent c9f18d45
No related branches found
No related tags found
No related merge requests found
class UsersController < ApplicationController
skip_before_filter :authenticate_user!, only: [:show, :activities]
layout :determine_layout
 
def show
@user = User.find_by_username!(params[:username])
unless current_user || @user.public_profile?
return authenticate_user!
end
# Projects user can view
visible_projects = ProjectsFinder.new.execute(current_user)
authorized_projects_ids = visible_projects.pluck(:id)
Loading
Loading
@@ -25,6 +18,15 @@ class UsersController < ApplicationController
 
@title = @user.name
 
respond_to do |format|
format.html
format.atom { render layout: false }
end
end
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)
Loading
Loading
@@ -32,10 +34,7 @@ class UsersController < ApplicationController
@starting_year = (Time.now - 1.year).strftime("%Y")
@starting_month = Date.today.strftime("%m").to_i
 
respond_to do |format|
format.html
format.atom { render layout: false }
end
render 'calendar', layout: false
end
 
def determine_layout
Loading
Loading
@@ -45,4 +44,14 @@ class UsersController < ApplicationController
'public_users'
end
end
private
def authenticate_user!
@user = User.find_by_username!(params[:username])
unless current_user || @user.public_profile?
return authenticate_user!
end
end
end
%h4 Calendar:
#cal-heatmap.calendar
:javascript
new calendar(
Loading
Loading
Loading
Loading
@@ -19,8 +19,9 @@
= render 'groups', groups: @groups
%hr
 
%h4 Calendar:
%div= render 'calendar'
.user-calendar
%h4.center.light
%i.fa.fa-spinner.fa-spin
%hr
%h4
User Activity:
Loading
Loading
@@ -36,3 +37,8 @@
= render 'profile', user: @user
- if @projects.present?
= render 'projects', projects: @projects
:coffeescript
$ ->
$(".user-calendar").load("#{user_calendar_path}")
Loading
Loading
@@ -157,10 +157,9 @@ Gitlab::Application.routes.draw do
end
end
 
# route for commits used by the cal-heatmap
get 'u/:username/activities' => 'users#activities', as: :user_activities,
constraints: { username: /(?:[^.]|\.(?!atom$))+/, format: /atom/ },
via: :get
get 'u/:username/calendar' => 'users#calendar', as: :user_calendar,
constraints: { username: /(?:[^.]|\.(?!atom$))+/, format: /atom/ }
get '/u/:username' => 'users#show', as: :user,
constraints: { username: /(?:[^.]|\.(?!atom$))+/, format: /atom/ }
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment