Commit c2f02fc1 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Refactor star and fork buttons

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 5be6cbac
class @ProjectShow class @ProjectShow
constructor: -> constructor: ->
$('.project-home-panel .star').on 'ajax:success', (e, data, status, xhr) ->
$(@).toggleClass('on').find('.count').html(data.star_count)
.on 'ajax:error', (e, xhr, status, error) ->
new Flash('Star toggle failed. Try again later.', 'alert')
$("a[data-toggle='tab']").on "shown.bs.tab", (e) -> $("a[data-toggle='tab']").on "shown.bs.tab", (e) ->
$.cookie "default_view", $(e.target).attr("href"), { expires: 30, path: '/' } $.cookie "default_view", $(e.target).attr("href"), { expires: 30, path: '/' }
......
...@@ -52,8 +52,11 @@ ...@@ -52,8 +52,11 @@
.project-repo-buttons { .project-repo-buttons {
margin-top: 25px; margin-top: 25px;
margin-bottom: 25px; margin-bottom: 25px;
.btn { .btn {
@extend .btn-info; @extend .btn-info;
margin-left: 10px;
font-weight: bold; font-weight: bold;
font-size: 14px; font-size: 14px;
line-height: 16px; line-height: 16px;
......
...@@ -75,8 +75,6 @@ class ProjectsController < ApplicationController ...@@ -75,8 +75,6 @@ class ProjectsController < ApplicationController
return return
end end
@show_star = !(current_user && current_user.starred?(@project))
respond_to do |format| respond_to do |format|
format.html do format.html do
if @project.repository_exists? if @project.repository_exists?
...@@ -152,7 +150,10 @@ class ProjectsController < ApplicationController ...@@ -152,7 +150,10 @@ class ProjectsController < ApplicationController
def toggle_star def toggle_star
current_user.toggle_star(@project) current_user.toggle_star(@project)
@project.reload @project.reload
render json: { star_count: @project.star_count }
render json: {
html: view_to_html_string("projects/buttons/_star")
}
end end
def markdown_preview def markdown_preview
......
...@@ -84,53 +84,6 @@ module ProjectsHelper ...@@ -84,53 +84,6 @@ module ProjectsHelper
@project.milestones.active.order("due_date, title ASC") @project.milestones.active.order("due_date, title ASC")
end end
def link_to_toggle_star(title, starred)
cls = 'star-btn btn'
toggle_text =
if starred
' Unstar'
else
' Star'
end
toggle_html = content_tag('span', class: 'toggle') do
icon('star') + toggle_text
end
count_html = content_tag('span', class: 'count') do
@project.star_count.to_s
end
link_opts = {
title: title,
class: cls,
method: :post,
remote: true,
data: { type: 'json' }
}
path = toggle_star_namespace_project_path(@project.namespace, @project)
content_tag 'span', class: starred ? 'turn-on' : 'turn-off' do
link_to(path, link_opts) do
toggle_html + ' ' + count_html
end
end
end
def link_to_toggle_fork
html = content_tag('span') do
icon('code-fork') + ' Fork'
end
count_html = content_tag(:span, class: 'count') do
@project.forks_count.to_s
end
html + count_html
end
def project_for_deploy_key(deploy_key) def project_for_deploy_key(deploy_key)
if deploy_key.projects.include?(@project) if deploy_key.projects.include?(@project)
@project @project
......
...@@ -8,34 +8,18 @@ ...@@ -8,34 +8,18 @@
.project-repo-buttons .project-repo-buttons
.inline.star.js-toggler-container{class: @show_star ? 'on' : ''} = render 'projects/buttons/star'
- if current_user
= link_to_toggle_star('Star this project.', false)
= link_to_toggle_star('Unstar this project.', true)
- else
= link_to new_user_session_path, class: 'btn star-btn has_tooltip', title: 'You must sign in to star a project' do
%span
= icon('star')
Star
%span.count
= @project.star_count
- unless empty_repo - unless empty_repo
- if current_user && can?(current_user, :fork_project, @project) && @project.namespace != current_user.namespace = render 'projects/buttons/fork'
.inline.fork-buttons.prepend-left-10
- if current_user.already_forked?(@project) && current_user.manageable_namespaces.size < 2 - if forked_from_project = @project.forked_from_project
= link_to namespace_project_path(current_user, current_user.fork_of(@project)), title: 'Go to your fork', class: 'btn' do
= link_to_toggle_fork
- else
= link_to new_namespace_project_fork_path(@project.namespace, @project), title: "Fork project", class: 'btn' do
= link_to_toggle_fork
- elsif forked_from_project = @project.forked_from_project
.inline.prepend-left-10
= link_to project_path(forked_from_project), class: 'btn' do = link_to project_path(forked_from_project), class: 'btn' do
= icon("code-fork fw") = icon("code-fork fw")
Forked from Forked from
= forked_from_project.namespace.try(:name) = forked_from_project.namespace.try(:name)
- if can? current_user, :download_code, @project - if can? current_user, :download_code, @project
.inline.prepend-left-10
= link_to archive_namespace_project_repository_path(@project.namespace, @project, ref: @ref, format: 'zip'), class: 'btn', rel: 'nofollow' do = link_to archive_namespace_project_repository_path(@project.namespace, @project, ref: @ref, format: 'zip'), class: 'btn', rel: 'nofollow' do
%i.fa.fa-download %i.fa.fa-download
......
- if current_user && can?(current_user, :fork_project, @project)
- if current_user.already_forked?(@project) && current_user.manageable_namespaces.size < 2
= link_to namespace_project_path(current_user, current_user.fork_of(@project)), title: 'Go to your fork', class: 'btn' do
= icon('code-fork')
Fork
%span.count
= @project.forks_count
- else
= link_to new_namespace_project_fork_path(@project.namespace, @project), title: "Fork project", class: 'btn' do
= icon('code-fork')
Fork
%span.count
= @project.forks_count
- if current_user
= link_to toggle_star_namespace_project_path(@project.namespace, @project), class: 'btn toggle-star', method: :post, remote: true do
- if current_user.starred?(@project)
Unstar
- else
Star
%span.count
= @project.star_count
- else
= link_to new_user_session_path, class: 'btn has_tooltip', title: 'You must sign in to star a project' do
= icon('star')
Star
%span.count
= @project.star_count
:coffeescript
$('.project-home-panel .toggle-star').on 'ajax:success', (e, data, status, xhr) ->
$(@).replaceWith(data.html)
.on 'ajax:error', (e, xhr, status, error) ->
new Flash('Star toggle failed. Try again later.', 'alert')
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