Commit 70b46b28 authored by Phil Hughes's avatar Phil Hughes Committed by Douwe Maan

Resolve all comments button

Store that manages the state of each button
parent af5fc6e2
#= require vue #= require vue
#= require_directory ./stores
#= require_directory ./components #= require_directory ./components
$ -> $ ->
new Vue new Vue
el: '#notes' el: '#notes'
new Vue
el: '#resolve-all-app'
ResolveAll = Vue.extend
data: ->
{ comments: CommentsStore.state }
computed:
resolved: ->
resolvedCount = 0
for noteId, resolved of this.comments
resolvedCount++ if resolved
resolvedCount
commentsCount: ->
Object.keys(this.comments).length
buttonText: ->
if this.resolved is this.commentsCount then 'Un-resolve all' else 'Resolve all'
methods:
updateAll: ->
resolveAll = !(this.resolved is this.commentsCount)
CommentsStore.updateAll(resolveAll)
Vue.component 'resolve-all', ResolveAll
LineBtn = Vue.extend ResolveBtn = Vue.extend
props: props:
noteId: Number noteId: Number
resolved: Boolean resolved: Boolean
data: -> comments: CommentsStore.state
computed: computed:
buttonText: -> buttonText: ->
if this.resolved then "Mark as un-resolved" else "Mark as resolved" if this.comments[this.noteId] then "Mark as un-resolved" else "Mark as resolved"
isResolved: -> this.comments[this.noteId]
methods: methods:
updateTooltip: -> updateTooltip: ->
$(this.$el) $(this.$el)
.tooltip('hide') .tooltip('hide')
.tooltip('fixTitle') .tooltip('fixTitle')
resolve: -> resolve: ->
this.$set('resolved', !this.resolved) CommentsStore.update(this.noteId, !this.comments[this.noteId])
this.$nextTick this.updateTooltip this.$nextTick this.updateTooltip
compiled: -> compiled: ->
$(this.$el).tooltip() $(this.$el).tooltip()
created: ->
CommentsStore.create(this.noteId, this.resolved)
Vue.component 'line-btn', LineBtn Vue.component 'resolve-btn', ResolveBtn
@CommentsStore =
state: {}
create: (id, resolved) ->
Vue.set(this.state, id, resolved)
update: (id, resolved) ->
this.state[id] = resolved
updateAll: (state) ->
for id,resolved of this.state
this.update(id, state) if resolved isnt state
...@@ -20,3 +20,7 @@ ...@@ -20,3 +20,7 @@
.turn-off { display: block; } .turn-off { display: block; }
} }
} }
[v-cloak="true"] {
display: none;
}
...@@ -44,7 +44,15 @@ ...@@ -44,7 +44,15 @@
= succeed '.' do = succeed '.' do
= link_to "command line", "#modal_merge_info", class: "how_to_merge_link vlink", title: "How To Merge", "data-toggle" => "modal" = link_to "command line", "#modal_merge_info", class: "how_to_merge_link vlink", title: "How To Merge", "data-toggle" => "modal"
- if @commits_count.nonzero? #resolve-all-app{ "v-cloak" => true }
%resolve-all{ "inline-template" => true }
.line-resolve-all{ "v-show" => "commentsCount > 0" }
%button.btn.btn-gray{ type: "button", "aria-label" => "Resolve all", "v-on:click" => "updateAll" }
{{ buttonText }}
%span.line-resolve-text
{{ resolved }}/{{ commentsCount }} comments resolved
- if @commits.nonzero?
%ul.merge-request-tabs.nav-links.no-top.no-bottom %ul.merge-request-tabs.nav-links.no-top.no-bottom
%li.notes-tab %li.notes-tab
= link_to namespace_project_merge_request_path(@project.namespace, @project, @merge_request), data: {target: 'div#notes', action: 'notes', toggle: 'tab'} do = link_to namespace_project_merge_request_path(@project.namespace, @project, @merge_request), data: {target: 'div#notes', action: 'notes', toggle: 'tab'} do
......
...@@ -21,8 +21,8 @@ ...@@ -21,8 +21,8 @@
- if access and not note.system - if access and not note.system
%span.note-role.hidden-xs= access %span.note-role.hidden-xs= access
- unless note.system - unless note.system
%line-btn{ ":note-id" => note.id, ":resolved" => "false", "inline-template" => true } %resolve-btn{ ":note-id" => note.id, ":resolved" => "false", "inline-template" => true }
%button.note-action-button.line-resolve-btn{ type: "button", "v-bind:class" => "{ 'is-active': resolved }", "v-bind:aria-label" => "buttonText", "v-on:click" => "resolve", "v-bind:title" => "buttonText" } %button.note-action-button.line-resolve-btn{ type: "button", "v-bind:class" => "{ 'is-active': isResolved }", "v-bind:aria-label" => "buttonText", "v-on:click" => "resolve", "v-bind:title" => "buttonText" }
= icon("check") = icon("check")
- if current_user and not note.system - if current_user and not note.system
= link_to '#', title: 'Award Emoji', class: 'note-action-button note-emoji-button js-add-award js-note-emoji', data: { position: 'right' } do = link_to '#', title: 'Award Emoji', class: 'note-action-button note-emoji-button js-add-award js-note-emoji', data: { position: 'right' } do
......
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