BigW Consortium Gitlab

issue.js 2.31 KB
Newer Older
1
/* eslint-disable no-unused-vars, space-before-function-paren, arrow-body-style, arrow-parens, comma-dangle, max-len */
2 3
/* global ListLabel */
/* global ListMilestone */
4
/* global ListAssignee */
5

6 7
import Vue from 'vue';

8
class ListIssue {
9
  constructor (obj, defaultAvatar) {
10
    this.globalId = obj.id;
Phil Hughes committed
11
    this.id = obj.iid;
12
    this.title = obj.title;
13
    this.confidential = obj.confidential;
14
    this.dueDate = obj.due_date;
15
    this.subscribed = obj.subscribed;
16
    this.labels = [];
17
    this.assignees = [];
Phil Hughes committed
18
    this.selected = false;
19
    this.position = obj.relative_position || Infinity;
20

21 22 23 24
    if (obj.milestone) {
      this.milestone = new ListMilestone(obj.milestone);
    }

25
    obj.labels.forEach((label) => {
26
      this.labels.push(new ListLabel(label));
27
    });
28

29
    this.assignees = obj.assignees.map(a => new ListAssignee(a, defaultAvatar));
30 31 32
  }

  addLabel (label) {
33 34
    if (!this.findLabel(label)) {
      this.labels.push(new ListLabel(label));
35 36 37 38
    }
  }

  findLabel (findLabel) {
39
    return this.labels.filter(label => label.title === findLabel.title)[0];
40 41 42
  }

  removeLabel (removeLabel) {
Phil Hughes committed
43
    if (removeLabel) {
44
      this.labels = this.labels.filter(label => removeLabel.title !== label.title);
Phil Hughes committed
45
    }
46
  }
47

48
  removeLabels (labels) {
49
    labels.forEach(this.removeLabel.bind(this));
50 51
  }

52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
  addAssignee (assignee) {
    if (!this.findAssignee(assignee)) {
      this.assignees.push(new ListAssignee(assignee));
    }
  }

  findAssignee (findAssignee) {
    return this.assignees.filter(assignee => assignee.id === findAssignee.id)[0];
  }

  removeAssignee (removeAssignee) {
    if (removeAssignee) {
      this.assignees = this.assignees.filter(assignee => assignee.id !== removeAssignee.id);
    }
  }

  removeAllAssignees () {
    this.assignees = [];
  }

72
  getLists () {
73
    return gl.issueBoards.BoardsStore.state.lists.filter(list => list.findIssue(this.id));
74
  }
75 76 77 78 79 80

  update (url) {
    const data = {
      issue: {
        milestone_id: this.milestone ? this.milestone.id : null,
        due_date: this.dueDate,
81
        assignee_ids: this.assignees.length > 0 ? this.assignees.map((u) => u.id) : [0],
82
        label_ids: this.labels.map((label) => label.id)
83 84 85
      }
    };

86 87 88 89
    if (!data.issue.label_ids.length) {
      data.issue.label_ids = [''];
    }

90 91
    return Vue.http.patch(url, data);
  }
92
}
93 94

window.ListIssue = ListIssue;