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

83 lines
1.8 KiB
Vue
Raw Normal View History

2018-11-08 19:23:39 +05:30
<script>
2018-12-13 13:39:08 +05:30
import Vue from 'vue';
import Flash from '../../../flash';
import { __ } from '../../../locale';
import boardsStore from '../../stores/boards_store';
2018-11-08 19:23:39 +05:30
2018-12-13 13:39:08 +05:30
export default Vue.extend({
props: {
issue: {
type: Object,
required: true,
2018-11-08 19:23:39 +05:30
},
2018-12-13 13:39:08 +05:30
list: {
type: Object,
required: true,
2018-11-08 19:23:39 +05:30
},
2018-12-13 13:39:08 +05:30
},
computed: {
updateUrl() {
return this.issue.path;
},
},
methods: {
removeIssue() {
const { issue } = this;
const lists = issue.getLists();
const req = this.buildPatchRequest(issue, lists);
2018-11-08 19:23:39 +05:30
2018-12-13 13:39:08 +05:30
const data = {
issue: this.seedPatchRequest(issue, req),
};
2018-11-08 19:23:39 +05:30
2018-12-13 13:39:08 +05:30
if (data.issue.label_ids.length === 0) {
data.issue.label_ids = [''];
}
2018-11-08 19:23:39 +05:30
2018-12-13 13:39:08 +05:30
// Post the remove data
Vue.http.patch(this.updateUrl, data).catch(() => {
Flash(__('Failed to remove issue from board, please try again.'));
2018-11-08 19:23:39 +05:30
lists.forEach(list => {
2018-12-13 13:39:08 +05:30
list.addIssue(issue);
2018-11-08 19:23:39 +05:30
});
2018-12-13 13:39:08 +05:30
});
2018-11-08 19:23:39 +05:30
2018-12-13 13:39:08 +05:30
// Remove from the frontend store
lists.forEach(list => {
list.removeIssue(issue);
});
2018-11-08 19:23:39 +05:30
2018-12-13 13:39:08 +05:30
boardsStore.detail.issue = {};
},
/**
* Build the default patch request.
*/
buildPatchRequest(issue, lists) {
const listLabelIds = lists.map(list => list.label.id);
const labelIds = issue.labels.map(label => label.id).filter(id => !listLabelIds.includes(id));
2018-11-08 19:23:39 +05:30
2018-12-13 13:39:08 +05:30
return {
label_ids: labelIds,
};
},
/**
* Seed the given patch request.
*
* (This is overridden in EE)
*/
seedPatchRequest(issue, req) {
return req;
2018-11-08 19:23:39 +05:30
},
2018-12-13 13:39:08 +05:30
},
});
2018-11-08 19:23:39 +05:30
</script>
<template>
2019-02-15 15:39:39 +05:30
<div class="block list">
<button class="btn btn-default btn-block" type="button" @click="removeIssue">
2018-11-08 19:23:39 +05:30
Remove from board
</button>
</div>
</template>