2016-08-01 09:18:30 -04:00
|
|
|
class List {
|
|
|
|
constructor (obj) {
|
|
|
|
this.id = obj.id;
|
2016-08-16 07:57:59 -04:00
|
|
|
this._uid = this.guid();
|
2016-08-04 11:16:50 -04:00
|
|
|
this.position = obj.position;
|
2016-08-01 09:18:30 -04:00
|
|
|
this.title = obj.title;
|
2016-08-04 11:16:50 -04:00
|
|
|
this.type = obj.list_type;
|
2016-08-15 04:57:01 -04:00
|
|
|
this.filters = gl.issueBoards.BoardsStore.state.filters;
|
2016-08-05 09:58:42 -04:00
|
|
|
this.page = 1;
|
2016-08-05 09:36:12 -04:00
|
|
|
this.loading = true;
|
2016-08-12 11:58:34 -04:00
|
|
|
this.loadingMore = false;
|
2016-08-04 12:24:53 -04:00
|
|
|
this.issues = [];
|
2016-08-01 09:18:30 -04:00
|
|
|
|
|
|
|
if (obj.label) {
|
2016-08-10 13:29:55 -04:00
|
|
|
this.label = new ListLabel(obj.label);
|
2016-08-01 09:18:30 -04:00
|
|
|
}
|
|
|
|
|
2016-08-05 09:36:12 -04:00
|
|
|
if (this.type !== 'blank' && this.id) {
|
2016-08-05 09:24:27 -04:00
|
|
|
this.getIssues();
|
2016-08-01 09:18:30 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-16 07:57:59 -04:00
|
|
|
guid() {
|
|
|
|
const s4 = () => {
|
|
|
|
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
|
|
|
|
}
|
|
|
|
return `${s4()}${s4()}-${s4()}-${s4()}-${s4()}-${s4()}${s4()}${s4()}`;
|
|
|
|
}
|
|
|
|
|
2016-08-05 08:40:35 -04:00
|
|
|
save () {
|
2016-08-08 06:18:38 -04:00
|
|
|
return gl.boardService.createList(this.label.id)
|
2016-08-05 08:40:35 -04:00
|
|
|
.then((resp) => {
|
|
|
|
const data = resp.json();
|
|
|
|
|
|
|
|
this.id = data.id;
|
|
|
|
this.type = data.list_type;
|
|
|
|
this.position = data.position;
|
2016-08-05 09:36:12 -04:00
|
|
|
|
2016-08-08 06:18:38 -04:00
|
|
|
return this.getIssues();
|
2016-08-05 08:40:35 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-08-04 11:16:50 -04:00
|
|
|
destroy () {
|
2016-08-05 09:00:06 -04:00
|
|
|
if (this.type !== 'blank') {
|
2016-08-15 11:06:19 -04:00
|
|
|
gl.issueBoards.BoardsStore.state.lists.$remove(this);
|
2016-08-15 04:57:01 -04:00
|
|
|
gl.issueBoards.BoardsStore.updateNewListDropdown(this.id);
|
2016-08-08 09:30:38 -04:00
|
|
|
|
2016-08-05 09:00:06 -04:00
|
|
|
gl.boardService.destroyList(this.id);
|
|
|
|
}
|
2016-08-04 11:16:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
update () {
|
2016-08-16 12:32:38 -04:00
|
|
|
gl.boardService.updateList(this.id, this.position);
|
2016-08-04 11:16:50 -04:00
|
|
|
}
|
|
|
|
|
2016-08-05 09:58:42 -04:00
|
|
|
nextPage () {
|
2016-08-16 05:14:40 -04:00
|
|
|
if (Math.floor(this.issues.length / 20) === this.page) {
|
2016-08-05 09:58:42 -04:00
|
|
|
this.page++;
|
|
|
|
|
|
|
|
return this.getIssues(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-04 11:16:50 -04:00
|
|
|
canSearch () {
|
|
|
|
return this.type === 'backlog';
|
|
|
|
}
|
|
|
|
|
2016-08-05 09:58:42 -04:00
|
|
|
getIssues (emptyIssues = true) {
|
2016-08-11 04:51:52 -04:00
|
|
|
const filters = this.filters;
|
|
|
|
let data = { page: this.page };
|
|
|
|
|
|
|
|
Object.keys(filters).forEach((key) => { data[key] = filters[key]; });
|
2016-08-05 13:27:12 -04:00
|
|
|
|
|
|
|
if (this.label) {
|
2016-08-11 04:51:52 -04:00
|
|
|
data.label_name = data.label_name.filter((label) => {
|
|
|
|
return label !== this.label.title;
|
2016-08-05 13:27:12 -04:00
|
|
|
});
|
|
|
|
}
|
2016-08-05 09:36:12 -04:00
|
|
|
|
2016-08-05 09:58:42 -04:00
|
|
|
if (emptyIssues) {
|
|
|
|
this.loading = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return gl.boardService.getIssuesForList(this.id, data)
|
2016-08-05 09:24:27 -04:00
|
|
|
.then((resp) => {
|
|
|
|
const data = resp.json();
|
|
|
|
this.loading = false;
|
|
|
|
|
2016-08-05 09:58:42 -04:00
|
|
|
if (emptyIssues) {
|
|
|
|
this.issues = [];
|
|
|
|
}
|
|
|
|
|
2016-08-05 09:24:27 -04:00
|
|
|
this.createIssues(data);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
createIssues (data) {
|
2016-08-11 04:51:52 -04:00
|
|
|
for (let i = 0, dataLength = data.length; i < dataLength; i++) {
|
|
|
|
const issueObj = data[i];
|
2016-08-10 13:29:55 -04:00
|
|
|
this.issues.push(new ListIssue(issueObj));
|
2016-08-11 04:51:52 -04:00
|
|
|
}
|
2016-08-05 09:24:27 -04:00
|
|
|
}
|
|
|
|
|
2016-08-05 08:40:35 -04:00
|
|
|
addIssue (issue, listFrom) {
|
|
|
|
this.issues.push(issue);
|
2016-08-01 09:18:30 -04:00
|
|
|
|
|
|
|
issue.addLabel(this.label);
|
2016-08-05 08:40:35 -04:00
|
|
|
|
2016-08-05 09:00:06 -04:00
|
|
|
gl.boardService.moveIssue(issue.id, listFrom.id, this.id);
|
2016-08-01 09:18:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
findIssue (id) {
|
2016-08-11 04:51:52 -04:00
|
|
|
return this.issues.filter((issue) => {
|
2016-08-01 09:18:30 -04:00
|
|
|
return issue.id === id;
|
2016-08-11 04:51:52 -04:00
|
|
|
})[0];
|
2016-08-01 09:18:30 -04:00
|
|
|
}
|
|
|
|
|
2016-08-05 13:27:12 -04:00
|
|
|
removeIssue (removeIssue) {
|
2016-08-11 04:51:52 -04:00
|
|
|
this.issues = this.issues.filter((issue) => {
|
2016-08-01 09:18:30 -04:00
|
|
|
const matchesRemove = removeIssue.id === issue.id;
|
|
|
|
|
|
|
|
if (matchesRemove) {
|
2016-08-05 13:27:12 -04:00
|
|
|
issue.removeLabel(this.label);
|
2016-08-01 09:18:30 -04:00
|
|
|
}
|
|
|
|
|
2016-08-11 04:51:52 -04:00
|
|
|
return !matchesRemove;
|
2016-08-01 09:18:30 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|