summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/sidebar/components/time_tracking/collapsed_state.vue
blob: 657ac837baff2e77087a8a04863e39df206e593f (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
<script>
import { __, sprintf } from '~/locale';
import { abbreviateTime } from '~/lib/utils/datetime_utility';
import icon from '~/vue_shared/components/icon.vue';
import tooltip from '~/vue_shared/directives/tooltip';

export default {
  name: 'TimeTrackingCollapsedState',
  components: {
    icon,
  },
  directives: {
    tooltip,
  },
  props: {
    showComparisonState: {
      type: Boolean,
      required: true,
    },
    showSpentOnlyState: {
      type: Boolean,
      required: true,
    },
    showEstimateOnlyState: {
      type: Boolean,
      required: true,
    },
    showNoTimeTrackingState: {
      type: Boolean,
      required: true,
    },
    timeSpentHumanReadable: {
      type: String,
      required: false,
      default: '',
    },
    timeEstimateHumanReadable: {
      type: String,
      required: false,
      default: '',
    },
  },
  computed: {
    timeSpent() {
      return this.abbreviateTime(this.timeSpentHumanReadable);
    },
    timeEstimate() {
      return this.abbreviateTime(this.timeEstimateHumanReadable);
    },
    divClass() {
      if (this.showComparisonState) {
        return 'compare';
      } else if (this.showEstimateOnlyState) {
        return 'estimate-only';
      } else if (this.showSpentOnlyState) {
        return 'spend-only';
      } else if (this.showNoTimeTrackingState) {
        return 'no-tracking';
      }

      return '';
    },
    spanClass() {
      if (this.showComparisonState) {
        return '';
      } else if (this.showEstimateOnlyState || this.showSpentOnlyState) {
        return 'bold';
      } else if (this.showNoTimeTrackingState) {
        return 'no-value';
      }

      return '';
    },
    text() {
      if (this.showComparisonState) {
        return `${this.timeSpent} / ${this.timeEstimate}`;
      } else if (this.showEstimateOnlyState) {
        return `-- / ${this.timeEstimate}`;
      } else if (this.showSpentOnlyState) {
        return `${this.timeSpent} / --`;
      } else if (this.showNoTimeTrackingState) {
        return 'None';
      }

      return '';
    },
    timeTrackedTooltipText() {
      let title;
      if (this.showComparisonState) {
        title = __('Time remaining');
      } else if (this.showEstimateOnlyState) {
        title = __('Estimated');
      } else if (this.showSpentOnlyState) {
        title = __('Time spent');
      }

      return sprintf('%{title}: %{text}', { title, text: this.text });
    },
    tooltipText() {
      return this.showNoTimeTrackingState ? __('Time tracking') : this.timeTrackedTooltipText;
    },
  },
  methods: {
    abbreviateTime(timeStr) {
      return abbreviateTime(timeStr);
    },
  },
};
</script>

<template>
  <div
    v-tooltip
    :title="tooltipText"
    class="sidebar-collapsed-icon"
    data-container="body"
    data-placement="left"
    data-boundary="viewport"
  >
    <icon name="timer" />
    <div class="time-tracking-collapsed-summary">
      <div :class="divClass">
        <span :class="spanClass"> {{ text }} </span>
      </div>
    </div>
  </div>
</template>