Commit ffda8a1a authored by Long Nguyen's avatar Long Nguyen

user routings refactor

parent 5f60841d
...@@ -10,11 +10,29 @@ class SnippetsController < ApplicationController ...@@ -10,11 +10,29 @@ class SnippetsController < ApplicationController
# Allow destroy snippet # Allow destroy snippet
before_action :authorize_admin_snippet!, only: [:destroy] before_action :authorize_admin_snippet!, only: [:destroy]
skip_before_action :authenticate_user!, only: [:show, :raw] skip_before_action :authenticate_user!, only: [:index, :show, :raw]
layout 'snippets' layout 'snippets'
respond_to :html respond_to :html
def index
if params[:username].present?
@user = User.find_by(username: params[:username])
render_404 and return unless @user
@snippets = SnippetsFinder.new.execute(current_user, {
filter: :by_user,
user: @user,
scope: params[:scope] }).
page(params[:page])
render 'index'
else
redirect_to(current_user ? dashboard_snippets_path : explore_snippets_path)
end
end
def new def new
@snippet = PersonalSnippet.new @snippet = PersonalSnippet.new
end end
...@@ -43,7 +61,7 @@ class SnippetsController < ApplicationController ...@@ -43,7 +61,7 @@ class SnippetsController < ApplicationController
@snippet.destroy @snippet.destroy
redirect_to dashboard_snippets_path redirect_to snippets_path
end end
def raw def raw
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
%span %span
= snippet.title = snippet.title
by by
= link_to user_snippets_path(snippet.author) do = link_to snippets_user_path(snippet.author) do
= image_tag avatar_icon(snippet.author_email), class: "avatar avatar-inline s16", alt: '' = image_tag avatar_icon(snippet.author_email), class: "avatar avatar-inline s16", alt: ''
= snippet.author_name = snippet.author_name
%span.light #{time_ago_with_tooltip(snippet.created_at)} %span.light #{time_ago_with_tooltip(snippet.created_at)}
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
= "##{snippet_title.id}" = "##{snippet_title.id}"
%span %span
by by
= link_to user_snippets_path(snippet_title.author) do = link_to snippets_user_path(snippet_title.author) do
= image_tag avatar_icon(snippet_title.author_email), class: "avatar avatar-inline s16", alt: '' = image_tag avatar_icon(snippet_title.author_email), class: "avatar avatar-inline s16", alt: ''
= snippet_title.author_name = snippet_title.author_name
%span.light #{time_ago_with_tooltip(snippet_title.created_at)} %span.light #{time_ago_with_tooltip(snippet_title.created_at)}
...@@ -16,6 +16,6 @@ ...@@ -16,6 +16,6 @@
= link_to snippet.project.name_with_namespace, namespace_project_path(snippet.project.namespace, snippet.project) = link_to snippet.project.name_with_namespace, namespace_project_path(snippet.project.namespace, snippet.project)
.snippet-info .snippet-info
= link_to user_snippets_path(snippet.author) do = link_to snippets_user_path(snippet.author) do
= snippet.author_name = snippet.author_name
authored #{time_ago_with_tooltip(snippet.created_at)} authored #{time_ago_with_tooltip(snippet.created_at)}
- page_title "By #{@user.name}", "Snippets"
%ol.breadcrumb
%li
= link_to snippets_path do
Snippets
%li
= @user.name
.pull-right.hidden-xs
= link_to user_path(@user) do
#{@user.name} profile page
= render 'snippets'
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#{@timestamps.to_json}, #{@timestamps.to_json},
#{@starting_year}, #{@starting_year},
#{@starting_month}, #{@starting_month},
'#{user_calendar_activities_path}' '#{calendar_activities_user_path}'
); );
.calendar-hint Summary of issues, merge requests, and push events .calendar-hint Summary of issues, merge requests, and push events
...@@ -70,19 +70,19 @@ ...@@ -70,19 +70,19 @@
%ul.nav-links.center.user-profile-nav %ul.nav-links.center.user-profile-nav
%li.js-activity-tab %li.js-activity-tab
= link_to user_calendar_activities_path, data: {target: 'div#activity', action: 'activity', toggle: 'tab'} do = link_to calendar_activities_user_path, data: {target: 'div#activity', action: 'activity', toggle: 'tab'} do
Activity Activity
%li.js-groups-tab %li.js-groups-tab
= link_to user_groups_path, data: {target: 'div#groups', action: 'groups', toggle: 'tab'} do = link_to groups_user_path, data: {target: 'div#groups', action: 'groups', toggle: 'tab'} do
Groups Groups
%li.js-contributed-tab %li.js-contributed-tab
= link_to user_contributed_projects_path, data: {target: 'div#contributed', action: 'contributed', toggle: 'tab'} do = link_to contributed_projects_user_path, data: {target: 'div#contributed', action: 'contributed', toggle: 'tab'} do
Contributed projects Contributed projects
%li.projects-tab %li.projects-tab
= link_to user_projects_path, data: {target: 'div#projects', action: 'projects', toggle: 'tab'} do = link_to projects_user_path, data: {target: 'div#projects', action: 'projects', toggle: 'tab'} do
Personal projects Personal projects
%li.snippets-tab %li.snippets-tab
= link_to user_snippets_path, data: {target: 'div#snippets', action: 'snippets', toggle: 'tab'} do = link_to snippets_user_path, data: {target: 'div#snippets', action: 'snippets', toggle: 'tab'} do
Snippets Snippets
%div{ class: container_class } %div{ class: container_class }
...@@ -90,7 +90,7 @@ ...@@ -90,7 +90,7 @@
#activity.tab-pane #activity.tab-pane
.gray-content-block.calender-block.white.second-block.hidden-xs .gray-content-block.calender-block.white.second-block.hidden-xs
%div{ class: container_class } %div{ class: container_class }
.user-calendar{data: {href: user_calendar_path}} .user-calendar{data: {href: calendar_user_path}}
%h4.center.light %h4.center.light
%i.fa.fa-spinner.fa-spin %i.fa.fa-spinner.fa-spin
.user-calendar-activities .user-calendar-activities
......
...@@ -91,6 +91,9 @@ Rails.application.routes.draw do ...@@ -91,6 +91,9 @@ Rails.application.routes.draw do
end end
end end
get '/s/:username', to: redirect('/u/:username/snippets'),
constraints: { username: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ }
# #
# Invites # Invites
# #
...@@ -340,26 +343,20 @@ Rails.application.routes.draw do ...@@ -340,26 +343,20 @@ Rails.application.routes.draw do
end end
end end
get 'u/:username/calendar' => 'users#calendar', as: :user_calendar, resources(:users,
constraints: { username: /.*/ } path: 'u',
param: :username,
get 'u/:username/calendar_activities' => 'users#calendar_activities', as: :user_calendar_activities, constraints: { username: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ },
constraints: { username: /.*/ } only: :show) do
member do
get 'u/:username/groups' => 'users#groups', as: :user_groups, get :calendar, as: :calendar
constraints: { username: /.*/ } get :calendar_activities, as: :calendar_activities
get :groups, as: :groups
get 'u/:username/projects' => 'users#projects', as: :user_projects, get :projects, as: :projects
constraints: { username: /.*/ } get :contributed, as: :contributed_projects
get :snippets, as: :snippets
get 'u/:username/contributed' => 'users#contributed', as: :user_contributed_projects, end
constraints: { username: /.*/ } end
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)/ }
# #
# Dashboard Area # Dashboard Area
......
...@@ -31,6 +31,10 @@ describe SnippetsController, "routing" do ...@@ -31,6 +31,10 @@ describe SnippetsController, "routing" do
expect(get("/snippets/1/raw")).to route_to('snippets#raw', id: '1') expect(get("/snippets/1/raw")).to route_to('snippets#raw', id: '1')
end end
it "to #index" do
expect(get("/snippets")).to route_to('snippets#index')
end
it "to #create" do it "to #create" do
expect(post("/snippets")).to route_to('snippets#create') expect(post("/snippets")).to route_to('snippets#create')
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment