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

74 lines
1.5 KiB
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
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';
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.RemoveIssueBtn = Vue.extend({
props: {
issue: {
type: Object,
required: true,
},
list: {
type: Object,
required: true,
},
2018-03-17 18:26:18 +05:30
},
computed: {
updateUrl() {
2018-05-09 12:01:36 +05:30
return this.issue.path;
2018-03-17 18:26:18 +05:30
},
2017-08-17 22:00:37 +05:30
},
methods: {
removeIssue() {
const issue = this.issue;
const lists = issue.getLists();
2018-03-17 18:26:18 +05:30
const listLabelIds = lists.map(list => list.label.id);
2018-03-27 19:54:05 +05:30
let labelIds = issue.labels
2018-03-17 18:26:18 +05:30
.map(label => label.id)
.filter(id => !listLabelIds.includes(id));
if (labelIds.length === 0) {
labelIds = [''];
}
2018-03-27 19:54:05 +05:30
2018-03-17 18:26:18 +05:30
const data = {
issue: {
label_ids: labelIds,
},
};
2018-03-27 19:54:05 +05:30
// Post the remove data
2018-03-17 18:26:18 +05:30
Vue.http.patch(this.updateUrl, data).catch(() => {
2018-03-27 19:54:05 +05:30
Flash(__('Failed to remove issue from board, please try again.'));
2017-08-17 22:00:37 +05:30
lists.forEach((list) => {
list.addIssue(issue);
});
});
// Remove from the frontend store
lists.forEach((list) => {
list.removeIssue(issue);
});
Store.detail.issue = {};
},
},
template: `
<div
2017-09-10 17:25:29 +05:30
class="block list">
2017-08-17 22:00:37 +05:30
<button
class="btn btn-default btn-block"
type="button"
@click="removeIssue">
Remove from board
</button>
</div>
`,
});