2021-01-03 14:25:43 +05:30
|
|
|
/* eslint-disable class-methods-use-this */
|
2018-11-20 20:47:30 +05:30
|
|
|
import { __ } from '~/locale';
|
2019-09-04 21:01:54 +05:30
|
|
|
import ListLabel from './label';
|
|
|
|
import ListAssignee from './assignee';
|
2020-10-24 23:57:45 +05:30
|
|
|
import { deprecatedCreateFlash as flash } from '~/flash';
|
2018-12-13 13:39:08 +05:30
|
|
|
import boardsStore from '../stores/boards_store';
|
2019-07-31 22:56:46 +05:30
|
|
|
import ListMilestone from './milestone';
|
2020-10-24 23:57:45 +05:30
|
|
|
import 'ee_else_ce/boards/models/issue';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
const TYPES = {
|
|
|
|
backlog: {
|
|
|
|
isPreset: true,
|
|
|
|
isExpandable: true,
|
|
|
|
isBlank: false,
|
|
|
|
},
|
|
|
|
closed: {
|
|
|
|
isPreset: true,
|
|
|
|
isExpandable: true,
|
|
|
|
isBlank: false,
|
|
|
|
},
|
|
|
|
blank: {
|
|
|
|
isPreset: true,
|
|
|
|
isExpandable: false,
|
|
|
|
isBlank: true,
|
|
|
|
},
|
2019-09-30 21:07:59 +05:30
|
|
|
default: {
|
|
|
|
// includes label, assignee, and milestone lists
|
|
|
|
isPreset: false,
|
|
|
|
isExpandable: true,
|
|
|
|
isBlank: false,
|
|
|
|
},
|
2018-11-08 19:23:39 +05:30
|
|
|
};
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
class List {
|
2020-04-08 14:13:33 +05:30
|
|
|
constructor(obj) {
|
2017-08-17 22:00:37 +05:30
|
|
|
this.id = obj.id;
|
|
|
|
this.position = obj.position;
|
2020-05-24 23:13:21 +05:30
|
|
|
this.title = (obj.list_type || obj.listType) === 'backlog' ? __('Open') : obj.title;
|
|
|
|
this.type = obj.list_type || obj.listType;
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
const typeInfo = this.getTypeInfo(this.type);
|
2019-09-04 21:01:54 +05:30
|
|
|
this.preset = Boolean(typeInfo.isPreset);
|
|
|
|
this.isExpandable = Boolean(typeInfo.isExpandable);
|
2019-12-04 20:38:33 +05:30
|
|
|
this.isExpanded = !obj.collapsed;
|
2017-08-17 22:00:37 +05:30
|
|
|
this.page = 1;
|
|
|
|
this.loading = true;
|
|
|
|
this.loadingMore = false;
|
2019-12-26 22:10:19 +05:30
|
|
|
this.issues = obj.issues || [];
|
2020-11-24 15:15:51 +05:30
|
|
|
this.issuesSize = obj.issuesSize || obj.issuesCount || 0;
|
2020-05-24 23:13:21 +05:30
|
|
|
this.maxIssueCount = obj.maxIssueCount || obj.max_issue_count || 0;
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
if (obj.label) {
|
|
|
|
this.label = new ListLabel(obj.label);
|
2020-05-24 23:13:21 +05:30
|
|
|
} else if (obj.user || obj.assignee) {
|
|
|
|
this.assignee = new ListAssignee(obj.user || obj.assignee);
|
2018-11-08 19:23:39 +05:30
|
|
|
this.title = this.assignee.name;
|
2019-09-30 21:07:59 +05:30
|
|
|
} else if (IS_EE && obj.milestone) {
|
2019-07-31 22:56:46 +05:30
|
|
|
this.milestone = new ListMilestone(obj.milestone);
|
|
|
|
this.title = this.milestone.title;
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
// doNotFetchIssues is a temporary workaround until issues are fetched using GraphQL on issue boards
|
|
|
|
// Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/229416
|
|
|
|
if (!typeInfo.isBlank && this.id && !obj.doNotFetchIssues) {
|
2017-08-17 22:00:37 +05:30
|
|
|
this.getIssues().catch(() => {
|
|
|
|
// TODO: handle request error
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
guid() {
|
2018-11-08 19:23:39 +05:30
|
|
|
const s4 = () =>
|
|
|
|
Math.floor((1 + Math.random()) * 0x10000)
|
|
|
|
.toString(16)
|
|
|
|
.substring(1);
|
2017-08-17 22:00:37 +05:30
|
|
|
return `${s4()}${s4()}-${s4()}-${s4()}-${s4()}-${s4()}${s4()}${s4()}`;
|
|
|
|
}
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
save() {
|
2020-03-13 15:44:24 +05:30
|
|
|
return boardsStore.saveList(this);
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
destroy() {
|
2020-06-23 00:09:42 +05:30
|
|
|
boardsStore.destroy(this);
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
update() {
|
2020-06-23 00:09:42 +05:30
|
|
|
return boardsStore.updateListFunc(this);
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
nextPage() {
|
2020-06-23 00:09:42 +05:30
|
|
|
return boardsStore.goToNextPage(this);
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
getIssues(emptyIssues = true) {
|
2020-05-24 23:13:21 +05:30
|
|
|
return boardsStore.getListIssues(this, emptyIssues);
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
newIssue(issue) {
|
2020-06-23 00:09:42 +05:30
|
|
|
return boardsStore.newListIssue(this, issue);
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
addMultipleIssues(issues, listFrom, newIndex) {
|
2020-03-13 15:44:24 +05:30
|
|
|
boardsStore.addMultipleListIssues(this, issues, listFrom, newIndex);
|
2019-12-21 20:55:43 +05:30
|
|
|
}
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
addIssue(issue, listFrom, newIndex) {
|
2020-05-24 23:13:21 +05:30
|
|
|
boardsStore.addListIssue(this, issue, listFrom, newIndex);
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
moveIssue(issue, oldIndex, newIndex, moveBeforeId, moveAfterId) {
|
2020-06-23 00:09:42 +05:30
|
|
|
boardsStore.moveListIssues(this, issue, oldIndex, newIndex, moveBeforeId, moveAfterId);
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
moveMultipleIssues({ issues, oldIndicies, newIndex, moveBeforeId, moveAfterId }) {
|
2020-01-01 13:55:28 +05:30
|
|
|
boardsStore
|
2020-07-28 23:09:34 +05:30
|
|
|
.moveListMultipleIssues({
|
|
|
|
list: this,
|
|
|
|
issues,
|
|
|
|
oldIndicies,
|
|
|
|
newIndex,
|
2019-12-21 20:55:43 +05:30
|
|
|
moveBeforeId,
|
|
|
|
moveAfterId,
|
|
|
|
})
|
|
|
|
.catch(() => flash(__('Something went wrong while moving issues.')));
|
|
|
|
}
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
updateIssueLabel(issue, listFrom, moveBeforeId, moveAfterId) {
|
2020-01-01 13:55:28 +05:30
|
|
|
boardsStore.moveIssue(issue.id, listFrom.id, this.id, moveBeforeId, moveAfterId).catch(() => {
|
|
|
|
// TODO: handle request error
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
updateMultipleIssues(issues, listFrom, moveBeforeId, moveAfterId) {
|
2020-01-01 13:55:28 +05:30
|
|
|
boardsStore
|
2019-12-21 20:55:43 +05:30
|
|
|
.moveMultipleIssues({
|
|
|
|
ids: issues.map(issue => issue.id),
|
|
|
|
fromListId: listFrom.id,
|
|
|
|
toListId: this.id,
|
|
|
|
moveBeforeId,
|
|
|
|
moveAfterId,
|
|
|
|
})
|
|
|
|
.catch(() => flash(__('Something went wrong while moving issues.')));
|
|
|
|
}
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
findIssue(id) {
|
2020-06-23 00:09:42 +05:30
|
|
|
return boardsStore.findListIssue(this, id);
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
removeMultipleIssues(removeIssues) {
|
2020-06-23 00:09:42 +05:30
|
|
|
return boardsStore.removeListMultipleIssues(this, removeIssues);
|
2019-12-21 20:55:43 +05:30
|
|
|
}
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
removeIssue(removeIssue) {
|
2020-06-23 00:09:42 +05:30
|
|
|
return boardsStore.removeListIssues(this, removeIssue);
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
getTypeInfo(type) {
|
2019-09-30 21:07:59 +05:30
|
|
|
return TYPES[type] || TYPES.default;
|
2018-11-08 19:23:39 +05:30
|
|
|
}
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
onNewIssueResponse(issue, data) {
|
2020-07-28 23:09:34 +05:30
|
|
|
boardsStore.onNewListIssueResponse(this, issue, data);
|
2018-11-08 19:23:39 +05:30
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
window.List = List;
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
export default List;
|