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

Use VueJS resource

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