2018-12-13 13:39:08 +05:30
|
|
|
/* eslint-disable no-unused-vars */
|
2017-08-17 22:00:37 +05:30
|
|
|
/* global ListLabel */
|
|
|
|
/* global ListMilestone */
|
|
|
|
/* global ListAssignee */
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2019-09-04 21:01:54 +05:30
|
|
|
import './label';
|
2019-09-30 21:07:59 +05:30
|
|
|
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
|
2018-03-27 19:54:05 +05:30
|
|
|
import IssueProject from './project';
|
2018-12-13 13:39:08 +05:30
|
|
|
import boardsStore from '../stores/boards_store';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
class ListIssue {
|
2018-12-13 13:39:08 +05:30
|
|
|
constructor(obj, defaultAvatar) {
|
2017-08-17 22:00:37 +05:30
|
|
|
this.subscribed = obj.subscribed;
|
|
|
|
this.labels = [];
|
|
|
|
this.assignees = [];
|
|
|
|
this.selected = false;
|
|
|
|
this.position = obj.relative_position || Infinity;
|
2018-03-17 18:26:18 +05:30
|
|
|
this.isFetching = {
|
|
|
|
subscriptions: true,
|
|
|
|
};
|
|
|
|
this.isLoading = {};
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
this.refreshData(obj, defaultAvatar);
|
|
|
|
}
|
|
|
|
|
|
|
|
refreshData(obj, defaultAvatar) {
|
|
|
|
this.id = obj.id;
|
|
|
|
this.iid = obj.iid;
|
|
|
|
this.title = obj.title;
|
|
|
|
this.confidential = obj.confidential;
|
|
|
|
this.dueDate = obj.due_date;
|
2018-03-17 18:26:18 +05:30
|
|
|
this.sidebarInfoEndpoint = obj.issue_sidebar_endpoint;
|
2018-05-09 12:01:36 +05:30
|
|
|
this.referencePath = obj.reference_path;
|
|
|
|
this.path = obj.real_path;
|
2018-03-17 18:26:18 +05:30
|
|
|
this.toggleSubscriptionEndpoint = obj.toggle_subscription_endpoint;
|
2018-03-27 19:54:05 +05:30
|
|
|
this.project_id = obj.project_id;
|
2018-12-13 13:39:08 +05:30
|
|
|
this.timeEstimate = obj.time_estimate;
|
|
|
|
this.assignableLabelsEndpoint = obj.assignable_labels_endpoint;
|
2020-03-13 15:44:24 +05:30
|
|
|
this.blocked = obj.blocked;
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
if (obj.project) {
|
|
|
|
this.project = new IssueProject(obj.project);
|
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
if (obj.milestone) {
|
|
|
|
this.milestone = new ListMilestone(obj.milestone);
|
2019-07-31 22:56:46 +05:30
|
|
|
this.milestone_id = obj.milestone.id;
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
if (obj.labels) {
|
|
|
|
this.labels = obj.labels.map(label => new ListLabel(label));
|
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
if (obj.assignees) {
|
|
|
|
this.assignees = obj.assignees.map(a => new ListAssignee(a, defaultAvatar));
|
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
addLabel(label) {
|
2017-08-17 22:00:37 +05:30
|
|
|
if (!this.findLabel(label)) {
|
|
|
|
this.labels.push(new ListLabel(label));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
findLabel(findLabel) {
|
2019-02-15 15:39:39 +05:30
|
|
|
return this.labels.find(label => label.id === findLabel.id);
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
removeLabel(removeLabel) {
|
2017-08-17 22:00:37 +05:30
|
|
|
if (removeLabel) {
|
2019-02-15 15:39:39 +05:30
|
|
|
this.labels = this.labels.filter(label => removeLabel.id !== label.id);
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
removeLabels(labels) {
|
2017-08-17 22:00:37 +05:30
|
|
|
labels.forEach(this.removeLabel.bind(this));
|
|
|
|
}
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
addAssignee(assignee) {
|
2017-08-17 22:00:37 +05:30
|
|
|
if (!this.findAssignee(assignee)) {
|
|
|
|
this.assignees.push(new ListAssignee(assignee));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
findAssignee(findAssignee) {
|
2019-02-15 15:39:39 +05:30
|
|
|
return this.assignees.find(assignee => assignee.id === findAssignee.id);
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
removeAssignee(removeAssignee) {
|
2017-08-17 22:00:37 +05:30
|
|
|
if (removeAssignee) {
|
|
|
|
this.assignees = this.assignees.filter(assignee => assignee.id !== removeAssignee.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
removeAllAssignees() {
|
2017-08-17 22:00:37 +05:30
|
|
|
this.assignees = [];
|
|
|
|
}
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
addMilestone(milestone) {
|
|
|
|
const miletoneId = this.milestone ? this.milestone.id : null;
|
2019-09-30 21:07:59 +05:30
|
|
|
if (IS_EE && milestone.id !== miletoneId) {
|
2019-07-31 22:56:46 +05:30
|
|
|
this.milestone = new ListMilestone(milestone);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
removeMilestone(removeMilestone) {
|
2019-09-30 21:07:59 +05:30
|
|
|
if (IS_EE && removeMilestone && removeMilestone.id === this.milestone.id) {
|
2019-07-31 22:56:46 +05:30
|
|
|
this.milestone = {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
getLists() {
|
|
|
|
return boardsStore.state.lists.filter(list => list.findIssue(this.id));
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
updateData(newData) {
|
|
|
|
Object.assign(this, newData);
|
|
|
|
}
|
|
|
|
|
|
|
|
setFetchingState(key, value) {
|
|
|
|
this.isFetching[key] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
setLoadingState(key, value) {
|
|
|
|
this.isLoading[key] = value;
|
|
|
|
}
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
update() {
|
2017-08-17 22:00:37 +05:30
|
|
|
const data = {
|
|
|
|
issue: {
|
|
|
|
milestone_id: this.milestone ? this.milestone.id : null,
|
|
|
|
due_date: this.dueDate,
|
2018-12-13 13:39:08 +05:30
|
|
|
assignee_ids: this.assignees.length > 0 ? this.assignees.map(u => u.id) : [0],
|
|
|
|
label_ids: this.labels.map(label => label.id),
|
|
|
|
},
|
2017-08-17 22:00:37 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
if (!data.issue.label_ids.length) {
|
|
|
|
data.issue.label_ids = [''];
|
|
|
|
}
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
const projectPath = this.project ? this.project.path : '';
|
2019-12-04 20:38:33 +05:30
|
|
|
return axios.patch(`${this.path}.json`, data).then(({ data: body = {} } = {}) => {
|
2019-07-07 11:18:12 +05:30
|
|
|
/**
|
|
|
|
* Since post implementation of Scoped labels, server can reject
|
|
|
|
* same key-ed labels. To keep the UI and server Model consistent,
|
|
|
|
* we're just assigning labels that server echo's back to us when we
|
|
|
|
* PATCH the said object.
|
|
|
|
*/
|
|
|
|
if (body) {
|
2019-07-31 22:56:46 +05:30
|
|
|
this.labels = convertObjectPropsToCamelCase(body.labels, { deep: true });
|
2019-07-07 11:18:12 +05:30
|
|
|
}
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
window.ListIssue = ListIssue;
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
export default ListIssue;
|