2017-01-12 00:55:11 -05:00
|
|
|
/* eslint-disable no-unused-vars, space-before-function-paren, arrow-body-style, arrow-parens, comma-dangle, max-len */
|
2016-12-13 22:01:05 -05:00
|
|
|
/* global ListLabel */
|
|
|
|
/* global ListMilestone */
|
2017-05-04 08:11:15 -04:00
|
|
|
/* global ListAssignee */
|
2016-12-13 22:01:05 -05:00
|
|
|
|
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) {
|
2017-09-06 01:02:30 -04:00
|
|
|
this.id = obj.id;
|
|
|
|
this.iid = obj.iid;
|
2016-08-01 09:18:30 -04:00
|
|
|
this.title = obj.title;
|
2016-08-10 12:19:56 -04:00
|
|
|
this.confidential = obj.confidential;
|
2016-10-05 03:49:40 -04:00
|
|
|
this.dueDate = obj.due_date;
|
2016-10-07 04:38:35 -04:00
|
|
|
this.subscribed = obj.subscribed;
|
2016-08-17 07:02:24 -04:00
|
|
|
this.labels = [];
|
2017-05-04 08:11:15 -04:00
|
|
|
this.assignees = [];
|
2017-01-24 07:20:49 -05:00
|
|
|
this.selected = false;
|
2017-02-07 03:56:33 -05:00
|
|
|
this.position = obj.relative_position || Infinity;
|
2017-11-14 01:05:40 -05:00
|
|
|
this.isFetching = {
|
|
|
|
subscriptions: true,
|
|
|
|
};
|
2017-12-03 21:43:10 -05:00
|
|
|
this.isLoading = {};
|
2017-11-14 01:05:40 -05:00
|
|
|
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-04 08:11:15 -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) {
|
2017-01-12 00:55:11 -05:00
|
|
|
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) {
|
2017-01-12 00:55:11 -05:00
|
|
|
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 08:40:35 -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
|
|
|
}
|
|
|
|
|
2017-05-04 08:11:15 -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 = [];
|
|
|
|
}
|
|
|
|
|
2016-08-05 08:40:35 -04:00
|
|
|
getLists () {
|
2017-01-12 00:55:11 -05:00
|
|
|
return gl.issueBoards.BoardsStore.state.lists.filter(list => list.findIssue(this.id));
|
2016-08-05 08:40:35 -04:00
|
|
|
}
|
2016-10-05 07:20:59 -04:00
|
|
|
|
2017-11-14 01:05:40 -05:00
|
|
|
updateData(newData) {
|
|
|
|
Object.assign(this, newData);
|
|
|
|
}
|
|
|
|
|
|
|
|
setFetchingState(key, value) {
|
|
|
|
this.isFetching[key] = value;
|
|
|
|
}
|
|
|
|
|
2017-12-03 21:43:10 -05:00
|
|
|
setLoadingState(key, value) {
|
|
|
|
this.isLoading[key] = value;
|
|
|
|
}
|
|
|
|
|
2016-10-05 07:20:59 -04:00
|
|
|
update (url) {
|
|
|
|
const data = {
|
|
|
|
issue: {
|
|
|
|
milestone_id: this.milestone ? this.milestone.id : null,
|
|
|
|
due_date: this.dueDate,
|
2017-05-04 08:11:15 -04:00
|
|
|
assignee_ids: this.assignees.length > 0 ? this.assignees.map((u) => u.id) : [0],
|
2017-01-12 00:55:11 -05:00
|
|
|
label_ids: this.labels.map((label) => label.id)
|
2016-10-05 07:20:59 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-10-06 04:03:10 -04:00
|
|
|
if (!data.issue.label_ids.length) {
|
|
|
|
data.issue.label_ids = [''];
|
|
|
|
}
|
|
|
|
|
2016-10-05 07:20:59 -04:00
|
|
|
return Vue.http.patch(url, data);
|
|
|
|
}
|
2016-08-01 09:18:30 -04:00
|
|
|
}
|
2016-12-14 01:51:53 -05:00
|
|
|
|
|
|
|
window.ListIssue = ListIssue;
|