Commit 2388fdd7 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Improve fork to namespaces feature

* Show namespace thumbnail differently if project was already forked
* Show loading spinner when click on fork
* Fork link navigates to personal namespace only if no manageable groups exists
Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent d2c3c98e
...@@ -75,6 +75,8 @@ class Dispatcher ...@@ -75,6 +75,8 @@ class Dispatcher
# Ensure we don't create a particular shortcut handler here. This is # Ensure we don't create a particular shortcut handler here. This is
# already created, where the network graph is created. # already created, where the network graph is created.
shortcut_handler = true shortcut_handler = true
when 'projects:forks:new'
new ProjectFork()
when 'users:show' when 'users:show'
new User() new User()
......
class @ProjectFork
constructor: ->
$('.fork-thumbnail a').on 'click', ->
$('.fork-namespaces').hide()
$('.save-project-loader').show()
...@@ -270,3 +270,28 @@ ul.nav.nav-projects-tabs { ...@@ -270,3 +270,28 @@ ul.nav.nav-projects-tabs {
color: #999; color: #999;
} }
} }
.fork-namespaces {
.thumbnail {
&.fork-exists-thumbnail {
border-color: #EEE;
.caption {
color: #999;
}
}
&.fork-thumbnail {
border-color: #AAA;
&:hover {
background-color: $hover;
}
}
a {
text-decoration: none;
}
}
}
...@@ -25,4 +25,12 @@ module NamespacesHelper ...@@ -25,4 +25,12 @@ module NamespacesHelper
hidden_field_tag(id, value, class: css_class) hidden_field_tag(id, value, class: css_class)
end end
def namespace_icon(namespace, size = 40)
if namespace.kind_of?(Group)
group_icon(namespace.path)
else
avatar_icon(namespace.owner.email, size)
end
end
end end
...@@ -90,4 +90,8 @@ class Namespace < ActiveRecord::Base ...@@ -90,4 +90,8 @@ class Namespace < ActiveRecord::Base
def kind def kind
type == 'Group' ? 'group' : 'user' type == 'Group' ? 'group' : 'user'
end end
def find_fork_of(project)
projects.joins(:forked_project_link).where('forked_project_links.forked_from_project_id = ?', project.id).first
end
end end
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
- unless @project.empty_repo? - unless @project.empty_repo?
.fork-buttons .fork-buttons
- if current_user && can?(current_user, :fork_project, @project) && @project.namespace != current_user.namespace - if current_user && can?(current_user, :fork_project, @project) && @project.namespace != current_user.namespace
- if current_user.already_forked?(@project) - if current_user.already_forked?(@project) && current_user.manageable_namespaces.size < 2
= link_to project_path(current_user.fork_of(@project)), title: 'Go to my fork' do = link_to project_path(current_user.fork_of(@project)), title: 'Go to my fork' do
= link_to_toggle_fork = link_to_toggle_fork
- else - else
......
...@@ -2,18 +2,37 @@ ...@@ -2,18 +2,37 @@
%p.lead Select namespace where to fork this project %p.lead Select namespace where to fork this project
%hr %hr
- @namespaces.in_groups_of(6, false) do |group| .fork-namespaces
- @namespaces.in_groups_of(6, false) do |group|
.row .row
- group.each do |namespace| - group.each do |namespace|
.col-md-2.col-sm-3 .col-md-2.col-sm-3
.thumbnail - if fork = namespace.find_fork_of(@project)
= link_to project_fork_path(@project, namespace_id: namespace.id), title: "Fork here", method: "POST" do .thumbnail.fork-exists-thumbnail
- if namespace.kind_of?(Group) = link_to project_path(fork), title: "Visit project fork", class: 'has_tooltip' do
= image_tag group_icon(namespace.path) = image_tag namespace_icon(namespace, 200)
.caption
%h4=namespace.human_name
%p
= namespace.path
- else - else
= image_tag avatar_icon(namespace.owner.email, 200) .thumbnail.fork-thumbnail
= link_to project_fork_path(@project, namespace_id: namespace.id), title: "Fork here", method: "POST", class: 'has_tooltip' do
= image_tag namespace_icon(namespace, 200)
.caption .caption
%h4=namespace.human_name %h4=namespace.human_name
%p %p
= namespace.path = namespace.path
%p.light
Fork is a copy of a project repository.
%br
Forking a repository allows you to do changes without affecting the original project.
.save-project-loader.hide
.center
%h2
%i.fa.fa-spinner.fa-spin
Forking repository
%p Please wait a moment, this page will automatically refresh when ready.
...@@ -6,9 +6,11 @@ Feature: Project Fork ...@@ -6,9 +6,11 @@ Feature: Project Fork
Scenario: User fork a project Scenario: User fork a project
Given I click link "Fork" Given I click link "Fork"
When I fork to my namespace
Then I should see the forked project page Then I should see the forked project page
Scenario: User already has forked the project Scenario: User already has forked the project
Given I already have a project named "Shop" in my namespace Given I already have a project named "Shop" in my namespace
And I click link "Fork" And I click link "Fork"
When I fork to my namespace
Then I should see a "Name has already been taken" warning Then I should see a "Name has already been taken" warning
...@@ -25,4 +25,10 @@ class Spinach::Features::ProjectFork < Spinach::FeatureSteps ...@@ -25,4 +25,10 @@ class Spinach::Features::ProjectFork < Spinach::FeatureSteps
step 'I should see a "Name has already been taken" warning' do step 'I should see a "Name has already been taken" warning' do
page.should have_content "Name has already been taken" page.should have_content "Name has already been taken"
end end
step 'I fork to my namespace' do
within '.fork-namespaces' do
click_link current_user.name
end
end
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