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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tatuya Kamada
gitlab-ce
Commits
1f73afd0
Commit
1f73afd0
authored
Jul 08, 2016
by
Luke "Jared" Bennett
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Registered FilesCommentButton as a jQuery plugin and made review changes
parent
71e4175f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
64 deletions
+62
-64
app/assets/javascripts/diff.js.coffee
app/assets/javascripts/diff.js.coffee
+1
-1
app/assets/javascripts/files_comment_button.js.coffee
app/assets/javascripts/files_comment_button.js.coffee
+58
-60
app/assets/javascripts/merge_request_tabs.js.coffee
app/assets/javascripts/merge_request_tabs.js.coffee
+1
-1
app/views/projects/diffs/_parallel_view.html.haml
app/views/projects/diffs/_parallel_view.html.haml
+2
-2
No files found.
app/assets/javascripts/diff.js.coffee
View file @
1f73afd0
class
@
Diff
UNFOLD_COUNT
=
20
constructor
:
->
@
filesCommentButton
=
new
FilesCommentButton
(
$
(
'.files'
)
)
@
filesCommentButton
=
$
(
'.files .diff-file'
).
filesCommentButton
(
)
$
(
document
).
off
(
'click'
,
'.js-unfold'
)
$
(
document
).
on
(
'click'
,
'.js-unfold'
,
(
event
)
=>
...
...
app/assets/javascripts/files_comment_button.js.coffee
View file @
1f73afd0
class
@
FilesCommentButton
constructor
:
(
@
filesContainerElement
)
->
return
unless
@
filesContainerElement
return
if
_
.
isUndefined
@
filesContainerElement
.
data
'can-create-note'
@
COMMENT_BUTTON_CLASS
=
'.add-diff-note'
@
COMMENT_BUTTON_TEMPLATE
=
_
.
template
'<button name="button" type="submit" class="btn <%- COMMENT_BUTTON_CLASS %> js-add-diff-note-button" title="Add a comment to this line"><i class="fa fa-comment-o"></i></button>'
@
LINE_NUMBER_CLASS
=
'diff-line-num'
@
LINE_CONTENT_CLASS
=
'line_content'
@
UNFOLDABLE_LINE_CLASS
=
'js-unfold'
@
EMPTY_CELL_CLASS
=
'empty-cell'
@
OLD_LINE_CLASS
=
'old_line'
@
LINE_COLUMN_CLASSES
=
".
#{
@
LINE_NUMBER_CLASS
}
, .line_content"
@
TEXT_FILE_SELECTOR
=
'.text-file'
@
DEBOUNCE_TIMEOUT_DURATION
=
150
COMMENT_BUTTON_CLASS
=
'.add-diff-note'
COMMENT_BUTTON_TEMPLATE
=
_
.
template
'<button name="button" type="submit" class="btn <%- COMMENT_BUTTON_CLASS %> js-add-diff-note-button" title="Add a comment to this line"><i class="fa fa-comment-o"></i></button>'
LINE_HOLDER_CLASS
=
'.line_holder'
LINE_NUMBER_CLASS
=
'diff-line-num'
LINE_CONTENT_CLASS
=
'line_content'
UNFOLDABLE_LINE_CLASS
=
'js-unfold'
EMPTY_CELL_CLASS
=
'empty-cell'
OLD_LINE_CLASS
=
'old_line'
LINE_COLUMN_CLASSES
=
".
#{
LINE_NUMBER_CLASS
}
, .line_content"
TEXT_FILE_SELECTOR
=
'.text-file'
DEBOUNCE_TIMEOUT_DURATION
=
100
constructor
:
(
@
filesContainerElement
)
->
@
VIEW_TYPE
=
$
(
'input#view[type=hidden]'
).
val
()
$
(
document
)
.
on
'mouseover'
,
@
LINE_COLUMN_CLASSES
,
@
debounceRender
.
on
'mouseleave'
,
@
LINE_COLUMN_CLASSES
,
@
destroy
debounceRender
:
(
e
)
=>
clearTimeout
@
debounceTimeout
if
@
debounceTimeout
@
debounceTimeout
=
setTimeout
=>
@
render
e
,
@
DEBOUNCE_TIMEOUT_DURATION
return
debounce
=
_
.
debounce
@
render
,
DEBOUNCE_TIMEOUT_DURATION
render
:
(
e
)
->
currentTarget
=
$
(
e
.
currentTarget
)
textFileElement
=
@
getTextFileElement
(
currentTarget
)
lineContentElement
=
@
getLineContent
(
currentTarget
)
buttonParentElement
=
@
getButtonParent
(
currentTarget
)
$
(
document
)
.
on
'mouseover'
,
LINE_COLUMN_CLASSES
,
debounce
.
on
'mouseleave'
,
LINE_COLUMN_CLASSES
,
@
destroy
render
:
(
e
)
=>
$currentTarget
=
$
(
e
.
currentTarget
)
buttonParentElement
=
@
getButtonParent
$currentTarget
return
unless
@
shouldRender
e
,
buttonParentElement
textFileElement
=
@
getTextFileElement
$currentTarget
lineContentElement
=
@
getLineContent
$currentTarget
buttonParentElement
.
append
@
buildButton
noteable
_t
ype
:
textFileElement
.
attr
'data-noteable-type'
noteable
_id
:
textFileElement
.
attr
'data-noteable-id'
commit
_id
:
textFileElement
.
attr
'data-commit-id'
note
_t
ype
:
lineContentElement
.
attr
'data-note-type'
noteable
T
ype
:
textFileElement
.
attr
'data-noteable-type'
noteable
ID
:
textFileElement
.
attr
'data-noteable-id'
commit
ID
:
textFileElement
.
attr
'data-commit-id'
note
T
ype
:
lineContentElement
.
attr
'data-note-type'
position
:
lineContentElement
.
attr
'data-position'
line
_t
ype
:
lineContentElement
.
attr
'data-line-type'
discussion
_id
:
lineContentElement
.
attr
'data-discussion-id'
line
_c
ode
:
lineContentElement
.
attr
'data-line-code'
line
T
ype
:
lineContentElement
.
attr
'data-line-type'
discussion
ID
:
lineContentElement
.
attr
'data-discussion-id'
line
C
ode
:
lineContentElement
.
attr
'data-line-code'
return
destroy
:
(
e
)
=>
return
if
@
isMovingToSameType
e
$
(
@
COMMENT_BUTTON_CLASS
,
@
getButtonParent
$
(
e
.
currentTarget
)).
remove
()
$
(
COMMENT_BUTTON_CLASS
,
@
getButtonParent
$
(
e
.
currentTarget
)).
remove
()
return
buildButton
:
(
buttonAttributes
)
->
initializedButtonTemplate
=
@
COMMENT_BUTTON_TEMPLATE
COMMENT_BUTTON_CLASS
:
@
COMMENT_BUTTON_CLASS
.
substr
1
initializedButtonTemplate
=
COMMENT_BUTTON_TEMPLATE
COMMENT_BUTTON_CLASS
:
COMMENT_BUTTON_CLASS
.
substr
1
$
(
initializedButtonTemplate
).
attr
'data-noteable-type'
:
buttonAttributes
.
noteable
_t
ype
'data-noteable-id'
:
buttonAttributes
.
noteable
_id
'data-commit-id'
:
buttonAttributes
.
commit
_id
'data-note-type'
:
buttonAttributes
.
note
_t
ype
'data-line-code'
:
buttonAttributes
.
line
_c
ode
'data-noteable-type'
:
buttonAttributes
.
noteable
T
ype
'data-noteable-id'
:
buttonAttributes
.
noteable
ID
'data-commit-id'
:
buttonAttributes
.
commit
ID
'data-note-type'
:
buttonAttributes
.
note
T
ype
'data-line-code'
:
buttonAttributes
.
line
C
ode
'data-position'
:
buttonAttributes
.
position
'data-discussion-id'
:
buttonAttributes
.
discussion
_id
'data-line-type'
:
buttonAttributes
.
line
_t
ype
'data-discussion-id'
:
buttonAttributes
.
discussion
ID
'data-line-type'
:
buttonAttributes
.
line
T
ype
getTextFileElement
:
(
hoveredElement
)
->
$
(
hoveredElement
.
closest
(
@
TEXT_FILE_SELECTOR
)
)
$
(
hoveredElement
.
closest
TEXT_FILE_SELECTOR
)
getLineContent
:
(
hoveredElement
)
->
return
hoveredElement
if
hoveredElement
.
hasClass
@
LINE_CONTENT_CLASS
return
hoveredElement
if
hoveredElement
.
hasClass
LINE_CONTENT_CLASS
$
(
hoveredElement
).
next
".
#{
@
LINE_CONTENT_CLASS
}
"
$
(
hoveredElement
).
next
".
#{
LINE_CONTENT_CLASS
}
"
getButtonParent
:
(
hoveredElement
)
->
if
@
VIEW_TYPE
is
'inline'
return
hoveredElement
if
hoveredElement
.
hasClass
@
OLD_LINE_CLASS
return
hoveredElement
if
hoveredElement
.
hasClass
OLD_LINE_CLASS
$
(
hoveredElement
).
parent
().
find
".
#{
@
OLD_LINE_CLASS
}
"
hoveredElement
.
parent
().
find
".
#{
OLD_LINE_CLASS
}
"
else
return
hoveredElement
if
hoveredElement
.
hasClass
@
LINE_NUMBER_CLASS
return
hoveredElement
if
hoveredElement
.
hasClass
LINE_NUMBER_CLASS
$
(
hoveredElement
).
prev
".
#{
@
LINE_NUMBER_CLASS
}
"
$
(
hoveredElement
).
prev
".
#{
LINE_NUMBER_CLASS
}
"
isMovingToSameType
:
(
e
)
->
newButtonParent
=
@
getButtonParent
(
$
(
e
.
toElement
)
)
newButtonParent
=
@
getButtonParent
$
(
e
.
toElement
)
return
false
unless
newButtonParent
(
newButtonParent
).
is
@
getButtonParent
(
$
(
e
.
currentTarget
)
)
newButtonParent
.
is
@
getButtonParent
$
(
e
.
currentTarget
)
shouldRender
:
(
e
,
buttonParentElement
)
->
(
!
buttonParentElement
.
hasClass
(
@
EMPTY_CELL_CLASS
)
and
\
!
buttonParentElement
.
hasClass
(
@
UNFOLDABLE_LINE_CLASS
)
and
\
$
(
@
COMMENT_BUTTON_CLASS
,
buttonParentElement
).
length
is
0
)
(
not
buttonParentElement
.
hasClass
(
EMPTY_CELL_CLASS
)
and
\
not
buttonParentElement
.
hasClass
(
UNFOLDABLE_LINE_CLASS
)
and
\
$
(
COMMENT_BUTTON_CLASS
,
buttonParentElement
).
length
is
0
)
$
.
fn
.
filesCommentButton
=
->
return
unless
this
and
@
parent
().
data
(
'can-create-note'
)
?
@
each
->
unless
$
.
data
this
,
'filesCommentButton'
$
.
data
this
,
'filesCommentButton'
,
new
FilesCommentButton
$
(
this
)
app/assets/javascripts/merge_request_tabs.js.coffee
View file @
1f73afd0
...
...
@@ -163,7 +163,7 @@ class @MergeRequestTabs
@
diffsLoaded
=
true
@
scrollToElement
(
"#diffs"
)
@
highlighSelectedLine
()
@
filesCommentButton
=
new
FilesCommentButton
(
$
(
'.files'
)
)
@
filesCommentButton
=
$
(
'.files .diff-file'
).
filesCommentButton
(
)
$
(
document
)
.
off
'click'
,
'.diff-line-num a'
...
...
app/views/projects/diffs/_parallel_view.html.haml
View file @
1f73afd0
...
...
@@ -15,7 +15,7 @@
-
else
%td
.old_line.diff-line-num
{
id:
left
[
:line_code
],
class:
[
left
[
:type
],
(
'empty-cell'
unless
left
[
:number
])],
data:
{
linenumber:
left
[
:number
]
}}
%a
{
href:
"##{left[:line_code]}"
}=
raw
(
left
[
:number
])
%td
.line_content.parallel.noteable_line
{
class:
[
left
[
:type
],
(
'empty-cell'
if
left
[
:text
].
empty?
)],
data:
diff_view_line_data
(
left
[
:line_code
],
left
[
:position
],
left
[
:type
]
)}=
diff_line_content
(
left
[
:text
])
%td
.line_content.parallel.noteable_line
{
class:
[
left
[
:type
],
(
'empty-cell'
if
left
[
:text
].
empty?
)],
data:
diff_view_line_data
(
left
[
:line_code
],
left
[
:position
],
'old'
)}=
diff_line_content
(
left
[
:text
])
-
if
right
[
:type
]
==
'new'
-
new_line_type
=
'new'
...
...
@@ -28,7 +28,7 @@
%td
.new_line.diff-line-num
{
id:
new_line_code
,
class:
[
new_line_type
,
(
'empty-cell'
unless
right
[
:number
])],
data:
{
linenumber:
right
[
:number
]
}}
%a
{
href:
"##{new_line_code}"
}=
raw
(
right
[
:number
])
%td
.line_content.parallel.noteable_line
{
class:
[
new_line_type
,
(
'empty-cell'
if
right
[
:text
].
empty?
)],
data:
diff_view_line_data
(
new_line_code
,
new_position
,
new_line_type
)}=
diff_line_content
(
right
[
:text
])
%td
.line_content.parallel.noteable_line
{
class:
[
new_line_type
,
(
'empty-cell'
if
right
[
:text
].
empty?
)],
data:
diff_view_line_data
(
new_line_code
,
new_position
,
'new'
)}=
diff_line_content
(
right
[
:text
])
-
unless
@diff_notes_disabled
-
notes_left
,
notes_right
=
organize_comments
(
left
,
right
)
...
...
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