Commit 420ba211 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Move star button to sidebar. Add counter to forks too

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent bb80741c
...@@ -47,7 +47,7 @@ $ -> ...@@ -47,7 +47,7 @@ $ ->
$(@).parents('.no-ssh-key-message').hide() $(@).parents('.no-ssh-key-message').hide()
e.preventDefault() e.preventDefault()
$('.project-home-panel .star').on 'ajax:success', (e, data, status, xhr) -> $('.project-side .star').on 'ajax:success', (e, data, status, xhr) ->
$(@).toggleClass('on').find('.count').html(data.star_count) $(@).toggleClass('on').find('.count').html(data.star_count)
.on 'ajax:error', (e, xhr, status, error) -> .on 'ajax:error', (e, xhr, status, error) ->
new Flash('Star toggle failed. Try again later.', 'alert') new Flash('Star toggle failed. Try again later.', 'alert')
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
.js-details-container.open .content.hide { display: none; } .js-details-container.open .content.hide { display: none; }
// Toggle between two states. // Toggle between two states.
.js-toggler-container .turn-on { display: inline-block; } .js-toggler-container .turn-on { display: block; }
.js-toggler-container .turn-off { display: none; } .js-toggler-container .turn-off { display: none; }
.js-toggler-container.on .turn-on { display: none; } .js-toggler-container.on .turn-on { display: none; }
.js-toggler-container.on .turn-off { display: inline-block; } .js-toggler-container.on .turn-off { display: block; }
...@@ -50,22 +50,6 @@ ...@@ -50,22 +50,6 @@
margin-left: 10px; margin-left: 10px;
font-weight: 500; font-weight: 500;
} }
.star .btn {
font-weight: bold;
line-height: 22px;
padding: 0px;
$margin-x: 6px;
.toggle {
display: inline-block;
padding: 0px $margin-x;
}
.count {
border-left: $btn-border;
display: inline-block;
padding: 0px $margin-x;
}
}
} }
} }
...@@ -206,28 +190,39 @@ ul.nav.nav-projects-tabs { ...@@ -206,28 +190,39 @@ ul.nav.nav-projects-tabs {
.project-side { .project-side {
.btn-block { .btn-block {
background-image: none; background-image: none;
.btn,
&.btn, .btn, &.btn {
&.btn-group ul.dropdown-menu { text-align: left;
padding: 10px 15px;
background-color: #F1f1f1; background-color: #F1f1f1;
border-color: #EEE; border-color: #EEE;
&:hover { &:hover {
background-color: #eee; background-color: #eee;
border-color: #DDD; border-color: #DDD;
} }
} }
.count {
float: right;
font-weight: 500;
text-shadow: 0 1px #FFF;
}
&.btn-group-justified { &.btn-group-justified {
.btn { .btn {
width: 100%; width: 100%;
} }
.dropdown-toggle { .dropdown-toggle {
width: 26px; width: 30px;
} padding: 10px;
} }
ul { ul {
width: 100%; width: 100%;
} }
} }
}
.project-fork-icon { .project-fork-icon {
float: left; float: left;
font-size: 26px; font-size: 26px;
......
...@@ -123,23 +123,35 @@ module ProjectsHelper ...@@ -123,23 +123,35 @@ module ProjectsHelper
end end
def link_to_toggle_star(title, starred, signed_in) def link_to_toggle_star(title, starred, signed_in)
cls = 'btn' cls = 'btn btn-block'
cls += ' disabled' unless signed_in cls += ' disabled' unless signed_in
content_tag 'span', class: starred ? 'turn-on' : 'turn-off' do
link_to toggle_star_project_path(@project), toggle_html = content_tag('span', class: 'toggle') do
title: title, class: cls, method: :post, remote: true, toggle_text = if starred
data: {type: 'json'} do
content_tag('span', class: 'toggle') do
content_tag('i', ' ', class: 'icon-star') <<
if starred
'Unstar' 'Unstar'
else else
'Star' 'Star'
end end
end <<
content_tag('span', class: 'count') do content_tag('i', ' ', class: 'icon-star') + toggle_text
end
count_html = content_tag('span', class: 'count') do
@project.star_count.to_s @project.star_count.to_s
end end
link_opts = {
title: title,
class: cls,
method: :post,
remote: true,
data: {type: 'json'}
}
content_tag 'span', class: starred ? 'turn-on' : 'turn-off' do
link_to toggle_star_project_path(@project), link_opts do
toggle_html + count_html
end end
end end
end end
......
...@@ -579,4 +579,8 @@ class Project < ActiveRecord::Base ...@@ -579,4 +579,8 @@ class Project < ActiveRecord::Base
def update_repository_size def update_repository_size
update_attribute(:repository_size, repository.size) update_attribute(:repository_size, repository.size)
end end
def forks_count
ForkedProjectLink.where(forked_from_project_id: self.id).count
end
end end
...@@ -34,9 +34,3 @@ ...@@ -34,9 +34,3 @@
= link_to pluralize(number_with_delimiter(@repository.branch_names.count), 'branch'), project_branches_path(@project) = link_to pluralize(number_with_delimiter(@repository.branch_names.count), 'branch'), project_branches_path(@project)
= link_to pluralize(number_with_delimiter(@repository.tag_names.count), 'tag'), project_tags_path(@project) = link_to pluralize(number_with_delimiter(@repository.tag_names.count), 'tag'), project_tags_path(@project)
%span.light.prepend-left-20= repository_size %span.light.prepend-left-20= repository_size
%span.star.js-toggler-container{class: @show_star ? 'on' : ''}
- if current_user
= link_to_toggle_star('Star this project.', false, true)
= link_to_toggle_star('Unstar this project.', true, true)
- else
= link_to_toggle_star('You must sign in to star a project.', false, false)
...@@ -15,24 +15,37 @@ ...@@ -15,24 +15,37 @@
Archived project! Archived project!
%p Repository is read-only %p Repository is read-only
- if @project.forked_from_project - if @project.forked_from_project
.alert.alert-success .alert.alert-success
%i.icon-code-fork.project-fork-icon %i.icon-code-fork.project-fork-icon
Forked from: Forked from:
%br %br
= link_to @project.forked_from_project.name_with_namespace, project_path(@project.forked_from_project) = link_to @project.forked_from_project.name_with_namespace, project_path(@project.forked_from_project)
.star-buttons
%span.star.js-toggler-container{class: @show_star ? 'on' : ''}
- if current_user
= link_to_toggle_star('Star this project.', false, true)
= link_to_toggle_star('Unstar this project.', true, true)
- else
= link_to_toggle_star('You must sign in to star a project.', false, false)
- unless @project.empty_repo? - unless @project.empty_repo?
.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)
= link_to project_path(current_user.fork_of(@project)), class: 'btn btn-block' do = link_to project_path(current_user.fork_of(@project)), class: 'btn btn-block' do
%i.icon-compass %i.icon-compass
Go to fork Go to fork
%span.count
= @project.forks_count
- else - else
= link_to fork_project_path(@project), title: "Fork", class: "btn btn-block", method: "POST" do = link_to fork_project_path(@project), title: "Fork", class: "btn btn-block", method: "POST" do
%i.icon-code-fork %i.icon-code-fork
Fork repository Fork repository
%span.count
= @project.forks_count
- unless @project.empty_repo?
- if can? current_user, :download_code, @project - if can? current_user, :download_code, @project
= render 'projects/repositories/download_archive', btn_class: 'btn-block btn-group-justified', split_button: true = render 'projects/repositories/download_archive', btn_class: 'btn-block btn-group-justified', split_button: true
...@@ -48,6 +61,7 @@ ...@@ -48,6 +61,7 @@
- version = @repository.version - version = @repository.version
= link_to project_blob_path(@project, tree_join(@repository.root_ref, version.name)), class: 'btn btn-block' do = link_to project_blob_path(@project, tree_join(@repository.root_ref, version.name)), class: 'btn btn-block' do
Version: Version:
%span.count
= @repository.blob_by_oid(version.id).data = @repository.blob_by_oid(version.id).data
.prepend-top-10 .prepend-top-10
......
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