summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLong Nguyen <long.polyglot@gmail.com>2016-05-02 16:37:12 +0700
committerLong Nguyen <long.polyglot@gmail.com>2016-05-02 16:37:12 +0700
commitc0f02aad4a1a178109a235d34bd70218c0aec86c (patch)
tree0fda1649d7d67e1308ed0aaee241a638e4117119
parentdf8fda60fbbd2b6b38bdcb1680a0f24598c29f79 (diff)
downloadgitlab-ce-c0f02aad4a1a178109a235d34bd70218c0aec86c.tar.gz
Add snippet tab under user profile
-rw-r--r--app/assets/javascripts/user_tabs.js.coffee9
-rw-r--r--app/controllers/users_controller.rb22
-rw-r--r--app/views/users/show.html.haml6
-rw-r--r--config/routes.rb5
4 files changed, 39 insertions, 3 deletions
diff --git a/app/assets/javascripts/user_tabs.js.coffee b/app/assets/javascripts/user_tabs.js.coffee
index 09b7eec9104..aa798b96ede 100644
--- a/app/assets/javascripts/user_tabs.js.coffee
+++ b/app/assets/javascripts/user_tabs.js.coffee
@@ -26,6 +26,10 @@
# Personal projects
# </a>
# </li>
+# <li class="snippets-tab">
+# <a data-action="snippets" data-target="#snippets" data-toggle="tab" href="/u/username/snippets">
+# </a>
+# </li>
# </ul>
#
# <div class="tab-content">
@@ -41,6 +45,9 @@
# <div class="tab-pane" id="projects">
# Projects content
# </div>
+# <div class="tab-pane" id="snippets">
+# Snippets content
+# </div>
# </div>
#
# <div class="loading-status">
@@ -100,7 +107,7 @@ class @UserTabs
if action is 'activity'
@loadActivities(source)
- if action in ['groups', 'contributed', 'projects']
+ if action in ['groups', 'contributed', 'projects', 'snippets']
@loadTab(source, action)
loadTab: (source, action) ->
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 2ae180c8a12..799421c185b 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -58,6 +58,19 @@ class UsersController < ApplicationController
end
end
+ def snippets
+ load_snippets
+
+ respond_to do |format|
+ format.html { render 'show' }
+ format.json do
+ render json: {
+ html: view_to_html_string("snippets/_snippets", collection: @snippets)
+ }
+ end
+ end
+ end
+
def calendar
calendar = contributions_calendar
@timestamps = calendar.timestamps
@@ -116,6 +129,15 @@ class UsersController < ApplicationController
@groups = JoinedGroupsFinder.new(user).execute(current_user)
end
+ def load_snippets
+ @snippets = SnippetsFinder.new.execute(
+ current_user,
+ filter: :by_user,
+ user: user,
+ scope: params[:scope]
+ ).page(params[:page])
+ end
+
def projects_for_current_user
ProjectsFinder.new.execute(current_user)
end
diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml
index 3028491e5b6..a453a7fedb7 100644
--- a/app/views/users/show.html.haml
+++ b/app/views/users/show.html.haml
@@ -81,6 +81,9 @@
%li.projects-tab
= link_to user_projects_path, data: {target: 'div#projects', action: 'projects', toggle: 'tab'} do
Personal projects
+ %li.snippets-tab
+ = link_to user_snippets_path, data: {target: 'div#snippets', action: 'snippets', toggle: 'tab'} do
+ Snippets
%div{ class: container_class }
.tab-content
@@ -104,6 +107,9 @@
#projects.tab-pane
- # This tab is always loaded via AJAX
+ #snippets.tab-pane
+ - # This tab is always loaded via AJAX
+
.loading-status
= spinner
diff --git a/config/routes.rb b/config/routes.rb
index 2f820aafed1..f6a41331ecf 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -89,8 +89,6 @@ Rails.application.routes.draw do
end
end
- get '/s/:username' => 'snippets#index', as: :user_snippets, constraints: { username: /.*/ }
-
#
# Invites
#
@@ -355,6 +353,9 @@ Rails.application.routes.draw do
get 'u/:username/contributed' => 'users#contributed', as: :user_contributed_projects,
constraints: { username: /.*/ }
+ get 'u/:username/snippets' => 'users#snippets', as: :user_snippets,
+ constraints: { username: /.*/ }
+
get '/u/:username' => 'users#show', as: :user,
constraints: { username: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ }