debian-mirror-gitlab/app/assets/javascripts/sidebar/components/subscriptions/subscriptions.vue

102 lines
2.5 KiB
Vue
Raw Normal View History

2018-03-17 18:26:18 +05:30
<script>
2018-12-13 13:39:08 +05:30
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';
import eventHub from '../../event_hub';
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
const ICON_ON = 'notifications';
const ICON_OFF = 'notifications-off';
const LABEL_ON = __('Notifications on');
const LABEL_OFF = __('Notifications off');
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
export default {
directives: {
tooltip,
},
components: {
icon,
toggleButton,
},
props: {
loading: {
type: Boolean,
required: false,
default: false,
2018-03-17 18:26:18 +05:30
},
2018-12-13 13:39:08 +05:30
subscribed: {
type: Boolean,
required: false,
default: null,
2018-03-17 18:26:18 +05:30
},
2018-12-13 13:39:08 +05:30
id: {
type: Number,
required: false,
default: null,
2018-03-17 18:26:18 +05:30
},
2018-12-13 13:39:08 +05:30
},
computed: {
showLoadingState() {
return this.subscribed === null;
2018-03-17 18:26:18 +05:30
},
2018-12-13 13:39:08 +05:30
notificationIcon() {
return this.subscribed ? ICON_ON : ICON_OFF;
},
notificationTooltip() {
return this.subscribed ? LABEL_ON : LABEL_OFF;
},
},
methods: {
/**
* We need to emit this event on both component & eventHub
* for 2 dependencies;
*
* 1. eventHub: This component is used in Issue Boards sidebar
* where component template is part of HAML
* and event listeners are tied to app's eventHub.
* 2. Component: This compone is also used in Epics in EE
* where listeners are tied to component event.
*/
toggleSubscription() {
// App's eventHub event emission.
eventHub.$emit('toggleSubscription', this.id);
2018-10-15 14:42:47 +05:30
2018-12-13 13:39:08 +05:30
// Component event emission.
this.$emit('toggleSubscription', this.id);
},
onClickCollapsedIcon() {
this.$emit('toggleSidebar');
2018-03-17 18:26:18 +05:30
},
2018-12-13 13:39:08 +05:30
},
};
2018-03-17 18:26:18 +05:30
</script>
<template>
<div>
2019-02-13 22:33:31 +05:30
<div class="sidebar-collapsed-icon" @click="onClickCollapsedIcon">
2018-03-17 18:26:18 +05:30
<span
v-tooltip
:title="notificationTooltip"
data-container="body"
data-placement="left"
2018-11-08 19:23:39 +05:30
data-boundary="viewport"
2018-03-17 18:26:18 +05:30
>
<icon
:name="notificationIcon"
:size="16"
aria-hidden="true"
class="sidebar-item-icon is-active"
/>
</span>
</div>
2019-02-13 22:33:31 +05:30
<span class="issuable-header-text hide-collapsed float-left"> {{ __('Notifications') }} </span>
2018-03-17 18:26:18 +05:30
<toggle-button
ref="toggleButton"
:is-loading="showLoadingState"
:value="subscribed"
2018-11-08 19:23:39 +05:30
class="float-right hide-collapsed js-issuable-subscribe-button"
2018-03-17 18:26:18 +05:30
@change="toggleSubscription"
/>
</div>
</template>