debian-mirror-gitlab/app/assets/javascripts/boards/models/issue.js

129 lines
3.2 KiB
JavaScript
Raw Normal View History

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 */
import Vue from 'vue';
2018-11-08 19:23:39 +05:30
import '~/vue_shared/models/label';
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) {
2018-03-17 18:26:18 +05:30
this.id = obj.id;
this.iid = obj.iid;
2017-08-17 22:00:37 +05:30
this.title = obj.title;
this.confidential = obj.confidential;
this.dueDate = obj.due_date;
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 = {};
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.milestone_id = obj.milestone_id;
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;
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);
}
2018-12-13 13:39:08 +05:30
obj.labels.forEach(label => {
2017-08-17 22:00:37 +05:30
this.labels.push(new ListLabel(label));
});
this.assignees = obj.assignees.map(a => new ListAssignee(a, defaultAvatar));
}
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) {
2017-08-17 22:00:37 +05:30
return this.labels.filter(label => label.title === findLabel.title)[0];
}
2018-12-13 13:39:08 +05:30
removeLabel(removeLabel) {
2017-08-17 22:00:37 +05:30
if (removeLabel) {
this.labels = this.labels.filter(label => removeLabel.title !== label.title);
}
}
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) {
2017-08-17 22:00:37 +05:30
return this.assignees.filter(assignee => assignee.id === findAssignee.id)[0];
}
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 = [];
}
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 : '';
2018-05-09 12:01:36 +05:30
return Vue.http.patch(`${this.path}.json`, data);
2017-08-17 22:00:37 +05:30
}
}
window.ListIssue = ListIssue;
2018-03-27 19:54:05 +05:30
export default ListIssue;