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

109 lines
2.4 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 */
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 {
2020-04-08 14:13:33 +05:30
constructor(obj) {
2017-08-17 22:00:37 +05:30
this.subscribed = obj.subscribed;
this.labels = [];
this.assignees = [];
this.selected = false;
2020-05-24 23:13:21 +05:30
this.position = obj.position || obj.relative_position || Infinity;
2018-03-17 18:26:18 +05:30
this.isFetching = {
subscriptions: true,
};
2020-04-08 14:13:33 +05:30
this.closed = obj.closed;
2018-03-17 18:26:18 +05:30
this.isLoading = {};
2019-12-04 20:38:33 +05:30
2020-04-08 14:13:33 +05:30
this.refreshData(obj);
2019-12-04 20:38:33 +05:30
}
2020-04-08 14:13:33 +05:30
refreshData(obj) {
boardsStore.refreshIssueData(this, obj);
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() {
2020-05-24 23:13:21 +05:30
return boardsStore.updateIssue(this);
2017-08-17 22:00:37 +05:30
}
}
window.ListIssue = ListIssue;
2018-03-27 19:54:05 +05:30
export default ListIssue;