BigW Consortium Gitlab

Refactor star and fork buttons

parent 5be6cbac
class @ProjectShow
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) ->
$.cookie "default_view", $(e.target).attr("href"), { expires: 30, path: '/' }
......
......@@ -52,8 +52,11 @@
.project-repo-buttons {
margin-top: 25px;
margin-bottom: 25px;
.btn {
@extend .btn-info;
margin-left: 10px;
font-weight: bold;
font-size: 14px;
line-height: 16px;
......
......@@ -75,8 +75,6 @@ class ProjectsController < ApplicationController
return
end
@show_star = !(current_user && current_user.starred?(@project))
respond_to do |format|
format.html do
if @project.repository_exists?
......@@ -152,7 +150,10 @@ class ProjectsController < ApplicationController
def toggle_star
current_user.toggle_star(@project)
@project.reload
render json: { star_count: @project.star_count }
render json: {
html: view_to_html_string("projects/buttons/_star")
}
end
def markdown_preview
......
......@@ -84,53 +84,6 @@ module ProjectsHelper
@project.milestones.active.order("due_date, title ASC")
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)
if deploy_key.projects.include?(@project)
@project
......
......@@ -8,35 +8,19 @@
.project-repo-buttons
.inline.star.js-toggler-container{class: @show_star ? 'on' : ''}
- 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
= render 'projects/buttons/star'
- unless empty_repo
- if current_user && can?(current_user, :fork_project, @project) && @project.namespace != current_user.namespace
.inline.fork-buttons.prepend-left-10
- 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
= 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
= icon("code-fork fw")
Forked from
= forked_from_project.namespace.try(:name)
= render 'projects/buttons/fork'
- if forked_from_project = @project.forked_from_project
= link_to project_path(forked_from_project), class: 'btn' do
= icon("code-fork fw")
Forked from
= forked_from_project.namespace.try(:name)
- 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
%i.fa.fa-download
= link_to archive_namespace_project_repository_path(@project.namespace, @project, ref: @ref, format: 'zip'), class: 'btn', rel: 'nofollow' do
%i.fa.fa-download
= render "shared/clone_panel"
- 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