gitlab-org--gitlab-foss/app/assets/javascripts/boards/models/issue.js

108 lines
2.6 KiB
JavaScript
Raw Normal View History

/* eslint-disable no-unused-vars, space-before-function-paren, arrow-body-style, arrow-parens, comma-dangle, max-len */
/* global ListLabel */
/* global ListMilestone */
/* global ListAssignee */
2017-03-17 13:21:25 -04:00
import Vue from 'vue';
2016-08-10 13:29:55 -04:00
class ListIssue {
2017-05-04 11:33:25 -04:00
constructor (obj, defaultAvatar) {
this.id = obj.id;
this.iid = obj.iid;
2016-08-01 09:18:30 -04:00
this.title = obj.title;
this.confidential = obj.confidential;
2016-10-05 03:49:40 -04:00
this.dueDate = obj.due_date;
this.subscribed = obj.subscribed;
2016-08-17 07:02:24 -04:00
this.labels = [];
this.assignees = [];
this.selected = false;
this.position = obj.relative_position || Infinity;
this.isFetching = {
subscriptions: true,
};
this.sidebarInfoEndpoint = obj.issue_sidebar_endpoint;
this.toggleSubscriptionEndpoint = obj.toggle_subscription_endpoint;
2016-08-05 03:44:26 -04:00
2016-10-05 03:49:40 -04:00
if (obj.milestone) {
this.milestone = new ListMilestone(obj.milestone);
}
2016-08-17 07:02:24 -04:00
obj.labels.forEach((label) => {
2016-08-10 13:29:55 -04:00
this.labels.push(new ListLabel(label));
2016-08-17 07:02:24 -04:00
});
2017-05-05 10:19:58 -04:00
this.assignees = obj.assignees.map(a => new ListAssignee(a, defaultAvatar));
2016-08-01 09:18:30 -04:00
}
addLabel (label) {
2016-08-17 07:02:24 -04:00
if (!this.findLabel(label)) {
this.labels.push(new ListLabel(label));
2016-08-01 09:18:30 -04:00
}
}
findLabel (findLabel) {
return this.labels.filter(label => label.title === findLabel.title)[0];
2016-08-01 09:18:30 -04:00
}
removeLabel (removeLabel) {
2016-08-17 08:57:36 -04:00
if (removeLabel) {
this.labels = this.labels.filter(label => removeLabel.title !== label.title);
2016-08-17 08:57:36 -04:00
}
2016-08-01 09:18:30 -04:00
}
2016-08-05 13:27:12 -04:00
removeLabels (labels) {
2016-08-17 07:02:24 -04:00
labels.forEach(this.removeLabel.bind(this));
2016-08-05 13:27:12 -04:00
}
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 = [];
}
getLists () {
return gl.issueBoards.BoardsStore.state.lists.filter(list => list.findIssue(this.id));
}
updateData(newData) {
Object.assign(this, newData);
}
setFetchingState(key, value) {
this.isFetching[key] = value;
}
update (url) {
const data = {
issue: {
milestone_id: this.milestone ? this.milestone.id : null,
due_date: this.dueDate,
assignee_ids: this.assignees.length > 0 ? this.assignees.map((u) => u.id) : [0],
label_ids: this.labels.map((label) => label.id)
}
};
if (!data.issue.label_ids.length) {
data.issue.label_ids = [''];
}
return Vue.http.patch(url, data);
}
2016-08-01 09:18:30 -04:00
}
window.ListIssue = ListIssue;