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

130 lines
3.7 KiB
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
/* eslint-disable comma-dangle, space-before-function-paren, no-new */
import Vue from 'vue';
2018-03-17 18:26:18 +05:30
import Flash from '../../flash';
2018-03-27 19:54:05 +05:30
import { __ } from '../../locale';
2018-03-17 18:26:18 +05:30
import Sidebar from '../../right_sidebar';
2017-08-17 22:00:37 +05:30
import eventHub from '../../sidebar/event_hub';
2018-03-17 18:26:18 +05:30
import assigneeTitle from '../../sidebar/components/assignees/assignee_title';
2018-03-27 19:54:05 +05:30
import assignees from '../../sidebar/components/assignees/assignees.vue';
2018-03-17 18:26:18 +05:30
import DueDateSelectors from '../../due_date_select';
2017-09-10 17:25:29 +05:30
import './sidebar/remove_issue';
2018-03-17 18:26:18 +05:30
import IssuableContext from '../../issuable_context';
import LabelsSelect from '../../labels_select';
import subscriptions from '../../sidebar/components/subscriptions/subscriptions.vue';
import MilestoneSelect from '../../milestone_select';
2017-08-17 22:00:37 +05:30
const Store = gl.issueBoards.BoardsStore;
window.gl = window.gl || {};
window.gl.issueBoards = window.gl.issueBoards || {};
gl.issueBoards.BoardSidebar = Vue.extend({
props: {
currentUser: Object
},
data() {
return {
detail: Store.detail,
issue: {},
list: {},
loadingAssignees: false,
};
},
computed: {
showSidebar () {
return Object.keys(this.issue).length;
},
2017-09-10 17:25:29 +05:30
milestoneTitle() {
return this.issue.milestone ? this.issue.milestone.title : 'No Milestone';
},
canRemove() {
return !this.list.preset;
},
2017-08-17 22:00:37 +05:30
},
watch: {
detail: {
handler () {
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) => {
$(el).data('glDropdown').clearMenu();
});
}
this.issue = this.detail.issue;
this.list = this.detail.list;
this.$nextTick(() => {
this.endpoint = this.$refs.assigneeDropdown.dataset.issueUpdate;
});
},
deep: true
},
},
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(this.endpoint)
.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
});
},
},
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();
2018-03-17 18:26:18 +05:30
new DueDateSelectors();
2017-08-17 22:00:37 +05:30
new LabelsSelect();
new Sidebar();
},
components: {
2018-03-17 18:26:18 +05:30
assigneeTitle,
assignees,
2017-08-17 22:00:37 +05:30
removeBtn: gl.issueBoards.RemoveIssueBtn,
2018-03-17 18:26:18 +05:30
subscriptions,
2017-08-17 22:00:37 +05:30
},
});