diff options
author | Valery Sizov <valery@gitlab.com> | 2017-03-06 19:50:59 +0300 |
---|---|---|
committer | Valery Sizov <valery@gitlab.com> | 2017-03-06 19:50:59 +0300 |
commit | 710e4df933ba2070dcc104a18de834c23dd1e5be (patch) | |
tree | dee3817e1ddc46179cdb6e0b3008a9e94b5440d5 /app/assets/javascripts/boards/services/board_service.js | |
parent | 13caadea7a123d1dc5f3475d360cd07f1aef4acb (diff) | |
parent | b63c41e12e9e6f7e9fd1d79bedf56bd42cc17035 (diff) |
Merge branch 'master' of gitlab.com:gitlab-org/gitlab-ce into orderable-issues
Diffstat (limited to 'app/assets/javascripts/boards/services/board_service.js')
-rw-r--r-- | app/assets/javascripts/boards/services/board_service.js | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/app/assets/javascripts/boards/services/board_service.js b/app/assets/javascripts/boards/services/board_service.js new file mode 100644 index 00000000000..e54102814d6 --- /dev/null +++ b/app/assets/javascripts/boards/services/board_service.js @@ -0,0 +1,97 @@ +/* eslint-disable space-before-function-paren, comma-dangle, no-param-reassign, camelcase, max-len, no-unused-vars */ +/* global Vue */ + +class BoardService { + constructor (root, bulkUpdatePath, boardId) { + this.boards = Vue.resource(`${root}{/id}.json`, {}, { + issues: { + method: 'GET', + url: `${root}/${boardId}/issues.json` + } + }); + this.lists = Vue.resource(`${root}/${boardId}/lists{/id}`, {}, { + generate: { + method: 'POST', + url: `${root}/${boardId}/lists/generate.json` + } + }); + this.issue = Vue.resource(`${root}/${boardId}/issues{/id}`, {}); + this.issues = Vue.resource(`${root}/${boardId}/lists{/id}/issues`, {}, { + bulkUpdate: { + method: 'POST', + url: bulkUpdatePath, + }, + }); + + Vue.http.interceptors.push((request, next) => { + request.headers['X-CSRF-Token'] = $.rails.csrfToken(); + next(); + }); + } + + 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 = {}) { + const data = { id }; + Object.keys(filter).forEach((key) => { data[key] = filter[key]; }); + + return this.issues.get(data); + } + + moveIssue (id, from_list_id = null, to_list_id = null, move_before_iid = null, move_after_iid = null) { + return this.issue.update({ id }, { + from_list_id, + to_list_id, + move_before_iid, + move_after_iid, + }); + } + + newIssue (id, issue) { + return this.issues.save({ id }, { + issue + }); + } + + 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; |