diff options
author | Winnie Hellmann <winnie@gitlab.com> | 2018-08-28 18:19:52 +0200 |
---|---|---|
committer | Winnie Hellmann <winnie@gitlab.com> | 2018-10-02 11:12:22 +0200 |
commit | 23563f5e0a5f3875289569126562f0f2fc63d3a6 (patch) | |
tree | dc7b3935d22f7ad12ef2508b0713e24780d7d95c /app | |
parent | 7c1cfd0bf5fd394e0e4387e350d69767aa873f84 (diff) | |
download | gitlab-ce-23563f5e0a5f3875289569126562f0f2fc63d3a6.tar.gz |
Highlight current user in comments and system notes
Diffstat (limited to 'app')
4 files changed, 27 insertions, 0 deletions
diff --git a/app/assets/javascripts/behaviors/markdown/highlight_current_user.js b/app/assets/javascripts/behaviors/markdown/highlight_current_user.js new file mode 100644 index 00000000000..6208b3f0032 --- /dev/null +++ b/app/assets/javascripts/behaviors/markdown/highlight_current_user.js @@ -0,0 +1,17 @@ +/** + * 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'); + } + }); +} diff --git a/app/assets/javascripts/behaviors/markdown/render_gfm.js b/app/assets/javascripts/behaviors/markdown/render_gfm.js index 429455f97ec..a2d4331b6d1 100644 --- a/app/assets/javascripts/behaviors/markdown/render_gfm.js +++ b/app/assets/javascripts/behaviors/markdown/render_gfm.js @@ -2,6 +2,7 @@ import $ from 'jquery'; import syntaxHighlight from '~/syntax_highlight'; import renderMath from './render_math'; import renderMermaid from './render_mermaid'; +import highlightCurrentUser from './highlight_current_user'; // Render GitLab flavoured Markdown // @@ -11,6 +12,7 @@ $.fn.renderGFM = function renderGFM() { syntaxHighlight(this.find('.js-syntax-highlight')); renderMath(this.find('.js-render-math')); renderMermaid(this.find('.js-render-mermaid')); + highlightCurrentUser(this.find('.gfm-project_member').get()); return this; }; diff --git a/app/assets/javascripts/notes/components/notes_app.vue b/app/assets/javascripts/notes/components/notes_app.vue index d8e8efb982a..618a1581d8f 100644 --- a/app/assets/javascripts/notes/components/notes_app.vue +++ b/app/assets/javascripts/notes/components/notes_app.vue @@ -11,6 +11,7 @@ import commentForm from './comment_form.vue'; import placeholderNote from '../../vue_shared/components/notes/placeholder_note.vue'; import placeholderSystemNote from '../../vue_shared/components/notes/placeholder_system_note.vue'; import skeletonLoadingContainer from '../../vue_shared/components/notes/skeleton_note.vue'; +import highlightCurrentUser from '~/behaviors/markdown/highlight_current_user'; export default { name: 'NotesApp', @@ -96,6 +97,9 @@ export default { }); } }, + updated() { + this.$nextTick(() => highlightCurrentUser(this.$el.querySelectorAll('.gfm-project_member'))); + }, methods: { ...mapActions({ fetchDiscussions: 'fetchDiscussions', diff --git a/app/assets/stylesheets/framework/gfm.scss b/app/assets/stylesheets/framework/gfm.scss index d2ba76f5160..50d4298d418 100644 --- a/app/assets/stylesheets/framework/gfm.scss +++ b/app/assets/stylesheets/framework/gfm.scss @@ -11,6 +11,10 @@ padding: 0 2px; background-color: $blue-100; border-radius: $border-radius-default; + + &.current-user { + background-color: $orange-100; + } } .gfm-color_chip { |