summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/boards/models/issue.js
blob: bc23639df6755adfb9558bdbf18838274d4f1f57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* eslint-disable no-unused-vars */
/* global ListLabel */
/* global ListMilestone */
/* global ListAssignee */

import axios from '~/lib/utils/axios_utils';
import './label';
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import boardsStore from '../stores/boards_store';
import IssueProject from './project';

class ListIssue {
  constructor(obj) {
    this.subscribed = obj.subscribed;
    this.labels = [];
    this.assignees = [];
    this.selected = false;
    this.position = obj.position || obj.relative_position || obj.relativePosition || Infinity;
    this.isFetching = {
      subscriptions: true,
    };
    this.closed = obj.closed;
    this.isLoading = {};

    this.refreshData(obj);
  }

  refreshData(obj) {
    boardsStore.refreshIssueData(this, obj);
  }

  addLabel(label) {
    boardsStore.addIssueLabel(this, label);
  }

  findLabel(findLabel) {
    return boardsStore.findIssueLabel(this, findLabel);
  }

  removeLabel(removeLabel) {
    boardsStore.removeIssueLabel(this, removeLabel);
  }

  removeLabels(labels) {
    boardsStore.removeIssueLabels(this, labels);
  }

  addAssignee(assignee) {
    boardsStore.addIssueAssignee(this, assignee);
  }

  findAssignee(findAssignee) {
    return boardsStore.findIssueAssignee(this, findAssignee);
  }

  removeAssignee(removeAssignee) {
    boardsStore.removeIssueAssignee(this, removeAssignee);
  }

  removeAllAssignees() {
    boardsStore.removeAllIssueAssignees(this);
  }

  addMilestone(milestone) {
    boardsStore.addIssueMilestone(this, milestone);
  }

  removeMilestone(removeMilestone) {
    boardsStore.removeIssueMilestone(this, removeMilestone);
  }

  getLists() {
    return boardsStore.state.lists.filter((list) => list.findIssue(this.id));
  }

  updateData(newData) {
    boardsStore.updateIssueData(this, newData);
  }

  setFetchingState(key, value) {
    boardsStore.setIssueFetchingState(this, key, value);
  }

  setLoadingState(key, value) {
    boardsStore.setIssueLoadingState(this, key, value);
  }

  update() {
    return boardsStore.updateIssue(this);
  }
}

window.ListIssue = ListIssue;

export default ListIssue;