summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/vue_merge_request_widget/components/mr_widget_header.js
blob: 4a1fd8811696b22c54972a2d6f9af21ca2a70cec (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
require('../../lib/utils/text_utility');

export default {
  name: 'MRWidgetHeader',
  props: {
    mr: { type: Object, required: true },
  },
  computed: {
    shouldShowCommitsBehindText() {
      return this.mr.divergedCommitsCount > 0;
    },
    commitsText() {
      return gl.text.pluralize('commit', this.mr.divergedCommitsCount);
    },
  },
  methods: {
    isBranchTitleLong(branchTitle) {
      return branchTitle.length > 32;
    },
  },
  template: `
    <div class="mr-source-target">
      <div
        v-if="mr.isOpen"
        class="pull-right">
        <a
          href="#modal_merge_info"
          data-toggle="modal"
          class="btn inline btn-grouped btn-sm">
          Check out branch
        </a>
        <span class="dropdown inline prepend-left-5">
          <a
            class="btn btn-sm dropdown-toggle"
            data-toggle="dropdown"
            aria-label="Download as"
            role="button">
            <i
              class="fa fa-download"
              aria-hidden="true" />
            <i
              class="fa fa-caret-down"
              aria-hidden="true" />
          </a>
          <ul class="dropdown-menu dropdown-menu-align-right">
            <li>
              <a
                :href="mr.emailPatchesPath"
                download>
                Email patches
              </a>
            </li>
            <li>
              <a
                :href="mr.plainDiffPath"
                download>
                Plain diff
              </a>
            </li>
          </ul>
        </span>
      </div>
      <div class="normal">
        <b>Request to merge</b>
        <span
          class="label-branch"
          :class="{'label-truncated has-tooltip': isBranchTitleLong(mr.sourceBranch)}"
          :title="isBranchTitleLong(mr.sourceBranch) ? mr.sourceBranch : ''"
          data-placement="bottom"
          v-html="mr.sourceBranchLink"></span>
        <button
          class="btn btn-transparent btn-clipboard has-tooltip"
          data-title="Copy branch name to clipboard"
          :data-clipboard-text="mr.sourceBranch">
          <i
            aria-hidden="true"
            class="fa fa-clipboard"></i>
        </button>
        <b>into</b>
        <span
          class="label-branch"
          :class="{'label-truncated has-tooltip': isBranchTitleLong(mr.targetBranch)}"
          :title="isBranchTitleLong(mr.targetBranch) ? mr.targetBranch : ''"
          data-placement="bottom">
          <a
            :href="mr.targetBranchCommitsPath">
            {{mr.targetBranch}}
          </a>
        </span>
        <span
          v-if="shouldShowCommitsBehindText"
          class="diverged-commits-count">
          ({{mr.divergedCommitsCount}} {{commitsText}} behind)
        </span>
      </div>
    </div>
  `,
};