debian-mirror-gitlab/app/assets/javascripts/boards/services/board_service.js

94 lines
2 KiB
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
/* eslint-disable space-before-function-paren, comma-dangle, no-param-reassign, camelcase, max-len, no-unused-vars */
import Vue from 'vue';
2016-09-13 17:45:13 +05:30
2017-08-17 22:00:37 +05:30
class BoardService {
constructor (root, bulkUpdatePath, boardId) {
this.boards = Vue.resource(`${root}{/id}.json`, {}, {
issues: {
method: 'GET',
url: `${root}/${boardId}/issues.json`
}
});
2016-11-03 12:29:30 +05:30
this.lists = Vue.resource(`${root}/${boardId}/lists{/id}`, {}, {
2016-09-13 17:45:13 +05:30
generate: {
method: 'POST',
2016-11-03 12:29:30 +05:30
url: `${root}/${boardId}/lists/generate.json`
2016-09-13 17:45:13 +05:30
}
});
2016-11-03 12:29:30 +05:30
this.issue = Vue.resource(`${root}/${boardId}/issues{/id}`, {});
2017-08-17 22:00:37 +05:30
this.issues = Vue.resource(`${root}/${boardId}/lists{/id}/issues`, {}, {
bulkUpdate: {
method: 'POST',
url: bulkUpdatePath,
},
});
2016-09-13 17:45:13 +05:30
}
all () {
return this.lists.get();
}
generateDefaultLists () {
return this.lists.generate({});
}
createList (label_id) {
return this.lists.save({}, {
list: {
label_id
}
});
}
updateList (id, position) {
return this.lists.update({ id }, {
list: {
position
}
});
}
destroyList (id) {
return this.lists.delete({ id });
}
getIssuesForList (id, filter = {}) {
2017-08-17 22:00:37 +05:30
const data = { id };
2016-09-13 17:45:13 +05:30
Object.keys(filter).forEach((key) => { data[key] = filter[key]; });
return this.issues.get(data);
}
2017-08-17 22:00:37 +05:30
moveIssue (id, from_list_id = null, to_list_id = null, move_before_iid = null, move_after_iid = null) {
2016-09-13 17:45:13 +05:30
return this.issue.update({ id }, {
from_list_id,
2017-08-17 22:00:37 +05:30
to_list_id,
move_before_iid,
move_after_iid,
2016-09-13 17:45:13 +05:30
});
}
2016-11-03 12:29:30 +05:30
newIssue (id, issue) {
return this.issues.save({ id }, {
issue
});
}
2017-08-17 22:00:37 +05:30
getBacklog(data) {
return this.boards.issues(data);
}
bulkUpdate(issueIds, extraData = {}) {
const data = {
update: Object.assign(extraData, {
issuable_ids: issueIds.join(','),
}),
};
return this.issues.bulkUpdate(data);
}
}
window.BoardService = BoardService;