BigW Consortium Gitlab

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

6 7
import Vue from 'vue';

8
class ListIssue {
9
  constructor (obj) {
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 = [];
Phil Hughes committed
17
    this.selected = false;
Phil Hughes committed
18
    this.assignee = false;
19
    this.position = obj.relative_position || Infinity;
20 21

    if (obj.assignee) {
22
      this.assignee = new ListUser(obj.assignee);
23
    }
24

25 26 27 28
    if (obj.milestone) {
      this.milestone = new ListMilestone(obj.milestone);
    }

29
    obj.labels.forEach((label) => {
30
      this.labels.push(new ListLabel(label));
31
    });
32 33 34
  }

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

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

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

50
  removeLabels (labels) {
51
    labels.forEach(this.removeLabel.bind(this));
52 53
  }

54
  getLists () {
55
    return gl.issueBoards.BoardsStore.state.lists.filter(list => list.findIssue(this.id));
56
  }
57 58 59 60 61 62 63

  update (url) {
    const data = {
      issue: {
        milestone_id: this.milestone ? this.milestone.id : null,
        due_date: this.dueDate,
        assignee_id: this.assignee ? this.assignee.id : null,
64
        label_ids: this.labels.map((label) => label.id)
65 66 67
      }
    };

68 69 70 71
    if (!data.issue.label_ids.length) {
      data.issue.label_ids = [''];
    }

72 73
    return Vue.http.patch(url, data);
  }
74
}
75 76

window.ListIssue = ListIssue;