2018-03-17 18:26:18 +05:30
|
|
|
import axios from '../../lib/utils/axios_utils';
|
|
|
|
import { mergeUrlParams } from '../../lib/utils/url_utility';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
export default class BoardService {
|
|
|
|
constructor({ boardsEndpoint, listsEndpoint, bulkUpdatePath, boardId }) {
|
|
|
|
this.boardsEndpoint = boardsEndpoint;
|
|
|
|
this.boardId = boardId;
|
|
|
|
this.listsEndpoint = listsEndpoint;
|
|
|
|
this.listsEndpointGenerate = `${listsEndpoint}/generate.json`;
|
|
|
|
this.bulkUpdatePath = bulkUpdatePath;
|
|
|
|
}
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
generateBoardsPath(id) {
|
|
|
|
return `${this.boardsEndpoint}${id ? `/${id}` : ''}.json`;
|
|
|
|
}
|
|
|
|
|
|
|
|
generateIssuesPath(id) {
|
|
|
|
return `${this.listsEndpoint}${id ? `/${id}` : ''}/issues`;
|
2016-09-13 17:45:13 +05:30
|
|
|
}
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
static generateIssuePath(boardId, id) {
|
2018-12-13 13:39:08 +05:30
|
|
|
return `${gon.relative_url_root}/-/boards/${boardId ? `${boardId}` : ''}/issues${
|
|
|
|
id ? `/${id}` : ''
|
|
|
|
}`;
|
2016-09-13 17:45:13 +05:30
|
|
|
}
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
all() {
|
|
|
|
return axios.get(this.listsEndpoint);
|
2016-09-13 17:45:13 +05:30
|
|
|
}
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
generateDefaultLists() {
|
|
|
|
return axios.post(this.listsEndpointGenerate, {});
|
|
|
|
}
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
createList(entityId, entityType) {
|
|
|
|
const list = {
|
|
|
|
[entityType]: entityId,
|
|
|
|
};
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
return axios.post(this.listsEndpoint, {
|
2018-11-08 19:23:39 +05:30
|
|
|
list,
|
2016-09-13 17:45:13 +05:30
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
updateList(id, position) {
|
|
|
|
return axios.put(`${this.listsEndpoint}/${id}`, {
|
2016-09-13 17:45:13 +05:30
|
|
|
list: {
|
2018-03-17 18:26:18 +05:30
|
|
|
position,
|
|
|
|
},
|
2016-09-13 17:45:13 +05:30
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
destroyList(id) {
|
|
|
|
return axios.delete(`${this.listsEndpoint}/${id}`);
|
2016-09-13 17:45:13 +05:30
|
|
|
}
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
getIssuesForList(id, filter = {}) {
|
2017-08-17 22:00:37 +05:30
|
|
|
const data = { id };
|
2018-12-13 13:39:08 +05:30
|
|
|
Object.keys(filter).forEach(key => {
|
|
|
|
data[key] = filter[key];
|
|
|
|
});
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
return axios.get(mergeUrlParams(data, this.generateIssuesPath(id)));
|
2016-09-13 17:45:13 +05:30
|
|
|
}
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
moveIssue(id, fromListId = null, toListId = null, moveBeforeId = null, moveAfterId = null) {
|
|
|
|
return axios.put(BoardService.generateIssuePath(this.boardId, id), {
|
|
|
|
from_list_id: fromListId,
|
|
|
|
to_list_id: toListId,
|
|
|
|
move_before_id: moveBeforeId,
|
|
|
|
move_after_id: moveAfterId,
|
2016-09-13 17:45:13 +05:30
|
|
|
});
|
|
|
|
}
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
newIssue(id, issue) {
|
|
|
|
return axios.post(this.generateIssuesPath(id), {
|
|
|
|
issue,
|
2016-11-03 12:29:30 +05:30
|
|
|
});
|
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
getBacklog(data) {
|
2018-12-13 13:39:08 +05:30
|
|
|
return axios.get(
|
|
|
|
mergeUrlParams(data, `${gon.relative_url_root}/-/boards/${this.boardId}/issues.json`),
|
|
|
|
);
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
bulkUpdate(issueIds, extraData = {}) {
|
|
|
|
const data = {
|
|
|
|
update: Object.assign(extraData, {
|
|
|
|
issuable_ids: issueIds.join(','),
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
return axios.post(this.bulkUpdatePath, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static getIssueInfo(endpoint) {
|
|
|
|
return axios.get(endpoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
static toggleIssueSubscription(endpoint) {
|
|
|
|
return axios.post(endpoint);
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
window.BoardService = BoardService;
|