2018-06-21 08:22:40 -04:00
|
|
|
/* eslint-disable func-names, new-cap */
|
2016-12-13 22:01:05 -05:00
|
|
|
|
2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2017-03-17 13:21:25 -04:00
|
|
|
import Vue from 'vue';
|
2017-05-16 16:48:57 -04:00
|
|
|
import './models/discussion';
|
|
|
|
import './models/note';
|
|
|
|
import './stores/comments';
|
|
|
|
import './services/resolve';
|
|
|
|
import './mixins/discussion';
|
|
|
|
import './components/comment_resolve_btn';
|
|
|
|
import './components/jump_to_discussion';
|
|
|
|
import './components/resolve_btn';
|
|
|
|
import './components/resolve_count';
|
|
|
|
import './components/diff_note_avatars';
|
|
|
|
import './components/new_issue_for_discussion';
|
2016-07-26 06:56:36 -04:00
|
|
|
|
2018-02-15 17:50:20 -05:00
|
|
|
export default () => {
|
2018-06-21 08:22:40 -04:00
|
|
|
const projectPathHolder =
|
|
|
|
document.querySelector('.merge-request') || document.querySelector('.commit-box');
|
2018-06-16 17:50:13 -04:00
|
|
|
const { projectPath } = projectPathHolder.dataset;
|
2018-06-21 08:22:40 -04:00
|
|
|
const COMPONENT_SELECTOR =
|
2020-02-24 07:09:00 -05:00
|
|
|
'resolve-btn, jump-to-discussion, comment-and-resolve-btn, new-issue-for-discussion-btn';
|
2016-11-09 03:54:48 -05:00
|
|
|
|
2016-11-08 11:54:18 -05:00
|
|
|
window.gl = window.gl || {};
|
|
|
|
window.gl.diffNoteApps = {};
|
2016-11-07 05:05:58 -05:00
|
|
|
|
2017-02-08 09:58:08 -05:00
|
|
|
window.ResolveService = new gl.DiffNotesResolveServiceClass(projectPath);
|
|
|
|
|
2016-11-08 11:54:18 -05:00
|
|
|
gl.diffNotesCompileComponents = () => {
|
2018-06-21 08:22:40 -04:00
|
|
|
$('diff-note-avatars').each(function() {
|
2017-03-08 11:07:26 -05:00
|
|
|
const tmp = Vue.extend({
|
2018-06-21 08:22:40 -04:00
|
|
|
template: $(this).get(0).outerHTML,
|
2017-03-08 11:07:26 -05:00
|
|
|
});
|
|
|
|
const tmpApp = new tmp().$mount();
|
|
|
|
|
|
|
|
$(this).replaceWith(tmpApp.$el);
|
2017-09-05 06:20:40 -04:00
|
|
|
$(tmpApp.$el).one('remove.vue', () => {
|
|
|
|
tmpApp.$destroy();
|
|
|
|
tmpApp.$el.remove();
|
|
|
|
});
|
2017-03-08 11:07:26 -05:00
|
|
|
});
|
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
const $components = $(COMPONENT_SELECTOR).filter(function() {
|
2016-11-09 03:54:48 -05:00
|
|
|
return $(this).closest('resolve-count').length !== 1;
|
|
|
|
});
|
2016-11-08 11:54:18 -05:00
|
|
|
|
|
|
|
if ($components) {
|
2018-06-21 08:22:40 -04:00
|
|
|
$components.each(function() {
|
2016-11-08 11:54:18 -05:00
|
|
|
const $this = $(this);
|
|
|
|
const noteId = $this.attr(':note-id');
|
2017-08-08 09:25:00 -04:00
|
|
|
const discussionId = $this.attr(':discussion-id');
|
|
|
|
|
|
|
|
if ($this.is('comment-and-resolve-btn') && !discussionId) return;
|
|
|
|
|
2016-11-08 11:54:18 -05:00
|
|
|
const tmp = Vue.extend({
|
2018-06-21 08:22:40 -04:00
|
|
|
template: $this.get(0).outerHTML,
|
2016-11-08 11:54:18 -05:00
|
|
|
});
|
|
|
|
const tmpApp = new tmp().$mount();
|
|
|
|
|
|
|
|
if (noteId) {
|
|
|
|
gl.diffNoteApps[`note_${noteId}`] = tmpApp;
|
2016-08-01 05:21:57 -04:00
|
|
|
}
|
2016-11-08 11:54:18 -05:00
|
|
|
|
|
|
|
$this.replaceWith(tmpApp.$el);
|
|
|
|
});
|
2016-07-26 06:56:36 -04:00
|
|
|
}
|
2016-11-08 11:54:18 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
gl.diffNotesCompileComponents();
|
2016-07-26 06:56:36 -04:00
|
|
|
|
2017-05-16 00:04:07 -04:00
|
|
|
$(window).trigger('resize.nav');
|
2018-02-15 17:50:20 -05:00
|
|
|
};
|