debian-mirror-gitlab/app/assets/javascripts/diff_notes/services/resolve.js.es6

89 lines
2.3 KiB
JavaScript
Raw Normal View History

2016-09-13 17:45:13 +05:30
((w) => {
class ResolveServiceClass {
constructor() {
this.noteResource = Vue.resource('notes{/noteId}/resolve');
this.discussionResource = Vue.resource('merge_requests{/mergeRequestId}/discussions{/discussionId}/resolve');
}
setCSRF() {
Vue.http.headers.common['X-CSRF-Token'] = $.rails.csrfToken();
}
2016-10-01 15:18:49 +05:30
prepareRequest(root) {
2016-09-13 17:45:13 +05:30
this.setCSRF();
2016-10-01 15:18:49 +05:30
Vue.http.options.root = root;
2016-09-13 17:45:13 +05:30
}
2016-10-01 15:18:49 +05:30
resolve(projectPath, noteId) {
this.prepareRequest(projectPath);
2016-09-13 17:45:13 +05:30
return this.noteResource.save({ noteId }, {});
}
2016-10-01 15:18:49 +05:30
unresolve(projectPath, noteId) {
this.prepareRequest(projectPath);
2016-09-13 17:45:13 +05:30
return this.noteResource.delete({ noteId }, {});
}
2016-10-01 15:18:49 +05:30
toggleResolveForDiscussion(projectPath, mergeRequestId, discussionId) {
2016-09-13 17:45:13 +05:30
const discussion = CommentsStore.state[discussionId],
isResolved = discussion.isResolved();
let promise;
if (isResolved) {
2016-10-01 15:18:49 +05:30
promise = this.unResolveAll(projectPath, mergeRequestId, discussionId);
2016-09-13 17:45:13 +05:30
} else {
2016-10-01 15:18:49 +05:30
promise = this.resolveAll(projectPath, mergeRequestId, discussionId);
2016-09-13 17:45:13 +05:30
}
promise.then((response) => {
discussion.loading = false;
if (response.status === 200) {
const data = response.json();
const resolved_by = data ? data.resolved_by : null;
if (isResolved) {
discussion.unResolveAllNotes();
} else {
discussion.resolveAllNotes(resolved_by);
}
discussion.updateHeadline(data);
} else {
new Flash('An error occurred when trying to resolve a discussion. Please try again.', 'alert');
}
})
}
2016-10-01 15:18:49 +05:30
resolveAll(projectPath, mergeRequestId, discussionId) {
2016-09-13 17:45:13 +05:30
const discussion = CommentsStore.state[discussionId];
2016-10-01 15:18:49 +05:30
this.prepareRequest(projectPath);
2016-09-13 17:45:13 +05:30
discussion.loading = true;
return this.discussionResource.save({
mergeRequestId,
discussionId
}, {});
}
2016-10-01 15:18:49 +05:30
unResolveAll(projectPath, mergeRequestId, discussionId) {
2016-09-13 17:45:13 +05:30
const discussion = CommentsStore.state[discussionId];
2016-10-01 15:18:49 +05:30
this.prepareRequest(projectPath);
2016-09-13 17:45:13 +05:30
discussion.loading = true;
return this.discussionResource.delete({
mergeRequestId,
discussionId
}, {});
}
}
w.ResolveService = new ResolveServiceClass();
})(window);