remove_issue.vue 1.8 KB
Newer Older
1
<script>
2
import axios from '~/lib/utils/axios_utils';
3 4 5
import Flash from '../../../flash';
import { __ } from '../../../locale';
import boardsStore from '../../stores/boards_store';
6

7
export default {
8 9 10 11
  props: {
    issue: {
      type: Object,
      required: true,
12
    },
13 14 15
    list: {
      type: Object,
      required: true,
16
    },
17 18 19 20 21 22 23 24 25 26 27
  },
  computed: {
    updateUrl() {
      return this.issue.path;
    },
  },
  methods: {
    removeIssue() {
      const { issue } = this;
      const lists = issue.getLists();
      const req = this.buildPatchRequest(issue, lists);
F
Felipe Artur 已提交
28

29 30 31
      const data = {
        issue: this.seedPatchRequest(issue, req),
      };
32

33 34 35
      if (data.issue.label_ids.length === 0) {
        data.issue.label_ids = [''];
      }
36

37
      // Post the remove data
38
      axios.patch(this.updateUrl, data).catch(() => {
39
        Flash(__('Failed to remove issue from board, please try again.'));
40

41
        lists.forEach(list => {
42
          list.addIssue(issue);
43
        });
44
      });
P
Phil Hughes 已提交
45

46 47 48 49
      // Remove from the frontend store
      lists.forEach(list => {
        list.removeIssue(issue);
      });
50

51
      boardsStore.clearDetailIssue();
52 53 54 55 56 57 58 59
    },
    /**
     * 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));
60

61 62 63 64 65 66 67 68 69 70 71
      return {
        label_ids: labelIds,
      };
    },
    /**
     * Seed the given patch request.
     *
     * (This is overridden in EE)
     */
    seedPatchRequest(issue, req) {
      return req;
P
Phil Hughes 已提交
72
    },
73
  },
74
};
75 76
</script>
<template>
M
Mike Greiling 已提交
77 78
  <div class="block list">
    <button class="btn btn-default btn-block" type="button" @click="removeIssue">
79
      {{ __('Remove from board') }}
80 81 82
    </button>
  </div>
</template>