Commit 3fdc6560 authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'ph-es-notes-module' into 'master'

Export and use Notes ES module

See merge request gitlab-org/gitlab-ce!15953
parents ceac0ae6 0a05d874
/* global CommentsStore */ /* global CommentsStore */
/* global notes */
import Vue from 'vue'; import Vue from 'vue';
import collapseIcon from '../icons/collapse_icon.svg'; import collapseIcon from '../icons/collapse_icon.svg';
import Notes from '../../notes';
import userAvatarImage from '../../vue_shared/components/user_avatar/user_avatar_image.vue'; import userAvatarImage from '../../vue_shared/components/user_avatar/user_avatar_image.vue';
const DiffNoteAvatars = Vue.extend({ const DiffNoteAvatars = Vue.extend({
...@@ -129,7 +129,7 @@ const DiffNoteAvatars = Vue.extend({ ...@@ -129,7 +129,7 @@ const DiffNoteAvatars = Vue.extend({
}, },
methods: { methods: {
clickedAvatar(e) { clickedAvatar(e) {
notes.onAddDiffNote(e); Notes.instance.onAddDiffNote(e);
// Toggle the active state of the toggle all button // Toggle the active state of the toggle all button
this.toggleDiscussionsToggleState(); this.toggleDiscussionsToggleState();
......
/* global Notes */ import Notes from './notes';
export default () => { export default () => {
const dataEl = document.querySelector('.js-notes-data'); const dataEl = document.querySelector('.js-notes-data');
...@@ -10,5 +10,7 @@ export default () => { ...@@ -10,5 +10,7 @@ export default () => {
autocomplete, autocomplete,
} = JSON.parse(dataEl.innerHTML); } = JSON.parse(dataEl.innerHTML);
window.notes = new Notes(notesUrl, notesIds, now, diffView, autocomplete); // Create a singleton so that we don't need to assign
// into the window object, we can just access the current isntance with Notes.instance
Notes.initialize(notesUrl, notesIds, now, diffView, autocomplete);
}; };
...@@ -45,9 +45,7 @@ import './layout_nav'; ...@@ -45,9 +45,7 @@ import './layout_nav';
import LazyLoader from './lazy_loader'; import LazyLoader from './lazy_loader';
import './line_highlighter'; import './line_highlighter';
import initLogoAnimation from './logo'; import initLogoAnimation from './logo';
import './merge_request_tabs';
import './milestone_select'; import './milestone_select';
import './notes';
import './preview_markdown'; import './preview_markdown';
import './projects_dropdown'; import './projects_dropdown';
import './render_gfm'; import './render_gfm';
......
/* eslint-disable no-new, class-methods-use-this */ /* eslint-disable no-new, class-methods-use-this */
/* global notes */
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
import Flash from './flash'; import Flash from './flash';
...@@ -16,6 +15,7 @@ import initDiscussionTab from './image_diff/init_discussion_tab'; ...@@ -16,6 +15,7 @@ import initDiscussionTab from './image_diff/init_discussion_tab';
import Diff from './diff'; import Diff from './diff';
import { localTimeAgo } from './lib/utils/datetime_utility'; import { localTimeAgo } from './lib/utils/datetime_utility';
import syntaxHighlight from './syntax_highlight'; import syntaxHighlight from './syntax_highlight';
import Notes from './notes';
/* eslint-disable max-len */ /* eslint-disable max-len */
// MergeRequestTabs // MergeRequestTabs
...@@ -324,7 +324,7 @@ export default class MergeRequestTabs { ...@@ -324,7 +324,7 @@ export default class MergeRequestTabs {
if (anchor && anchor.length > 0) { if (anchor && anchor.length > 0) {
const notesContent = anchor.closest('.notes_content'); const notesContent = anchor.closest('.notes_content');
const lineType = notesContent.hasClass('new') ? 'new' : 'old'; const lineType = notesContent.hasClass('new') ? 'new' : 'old';
notes.toggleDiffNote({ Notes.instance.toggleDiffNote({
target: anchor, target: anchor,
lineType, lineType,
forceShow: true, forceShow: true,
......
...@@ -37,6 +37,12 @@ const MAX_VISIBLE_COMMIT_LIST_COUNT = 3; ...@@ -37,6 +37,12 @@ const MAX_VISIBLE_COMMIT_LIST_COUNT = 3;
const REGEX_QUICK_ACTIONS = /^\/\w+.*$/gm; const REGEX_QUICK_ACTIONS = /^\/\w+.*$/gm;
export default class Notes { export default class Notes {
static initialize(notes_url, note_ids, last_fetched_at, view, enableGFM = true) {
if (!this.instance) {
this.instance = new Notes(notes_url, note_ids, last_fetched_at, view, enableGFM);
}
}
constructor(notes_url, note_ids, last_fetched_at, view, enableGFM = true) { constructor(notes_url, note_ids, last_fetched_at, view, enableGFM = true) {
this.updateTargetButtons = this.updateTargetButtons.bind(this); this.updateTargetButtons = this.updateTargetButtons.bind(this);
this.updateComment = this.updateComment.bind(this); this.updateComment = this.updateComment.bind(this);
......
/* global Notes */
import 'autosize'; import 'autosize';
import '~/gl_form'; import '~/gl_form';
import '~/lib/utils/text_utility'; import '~/lib/utils/text_utility';
import '~/render_gfm'; import '~/render_gfm';
import '~/render_math'; import '~/render_math';
import '~/notes'; import Notes from '~/notes';
const upArrowKeyCode = 38; const upArrowKeyCode = 38;
......
/* eslint-disable no-var, comma-dangle, object-shorthand */ /* eslint-disable no-var, comma-dangle, object-shorthand */
/* global Notes */
import * as urlUtils from '~/lib/utils/url_utility'; import * as urlUtils from '~/lib/utils/url_utility';
import MergeRequestTabs from '~/merge_request_tabs'; import MergeRequestTabs from '~/merge_request_tabs';
...@@ -7,7 +6,7 @@ import '~/commit/pipelines/pipelines_bundle'; ...@@ -7,7 +6,7 @@ import '~/commit/pipelines/pipelines_bundle';
import '~/breakpoints'; import '~/breakpoints';
import '~/lib/utils/common_utils'; import '~/lib/utils/common_utils';
import Diff from '~/diff'; import Diff from '~/diff';
import '~/notes'; import Notes from '~/notes';
import 'vendor/jquery.scrollTo'; import 'vendor/jquery.scrollTo';
(function () { (function () {
...@@ -279,8 +278,8 @@ import 'vendor/jquery.scrollTo'; ...@@ -279,8 +278,8 @@ import 'vendor/jquery.scrollTo';
loadFixtures('merge_requests/diff_comment.html.raw'); loadFixtures('merge_requests/diff_comment.html.raw');
$('body').attr('data-page', 'projects:merge_requests:show'); $('body').attr('data-page', 'projects:merge_requests:show');
window.gl.ImageFile = () => {}; window.gl.ImageFile = () => {};
window.notes = new Notes('', []); Notes.initialize('', []);
spyOn(window.notes, 'toggleDiffNote').and.callThrough(); spyOn(Notes.instance, 'toggleDiffNote').and.callThrough();
}); });
afterEach(() => { afterEach(() => {
...@@ -338,7 +337,7 @@ import 'vendor/jquery.scrollTo'; ...@@ -338,7 +337,7 @@ import 'vendor/jquery.scrollTo';
this.class.loadDiff('/foo/bar/merge_requests/1/diffs'); this.class.loadDiff('/foo/bar/merge_requests/1/diffs');
expect(noteId.length).toBeGreaterThan(0); expect(noteId.length).toBeGreaterThan(0);
expect(window.notes.toggleDiffNote).toHaveBeenCalledWith({ expect(Notes.instance.toggleDiffNote).toHaveBeenCalledWith({
target: jasmine.any(Object), target: jasmine.any(Object),
lineType: 'old', lineType: 'old',
forceShow: true, forceShow: true,
...@@ -349,7 +348,7 @@ import 'vendor/jquery.scrollTo'; ...@@ -349,7 +348,7 @@ import 'vendor/jquery.scrollTo';
spyOn(urlUtils, 'getLocationHash').and.returnValue('note_something-that-does-not-exist'); spyOn(urlUtils, 'getLocationHash').and.returnValue('note_something-that-does-not-exist');
this.class.loadDiff('/foo/bar/merge_requests/1/diffs'); this.class.loadDiff('/foo/bar/merge_requests/1/diffs');
expect(window.notes.toggleDiffNote).not.toHaveBeenCalled(); expect(Notes.instance.toggleDiffNote).not.toHaveBeenCalled();
}); });
}); });
...@@ -359,7 +358,7 @@ import 'vendor/jquery.scrollTo'; ...@@ -359,7 +358,7 @@ import 'vendor/jquery.scrollTo';
this.class.loadDiff('/foo/bar/merge_requests/1/diffs'); this.class.loadDiff('/foo/bar/merge_requests/1/diffs');
expect(noteLineNumId.length).toBeGreaterThan(0); expect(noteLineNumId.length).toBeGreaterThan(0);
expect(window.notes.toggleDiffNote).not.toHaveBeenCalled(); expect(Notes.instance.toggleDiffNote).not.toHaveBeenCalled();
}); });
}); });
}); });
...@@ -393,7 +392,7 @@ import 'vendor/jquery.scrollTo'; ...@@ -393,7 +392,7 @@ import 'vendor/jquery.scrollTo';
this.class.loadDiff('/foo/bar/merge_requests/1/diffs'); this.class.loadDiff('/foo/bar/merge_requests/1/diffs');
expect(noteId.length).toBeGreaterThan(0); expect(noteId.length).toBeGreaterThan(0);
expect(window.notes.toggleDiffNote).toHaveBeenCalledWith({ expect(Notes.instance.toggleDiffNote).toHaveBeenCalledWith({
target: jasmine.any(Object), target: jasmine.any(Object),
lineType: 'new', lineType: 'new',
forceShow: true, forceShow: true,
...@@ -404,7 +403,7 @@ import 'vendor/jquery.scrollTo'; ...@@ -404,7 +403,7 @@ import 'vendor/jquery.scrollTo';
spyOn(urlUtils, 'getLocationHash').and.returnValue('note_something-that-does-not-exist'); spyOn(urlUtils, 'getLocationHash').and.returnValue('note_something-that-does-not-exist');
this.class.loadDiff('/foo/bar/merge_requests/1/diffs'); this.class.loadDiff('/foo/bar/merge_requests/1/diffs');
expect(window.notes.toggleDiffNote).not.toHaveBeenCalled(); expect(Notes.instance.toggleDiffNote).not.toHaveBeenCalled();
}); });
}); });
...@@ -414,7 +413,7 @@ import 'vendor/jquery.scrollTo'; ...@@ -414,7 +413,7 @@ import 'vendor/jquery.scrollTo';
this.class.loadDiff('/foo/bar/merge_requests/1/diffs'); this.class.loadDiff('/foo/bar/merge_requests/1/diffs');
expect(noteLineNumId.length).toBeGreaterThan(0); expect(noteLineNumId.length).toBeGreaterThan(0);
expect(window.notes.toggleDiffNote).not.toHaveBeenCalled(); expect(Notes.instance.toggleDiffNote).not.toHaveBeenCalled();
}); });
}); });
}); });
......
/* eslint-disable space-before-function-paren, no-unused-expressions, no-var, object-shorthand, comma-dangle, max-len */ /* eslint-disable space-before-function-paren, no-unused-expressions, no-var, object-shorthand, comma-dangle, max-len */
/* global Notes */
import * as urlUtils from '~/lib/utils/url_utility'; import * as urlUtils from '~/lib/utils/url_utility';
import 'autosize'; import 'autosize';
import '~/gl_form'; import '~/gl_form';
import '~/lib/utils/text_utility'; import '~/lib/utils/text_utility';
import '~/render_gfm'; import '~/render_gfm';
import '~/notes'; import Notes from '~/notes';
(function() { (function() {
window.gon || (window.gon = {}); window.gon || (window.gon = {});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment