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

Posts to rails to update note eventually

parent 662f5edd
#= require vue #= require vue
#= require_directory ./stores #= require_directory ./stores
#= require_directory ./services
#= require_directory ./components #= require_directory ./components
$ => $ =>
......
@ResolveAll = Vue.extend @ResolveAll = Vue.extend
data: -> data: ->
{ comments: CommentsStore.state } comments: CommentsStore.state
loading: false
computed: computed:
resolved: -> resolved: ->
resolvedCount = 0 resolvedCount = 0
...@@ -10,8 +11,18 @@ ...@@ -10,8 +11,18 @@
commentsCount: -> commentsCount: ->
Object.keys(this.comments).length Object.keys(this.comments).length
buttonText: -> buttonText: ->
if this.resolved is this.commentsCount then 'Un-resolve all' else 'Resolve all' if this.allResolved then 'Un-resolve all' else 'Resolve all'
allResolved: ->
this.resolved is this.commentsCount
methods: methods:
updateAll: -> updateAll: ->
resolveAll = !(this.resolved is this.commentsCount) ids = CommentsStore.getAllForState(this.allResolved)
CommentsStore.updateAll(resolveAll) this.$set('loading', true)
promise = if this.allResolved then ResolveService.resolveAll(ids) else ResolveService.resolveAll(ids)
promise
.done =>
CommentsStore.updateAll(!this.allResolved)
.always =>
this.$set('loading', false)
...@@ -2,22 +2,32 @@ ...@@ -2,22 +2,32 @@
props: props:
noteId: Number noteId: Number
resolved: Boolean resolved: Boolean
data: -> comments: CommentsStore.state endpoint: String
data: ->
comments: CommentsStore.state
loading: false
computed: computed:
buttonText: -> buttonText: ->
if this.comments[this.noteId] 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] isResolved: -> this.comments[this.noteId]
methods: methods:
updateTooltip: -> updateTooltip: ->
$(this.$el) $(this.$els.button)
.tooltip('hide') .tooltip('hide')
.tooltip('fixTitle') .tooltip('fixTitle')
resolve: -> resolve: ->
CommentsStore.update(this.noteId, !this.comments[this.noteId]) this.$set('loading', true)
ResolveService
.resolve(this.endpoint, !this.isResolved)
.done =>
this.$set('loading', false)
CommentsStore.update(this.noteId, !this.isResolved)
this.$nextTick this.updateTooltip this.$nextTick this.updateTooltip
.always =>
this.$set('loading', false)
compiled: -> compiled: ->
$(this.$el).tooltip() $(this.$els.button).tooltip()
destroyed: -> destroyed: ->
CommentsStore.delete(this.noteId) CommentsStore.delete(this.noteId)
created: -> created: ->
......
@ResolveService =
resolve: (endpoint, resolve) ->
$.ajax
data:
resolved: resolve
type: 'post'
url: endpoint
resolveAll: (ids) ->
$.ajax
data:
id: ids
type: 'get'
url: '/'
unResolveAll: (ids) ->
$.ajax
data:
id: ids
type: 'get'
url: '/'
...@@ -9,3 +9,8 @@ ...@@ -9,3 +9,8 @@
updateAll: (state) -> updateAll: (state) ->
for id,resolved of this.state for id,resolved of this.state
this.update(id, state) if resolved isnt state this.update(id, state) if resolved isnt state
getAllForState: (state) ->
ids = []
for id,resolved of this.state
ids.push(id) if resolved is state
ids
...@@ -387,7 +387,7 @@ ul.notes { ...@@ -387,7 +387,7 @@ ul.notes {
.line-resolve-all { .line-resolve-all {
padding: 10px; padding: 10px;
border: 1px solid $border-color; border: 1px solid $border-color;
border-radius: 2px; border-radius: $border-radius-default;
.btn { .btn {
margin-right: 10px; margin-right: 10px;
......
...@@ -66,6 +66,11 @@ class Projects::NotesController < Projects::ApplicationController ...@@ -66,6 +66,11 @@ class Projects::NotesController < Projects::ApplicationController
end end
end end
def resolve
sleep 2
render nothing: true, status: 200
end
private private
def note def note
......
...@@ -47,7 +47,8 @@ ...@@ -47,7 +47,8 @@
#resolve-all-app{ "v-cloak" => true } #resolve-all-app{ "v-cloak" => true }
%resolve-all{ "inline-template" => true } %resolve-all{ "inline-template" => true }
.line-resolve-all{ "v-show" => "commentsCount > 0" } .line-resolve-all{ "v-show" => "commentsCount > 0" }
%button.btn.btn-gray{ type: "button", "aria-label" => "Resolve all", "@click" => "updateAll" } %button.btn.btn-gray{ type: "button", "aria-label" => "Resolve all", "@click" => "updateAll", ":disabled" => "loading" }
= icon("spinner spin", "v-show" => "loading")
{{ buttonText }} {{ buttonText }}
%span.line-resolve-text %span.line-resolve-text
{{ resolved }}/{{ commentsCount }} comments resolved {{ resolved }}/{{ commentsCount }} comments resolved
......
...@@ -21,8 +21,10 @@ ...@@ -21,8 +21,10 @@
- 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
%resolve-btn{ ":note-id" => note.id, ":resolved" => "false", "inline-template" => true, "v-ref:note_#{note.id}" => true } %resolve-btn{ ":endpoint" => "'#{resolve_namespace_project_note_path(note.project.namespace, note.project, note)}'", ":note-id" => note.id, ":resolved" => "false", "inline-template" => true, "v-ref:note_#{note.id}" => true }
%button.note-action-button.line-resolve-btn{ type: "button", ":class" => "{ 'is-active': isResolved }", ":aria-label" => "buttonText", "@click" => "resolve", ":title" => "buttonText" } .note-action-button
= icon("spin spinner", "v-show" => "loading")
%button.line-resolve-btn{ type: "button", ":class" => "{ 'is-active': isResolved }", ":aria-label" => "buttonText", "@click" => "resolve", ":title" => "buttonText", "v-show" => "!loading", "v-el:button" => true }
= 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
......
...@@ -828,6 +828,7 @@ Rails.application.routes.draw do ...@@ -828,6 +828,7 @@ Rails.application.routes.draw do
member do member do
post :toggle_award_emoji post :toggle_award_emoji
delete :delete_attachment delete :delete_attachment
post :resolve
end end
end end
......
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