debian-mirror-gitlab/app/assets/javascripts/notes/services/notes_service.js

52 lines
1.5 KiB
JavaScript
Raw Normal View History

2018-03-17 18:26:18 +05:30
import Vue from 'vue';
2019-02-15 15:39:39 +05:30
import Api from '~/api';
2018-03-17 18:26:18 +05:30
import VueResource from 'vue-resource';
2018-03-27 19:54:05 +05:30
import * as constants from '../constants';
2018-03-17 18:26:18 +05:30
Vue.use(VueResource);
export default {
2018-12-13 13:39:08 +05:30
fetchDiscussions(endpoint, filter) {
const config = filter !== undefined ? { params: { notes_filter: filter } } : null;
return Vue.http.get(endpoint, config);
2018-03-17 18:26:18 +05:30
},
deleteNote(endpoint) {
return Vue.http.delete(endpoint);
},
replyToDiscussion(endpoint, data) {
return Vue.http.post(endpoint, data, { emulateJSON: true });
},
updateNote(endpoint, data) {
return Vue.http.put(endpoint, data, { emulateJSON: true });
},
createNewNote(endpoint, data) {
return Vue.http.post(endpoint, data, { emulateJSON: true });
},
2018-03-27 19:54:05 +05:30
toggleResolveNote(endpoint, isResolved) {
const { RESOLVE_NOTE_METHOD_NAME, UNRESOLVE_NOTE_METHOD_NAME } = constants;
2018-11-08 19:23:39 +05:30
const method = isResolved ? UNRESOLVE_NOTE_METHOD_NAME : RESOLVE_NOTE_METHOD_NAME;
2018-03-27 19:54:05 +05:30
return Vue.http[method](endpoint);
},
2018-03-17 18:26:18 +05:30
poll(data = {}) {
2018-03-27 19:54:05 +05:30
const endpoint = data.notesData.notesPath;
2018-11-08 19:23:39 +05:30
const { lastFetchedAt } = data;
2018-03-17 18:26:18 +05:30
const options = {
headers: {
2018-03-27 19:54:05 +05:30
'X-Last-Fetched-At': lastFetchedAt ? `${lastFetchedAt}` : undefined,
2018-03-17 18:26:18 +05:30
},
};
return Vue.http.get(endpoint, options);
},
toggleAward(endpoint, data) {
return Vue.http.post(endpoint, data, { emulateJSON: true });
},
2018-03-27 19:54:05 +05:30
toggleIssueState(endpoint, data) {
return Vue.http.put(endpoint, data);
},
2019-02-15 15:39:39 +05:30
applySuggestion(id) {
return Api.applySuggestion(id);
},
2018-03-17 18:26:18 +05:30
};