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
# Ensure we don't create a particular shortcut handler here. This is
# already created, where the network graph is created.
shortcut_handler = true
when 'projects:forks:new'
new ProjectFork()
when 'users:show'
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 {
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
hidden_field_tag(id, value, class: css_class)
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
......@@ -90,4 +90,8 @@ class Namespace < ActiveRecord::Base
def kind
type == 'Group' ? 'group' : 'user'
end
def find_fork_of(project)
projects.joins(:forked_project_link).where('forked_project_links.forked_from_project_id = ?', project.id).first
end
end
......@@ -16,7 +16,7 @@
- unless @project.empty_repo?
.fork-buttons
- 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_toggle_fork
- else
......
......@@ -2,18 +2,37 @@
%p.lead Select namespace where to fork this project
%hr
- @namespaces.in_groups_of(6, false) do |group|
.fork-namespaces
- @namespaces.in_groups_of(6, false) do |group|
.row
- group.each do |namespace|
.col-md-2.col-sm-3
.thumbnail
= link_to project_fork_path(@project, namespace_id: namespace.id), title: "Fork here", method: "POST" do
- if namespace.kind_of?(Group)
= image_tag group_icon(namespace.path)
- if fork = namespace.find_fork_of(@project)
.thumbnail.fork-exists-thumbnail
= link_to project_path(fork), title: "Visit project fork", class: 'has_tooltip' do
= image_tag namespace_icon(namespace, 200)
.caption
%h4=namespace.human_name
%p
= namespace.path
- 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
%h4=namespace.human_name
%p
= 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
Scenario: User fork a project
Given I click link "Fork"
When I fork to my namespace
Then I should see the forked project page
Scenario: User already has forked the project
Given I already have a project named "Shop" in my namespace
And I click link "Fork"
When I fork to my namespace
Then I should see a "Name has already been taken" warning
......@@ -25,4 +25,10 @@ class Spinach::Features::ProjectFork < Spinach::FeatureSteps
step 'I should see a "Name has already been taken" warning' do
page.should have_content "Name has already been taken"
end
step 'I fork to my namespace' do
within '.fork-namespaces' do
click_link current_user.name
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