debian-mirror-gitlab/app/assets/javascripts/boards/components/board_sidebar.js

157 lines
4.5 KiB
JavaScript
Raw Normal View History

2018-12-13 13:39:08 +05:30
/* eslint-disable no-new */
2017-08-17 22:00:37 +05:30
2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2017-08-17 22:00:37 +05:30
import Vue from 'vue';
2020-04-08 14:13:33 +05:30
import { GlLabel } from '@gitlab/ui';
2019-07-31 22:56:46 +05:30
import Flash from '~/flash';
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';
2018-11-08 19:23:39 +05:30
import RemoveBtn from './sidebar/remove_issue.vue';
2018-12-13 13:39:08 +05:30
import boardsStore from '../stores/boards_store';
2019-07-31 22:56:46 +05:30
import { isScopedLabel } from '~/lib/utils/common_utils';
2017-08-17 22:00:37 +05:30
2018-12-13 13:39:08 +05:30
export default Vue.extend({
2018-11-08 19:23:39 +05:30
components: {
AssigneeTitle,
Assignees,
2020-04-08 14:13:33 +05:30
GlLabel,
2019-12-04 20:38:33 +05:30
SidebarEpicsSelect: () =>
import('ee_component/sidebar/components/sidebar_item_epics_select.vue'),
2018-11-08 19:23:39 +05:30
RemoveBtn,
Subscriptions,
2019-07-31 22:56:46 +05:30
TimeTracker,
2018-11-08 19:23:39 +05:30
},
2017-08-17 22:00:37 +05:30
props: {
2018-11-08 19:23:39 +05:30
currentUser: {
type: Object,
default: () => ({}),
},
2017-08-17 22:00:37 +05:30
},
data() {
return {
2018-12-13 13:39:08 +05:30
detail: boardsStore.detail,
2017-08-17 22:00:37 +05:30
issue: {},
list: {},
loadingAssignees: false,
2019-09-30 21:07:59 +05:30
timeTrackingLimitToHours: boardsStore.timeTracking.limitToHours,
2017-08-17 22:00:37 +05:30
};
},
computed: {
2018-12-13 13:39:08 +05:30
showSidebar() {
2017-08-17 22:00:37 +05:30
return Object.keys(this.issue).length;
},
2017-09-10 17:25:29 +05:30
milestoneTitle() {
2019-07-31 22:56:46 +05:30
return this.issue.milestone ? this.issue.milestone.title : __('No Milestone');
2017-09-10 17:25:29 +05:30
},
canRemove() {
return !this.list.preset;
},
2018-11-18 11:00:15 +05:30
hasLabels() {
return this.issue.labels && this.issue.labels.length;
},
labelDropdownTitle() {
2018-12-13 13:39:08 +05:30
return this.hasLabels
? sprintf(__('%{firstLabel} +%{labelCount} more'), {
firstLabel: this.issue.labels[0].title,
labelCount: this.issue.labels.length - 1,
})
: __('Label');
2018-11-18 11:00:15 +05:30
},
selectedLabels() {
return this.hasLabels ? this.issue.labels.map(l => l.title).join(',') : '';
2018-12-13 13:39:08 +05:30
},
2020-04-08 14:13:33 +05:30
helpLink() {
return boardsStore.scopedLabels.helpLink;
},
2017-08-17 22:00:37 +05:30
},
watch: {
detail: {
2018-12-13 13:39:08 +05:30
handler() {
2017-08-17 22:00:37 +05:30
if (this.issue.id !== this.detail.issue.id) {
$('.block.assignee')
.find('input:not(.js-vue)[name="issue[assignee_ids][]"]')
.each((i, el) => {
$(el).remove();
});
$('.js-issue-board-sidebar', this.$el).each((i, el) => {
2018-12-13 13:39:08 +05:30
$(el)
.data('glDropdown')
.clearMenu();
2017-08-17 22:00:37 +05:30
});
}
this.issue = this.detail.issue;
this.list = this.detail.list;
},
2018-12-13 13:39:08 +05:30
deep: true,
2017-08-17 22:00:37 +05:30
},
},
2018-12-13 13:39:08 +05:30
created() {
2018-11-08 19:23:39 +05:30
// Get events from glDropdown
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);
},
2018-12-13 13:39:08 +05:30
mounted() {
2018-11-08 19:23:39 +05:30
new IssuableContext(this.currentUser);
new MilestoneSelect();
new DueDateSelectors();
new LabelsSelect();
new Sidebar();
},
2017-08-17 22:00:37 +05:30
methods: {
2018-12-13 13:39:08 +05:30
closeSidebar() {
2017-08-17 22:00:37 +05:30
this.detail.issue = {};
},
2018-12-13 13:39:08 +05:30
assignSelf() {
2017-08-17 22:00:37 +05:30
// 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-12-13 13:39:08 +05:30
removeAssignee(a) {
boardsStore.detail.issue.removeAssignee(a);
2017-08-17 22:00:37 +05:30
},
2018-12-13 13:39:08 +05:30
addAssignee(a) {
boardsStore.detail.issue.addAssignee(a);
2017-08-17 22:00:37 +05:30
},
2018-12-13 13:39:08 +05:30
removeAllAssignees() {
boardsStore.detail.issue.removeAllAssignees();
2017-08-17 22:00:37 +05:30
},
2018-12-13 13:39:08 +05:30
saveAssignees() {
2017-08-17 22:00:37 +05:30
this.loadingAssignees = true;
2018-12-13 13:39:08 +05:30
boardsStore.detail.issue
.update()
2017-08-17 22:00:37 +05:30
.then(() => {
this.loadingAssignees = false;
})
.catch(() => {
this.loadingAssignees = false;
2018-03-27 19:54:05 +05:30
Flash(__('An error occurred while saving assignees'));
2017-08-17 22:00:37 +05:30
});
},
2019-07-31 22:56:46 +05:30
showScopedLabels(label) {
return boardsStore.scopedLabels.enabled && isScopedLabel(label);
},
2017-08-17 22:00:37 +05:30
},
});