issue.js.es6 1.07 KB
Newer Older
1 2
class Issue {
  constructor (obj) {
Phil Hughes's avatar
Phil Hughes committed
3
    this.id = obj.iid;
4
    this.title = obj.title;
Phil Hughes's avatar
Phil Hughes committed
5 6 7 8

    if (obj.assignee) {
      this.assignee = new User(obj.assignee);
    }
9

10 11 12 13 14
    this.labels = [];

    obj.labels.forEach((label) => {
      this.labels.push(new Label(label));
    });
15 16 17 18

    this.priority = this.labels.reduce((max, label) => {
      return (label.priority < max) ? label.priority : max;
    }, Infinity);
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
  }

  addLabel (label) {
    if (label) {
      const hasLabel = this.findLabel(label);

      if (!hasLabel) {
        this.labels.push(new Label(label));
      }
    }
  }

  findLabel (findLabel) {
    return _.find(this.labels, (label) => {
      return label.title === findLabel.title;
    });
  }

  removeLabel (removeLabel) {
    if (removeLabel) {
      this.labels = _.reject(this.labels, (label) => {
        return removeLabel.title === label.title;
      });
    }
  }
44

Phil Hughes's avatar
Phil Hughes committed
45
  removeLabels (labels) {
46
    _.each(labels, this.removeLabel.bind(this));
Phil Hughes's avatar
Phil Hughes committed
47 48
  }

49 50 51 52 53
  getLists () {
    return _.filter(BoardsStore.state.lists, (list) => {
      return list.findIssue(this.id);
    });
  }
54
}