ide_status_bar.vue 3.64 KB
Newer Older
Phil Hughes's avatar
Phil Hughes committed
1
<script>
2
import { mapActions, mapState, mapGetters } from 'vuex';
3 4 5
import icon from '~/vue_shared/components/icon.vue';
import tooltip from '~/vue_shared/directives/tooltip';
import timeAgoMixin from '~/vue_shared/mixins/timeago';
6
import CiIcon from '../../vue_shared/components/ci_icon.vue';
7
import userAvatarImage from '../../vue_shared/components/user_avatar/user_avatar_image.vue';
8
import { rightSidebarViews } from '../constants';
Phil Hughes's avatar
Phil Hughes committed
9

10 11 12
export default {
  components: {
    icon,
13
    userAvatarImage,
14
    CiIcon,
15 16 17 18 19 20 21 22
  },
  directives: {
    tooltip,
  },
  mixins: [timeAgoMixin],
  props: {
    file: {
      type: Object,
23 24 25 26 27 28 29 30 31 32
      required: false,
      default: null,
    },
  },
  data() {
    return {
      lastCommitFormatedAge: null,
    };
  },
  computed: {
33
    ...mapState(['currentBranchId', 'currentProjectId']),
34
    ...mapGetters(['currentProject', 'lastCommit']),
35
    ...mapState('pipelines', ['latestPipeline']),
36
  },
37 38
  watch: {
    lastCommit() {
39
      this.initPipelinePolling();
40 41
    },
  },
42 43 44 45 46 47 48
  mounted() {
    this.startTimer();
  },
  beforeDestroy() {
    if (this.intervalId) {
      clearInterval(this.intervalId);
    }
49 50

    this.stopPipelinePolling();
51 52
  },
  methods: {
53 54 55
    ...mapActions('rightPane', {
      openRightPane: 'open',
    }),
56
    ...mapActions('pipelines', ['fetchLatestPipeline', 'stopPipelinePolling']),
57 58 59 60 61
    startTimer() {
      this.intervalId = setInterval(() => {
        this.commitAgeUpdate();
      }, 1000);
    },
62
    initPipelinePolling() {
63 64 65
      if (this.lastCommit) {
        this.fetchLatestPipeline();
      }
66
    },
67 68 69 70 71 72 73
    commitAgeUpdate() {
      if (this.lastCommit) {
        this.lastCommitFormatedAge = this.timeFormated(this.lastCommit.committed_date);
      }
    },
    getCommitPath(shortSha) {
      return `${this.currentProject.web_url}/commit/${shortSha}`;
Phil Hughes's avatar
Phil Hughes committed
74
    },
75
  },
76
  rightSidebarViews,
77
};
Phil Hughes's avatar
Phil Hughes committed
78 79 80
</script>

<template>
81
  <footer class="ide-status-bar">
Mike Greiling's avatar
Mike Greiling committed
82 83
    <div v-if="lastCommit" class="ide-status-branch">
      <span v-if="latestPipeline && latestPipeline.details" class="ide-status-pipeline">
84 85 86
        <button
          type="button"
          class="p-0 border-0 h-50"
87
          @click="openRightPane($options.rightSidebarViews.pipelines)"
88 89 90 91 92 93 94
        >
          <ci-icon
            v-tooltip
            :status="latestPipeline.details.status"
            :title="latestPipeline.details.status.text"
          />
        </button>
95
        Pipeline
Mike Greiling's avatar
Mike Greiling committed
96 97 98 99
        <a :href="latestPipeline.details.status.details_path" class="monospace"
          >#{{ latestPipeline.id }}</a
        >
        {{ latestPipeline.details.status.text }} for
100 101
      </span>

Mike Greiling's avatar
Mike Greiling committed
102
      <icon name="commit" />
103 104 105 106
      <a
        v-tooltip
        :title="lastCommit.message"
        :href="getCommitPath(lastCommit.short_id)"
107
        class="commit-sha"
Mike Greiling's avatar
Mike Greiling committed
108 109
        >{{ lastCommit.short_id }}</a
      >
110 111 112 113 114 115 116 117 118
      by
      <user-avatar-image
        css-classes="ide-status-avatar"
        :size="18"
        :img-src="latestPipeline && latestPipeline.commit.author_gravatar_url"
        :img-alt="lastCommit.author_name"
        :tooltip-text="lastCommit.author_name"
      />
      {{ lastCommit.author_name }}
119 120 121 122
      <time
        v-tooltip
        :datetime="lastCommit.committed_date"
        :title="tooltipTitle(lastCommit.committed_date)"
123 124
        data-placement="top"
        data-container="body"
125
        >{{ lastCommitFormatedAge }}</time
126
      >
Phil Hughes's avatar
Phil Hughes committed
127
    </div>
Mike Greiling's avatar
Mike Greiling committed
128 129 130
    <div v-if="file" class="ide-status-file">{{ file.name }}</div>
    <div v-if="file" class="ide-status-file">{{ file.eol }}</div>
    <div v-if="file && !file.binary" class="ide-status-file">
Phil Hughes's avatar
Phil Hughes committed
131 132
      {{ file.editorRow }}:{{ file.editorColumn }}
    </div>
Mike Greiling's avatar
Mike Greiling committed
133
    <div v-if="file" class="ide-status-file">{{ file.fileLanguage }}</div>
134
  </footer>
Phil Hughes's avatar
Phil Hughes committed
135
</template>