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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

158 lines
4.1 KiB
Vue
Raw Normal View History

2018-03-27 19:54:05 +05:30
<script>
2021-03-11 19:13:27 +05:30
import { refreshUserMergeRequestCounts } from '~/commons/nav/user_merge_requests';
2021-09-30 23:02:18 +05:30
import createFlash from '~/flash';
2021-03-11 19:13:27 +05:30
import { __ } from '~/locale';
2018-10-15 14:42:47 +05:30
import eventHub from '~/sidebar/event_hub';
import Store from '~/sidebar/stores/sidebar_store';
2020-05-24 23:13:21 +05:30
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
2018-05-09 12:01:36 +05:30
import AssigneeTitle from './assignee_title.vue';
2018-03-27 19:54:05 +05:30
import Assignees from './assignees.vue';
2020-05-24 23:13:21 +05:30
import AssigneesRealtime from './assignees_realtime.vue';
2017-08-17 22:00:37 +05:30
export default {
name: 'SidebarAssignees',
2018-03-27 19:54:05 +05:30
components: {
AssigneeTitle,
Assignees,
2020-05-24 23:13:21 +05:30
AssigneesRealtime,
2017-08-17 22:00:37 +05:30
},
2020-05-24 23:13:21 +05:30
mixins: [glFeatureFlagsMixin()],
2018-03-17 18:26:18 +05:30
props: {
mediator: {
type: Object,
required: true,
},
field: {
type: String,
required: true,
},
signedIn: {
type: Boolean,
required: false,
default: false,
},
2018-10-15 14:42:47 +05:30
issuableType: {
type: String,
2019-12-04 20:38:33 +05:30
required: false,
2018-10-15 14:42:47 +05:30
default: 'issue',
},
2020-05-24 23:13:21 +05:30
issuableIid: {
type: String,
required: true,
},
projectPath: {
type: String,
required: true,
},
2021-06-08 01:23:25 +05:30
issuableId: {
type: Number,
required: true,
},
2021-03-11 19:13:27 +05:30
assigneeAvailabilityStatus: {
type: Object,
required: false,
default: () => ({}),
},
2018-03-17 18:26:18 +05:30
},
2018-03-27 19:54:05 +05:30
data() {
return {
store: new Store(),
loading: false,
};
},
2020-05-24 23:13:21 +05:30
computed: {
shouldEnableRealtime() {
// Note: Realtime is only available on issues right now, future support for MR wil be built later.
2022-05-07 20:08:51 +05:30
return this.issuableType === 'issue';
2020-05-24 23:13:21 +05:30
},
2021-06-08 01:23:25 +05:30
queryVariables() {
return {
iid: this.issuableIid,
fullPath: this.projectPath,
};
},
2021-01-03 14:25:43 +05:30
relativeUrlRoot() {
return gon.relative_url_root ?? '';
},
2020-05-24 23:13:21 +05:30
},
2018-03-27 19:54:05 +05:30
created() {
this.removeAssignee = this.store.removeAssignee.bind(this.store);
this.addAssignee = this.store.addAssignee.bind(this.store);
this.removeAllAssignees = this.store.removeAllAssignees.bind(this.store);
2020-11-24 15:15:51 +05:30
// Get events from deprecatedJQueryDropdown
2018-03-27 19:54:05 +05:30
eventHub.$on('sidebar.removeAssignee', this.removeAssignee);
eventHub.$on('sidebar.addAssignee', this.addAssignee);
eventHub.$on('sidebar.removeAllAssignees', this.removeAllAssignees);
eventHub.$on('sidebar.saveAssignees', this.saveAssignees);
},
beforeDestroy() {
eventHub.$off('sidebar.removeAssignee', this.removeAssignee);
eventHub.$off('sidebar.addAssignee', this.addAssignee);
eventHub.$off('sidebar.removeAllAssignees', this.removeAllAssignees);
eventHub.$off('sidebar.saveAssignees', this.saveAssignees);
2017-08-17 22:00:37 +05:30
},
methods: {
assignSelf() {
// Notify gl dropdown that we are now assigning to current user
this.$el.parentElement.dispatchEvent(new Event('assignYourself'));
this.mediator.assignYourself();
this.saveAssignees();
},
saveAssignees() {
this.loading = true;
2018-12-13 13:39:08 +05:30
this.mediator
.saveAssignees(this.field)
2019-09-30 21:07:59 +05:30
.then(() => {
2019-12-04 20:38:33 +05:30
this.loading = false;
2021-01-03 14:25:43 +05:30
this.store.resetChanging();
2019-09-30 21:07:59 +05:30
refreshUserMergeRequestCounts();
})
2017-08-17 22:00:37 +05:30
.catch(() => {
2019-12-04 20:38:33 +05:30
this.loading = false;
2021-09-30 23:02:18 +05:30
return createFlash({
message: __('Error occurred when saving assignees'),
});
2017-08-17 22:00:37 +05:30
});
},
2021-03-11 19:13:27 +05:30
exposeAvailabilityStatus(users) {
return users.map(({ username, ...rest }) => ({
...rest,
username,
availability: this.assigneeAvailabilityStatus[username] || '',
}));
},
2017-08-17 22:00:37 +05:30
},
};
2018-03-27 19:54:05 +05:30
</script>
<template>
<div>
2020-05-24 23:13:21 +05:30
<assignees-realtime
v-if="shouldEnableRealtime"
2021-04-29 21:17:54 +05:30
:issuable-type="issuableType"
2021-06-08 01:23:25 +05:30
:issuable-id="issuableId"
:query-variables="queryVariables"
2020-05-24 23:13:21 +05:30
:mediator="mediator"
/>
2018-03-27 19:54:05 +05:30
<assignee-title
:number-of-assignees="store.assignees.length"
:loading="loading || store.isFetching.assignees"
:editable="store.editable"
:show-toggle="!signedIn"
2021-01-03 14:25:43 +05:30
:changing="store.changing"
2018-03-27 19:54:05 +05:30
/>
<assignees
v-if="!store.isFetching.assignees"
2021-01-03 14:25:43 +05:30
:root-path="relativeUrlRoot"
2021-03-11 19:13:27 +05:30
:users="exposeAvailabilityStatus(store.assignees)"
2018-03-27 19:54:05 +05:30
:editable="store.editable"
2018-10-15 14:42:47 +05:30
:issuable-type="issuableType"
2018-11-08 19:23:39 +05:30
@assign-self="assignSelf"
2018-03-27 19:54:05 +05:30
/>
</div>
</template>