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

Use VueJS resource

parent 4af0146f
#= require vue
#= require vue-resource
#= require_directory ./stores
#= require_directory ./services
#= require_directory ./components
......
......@@ -3,7 +3,7 @@
comments: CommentsStore.state
loading: false
props:
endpoint: String
namespace: String
computed:
resolved: ->
resolvedCount = 0
......@@ -22,8 +22,6 @@
this.loading = true
ResolveService
.resolveAll(this.endpoint, ids, !this.allResolved)
.done =>
CommentsStore.updateAll(!this.allResolved)
.always =>
.resolveAll(this.namespace, ids, !this.allResolved)
.then =>
this.loading = false
......@@ -2,7 +2,7 @@
props:
noteId: Number
resolved: Boolean
endpoint: String
namespace: String
data: ->
comments: CommentsStore.state
loading: false
......@@ -18,13 +18,10 @@
resolve: ->
this.loading = true
ResolveService
.resolve(this.endpoint, !this.isResolved)
.done =>
CommentsStore.update(this.noteId, !this.isResolved)
this.$nextTick this.updateTooltip
.always =>
.resolve(this.namespace, this.noteId, !this.isResolved)
.then =>
this.loading = false
this.$nextTick this.updateTooltip
compiled: ->
$(this.$els.button).tooltip()
destroyed: ->
......
@ResolveService =
resolve: (endpoint, resolve) ->
$.ajax
data:
resolved: resolve
type: 'post'
url: endpoint
resolveAll: (endpoint, ids, resolve) ->
$.ajax
data:
id: ids
resolve: resolve
type: 'post'
url: endpoint
class ResolveService
constructor: ->
actions = {
resolve:
method: 'POST'
url: 'notes{/id}/resolve'
all:
method: 'POST'
url: 'notes/resolve_all'
}
Vue.http.headers.common['X-CSRF-Token'] = $.rails.csrfToken()
@resource = Vue.resource('notes{/id}', {}, actions)
resolve: (namespace, id, resolve) ->
Vue.http.options.root = "/#{namespace}"
@resource
.resolve({ id: id }, { resolved: resolve })
.then (response) ->
if response.status is 200
CommentsStore.update(id, resolve)
resolveAll: (namespace, ids, resolve) ->
Vue.http.options.root = "/#{namespace}"
@resource
.all({}, { ids: ids, resolve: resolve })
.then (response) ->
CommentsStore.updateAll(resolve)
$ ->
@ResolveService = new ResolveService()
......@@ -46,7 +46,7 @@
- if current_user
#resolve-all-app{ "v-cloak" => true }
%resolve-all{ ":endpoint" => "'#{resolve_all_namespace_project_notes_path(@project.namespace, @project)}'", "inline-template" => true }
%resolve-all{ ":namespace" => "'#{@project.namespace.path}/#{@project.path}'", "inline-template" => true }
.line-resolve-all{ "v-show" => "commentsCount > 0" }
%button.btn.btn-gray{ type: "button", "aria-label" => "Resolve all", "@click" => "updateAll", ":disabled" => "loading" }
= icon("spinner spin", "v-show" => "loading")
......
......@@ -21,7 +21,7 @@
- if access and not note.system
%span.note-role.hidden-xs= access
- if !note.system && current_user
%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 }
%resolve-btn{ ":namespace" => "'#{note.project.namespace.path}/#{note.project.path}'", ":note-id" => note.id, ":resolved" => "false", "inline-template" => true, "v-ref:note_#{note.id}" => true }
.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 }
......
This diff is collapsed.
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