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