Commit 5e860656 authored by Phil Hughes's avatar Phil Hughes

Added ability to toggle resolving by commenting

parent 6537a4a8
...@@ -40,15 +40,7 @@ ...@@ -40,15 +40,7 @@
}, },
methods: { methods: {
resolve: function () { resolve: function () {
let promise; ResolveService.toggleResolveForDiscussion(this.namespace, this.mergeRequestId, this.discussionId);
if (this.allResolved) {
promise = ResolveService
.unResolveAll(this.namespace, this.mergeRequestId, this.discussionId);
} else {
promise = ResolveService
.resolveAll(this.namespace, this.mergeRequestId, this.discussionId);
}
} }
} }
}); });
......
...@@ -23,6 +23,25 @@ ...@@ -23,6 +23,25 @@
return this.noteResource.delete({ noteId }, {}); return this.noteResource.delete({ noteId }, {});
} }
toggleResolveForDiscussion(namespace, mergeRequestId, discussionId) {
const noteIds = CommentsStore.notesForDiscussion(discussionId);
let isResolved = true;
for (const noteId of noteIds) {
const resolved = CommentsStore.state[discussionId][noteId];
if (!resolved) {
isResolved = false;
}
}
if (isResolved) {
return this.unResolveAll(namespace, mergeRequestId, discussionId);
} else {
return this.resolveAll(namespace, mergeRequestId, discussionId);
}
}
resolveAll(namespace, mergeRequestId, discussionId) { resolveAll(namespace, mergeRequestId, discussionId) {
this.setCSRF(); this.setCSRF();
Vue.http.options.root = `/${namespace}`; Vue.http.options.root = `/${namespace}`;
......
...@@ -25,13 +25,22 @@ ...@@ -25,13 +25,22 @@
} }
}, },
updateCommentsForDiscussion: function (discussionId, resolve) { updateCommentsForDiscussion: function (discussionId, resolve) {
const noteIds = CommentsStore.notesForDiscussion(discussionId, resolve); const noteIds = CommentsStore.resolvedNotesForDiscussion(discussionId, resolve);
for (const noteId of noteIds) { for (const noteId of noteIds) {
CommentsStore.update(discussionId, noteId, resolve); CommentsStore.update(discussionId, noteId, resolve);
} }
}, },
notesForDiscussion: function (discussionId, resolve) { notesForDiscussion: function (discussionId) {
let ids = [];
for (const noteId in CommentsStore.state[discussionId]) {
ids.push(noteId);
}
return ids;
},
resolvedNotesForDiscussion: function (discussionId, resolve) {
let ids = []; let ids = [];
for (const noteId in CommentsStore.state[discussionId]) { for (const noteId in CommentsStore.state[discussionId]) {
......
...@@ -401,11 +401,14 @@ ...@@ -401,11 +401,14 @@
this.removeDiscussionNoteForm($form); this.removeDiscussionNoteForm($form);
if ($form.attr('data-resolve-all') != null) { if ($form.attr('data-resolve-all') != null) {
var namespace = $form.attr('data-namespace'), var namespacePath = $form.attr('data-namespace-path'),
discussionId = $form.attr('data-discussion-id'); projectPath = $form.attr('data-project-path')
discussionId = $form.attr('data-discussion-id'),
mergeRequestId = $('input[name="noteable_iid"]', $form).val(),
namespace = `${namespacePath}/${projectPath}`;
if (ResolveService != null) { if (ResolveService != null) {
ResolveService.resolveAll(namespace, discussionId, false) ResolveService.toggleResolveForDiscussion(namespace, mergeRequestId, discussionId);
} }
} }
}; };
...@@ -771,7 +774,8 @@ ...@@ -771,7 +774,8 @@
.closest('form') .closest('form')
.attr('data-discussion-id', discussionId) .attr('data-discussion-id', discussionId)
.attr('data-resolve-all', 'true') .attr('data-resolve-all', 'true')
.attr('data-namespace', $this.attr('data-namespace')); .attr('data-namespace-path', $this.attr('data-namespace-path'))
.attr('data-project-path', $this.attr('data-project-path'));
}; };
return Notes; return Notes;
......
...@@ -4,6 +4,6 @@ ...@@ -4,6 +4,6 @@
= link_to 'Close merge request', merge_request_path(@merge_request, merge_request: {state_event: :close }), method: :put, class: "btn btn-nr btn-comment btn-close close-mr-link js-note-target-close", title: "Close merge request", data: {original_text: "Close merge request", alternative_text: "Comment & close merge request"} = link_to 'Close merge request', merge_request_path(@merge_request, merge_request: {state_event: :close }), method: :put, class: "btn btn-nr btn-comment btn-close close-mr-link js-note-target-close", title: "Close merge request", data: {original_text: "Close merge request", alternative_text: "Comment & close merge request"}
- if @merge_request.closed? - if @merge_request.closed?
= link_to 'Reopen merge request', merge_request_path(@merge_request, merge_request: {state_event: :reopen }), method: :put, class: "btn btn-nr btn-comment btn-reopen reopen-mr-link js-note-target-reopen", title: "Reopen merge request", data: {original_text: "Reopen merge request", alternative_text: "Comment & reopen merge request"} = link_to 'Reopen merge request', merge_request_path(@merge_request, merge_request: {state_event: :reopen }), method: :put, class: "btn btn-nr btn-comment btn-reopen reopen-mr-link js-note-target-reopen", title: "Reopen merge request", data: {original_text: "Reopen merge request", alternative_text: "Comment & reopen merge request"}
= submit_tag 'Comment & resolve discussion', class: "btn btn-nr btn-create append-right-10 comment-btn js-comment-resolve-button", data: { namespace: "#{@merge_request.project.namespace.path}/#{@merge_request.project.path}" } = submit_tag 'Comment & resolve discussion', class: "btn btn-nr btn-create append-right-10 comment-btn js-comment-resolve-button", data: { namespace_path: "#{@merge_request.project.namespace.path}", project_path: "#{@merge_request.project.path}" }
#notes= render "projects/notes/notes_with_form" #notes= render "projects/notes/notes_with_form"
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
= f.hidden_field :commit_id = f.hidden_field :commit_id
= f.hidden_field :line_code = f.hidden_field :line_code
= f.hidden_field :noteable_id = f.hidden_field :noteable_id
= hidden_field_tag :noteable_iid, @note.noteable.iid
= f.hidden_field :noteable_type = f.hidden_field :noteable_type
= f.hidden_field :type = f.hidden_field :type
= f.hidden_field :position = f.hidden_field :position
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment