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
23563f5e
Commit
23563f5e
authored
Aug 28, 2018
by
Winnie Hellmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Highlight current user in comments and system notes
parent
7c1cfd0b
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
106 additions
and
4 deletions
+106
-4
app/assets/javascripts/behaviors/markdown/highlight_current_user.js
.../javascripts/behaviors/markdown/highlight_current_user.js
+17
-0
app/assets/javascripts/behaviors/markdown/render_gfm.js
app/assets/javascripts/behaviors/markdown/render_gfm.js
+2
-0
app/assets/javascripts/notes/components/notes_app.vue
app/assets/javascripts/notes/components/notes_app.vue
+4
-0
app/assets/stylesheets/framework/gfm.scss
app/assets/stylesheets/framework/gfm.scss
+4
-0
changelogs/unreleased/winh-highlight-current-user.yml
changelogs/unreleased/winh-highlight-current-user.yml
+5
-0
spec/features/issues/notes_on_issues_spec.rb
spec/features/issues/notes_on_issues_spec.rb
+19
-4
spec/javascripts/behaviors/markdown/highlight_current_user_spec.js
...scripts/behaviors/markdown/highlight_current_user_spec.js
+55
-0
No files found.
app/assets/javascripts/behaviors/markdown/highlight_current_user.js
0 → 100644
View file @
23563f5e
/**
* Highlights the current user in existing elements with a user ID data attribute.
*
* @param elements DOM elements that represent user mentions
*/
export
default
function
highlightCurrentUser
(
elements
)
{
const
currentUserId
=
gon
&&
gon
.
current_user_id
;
if
(
!
currentUserId
)
{
return
;
}
elements
.
forEach
(
element
=>
{
if
(
parseInt
(
element
.
dataset
.
user
,
10
)
===
currentUserId
)
{
element
.
classList
.
add
(
'
current-user
'
);
}
});
}
app/assets/javascripts/behaviors/markdown/render_gfm.js
View file @
23563f5e
...
@@ -2,6 +2,7 @@ import $ from 'jquery';
...
@@ -2,6 +2,7 @@ import $ from 'jquery';
import
syntaxHighlight
from
'
~/syntax_highlight
'
;
import
syntaxHighlight
from
'
~/syntax_highlight
'
;
import
renderMath
from
'
./render_math
'
;
import
renderMath
from
'
./render_math
'
;
import
renderMermaid
from
'
./render_mermaid
'
;
import
renderMermaid
from
'
./render_mermaid
'
;
import
highlightCurrentUser
from
'
./highlight_current_user
'
;
// Render GitLab flavoured Markdown
// Render GitLab flavoured Markdown
//
//
...
@@ -11,6 +12,7 @@ $.fn.renderGFM = function renderGFM() {
...
@@ -11,6 +12,7 @@ $.fn.renderGFM = function renderGFM() {
syntaxHighlight
(
this
.
find
(
'
.js-syntax-highlight
'
));
syntaxHighlight
(
this
.
find
(
'
.js-syntax-highlight
'
));
renderMath
(
this
.
find
(
'
.js-render-math
'
));
renderMath
(
this
.
find
(
'
.js-render-math
'
));
renderMermaid
(
this
.
find
(
'
.js-render-mermaid
'
));
renderMermaid
(
this
.
find
(
'
.js-render-mermaid
'
));
highlightCurrentUser
(
this
.
find
(
'
.gfm-project_member
'
).
get
());
return
this
;
return
this
;
};
};
...
...
app/assets/javascripts/notes/components/notes_app.vue
View file @
23563f5e
...
@@ -11,6 +11,7 @@ import commentForm from './comment_form.vue';
...
@@ -11,6 +11,7 @@ import commentForm from './comment_form.vue';
import
placeholderNote
from
'
../../vue_shared/components/notes/placeholder_note.vue
'
;
import
placeholderNote
from
'
../../vue_shared/components/notes/placeholder_note.vue
'
;
import
placeholderSystemNote
from
'
../../vue_shared/components/notes/placeholder_system_note.vue
'
;
import
placeholderSystemNote
from
'
../../vue_shared/components/notes/placeholder_system_note.vue
'
;
import
skeletonLoadingContainer
from
'
../../vue_shared/components/notes/skeleton_note.vue
'
;
import
skeletonLoadingContainer
from
'
../../vue_shared/components/notes/skeleton_note.vue
'
;
import
highlightCurrentUser
from
'
~/behaviors/markdown/highlight_current_user
'
;
export
default
{
export
default
{
name
:
'
NotesApp
'
,
name
:
'
NotesApp
'
,
...
@@ -96,6 +97,9 @@ export default {
...
@@ -96,6 +97,9 @@ export default {
});
});
}
}
},
},
updated
()
{
this
.
$nextTick
(()
=>
highlightCurrentUser
(
this
.
$el
.
querySelectorAll
(
'
.gfm-project_member
'
)));
},
methods
:
{
methods
:
{
...
mapActions
({
...
mapActions
({
fetchDiscussions
:
'
fetchDiscussions
'
,
fetchDiscussions
:
'
fetchDiscussions
'
,
...
...
app/assets/stylesheets/framework/gfm.scss
View file @
23563f5e
...
@@ -11,6 +11,10 @@
...
@@ -11,6 +11,10 @@
padding
:
0
2px
;
padding
:
0
2px
;
background-color
:
$blue-100
;
background-color
:
$blue-100
;
border-radius
:
$border-radius-default
;
border-radius
:
$border-radius-default
;
&
.current-user
{
background-color
:
$orange-100
;
}
}
}
.gfm-color_chip
{
.gfm-color_chip
{
...
...
changelogs/unreleased/winh-highlight-current-user.yml
0 → 100644
View file @
23563f5e
---
title
:
Highlight current user in comments
merge_request
:
21406
author
:
type
:
changed
spec/features/issues/notes_on_issues_spec.rb
View file @
23563f5e
...
@@ -3,6 +3,12 @@ require 'spec_helper'
...
@@ -3,6 +3,12 @@ require 'spec_helper'
describe
'Create notes on issues'
,
:js
do
describe
'Create notes on issues'
,
:js
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
def
submit_comment
(
text
)
fill_in
'note[note]'
,
with:
text
click_button
'Comment'
wait_for_requests
end
shared_examples
'notes with reference'
do
shared_examples
'notes with reference'
do
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:note_text
)
{
"Check
#{
mention
.
to_reference
}
"
}
let
(
:note_text
)
{
"Check
#{
mention
.
to_reference
}
"
}
...
@@ -12,10 +18,7 @@ describe 'Create notes on issues', :js do
...
@@ -12,10 +18,7 @@ describe 'Create notes on issues', :js do
sign_in
(
user
)
sign_in
(
user
)
visit
project_issue_path
(
project
,
issue
)
visit
project_issue_path
(
project
,
issue
)
fill_in
'note[note]'
,
with:
note_text
submit_comment
(
note_text
)
click_button
'Comment'
wait_for_requests
end
end
it
'creates a note with reference and cross references the issue'
do
it
'creates a note with reference and cross references the issue'
do
...
@@ -74,4 +77,16 @@ describe 'Create notes on issues', :js do
...
@@ -74,4 +77,16 @@ describe 'Create notes on issues', :js do
let
(
:mention
)
{
create
(
:merge_request
,
source_project:
project
)
}
let
(
:mention
)
{
create
(
:merge_request
,
source_project:
project
)
}
end
end
end
end
it
'highlights the current user in a comment'
do
project
=
create
(
:project
)
issue
=
create
(
:issue
,
project:
project
)
project
.
add_developer
(
user
)
sign_in
(
user
)
visit
project_issue_path
(
project
,
issue
)
submit_comment
(
"@
#{
user
.
username
}
note to self"
)
expect
(
page
).
to
have_selector
'.gfm-project_member.current-user'
,
text:
user
.
username
end
end
end
spec/javascripts/behaviors/markdown/highlight_current_user_spec.js
0 → 100644
View file @
23563f5e
import
highlightCurrentUser
from
'
~/behaviors/markdown/highlight_current_user
'
;
describe
(
'
highlightCurrentUser
'
,
()
=>
{
let
rootElement
;
let
elements
;
beforeEach
(()
=>
{
setFixtures
(
`
<div id="dummy-root-element">
<div data-user="1">@first</div>
<div data-user="2">@second</div>
</div>
`
);
rootElement
=
document
.
getElementById
(
'
dummy-root-element
'
);
elements
=
rootElement
.
querySelectorAll
(
'
[data-user]
'
);
});
describe
(
'
without current user
'
,
()
=>
{
beforeEach
(()
=>
{
window
.
gon
=
window
.
gon
||
{};
window
.
gon
.
current_user_id
=
null
;
});
afterEach
(()
=>
{
delete
window
.
gon
.
current_user_id
;
});
it
(
'
does not highlight the user
'
,
()
=>
{
const
initialHtml
=
rootElement
.
outerHTML
;
highlightCurrentUser
(
elements
);
expect
(
rootElement
.
outerHTML
).
toBe
(
initialHtml
);
});
});
describe
(
'
with current user
'
,
()
=>
{
beforeEach
(()
=>
{
window
.
gon
=
window
.
gon
||
{};
window
.
gon
.
current_user_id
=
2
;
});
afterEach
(()
=>
{
delete
window
.
gon
.
current_user_id
;
});
it
(
'
highlights current user
'
,
()
=>
{
highlightCurrentUser
(
elements
);
expect
(
elements
.
length
).
toBe
(
2
);
expect
(
elements
[
0
]).
not
.
toHaveClass
(
'
current-user
'
);
expect
(
elements
[
1
]).
toHaveClass
(
'
current-user
'
);
});
});
});
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