2021-01-27 15:09:15 +00:00
|
|
|
// This is a true violation of @gitlab/no-runtime-template-compiler, as it
|
|
|
|
// relies on app/views/shared/boards/components/_sidebar.html.haml for its
|
|
|
|
// template.
|
|
|
|
/* eslint-disable no-new, @gitlab/no-runtime-template-compiler */
|
2016-12-14 03:01:05 +00:00
|
|
|
|
2018-03-09 20:18:59 +00:00
|
|
|
import $ from 'jquery';
|
2017-03-17 17:21:25 +00:00
|
|
|
import Vue from 'vue';
|
2020-02-25 15:08:50 +00:00
|
|
|
import { GlLabel } from '@gitlab/ui';
|
2020-08-20 09:09:55 +00:00
|
|
|
import { deprecatedCreateFlash as Flash } from '~/flash';
|
2019-04-09 10:39:42 +00:00
|
|
|
import { sprintf, __ } from '~/locale';
|
|
|
|
import Sidebar from '~/right_sidebar';
|
|
|
|
import eventHub from '~/sidebar/event_hub';
|
|
|
|
import DueDateSelectors from '~/due_date_select';
|
|
|
|
import IssuableContext from '~/issuable_context';
|
|
|
|
import LabelsSelect from '~/labels_select';
|
|
|
|
import AssigneeTitle from '~/sidebar/components/assignees/assignee_title.vue';
|
|
|
|
import Assignees from '~/sidebar/components/assignees/assignees.vue';
|
|
|
|
import Subscriptions from '~/sidebar/components/subscriptions/subscriptions.vue';
|
|
|
|
import TimeTracker from '~/sidebar/components/time_tracking/time_tracker.vue';
|
|
|
|
import MilestoneSelect from '~/milestone_select';
|
2019-04-15 09:58:30 +00:00
|
|
|
import { isScopedLabel } from '~/lib/utils/common_utils';
|
2021-02-01 15:08:56 +00:00
|
|
|
import boardsStore from '../stores/boards_store';
|
|
|
|
import RemoveBtn from './sidebar/remove_issue.vue';
|
2016-12-14 03:01:05 +00:00
|
|
|
|
2018-10-10 17:08:43 +00:00
|
|
|
export default Vue.extend({
|
2018-06-11 09:49:47 +00:00
|
|
|
components: {
|
2018-06-25 09:06:04 +00:00
|
|
|
AssigneeTitle,
|
|
|
|
Assignees,
|
2020-02-25 15:08:50 +00:00
|
|
|
GlLabel,
|
2019-08-15 16:19:25 +00:00
|
|
|
SidebarEpicsSelect: () =>
|
|
|
|
import('ee_component/sidebar/components/sidebar_item_epics_select.vue'),
|
2018-06-25 09:06:04 +00:00
|
|
|
RemoveBtn,
|
|
|
|
Subscriptions,
|
2019-04-09 10:39:42 +00:00
|
|
|
TimeTracker,
|
2018-06-11 09:49:47 +00:00
|
|
|
},
|
2017-04-10 23:52:46 +00:00
|
|
|
props: {
|
2018-06-11 09:49:47 +00:00
|
|
|
currentUser: {
|
|
|
|
type: Object,
|
|
|
|
default: () => ({}),
|
2020-03-18 15:09:45 +00:00
|
|
|
required: false,
|
2018-06-11 09:49:47 +00:00
|
|
|
},
|
2017-04-10 23:52:46 +00:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2018-10-10 17:08:43 +00:00
|
|
|
detail: boardsStore.detail,
|
2017-04-10 23:52:46 +00:00
|
|
|
issue: {},
|
|
|
|
list: {},
|
2017-05-04 12:11:15 +00:00
|
|
|
loadingAssignees: false,
|
2019-06-11 10:40:01 +00:00
|
|
|
timeTrackingLimitToHours: boardsStore.timeTracking.limitToHours,
|
2017-04-10 23:52:46 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
2018-10-30 20:28:31 +00:00
|
|
|
showSidebar() {
|
2017-04-10 23:52:46 +00:00
|
|
|
return Object.keys(this.issue).length;
|
2017-05-02 21:38:40 +00:00
|
|
|
},
|
2017-05-03 22:21:14 +00:00
|
|
|
milestoneTitle() {
|
2020-05-12 21:08:14 +00:00
|
|
|
return this.issue.milestone ? this.issue.milestone.title : __('No milestone');
|
2017-07-03 07:44:58 +00:00
|
|
|
},
|
|
|
|
canRemove() {
|
2020-06-01 18:08:07 +00:00
|
|
|
return !this.list?.preset;
|
2017-07-03 07:44:58 +00:00
|
|
|
},
|
2018-08-07 19:29:53 +00:00
|
|
|
hasLabels() {
|
|
|
|
return this.issue.labels && this.issue.labels.length;
|
|
|
|
},
|
|
|
|
labelDropdownTitle() {
|
2018-10-30 20:28:31 +00:00
|
|
|
return this.hasLabels
|
|
|
|
? sprintf(__('%{firstLabel} +%{labelCount} more'), {
|
|
|
|
firstLabel: this.issue.labels[0].title,
|
|
|
|
labelCount: this.issue.labels.length - 1,
|
|
|
|
})
|
|
|
|
: __('Label');
|
2018-08-07 19:29:53 +00:00
|
|
|
},
|
|
|
|
selectedLabels() {
|
2020-12-23 21:10:24 +00:00
|
|
|
return this.hasLabels ? this.issue.labels.map((l) => l.title).join(',') : '';
|
2018-10-30 20:28:31 +00:00
|
|
|
},
|
2017-04-10 23:52:46 +00:00
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
detail: {
|
2018-10-30 20:28:31 +00:00
|
|
|
handler() {
|
2017-04-10 23:52:46 +00:00
|
|
|
if (this.issue.id !== this.detail.issue.id) {
|
2017-05-17 15:26:52 +00:00
|
|
|
$('.block.assignee')
|
|
|
|
.find('input:not(.js-vue)[name="issue[assignee_ids][]"]')
|
|
|
|
.each((i, el) => {
|
|
|
|
$(el).remove();
|
|
|
|
});
|
|
|
|
|
2017-04-10 23:52:46 +00:00
|
|
|
$('.js-issue-board-sidebar', this.$el).each((i, el) => {
|
2020-12-23 12:10:26 +00:00
|
|
|
$(el).data('deprecatedJQueryDropdown').clearMenu();
|
2016-10-05 07:49:40 +00:00
|
|
|
});
|
|
|
|
}
|
2017-04-10 23:52:46 +00:00
|
|
|
|
|
|
|
this.issue = this.detail.issue;
|
|
|
|
this.list = this.detail.list;
|
|
|
|
},
|
2018-10-30 20:28:31 +00:00
|
|
|
deep: true,
|
2016-10-05 07:49:40 +00:00
|
|
|
},
|
2017-04-10 23:52:46 +00:00
|
|
|
},
|
2018-10-30 20:28:31 +00:00
|
|
|
created() {
|
2020-08-24 18:10:19 +00:00
|
|
|
// Get events from deprecatedJQueryDropdown
|
2018-06-11 09:49:47 +00:00
|
|
|
eventHub.$on('sidebar.removeAssignee', this.removeAssignee);
|
|
|
|
eventHub.$on('sidebar.addAssignee', this.addAssignee);
|
|
|
|
eventHub.$on('sidebar.removeAllAssignees', this.removeAllAssignees);
|
|
|
|
eventHub.$on('sidebar.saveAssignees', this.saveAssignees);
|
2020-04-09 12:09:24 +00:00
|
|
|
eventHub.$on('sidebar.closeAll', this.closeSidebar);
|
2018-06-11 09:49:47 +00:00
|
|
|
},
|
|
|
|
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);
|
2020-04-09 12:09:24 +00:00
|
|
|
eventHub.$off('sidebar.closeAll', this.closeSidebar);
|
2018-06-11 09:49:47 +00:00
|
|
|
},
|
2018-10-30 20:28:31 +00:00
|
|
|
mounted() {
|
2018-06-11 09:49:47 +00:00
|
|
|
new IssuableContext(this.currentUser);
|
|
|
|
new MilestoneSelect();
|
|
|
|
new DueDateSelectors();
|
|
|
|
new LabelsSelect();
|
|
|
|
new Sidebar();
|
|
|
|
},
|
2017-04-10 23:52:46 +00:00
|
|
|
methods: {
|
2018-10-30 20:28:31 +00:00
|
|
|
closeSidebar() {
|
2017-04-10 23:52:46 +00:00
|
|
|
this.detail.issue = {};
|
2017-05-04 12:11:15 +00:00
|
|
|
},
|
2018-10-30 20:28:31 +00:00
|
|
|
assignSelf() {
|
2017-05-04 12:11:15 +00:00
|
|
|
// Notify gl dropdown that we are now assigning to current user
|
|
|
|
this.$refs.assigneeBlock.dispatchEvent(new Event('assignYourself'));
|
|
|
|
|
|
|
|
this.addAssignee(this.currentUser);
|
|
|
|
this.saveAssignees();
|
|
|
|
},
|
2018-10-30 20:28:31 +00:00
|
|
|
removeAssignee(a) {
|
2018-10-10 17:08:43 +00:00
|
|
|
boardsStore.detail.issue.removeAssignee(a);
|
2017-05-04 12:11:15 +00:00
|
|
|
},
|
2018-10-30 20:28:31 +00:00
|
|
|
addAssignee(a) {
|
2018-10-10 17:08:43 +00:00
|
|
|
boardsStore.detail.issue.addAssignee(a);
|
2017-05-04 12:11:15 +00:00
|
|
|
},
|
2018-10-30 20:28:31 +00:00
|
|
|
removeAllAssignees() {
|
2018-10-10 17:08:43 +00:00
|
|
|
boardsStore.detail.issue.removeAllAssignees();
|
2017-05-04 12:11:15 +00:00
|
|
|
},
|
2018-10-30 20:28:31 +00:00
|
|
|
saveAssignees() {
|
2017-05-04 12:11:15 +00:00
|
|
|
this.loadingAssignees = true;
|
|
|
|
|
2018-10-30 20:28:31 +00:00
|
|
|
boardsStore.detail.issue
|
|
|
|
.update()
|
2017-05-04 12:11:15 +00:00
|
|
|
.then(() => {
|
|
|
|
this.loadingAssignees = false;
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
this.loadingAssignees = false;
|
2018-02-12 20:28:57 +00:00
|
|
|
Flash(__('An error occurred while saving assignees'));
|
2017-05-04 12:11:15 +00:00
|
|
|
});
|
|
|
|
},
|
2019-04-15 09:58:30 +00:00
|
|
|
showScopedLabels(label) {
|
|
|
|
return boardsStore.scopedLabels.enabled && isScopedLabel(label);
|
|
|
|
},
|
2017-05-04 12:11:15 +00:00
|
|
|
},
|
2017-04-10 23:52:46 +00:00
|
|
|
});
|