gitlab-org--gitlab-foss/app/assets/javascripts/boards/components/board_sidebar.js

130 lines
3.7 KiB
JavaScript
Raw Normal View History

2018-06-16 13:20:30 +00:00
/* eslint-disable comma-dangle, no-new */
import $ from 'jquery';
2017-03-17 17:21:25 +00:00
import Vue from 'vue';
import Flash from '../../flash';
import { __ } from '../../locale';
2017-12-15 12:57:08 +00:00
import Sidebar from '../../right_sidebar';
import eventHub from '../../sidebar/event_hub';
2018-02-27 17:44:10 +00:00
import assigneeTitle from '../../sidebar/components/assignees/assignee_title.vue';
2018-02-06 16:30:35 +00:00
import assignees from '../../sidebar/components/assignees/assignees.vue';
2017-10-18 11:31:01 +00:00
import DueDateSelectors from '../../due_date_select';
import removeBtn from './sidebar/remove_issue.vue';
import IssuableContext from '../../issuable_context';
import LabelsSelect from '../../labels_select';
import subscriptions from '../../sidebar/components/subscriptions/subscriptions.vue';
2017-12-28 20:07:05 +00:00
import MilestoneSelect from '../../milestone_select';
2017-04-10 23:52:46 +00:00
const Store = gl.issueBoards.BoardsStore;
2016-10-04 14:27:02 +00:00
2017-04-10 23:52:46 +00:00
window.gl = window.gl || {};
window.gl.issueBoards = window.gl.issueBoards || {};
2016-10-04 14:27:02 +00:00
2017-04-10 23:52:46 +00:00
gl.issueBoards.BoardSidebar = Vue.extend({
2018-06-11 09:49:47 +00:00
components: {
assigneeTitle,
assignees,
removeBtn,
2018-06-11 09:49:47 +00:00
subscriptions,
},
2017-04-10 23:52:46 +00:00
props: {
2018-06-11 09:49:47 +00:00
currentUser: {
type: Object,
default: () => ({}),
},
2017-04-10 23:52:46 +00:00
},
data() {
return {
detail: Store.detail,
issue: {},
list: {},
loadingAssignees: false,
2017-04-10 23:52:46 +00:00
};
},
computed: {
showSidebar () {
return Object.keys(this.issue).length;
},
milestoneTitle() {
return this.issue.milestone ? this.issue.milestone.title : 'No Milestone';
},
canRemove() {
return !this.list.preset;
},
2017-04-10 23:52:46 +00:00
},
watch: {
detail: {
handler () {
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) => {
$(el).data('glDropdown').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;
},
deep: true
2016-10-05 07:49:40 +00:00
},
2017-04-10 23:52:46 +00:00
},
2018-06-11 09:49:47 +00:00
created () {
// 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);
},
mounted () {
new IssuableContext(this.currentUser);
new MilestoneSelect();
new DueDateSelectors();
new LabelsSelect();
new Sidebar();
},
2017-04-10 23:52:46 +00:00
methods: {
closeSidebar () {
this.detail.issue = {};
},
assignSelf () {
// Notify gl dropdown that we are now assigning to current user
this.$refs.assigneeBlock.dispatchEvent(new Event('assignYourself'));
this.addAssignee(this.currentUser);
this.saveAssignees();
},
removeAssignee (a) {
gl.issueBoards.BoardsStore.detail.issue.removeAssignee(a);
},
addAssignee (a) {
gl.issueBoards.BoardsStore.detail.issue.addAssignee(a);
},
removeAllAssignees () {
gl.issueBoards.BoardsStore.detail.issue.removeAllAssignees();
},
saveAssignees () {
this.loadingAssignees = true;
gl.issueBoards.BoardsStore.detail.issue.update()
.then(() => {
this.loadingAssignees = false;
})
.catch(() => {
this.loadingAssignees = false;
Flash(__('An error occurred while saving assignees'));
});
},
},
2017-04-10 23:52:46 +00:00
});