summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/notes/components/diff_with_note.vue
blob: 1dba84fac1887debec271f8219874e5caf50d6ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<script>
  import $ from 'jquery';
  import syntaxHighlight from '~/syntax_highlight';
  import imageDiffHelper from '~/image_diff/helpers/index';
  import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
  import DiffFileHeader from './diff_file_header.vue';

  export default {
    components: {
      DiffFileHeader,
    },
    props: {
      discussion: {
        type: Object,
        required: true,
      },
    },
    computed: {
      isImageDiff() {
        return !this.diffFile.text;
      },
      diffFileClass() {
        const { text } = this.diffFile;
        return text ? 'text-file' : 'js-image-file';
      },
      diffRows() {
        return $(this.discussion.truncatedDiffLines);
      },
      diffFile() {
        return convertObjectPropsToCamelCase(this.discussion.diffFile);
      },
      imageDiffHtml() {
        return this.discussion.imageDiffHtml;
      },
    },
    mounted() {
      if (this.isImageDiff) {
        const canCreateNote = false;
        const renderCommentBadge = true;
        imageDiffHelper.initImageDiff(this.$refs.fileHolder, canCreateNote, renderCommentBadge);
      } else {
        const fileHolder = $(this.$refs.fileHolder);
        this.$nextTick(() => {
          syntaxHighlight(fileHolder);
        });
      }
    },
    methods: {
      rowTag(html) {
        return html.outerHTML ? 'tr' : 'template';
      },
    },
  };
</script>

<template>
  <div
    ref="fileHolder"
    class="diff-file file-holder"
    :class="diffFileClass"
  >
    <div class="js-file-title file-title file-title-flex-parent">
      <diff-file-header
        :diff-file="diffFile"
      />
    </div>
    <div
      v-if="diffFile.text"
      class="diff-content code js-syntax-highlight"
    >
      <table>
        <component
          :is="rowTag(html)"
          :class="html.className"
          v-for="(html, index) in diffRows"
          v-html="html.outerHTML"
          :key="index"
        />
        <tr class="notes_holder">
          <td
            class="notes_line"
            colspan="2"
          ></td>
          <td class="notes_content">
            <slot></slot>
          </td>
        </tr>
      </table>
    </div>
    <div
      v-else
    >
      <div v-html="imageDiffHtml"></div>
      <slot></slot>
    </div>
  </div>
</template>