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

87 lines
2 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';
2019-07-31 22:56:46 +05:30
import { __ } from '~/locale';
2017-08-17 22:00:37 +05:30
window.gl = window.gl || {};
class ResolveServiceClass {
constructor(root) {
2018-11-20 20:47:30 +05:30
this.noteResource = Vue.resource(`${root}/notes{/noteId}/resolve?html=true`);
2018-11-08 19:23:39 +05:30
this.discussionResource = Vue.resource(
`${root}/merge_requests{/mergeRequestId}/discussions{/discussionId}/resolve?html=true`,
);
2017-08-17 22:00:37 +05:30
}
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())
2018-11-08 19:23:39 +05:30
.then(data => {
2017-09-10 17:25:29 +05:30
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
})
2018-11-08 19:23:39 +05:30
.catch(
2019-07-31 22:56:46 +05:30
() =>
new Flash(__('An error occurred when trying to resolve a discussion. Please try again.')),
2018-11-08 19:23:39 +05:30
);
2017-08-17 22:00:37 +05:30
}
resolveAll(mergeRequestId, discussionId) {
const discussion = CommentsStore.state[discussionId];
discussion.loading = true;
2018-11-08 19:23:39 +05:30
return this.discussionResource.save(
{
mergeRequestId,
discussionId,
},
{},
);
2017-08-17 22:00:37 +05:30
}
unResolveAll(mergeRequestId, discussionId) {
const discussion = CommentsStore.state[discussionId];
discussion.loading = true;
2018-11-08 19:23:39 +05:30
return this.discussionResource.delete(
{
mergeRequestId,
discussionId,
},
{},
);
2017-08-17 22:00:37 +05:30
}
}
gl.DiffNotesResolveServiceClass = ResolveServiceClass;