subscriptions.vue 1.95 KB
Newer Older
Eric Eastwood's avatar
Eric Eastwood committed
1
<script>
2 3 4 5
  import { __ } from '~/locale';
  import icon from '~/vue_shared/components/icon.vue';
  import toggleButton from '~/vue_shared/components/toggle_button.vue';
  import tooltip from '~/vue_shared/directives/tooltip';
6
  import eventHub from '../../event_hub';
7 8 9 10 11

  const ICON_ON = 'notifications';
  const ICON_OFF = 'notifications-off';
  const LABEL_ON = __('Notifications on');
  const LABEL_OFF = __('Notifications off');
Eric Eastwood's avatar
Eric Eastwood committed
12

Filipa Lacerda's avatar
Filipa Lacerda committed
13
  export default {
14 15 16
    directives: {
      tooltip,
    },
Filipa Lacerda's avatar
Filipa Lacerda committed
17
    components: {
18
      icon,
19
      toggleButton,
Eric Eastwood's avatar
Eric Eastwood committed
20
    },
Filipa Lacerda's avatar
Filipa Lacerda committed
21 22 23 24 25 26 27 28 29
    props: {
      loading: {
        type: Boolean,
        required: false,
        default: false,
      },
      subscribed: {
        type: Boolean,
        required: false,
Mike Greiling's avatar
Mike Greiling committed
30
        default: null,
Filipa Lacerda's avatar
Filipa Lacerda committed
31 32 33 34
      },
      id: {
        type: Number,
        required: false,
Mike Greiling's avatar
Mike Greiling committed
35
        default: null,
Filipa Lacerda's avatar
Filipa Lacerda committed
36
      },
Eric Eastwood's avatar
Eric Eastwood committed
37
    },
Filipa Lacerda's avatar
Filipa Lacerda committed
38
    computed: {
39
      showLoadingState() {
40
        return this.subscribed === null;
Filipa Lacerda's avatar
Filipa Lacerda committed
41
      },
42
      notificationIcon() {
43
        return this.subscribed ? ICON_ON : ICON_OFF;
44
      },
45 46
      notificationTooltip() {
        return this.subscribed ? LABEL_ON : LABEL_OFF;
Mike Greiling's avatar
Mike Greiling committed
47
      },
Eric Eastwood's avatar
Eric Eastwood committed
48
    },
Filipa Lacerda's avatar
Filipa Lacerda committed
49 50
    methods: {
      toggleSubscription() {
51
        eventHub.$emit('toggleSubscription', this.id);
Filipa Lacerda's avatar
Filipa Lacerda committed
52
      },
Eric Eastwood's avatar
Eric Eastwood committed
53
    },
Filipa Lacerda's avatar
Filipa Lacerda committed
54
  };
Eric Eastwood's avatar
Eric Eastwood committed
55 56 57 58 59
</script>

<template>
  <div>
    <div class="sidebar-collapsed-icon">
60 61 62 63 64 65 66 67 68 69 70 71 72
      <span
        v-tooltip
        :title="notificationTooltip"
        data-container="body"
        data-placement="left"
      >
        <icon
          :name="notificationIcon"
          :size="16"
          aria-hidden="true"
          class="sidebar-item-icon is-active"
        />
      </span>
Eric Eastwood's avatar
Eric Eastwood committed
73 74 75 76
    </div>
    <span class="issuable-header-text hide-collapsed pull-left">
      {{ __('Notifications') }}
    </span>
77
    <toggle-button
Mike Greiling's avatar
Mike Greiling committed
78
      ref="toggleButton"
79 80 81 82
      class="pull-right hide-collapsed js-issuable-subscribe-button"
      :is-loading="showLoadingState"
      :value="subscribed"
      @change="toggleSubscription"
Eric Eastwood's avatar
Eric Eastwood committed
83 84 85
    />
  </div>
</template>