summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/notes/components/diff_file_header.vue
blob: 3e09391a9acb9a135c04c13b6abd262edc01334b (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<script>
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
import Icon from '~/vue_shared/components/icon.vue';

export default {
  components: {
    ClipboardButton,
    Icon,
  },
  props: {
    diffFile: {
      type: Object,
      required: true,
    },
    collapsible: {
      type: Boolean,
      required: false,
      default: false,
    },
    addMergeRequestButtons: {
      type: Boolean,
      required: false,
      default: false,
    },
  },
  computed: {
    titleTag() {
      return this.diffFile.fileHash ? 'a' : 'span';
    },
  },
  methods: {
    handleToggle(e, checkTarget) {
      if (checkTarget) {
        if (e.target === this.$refs.header) {
          this.$emit('toggleFile');
        }
      } else {
        this.$emit('toggleFile');
      }
    },
    noop() {},
  },
};
</script>

<template>
  <div
    @click="handleToggle($event, true)"
    ref="header"
    class="file-header-content"
  >
    <i
      v-if="collapsible"
      @click.stop="handleToggle"
      class="fa diff-toggle-caret fa-fw fa-caret-down"
    ></i>
    <div
      v-if="diffFile.submodule"
    >
      <span>
        <icon name="archive" />
        <strong
          v-html="diffFile.submoduleLink"
          class="file-title-name"
        ></strong>
        <clipboard-button
          :text="diffFile.submoduleLink"
          title="Copy file path to clipboard"
          css-class="btn-default btn-transparent btn-clipboard"
        />
      </span>
    </div>
    <template v-else>
      <component
        ref="titleWrapper"
        :is="titleTag"
        :href="`#${diffFile.fileHash}`"
      >
        <span v-html="diffFile.blobIcon"></span>
        <span v-if="diffFile.renamedFile">
          <strong
            class="file-title-name has-tooltip"
            :title="diffFile.oldPath"
            data-container="body"
          >
            {{ diffFile.oldPath }}
          </strong>
          &rarr;
          <strong
            class="file-title-name has-tooltip"
            :title="diffFile.newPath"
            data-container="body"
          >
            {{ diffFile.newPath }}
          </strong>
        </span>

        <strong
          v-else
          class="file-title-name has-tooltip"
          :title="diffFile.oldPath"
          data-container="body"
        >
          {{ diffFile.filePath }}
          <span v-if="diffFile.deletedFile">
            deleted
          </span>
        </strong>
      </component>

      <clipboard-button
        title="Copy file path to clipboard"
        :text="diffFile.filePath"
        css-class="btn-default btn-transparent btn-clipboard"
      />

      <small
        v-if="diffFile.modeChanged"
        ref="fileMode"
      >
        {{ diffFile.aMode }} → {{ diffFile.bMode }}
      </small>
    </template>
  </div>
</template>