summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/sidebar/components/time_tracking/time_tracker.js
blob: ed0d71a4f797d6e5cb6e0a5413f0d248e96a84d8 (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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import timeTrackingHelpState from './help_state';
import timeTrackingCollapsedState from './collapsed_state';
import timeTrackingSpentOnlyPane from './spent_only_pane';
import timeTrackingNoTrackingPane from './no_tracking_pane';
import timeTrackingEstimateOnlyPane from './estimate_only_pane';
import timeTrackingComparisonPane from './comparison_pane';

import eventHub from '../../event_hub';

export default {
  name: 'issuable-time-tracker',
  props: {
    time_estimate: {
      type: Number,
      required: true,
    },
    time_spent: {
      type: Number,
      required: true,
    },
    human_time_estimate: {
      type: String,
      required: false,
      default: '',
    },
    human_time_spent: {
      type: String,
      required: false,
      default: '',
    },
    rootPath: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      showHelp: false,
    };
  },
  components: {
    'time-tracking-collapsed-state': timeTrackingCollapsedState,
    'time-tracking-estimate-only-pane': timeTrackingEstimateOnlyPane,
    'time-tracking-spent-only-pane': timeTrackingSpentOnlyPane,
    'time-tracking-no-tracking-pane': timeTrackingNoTrackingPane,
    'time-tracking-comparison-pane': timeTrackingComparisonPane,
    'time-tracking-help-state': timeTrackingHelpState,
  },
  computed: {
    timeSpent() {
      return this.time_spent;
    },
    timeEstimate() {
      return this.time_estimate;
    },
    timeEstimateHumanReadable() {
      return this.human_time_estimate;
    },
    timeSpentHumanReadable() {
      return this.human_time_spent;
    },
    hasTimeSpent() {
      return !!this.timeSpent;
    },
    hasTimeEstimate() {
      return !!this.timeEstimate;
    },
    showComparisonState() {
      return this.hasTimeEstimate && this.hasTimeSpent;
    },
    showEstimateOnlyState() {
      return this.hasTimeEstimate && !this.hasTimeSpent;
    },
    showSpentOnlyState() {
      return this.hasTimeSpent && !this.hasTimeEstimate;
    },
    showNoTimeTrackingState() {
      return !this.hasTimeEstimate && !this.hasTimeSpent;
    },
    showHelpState() {
      return !!this.showHelp;
    },
  },
  methods: {
    toggleHelpState(show) {
      this.showHelp = show;
    },
    update(data) {
      this.time_estimate = data.time_estimate;
      this.time_spent = data.time_spent;
      this.human_time_estimate = data.human_time_estimate;
      this.human_time_spent = data.human_time_spent;
    },
  },
  created() {
    eventHub.$on('timeTracker:updateData', this.update);
  },
  template: `
    <div
      class="time_tracker time-tracking-component-wrap"
      v-cloak
    >
      <time-tracking-collapsed-state
        :show-comparison-state="showComparisonState"
        :show-no-time-tracking-state="showNoTimeTrackingState"
        :show-help-state="showHelpState"
        :show-spent-only-state="showSpentOnlyState"
        :show-estimate-only-state="showEstimateOnlyState"
        :time-spent-human-readable="timeSpentHumanReadable"
        :time-estimate-human-readable="timeEstimateHumanReadable"
      />
      <div class="title hide-collapsed">
        Time tracking
        <div
          class="help-button pull-right"
          v-if="!showHelpState"
          @click="toggleHelpState(true)"
        >
            <i
              class="fa fa-question-circle"
              aria-hidden="true"
            />
        </div>
        <div
          class="close-help-button pull-right"
          v-if="showHelpState"
          @click="toggleHelpState(false)"
        >
          <i
            class="fa fa-close"
            aria-hidden="true"
          />
        </div>
      </div>
      <div class="time-tracking-content hide-collapsed">
        <time-tracking-estimate-only-pane
          v-if="showEstimateOnlyState"
          :time-estimate-human-readable="timeEstimateHumanReadable"
        />
        <time-tracking-spent-only-pane
          v-if="showSpentOnlyState"
          :time-spent-human-readable="timeSpentHumanReadable"
        />
        <time-tracking-no-tracking-pane
          v-if="showNoTimeTrackingState"
        />
        <time-tracking-comparison-pane
          v-if="showComparisonState"
          :time-estimate="timeEstimate"
          :time-spent="timeSpent"
          :time-spent-human-readable="timeSpentHumanReadable"
          :time-estimate-human-readable="timeEstimateHumanReadable"
        />
        <transition name="help-state-toggle">
          <time-tracking-help-state
            v-if="showHelpState"
            :rootPath="rootPath"
          />
        </transition>
      </div>
    </div>
  `,
};