summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/jobs/components/job_log_controllers.vue
blob: 7e7d9a0549b25816ea8e3144db685b24b7e1af33 (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
126
127
128
129
130
131
132
133
134
135
136
137
<script>
/* eslint-disable vue/no-v-html */
import { GlTooltipDirective, GlLink, GlButton } from '@gitlab/ui';
import { polyfillSticky } from '~/lib/utils/sticky';
import { numberToHumanSize } from '~/lib/utils/number_utils';
import { __, sprintf } from '~/locale';
import scrollDown from '../svg/scroll_down.svg';

export default {
  components: {
    GlLink,
    GlButton,
  },
  directives: {
    GlTooltip: GlTooltipDirective,
  },
  scrollDown,
  props: {
    erasePath: {
      type: String,
      required: false,
      default: null,
    },
    size: {
      type: Number,
      required: true,
    },
    rawPath: {
      type: String,
      required: false,
      default: null,
    },
    isScrollTopDisabled: {
      type: Boolean,
      required: true,
    },
    isScrollBottomDisabled: {
      type: Boolean,
      required: true,
    },
    isScrollingDown: {
      type: Boolean,
      required: true,
    },
    isTraceSizeVisible: {
      type: Boolean,
      required: true,
    },
  },
  computed: {
    jobLogSize() {
      return sprintf(__('Showing last %{size} of log -'), {
        size: numberToHumanSize(this.size),
      });
    },
  },
  mounted() {
    polyfillSticky(this.$el);
  },
  methods: {
    handleScrollToTop() {
      this.$emit('scrollJobLogTop');
    },
    handleScrollToBottom() {
      this.$emit('scrollJobLogBottom');
    },
  },
};
</script>
<template>
  <div class="top-bar">
    <!-- truncate information -->
    <div class="truncated-info d-none d-sm-block float-left" data-testid="log-truncated-info">
      <template v-if="isTraceSizeVisible">
        {{ jobLogSize }}
        <gl-link
          v-if="rawPath"
          :href="rawPath"
          class="text-plain text-underline gl-ml-2"
          data-testid="raw-link"
          >{{ s__('Job|Complete Raw') }}</gl-link
        >
      </template>
    </div>
    <!-- eo truncate information -->

    <div class="controllers float-right">
      <!-- links -->
      <gl-button
        v-if="rawPath"
        v-gl-tooltip.body
        :title="s__('Job|Show complete raw')"
        :href="rawPath"
        class="controllers-buttons"
        data-testid="job-raw-link-controller"
        icon="doc-text"
      />

      <gl-button
        v-if="erasePath"
        v-gl-tooltip.body
        :title="s__('Job|Erase job log')"
        :href="erasePath"
        :data-confirm="__('Are you sure you want to erase this build?')"
        class="controllers-buttons"
        data-testid="job-log-erase-link"
        data-method="post"
        icon="remove"
      />
      <!-- eo links -->

      <!-- scroll buttons -->
      <div v-gl-tooltip :title="s__('Job|Scroll to top')" class="controllers-buttons">
        <gl-button
          :disabled="isScrollTopDisabled"
          class="btn-scroll btn-transparent btn-blank"
          data-testid="job-controller-scroll-top"
          icon="scroll_up"
          @click="handleScrollToTop"
        />
      </div>

      <div v-gl-tooltip :title="s__('Job|Scroll to bottom')" class="controllers-buttons">
        <gl-button
          :disabled="isScrollBottomDisabled"
          class="js-scroll-bottom btn-scroll btn-transparent btn-blank"
          data-testid="job-controller-scroll-bottom"
          icon="scroll_down"
          :class="{ animate: isScrollingDown }"
          @click="handleScrollToBottom"
          v-html="$options.scrollDown"
        />
      </div>
      <!-- eo scroll buttons -->
    </div>
  </div>
</template>