summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/branches/components/divergence_graph.vue
blob: 36fff370ea160882e7e96db0bffcb1f2918c096a (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
<script>
import { sprintf, __ } from '~/locale';
import GraphBar from './graph_bar.vue';
import { MAX_COMMIT_COUNT } from '../constants';

export default {
  components: {
    GraphBar,
  },
  props: {
    defaultBranch: {
      type: String,
      required: true,
    },
    distance: {
      type: Number,
      required: false,
      default: null,
    },
    aheadCount: {
      type: Number,
      required: true,
    },
    behindCount: {
      type: Number,
      required: true,
    },
    maxCommits: {
      type: Number,
      required: true,
    },
  },
  computed: {
    title() {
      if (this.distance) {
        return sprintf(
          __('More than %{number_commits_distance} commits different with %{default_branch}'),
          {
            number_commits_distance:
              this.distance >= MAX_COMMIT_COUNT ? `${MAX_COMMIT_COUNT - 1}+` : this.distance,
            default_branch: this.defaultBranch,
          },
        );
      }

      return sprintf(
        __(
          '%{number_commits_behind} commits behind %{default_branch}, %{number_commits_ahead} commits ahead',
        ),
        {
          number_commits_behind: this.behindCount,
          number_commits_ahead: this.aheadCount,
          default_branch: this.defaultBranch,
        },
      );
    },
  },
};
</script>

<template>
  <div :title="title" class="divergence-graph px-2 d-none d-md-block">
    <template v-if="distance">
      <graph-bar :count="distance" :max-commits="maxCommits" position="full" />
    </template>
    <template v-else>
      <graph-bar :count="behindCount" :max-commits="maxCommits" position="left" />
      <div class="graph-separator pull-left mt-1"></div>
      <graph-bar :count="aheadCount" :max-commits="maxCommits" position="right" />
    </template>
  </div>
</template>