Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
c2f02fc1
Commit
c2f02fc1
authored
Jul 08, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor star and fork buttons
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
5be6cbac
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
54 additions
and
83 deletions
+54
-83
app/assets/javascripts/project_show.js.coffee
app/assets/javascripts/project_show.js.coffee
+0
-5
app/assets/stylesheets/pages/projects.scss
app/assets/stylesheets/pages/projects.scss
+3
-0
app/controllers/projects_controller.rb
app/controllers/projects_controller.rb
+4
-3
app/helpers/projects_helper.rb
app/helpers/projects_helper.rb
+0
-47
app/views/projects/_home_panel.html.haml
app/views/projects/_home_panel.html.haml
+12
-28
app/views/projects/buttons/_fork.html.haml
app/views/projects/buttons/_fork.html.haml
+13
-0
app/views/projects/buttons/_star.html.haml
app/views/projects/buttons/_star.html.haml
+22
-0
No files found.
app/assets/javascripts/project_show.js.coffee
View file @
c2f02fc1
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
:
'/'
}
...
...
app/assets/stylesheets/pages/projects.scss
View file @
c2f02fc1
...
...
@@ -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
;
...
...
app/controllers/projects_controller.rb
View file @
c2f02fc1
...
...
@@ -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
...
...
app/helpers/projects_helper.rb
View file @
c2f02fc1
...
...
@@ -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
...
...
app/views/projects/_home_panel.html.haml
View file @
c2f02fc1
...
...
@@ -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"
app/views/projects/buttons/_fork.html.haml
0 → 100644
View file @
c2f02fc1
-
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
app/views/projects/buttons/_star.html.haml
0 → 100644
View file @
c2f02fc1
-
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')
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment