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
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
4a14efb0
Commit
4a14efb0
authored
Aug 25, 2017
by
Dimitrie Hoekstra
Committed by
Tim Zallmann
Aug 25, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for copying permalink to notes via more actions dropdown
parent
0036fc6f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
92 additions
and
12 deletions
+92
-12
app/assets/javascripts/copy_to_clipboard.js
app/assets/javascripts/copy_to_clipboard.js
+8
-6
app/helpers/button_helper.rb
app/helpers/button_helper.rb
+14
-6
app/views/projects/notes/_more_actions_dropdown.html.haml
app/views/projects/notes/_more_actions_dropdown.html.haml
+2
-0
changelogs/unreleased/35811-copy-link-note.yml
changelogs/unreleased/35811-copy-link-note.yml
+5
-0
spec/helpers/button_helper_spec.rb
spec/helpers/button_helper_spec.rb
+63
-0
No files found.
app/assets/javascripts/copy_to_clipboard.js
View file @
4a14efb0
...
@@ -29,12 +29,14 @@ showTooltip = function(target, title) {
...
@@ -29,12 +29,14 @@ showTooltip = function(target, title) {
var
$target
=
$
(
target
);
var
$target
=
$
(
target
);
var
originalTitle
=
$target
.
data
(
'
original-title
'
);
var
originalTitle
=
$target
.
data
(
'
original-title
'
);
$target
if
(
!
$target
.
data
(
'
hideTooltip
'
))
{
.
attr
(
'
title
'
,
'
Copied
'
)
$target
.
tooltip
(
'
fixTitle
'
)
.
attr
(
'
title
'
,
'
Copied
'
)
.
tooltip
(
'
show
'
)
.
tooltip
(
'
fixTitle
'
)
.
attr
(
'
title
'
,
originalTitle
)
.
tooltip
(
'
show
'
)
.
tooltip
(
'
fixTitle
'
);
.
attr
(
'
title
'
,
originalTitle
)
.
tooltip
(
'
fixTitle
'
);
}
};
};
$
(
function
()
{
$
(
function
()
{
...
...
app/helpers/button_helper.rb
View file @
4a14efb0
...
@@ -20,6 +20,9 @@ module ButtonHelper
...
@@ -20,6 +20,9 @@ module ButtonHelper
def
clipboard_button
(
data
=
{})
def
clipboard_button
(
data
=
{})
css_class
=
data
[
:class
]
||
'btn-clipboard btn-transparent'
css_class
=
data
[
:class
]
||
'btn-clipboard btn-transparent'
title
=
data
[
:title
]
||
'Copy to clipboard'
title
=
data
[
:title
]
||
'Copy to clipboard'
button_text
=
data
[
:button_text
]
||
''
hide_tooltip
=
data
[
:hide_tooltip
]
||
false
hide_button_icon
=
data
[
:hide_button_icon
]
||
false
# This supports code in app/assets/javascripts/copy_to_clipboard.js that
# This supports code in app/assets/javascripts/copy_to_clipboard.js that
# works around ClipboardJS limitations to allow the context-specific copy/pasting of plain text or GFM.
# works around ClipboardJS limitations to allow the context-specific copy/pasting of plain text or GFM.
...
@@ -35,17 +38,22 @@ module ButtonHelper
...
@@ -35,17 +38,22 @@ module ButtonHelper
target
=
data
.
delete
(
:target
)
target
=
data
.
delete
(
:target
)
data
[
:clipboard_target
]
=
target
if
target
data
[
:clipboard_target
]
=
target
if
target
data
=
{
toggle:
'tooltip'
,
placement:
'bottom'
,
container:
'body'
}.
merge
(
data
)
unless
hide_tooltip
data
=
{
toggle:
'tooltip'
,
placement:
'bottom'
,
container:
'body'
}.
merge
(
data
)
end
content_tag
:button
,
button_attributes
=
{
icon
(
'clipboard'
,
'aria-hidden'
:
'true'
),
class:
"btn
#{
css_class
}
"
,
class:
"btn
#{
css_class
}
"
,
data:
data
,
data:
data
,
type: :button
,
type: :button
,
title:
title
,
title:
title
,
aria:
{
aria:
{
label:
title
}
label:
title
}
}
content_tag
:button
,
button_attributes
do
concat
(
icon
(
'clipboard'
,
'aria-hidden'
:
'true'
))
unless
hide_button_icon
concat
(
button_text
)
end
end
end
def
http_clone_button
(
project
,
placement
=
'right'
,
append_link:
true
)
def
http_clone_button
(
project
,
placement
=
'right'
,
append_link:
true
)
...
...
app/views/projects/notes/_more_actions_dropdown.html.haml
View file @
4a14efb0
...
@@ -6,6 +6,8 @@
...
@@ -6,6 +6,8 @@
%span
.icon
%span
.icon
=
custom_icon
(
'ellipsis_v'
)
=
custom_icon
(
'ellipsis_v'
)
%ul
.dropdown-menu.more-actions-dropdown.dropdown-open-left
%ul
.dropdown-menu.more-actions-dropdown.dropdown-open-left
%li
=
clipboard_button
(
text:
noteable_note_url
(
note
),
title:
"Copy reference to clipboard"
,
button_text:
'Copy link'
,
hide_tooltip:
true
,
hide_button_icon:
true
)
-
unless
is_current_user
-
unless
is_current_user
%li
%li
=
link_to
new_abuse_report_path
(
user_id:
note
.
author
.
id
,
ref_url:
noteable_note_url
(
note
))
do
=
link_to
new_abuse_report_path
(
user_id:
note
.
author
.
id
,
ref_url:
noteable_note_url
(
note
))
do
...
...
changelogs/unreleased/35811-copy-link-note.yml
0 → 100644
View file @
4a14efb0
---
title
:
Add support for copying permalink to notes via more actions dropdown
merge_request
:
13299
author
:
type
:
added
spec/helpers/button_helper_spec.rb
View file @
4a14efb0
...
@@ -62,4 +62,67 @@ describe ButtonHelper do
...
@@ -62,4 +62,67 @@ describe ButtonHelper do
end
end
end
end
end
end
describe
'clipboard_button'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
build_stubbed
(
:project
)
}
def
element
(
data
=
{})
element
=
helper
.
clipboard_button
(
data
)
Nokogiri
::
HTML
::
DocumentFragment
.
parse
(
element
).
first_element_child
end
before
do
allow
(
helper
).
to
receive
(
:current_user
).
and_return
(
user
)
end
context
'with default options'
do
context
'when no `text` attribute is not provided'
do
it
'shows copy to clipboard button with default configuration and no text set to copy'
do
expect
(
element
.
attr
(
'class'
)).
to
eq
(
'btn btn-clipboard btn-transparent'
)
expect
(
element
.
attr
(
'type'
)).
to
eq
(
'button'
)
expect
(
element
.
attr
(
'aria-label'
)).
to
eq
(
'Copy to clipboard'
)
expect
(
element
.
attr
(
'data-toggle'
)).
to
eq
(
'tooltip'
)
expect
(
element
.
attr
(
'data-placement'
)).
to
eq
(
'bottom'
)
expect
(
element
.
attr
(
'data-container'
)).
to
eq
(
'body'
)
expect
(
element
.
attr
(
'data-clipboard-text'
)).
to
eq
(
nil
)
expect
(
element
.
inner_text
).
to
eq
(
""
)
expect
(
element
).
to
have_selector
(
'.fa.fa-clipboard'
)
end
end
context
'when `text` attribute is provided'
do
it
'shows copy to clipboard button with provided `text` to copy'
do
expect
(
element
(
text:
'Hello World!'
).
attr
(
'data-clipboard-text'
)).
to
eq
(
'Hello World!'
)
end
end
context
'when `title` attribute is provided'
do
it
'shows copy to clipboard button with provided `title` as tooltip'
do
expect
(
element
(
title:
'Copy to my clipboard!'
).
attr
(
'aria-label'
)).
to
eq
(
'Copy to my clipboard!'
)
end
end
end
context
'with `button_text` attribute provided'
do
it
'shows copy to clipboard button with provided `button_text` as button label'
do
expect
(
element
(
button_text:
'Copy text'
).
inner_text
).
to
eq
(
'Copy text'
)
end
end
context
'with `hide_tooltip` attribute provided'
do
it
'shows copy to clipboard button without tooltip support'
do
expect
(
element
(
hide_tooltip:
true
).
attr
(
'data-placement'
)).
to
eq
(
nil
)
expect
(
element
(
hide_tooltip:
true
).
attr
(
'data-toggle'
)).
to
eq
(
nil
)
expect
(
element
(
hide_tooltip:
true
).
attr
(
'data-container'
)).
to
eq
(
nil
)
end
end
context
'with `hide_button_icon` attribute provided'
do
it
'shows copy to clipboard button without tooltip support'
do
expect
(
element
(
hide_button_icon:
true
)).
not_to
have_selector
(
'.fa.fa-clipboard'
)
end
end
end
end
end
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