summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/sidebar/components/time_tracking/sidebar_time_tracking.vue
blob: 8e8b9f19b6e7a42551a75a1b473a34ed3bf7dbec (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
<script>
import $ from 'jquery';
import _ from 'underscore';

import '~/smart_interval';

import IssuableTimeTracker from './time_tracker.vue';

import Store from '../../stores/sidebar_store';
import Mediator from '../../sidebar_mediator';
import eventHub from '../../event_hub';

export default {
  components: {
    IssuableTimeTracker,
  },
  data() {
    return {
      mediator: new Mediator(),
      store: new Store(),
    };
  },
  mounted() {
    this.listenForQuickActions();
  },
  methods: {
    listenForQuickActions() {
      $(document).on('ajax:success', '.gfm-form', this.quickActionListened);
      eventHub.$on('timeTrackingUpdated', data => {
        this.quickActionListened(null, data);
      });
    },
    quickActionListened(e, data) {
      const subscribedCommands = ['spend_time', 'time_estimate'];
      let changedCommands;
      if (data !== undefined) {
        changedCommands = data.commands_changes ? Object.keys(data.commands_changes) : [];
      } else {
        changedCommands = [];
      }
      if (changedCommands && _.intersection(subscribedCommands, changedCommands).length) {
        this.mediator.fetch();
      }
    },
  },
};
</script>

<template>
  <div class="block">
    <issuable-time-tracker
      :time-estimate="store.timeEstimate"
      :time-spent="store.totalTimeSpent"
      :human-time-estimate="store.humanTimeEstimate"
      :human-time-spent="store.humanTotalTimeSpent"
      :root-path="store.rootPath"
    />
  </div>
</template>