Add basic dunlop/user-filter model connected to the dunlop-core api since these filters are engine/adapter independent
This commit is contained in:
@@ -0,0 +1,34 @@
|
|||||||
|
import JSONAPIAdapter from 'ember-data/adapters/json-api'
|
||||||
|
import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin'
|
||||||
|
import { pluralize } from 'ember-inflector'
|
||||||
|
import config from 'ember-get-config'
|
||||||
|
|
||||||
|
export default JSONAPIAdapter.extend DataAdapterMixin,
|
||||||
|
#namespace: config.apiNamespace
|
||||||
|
host: config.apiHost
|
||||||
|
authorizer: 'authorizer:devise'
|
||||||
|
createRecord: (store, type, snapshot) ->
|
||||||
|
data = {}
|
||||||
|
#var serializer = store.serializerFor(type.modelName);
|
||||||
|
serializer = Ember.get(snapshot.record, 'store').serializerFor('create-and-update')
|
||||||
|
url = @buildURL(type.modelName, null, snapshot, 'createRecord')
|
||||||
|
|
||||||
|
serializer.serializeIntoHash data, type, snapshot, includeId: true
|
||||||
|
|
||||||
|
@ajax url, 'POST', data: data
|
||||||
|
|
||||||
|
# return pluralized underscored version
|
||||||
|
pathForType: (modelName) ->
|
||||||
|
base = Ember.String.underscore(modelName)
|
||||||
|
base = base.replace(/\./g, '/')
|
||||||
|
#base.split(/\//).map( (str) -> pluralize(str) ).join('/') # all parts pluralized
|
||||||
|
pluralize(base)
|
||||||
|
|
||||||
|
updateRecord: (store, type, snapshot) ->
|
||||||
|
data = {}
|
||||||
|
#var serializer = store.serializerFor(type.modelName);
|
||||||
|
serializer = Ember.get(snapshot.record, 'store').serializerFor('create-and-update')
|
||||||
|
id = snapshot.id
|
||||||
|
url = @buildURL(type.modelName, id, snapshot, 'updateRecord')
|
||||||
|
serializer.serializeIntoHash data, type, snapshot, includeId: true
|
||||||
|
@ajax url, 'PUT', data: data
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import DS from 'ember-data'
|
||||||
|
|
||||||
|
export default DS.Model.extend
|
||||||
|
scope_key: DS.attr('string')
|
||||||
|
filters: DS.attr(defaultValue: -> {})
|
||||||
|
is_default: DS.attr('boolean', defaultValue: false)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export { default } from 'ember-cli-dunlop/adapters/dunlop/user-filter';
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export { default } from 'ember-cli-dunlop/models/dunlop/user-filter';
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { moduleFor, test } from 'ember-qunit'
|
||||||
|
|
||||||
|
moduleFor 'adapter:dunlop/user-filter', 'Unit | Adapter | dunlop/user filter', {
|
||||||
|
# Specify the other units that are required for this test.
|
||||||
|
# needs: ['serializer:foo']
|
||||||
|
}
|
||||||
|
|
||||||
|
# Replace this with your real tests.
|
||||||
|
test 'it exists', (assert) ->
|
||||||
|
adapter = @subject()
|
||||||
|
assert.ok adapter
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { moduleForModel, test } from 'ember-qunit'
|
||||||
|
|
||||||
|
moduleForModel 'dunlop/user-filter', 'Unit | Model | dunlop/user filter', {
|
||||||
|
# Specify the other units that are required for this test.
|
||||||
|
needs: []
|
||||||
|
}
|
||||||
|
|
||||||
|
test 'it exists', (assert) ->
|
||||||
|
model = @subject()
|
||||||
|
# store = @store()
|
||||||
|
assert.ok !!model
|
||||||
Reference in New Issue
Block a user