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

76 lines
1.9 KiB
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
/* global CommentsStore */
import Vue from 'vue';
2018-03-17 18:26:18 +05:30
import Flash from '../../flash';
2017-09-10 17:25:29 +05:30
import '../../vue_shared/vue_resource_interceptor';
2017-08-17 22:00:37 +05:30
window.gl = window.gl || {};
class ResolveServiceClass {
constructor(root) {
this.noteResource = Vue.resource(`${root}/notes{/noteId}/resolve`);
this.discussionResource = Vue.resource(`${root}/merge_requests{/mergeRequestId}/discussions{/discussionId}/resolve`);
}
resolve(noteId) {
return this.noteResource.save({ noteId }, {});
}
unresolve(noteId) {
return this.noteResource.delete({ noteId }, {});
}
toggleResolveForDiscussion(mergeRequestId, discussionId) {
const discussion = CommentsStore.state[discussionId];
const isResolved = discussion.isResolved();
let promise;
if (isResolved) {
promise = this.unResolveAll(mergeRequestId, discussionId);
} else {
promise = this.resolveAll(mergeRequestId, discussionId);
}
2017-09-10 17:25:29 +05:30
promise
.then(resp => resp.json())
.then((data) => {
discussion.loading = false;
const resolvedBy = data ? data.resolved_by : null;
2017-08-17 22:00:37 +05:30
if (isResolved) {
discussion.unResolveAllNotes();
} else {
2017-09-10 17:25:29 +05:30
discussion.resolveAllNotes(resolvedBy);
2017-08-17 22:00:37 +05:30
}
2018-03-17 18:26:18 +05:30
if (gl.mrWidget) gl.mrWidget.checkStatus();
2017-08-17 22:00:37 +05:30
discussion.updateHeadline(data);
2017-09-10 17:25:29 +05:30
})
.catch(() => new Flash('An error occurred when trying to resolve a discussion. Please try again.'));
2017-08-17 22:00:37 +05:30
}
resolveAll(mergeRequestId, discussionId) {
const discussion = CommentsStore.state[discussionId];
discussion.loading = true;
return this.discussionResource.save({
mergeRequestId,
2017-09-10 17:25:29 +05:30
discussionId,
2017-08-17 22:00:37 +05:30
}, {});
}
unResolveAll(mergeRequestId, discussionId) {
const discussion = CommentsStore.state[discussionId];
discussion.loading = true;
return this.discussionResource.delete({
mergeRequestId,
2017-09-10 17:25:29 +05:30
discussionId,
2017-08-17 22:00:37 +05:30
}, {});
}
}
gl.DiffNotesResolveServiceClass = ResolveServiceClass;