Commit e7626eb0 authored by Phil Hughes's avatar Phil Hughes Committed by Douwe Maan

Added comment & resolve button to reply form

parent 44cb5803
......@@ -24,6 +24,7 @@ class @GLForm
@form.find('.div-dropzone').remove()
@form.addClass('gfm-form')
disableButtonIfEmptyField @form.find('.js-note-text'), @form.find('.js-comment-button')
disableButtonIfEmptyField @form.find('.js-note-text'), @form.find('.js-comment-resolve-button')
# remove notify commit author checkbox for non-commit notes
GitLab.GfmAutoComplete.setup()
......
......@@ -4,19 +4,17 @@
namespace: String
data: ->
comments: CommentsStore.state
loading: false
computed:
allResolved: ->
isResolved = true
for noteId, resolved of this.comments[this.discussionId]
isResolved = false unless resolved
unless noteId is "loading"
isResolved = false unless resolved
isResolved
buttonText: ->
if this.allResolved then "Un-resolve all" else "Resolve all"
loading: -> this.comments[this.discussionId].loading
methods:
resolve: ->
this.loading = true
ResolveService
.resolveAll(this.namespace, this.discussionId, this.allResolved)
.then =>
this.loading = false
......@@ -9,11 +9,15 @@ class ResolveService
url: 'notes/resolve_all'
}
Vue.http.headers.common['X-CSRF-Token'] = $.rails.csrfToken()
@resource = Vue.resource('notes{/id}', {}, actions)
setCSRF: ->
Vue.http.headers.common['X-CSRF-Token'] = $.rails.csrfToken()
resolve: (namespace, discussionId, noteId, resolve) ->
@setCSRF()
Vue.http.options.root = "/#{namespace}"
@resource
.resolve({ id: noteId }, { discussion: discussionId, resolved: resolve })
.then (response) ->
......@@ -21,12 +25,14 @@ class ResolveService
CommentsStore.update(discussionId, noteId, resolve)
resolveAll: (namespace, discussionId, allResolve) ->
@setCSRF()
Vue.http.options.root = "/#{namespace}"
ids = []
for noteId, resolved of CommentsStore.state[discussionId]
ids.push(noteId) if resolved is allResolve
CommentsStore.state[discussionId].loading = true
@resource
.all({}, { ids: ids, discussion: discussionId, resolved: !allResolve })
.then (response) ->
......@@ -34,5 +40,6 @@ class ResolveService
for noteId in ids
CommentsStore.update(discussionId, noteId, !allResolve)
$ ->
@ResolveService = new ResolveService()
CommentsStore.state[discussionId].loading = false
@ResolveService = new ResolveService()
......@@ -4,7 +4,7 @@
this.state[discussionId][noteId]
create: (discussionId, noteId, resolved) ->
unless this.state[discussionId]?
Vue.set(this.state, discussionId, {})
Vue.set(this.state, discussionId, { loading: false })
Vue.set(this.state[discussionId], noteId, resolved)
update: (discussionId, noteId, resolved) ->
......
......@@ -43,6 +43,7 @@ class @Notes
# Reopen and close actions for Issue/MR combined with note form submit
$(document).on "click", ".js-comment-button", @updateCloseButton
$(document).on "keyup input", ".js-note-text", @updateTargetButtons
$(document).on 'click', '.js-comment-resolve-button', @resolveDiscussion
# remove a note (in general)
$(document).on "click", ".js-note-delete", @removeNote
......@@ -96,6 +97,7 @@ class @Notes
$(document).off "click", ".js-note-target-close"
$(document).off "click", ".js-note-discard"
$(document).off "keydown", ".js-note-text"
$(document).off 'click', '.js-comment-resolve-button'
$('.note .js-task-list-container').taskList('disable')
$(document).off 'tasklist:changed', '.note .js-task-list-container'
......@@ -327,6 +329,7 @@ class @Notes
form.find("#note_line_code").remove()
form.find("#note_position").remove()
form.find("#note_type").remove()
form.find('.js-comment-resolve-button').remove()
@parentTimeline = form.parents('.timeline')
......@@ -370,10 +373,18 @@ class @Notes
Adds new note to list.
###
addDiscussionNote: (xhr, note, status) =>
$form = $(xhr.target)
@renderDiscussionNote(note)
# cleanup after successfully creating a diff/discussion note
@removeDiscussionNoteForm($(xhr.target))
@removeDiscussionNoteForm($form)
if $form.attr('data-resolve-all')?
namespace = $form.attr('data-namespace')
discussionId = $form.attr('data-discussion-id')
if ResolveService?
ResolveService.resolveAll(namespace, discussionId, false)
###
Called in response to the edit note form being submitted
......@@ -541,6 +552,9 @@ class @Notes
.text(form.find('.js-close-discussion-note-form').data('cancel-text'))
@setupNoteForm form
form.find(".js-note-text").focus()
form
.find('.js-comment-resolve-button')
.attr('data-discussion-id', dataHolder.data('discussionId'))
form
.removeClass('js-main-target-form')
.addClass("discussion-form js-discussion-note-form")
......@@ -701,3 +715,13 @@ class @Notes
updateNotesCount: (updateCount) ->
@notesCountBadge.text(parseInt(@notesCountBadge.text()) + updateCount)
resolveDiscussion: ->
$this = $(this)
discussionId = $this.attr('data-discussion-id')
$this
.closest('form')
.attr('data-discussion-id', discussionId)
.attr('data-resolve-all', 'true')
.attr('data-namespace', $this.attr('data-namespace'))
......@@ -4,5 +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"}
- 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"}
= submit_tag 'Comment & resolve all', 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}" }
#notes= render "projects/notes/notes_with_form"
......@@ -20,7 +20,7 @@
- access = note_max_access_for_user(note)
- if access and not note.system
%span.note-role.hidden-xs= access
- if !note.system && note.discussion_id && current_user
- if !note.system && note.new_diff_note? && current_user
%resolve-btn{ ":namespace" => "'#{note.project.namespace.path}/#{note.project.path}'", ":discussion-id" => "'#{note.discussion_id}'", ":note-id" => note.id, ":resolved" => "false", "inline-template" => true, "v-ref:note_#{note.id}" => true }
.note-action-button
= icon("spin spinner", "v-show" => "loading")
......
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