From e2876d94866287c52c1357cbe2e5d48b0ccc61bd Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Tue, 24 Apr 2018 17:44:06 -0300 Subject: [PATCH] backup commit --- addon/mixins/application-route.coffee | 4 +++- addon/utils/paged-remote-array.coffee | 30 ++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/addon/mixins/application-route.coffee b/addon/mixins/application-route.coffee index 635b292..dbaa2ea 100644 --- a/addon/mixins/application-route.coffee +++ b/addon/mixins/application-route.coffee @@ -78,7 +78,9 @@ export default Ember.Mixin.create ApplicationRouteMixin, options = {model: options.content} else if typeof options isnt 'object' options = {model: options} - options.model = options.model.content if options.model?.promise? and options.model.content + + # opening a model on an unresolved promise is a bad thing, so we can assume (model) promise content for non paginated arrays as model + options.model = options.model.content if options.model?.promise? and options.model.content and not options.model.dunlop_remote_array container = Ember.getOwner(@) modalNameParts = modalName.split('/') diff --git a/addon/utils/paged-remote-array.coffee b/addon/utils/paged-remote-array.coffee index d2c74f1..2ec8db4 100644 --- a/addon/utils/paged-remote-array.coffee +++ b/addon/utils/paged-remote-array.coffee @@ -1,8 +1,11 @@ +import Ember from 'ember' import PagedRemoteArray from 'ember-cli-pagination/remote/paged-remote-array' +{get} = Ember export default PagedRemoteArray.extend - a: 42 + dunlop_remote_array: true # for identification #params: {} + session: Ember.inject.service() filters: {} init: -> query = @get('filters')?.toProperties() || {} @@ -12,14 +15,35 @@ export default PagedRemoteArray.extend @_super arguments... reload: -> - query = @get('filters')?.toProperties() || {} @incrementProperty('filters.filter_calls') @set 'page', 1 @set 'lastPage', null - @setOtherParam('q', query) + @setOtherParam('q', @getQuery()) + + getQuery: -> + @get('filters')?.toProperties() || {} paramMapping: total_pages: 'total-pages' total_count: 'total-count' + postRequest: (action_name, data = {}) -> + container = Ember.getOwner(@store) + adapter = @store.adapterFor(@modelName) + session = container.lookup('service:session') + base_url = adapter.buildURL(@modelName) + url = "#{base_url}/#{action_name}" + request_data = data + request_data = JSON.stringify(data) if typeof data is 'object' + request = + url: url + type: 'POST' + data: request_data + contentType: "application/json" + dataType: "json" + if session and get(session, 'isAuthenticated') + session.authorize 'authorizer:devise', (key, authorization) -> + request.crossDomain = true + request.headers = {"#{key}": authorization} + Ember.$.ajax(request)