BigW Consortium Gitlab

diff_notes_bundle.js 2.13 KB
Newer Older
1
/* eslint-disable func-names, comma-dangle, new-cap, no-new, max-len */
2 3
/* global ResolveCount */

4
import Vue from 'vue';
5 6 7 8 9 10 11 12 13 14 15 16
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/resolve_discussion_btn';
import './components/diff_note_avatars';
import './components/new_issue_for_discussion';
Phil Hughes committed
17 18

$(() => {
19
  const projectPath = document.querySelector('.merge-request').dataset.projectPath;
20
  const COMPONENT_SELECTOR = 'resolve-btn, resolve-discussion-btn, jump-to-discussion, comment-and-resolve-btn, new-issue-for-discussion-btn';
21

22 23
  window.gl = window.gl || {};
  window.gl.diffNoteApps = {};
24

25 26
  window.ResolveService = new gl.DiffNotesResolveServiceClass(projectPath);

27
  gl.diffNotesCompileComponents = () => {
28 29 30 31 32 33 34
    $('diff-note-avatars').each(function () {
      const tmp = Vue.extend({
        template: $(this).get(0).outerHTML
      });
      const tmpApp = new tmp().$mount();

      $(this).replaceWith(tmpApp.$el);
35 36 37 38
      $(tmpApp.$el).one('remove.vue', () => {
        tmpApp.$destroy();
        tmpApp.$el.remove();
      });
39 40
    });

41 42 43
    const $components = $(COMPONENT_SELECTOR).filter(function () {
      return $(this).closest('resolve-count').length !== 1;
    });
44 45 46 47 48

    if ($components) {
      $components.each(function () {
        const $this = $(this);
        const noteId = $this.attr(':note-id');
49 50 51 52
        const discussionId = $this.attr(':discussion-id');

        if ($this.is('comment-and-resolve-btn') && !discussionId) return;

53 54 55 56 57 58 59
        const tmp = Vue.extend({
          template: $this.get(0).outerHTML
        });
        const tmpApp = new tmp().$mount();

        if (noteId) {
          gl.diffNoteApps[`note_${noteId}`] = tmpApp;
60
        }
61 62 63

        $this.replaceWith(tmpApp.$el);
      });
Phil Hughes committed
64
    }
65 66 67
  };

  gl.diffNotesCompileComponents();
Phil Hughes committed
68 69 70 71 72 73 74

  new Vue({
    el: '#resolve-count-app',
    components: {
      'resolve-count': ResolveCount
    }
  });
75 76

  $(window).trigger('resize.nav');
Phil Hughes committed
77
});