diff --git a/app/mirage/config.js b/app/mirage/config.js index 9b41d41..93550ca 100644 --- a/app/mirage/config.js +++ b/app/mirage/config.js @@ -1,77 +1,9 @@ export default function() { - - // These comments are here to help you get started. Feel free to delete them. - - /* - Config (with defaults). - - Note: these only affect routes defined *after* them! - */ - // this.urlPrefix = ''; // make this `http://localhost:8080`, for example, if your API is on a different server - // this.namespace = ''; // make this `api`, for example, if your API is namespaced - // this.timing = 400; // delay for each request, automatically set to 0 during testing - - /* - Route shorthand cheatsheet - */ - /* - GET shorthands - - // Collections - this.get('/contacts'); - this.get('/contacts', 'users'); - this.get('/contacts', ['contacts', 'addresses']); - - // Single objects - this.get('/contacts/:id'); - this.get('/contacts/:id', 'user'); - this.get('/contacts/:id', ['contact', 'addresses']); - */ - - /* - POST shorthands - - this.post('/contacts'); - this.post('/contacts', 'user'); // specify the type of resource to be created - */ - - /* - PUT shorthands - - this.put('/contacts/:id'); - this.put('/contacts/:id', 'user'); // specify the type of resource to be updated - */ - - /* - DELETE shorthands - - this.del('/contacts/:id'); - this.del('/contacts/:id', 'user'); // specify the type of resource to be deleted - - // Single object + related resources. Make sure parent resource is first. - this.del('/contacts/:id', ['contact', 'addresses']); - */ - - /* - Function fallback. Manipulate data in the db via - - - db.{collection} - - db.{collection}.find(id) - - db.{collection}.where(query) - - db.{collection}.update(target, attrs) - - db.{collection}.remove(target) - - // Example: return a single object with related models - this.get('/contacts/:id', function(db, request) { - var contactId = +request.params.id; - - return { - contact: db.contacts.find(contactId), - addresses: db.addresses.where({contact_id: contactId}); - }; - }); - - */ + this.get('/properties', function(db, request) { + return { + data: db.properties.map(attrs => ({ type: 'properties', id: attrs.id, attributes: attrs })) + } + }); } /* diff --git a/app/mirage/factories/property.js b/app/mirage/factories/property.js new file mode 100644 index 0000000..56d85e7 --- /dev/null +++ b/app/mirage/factories/property.js @@ -0,0 +1,7 @@ +import Mirage, {faker} from 'ember-cli-mirage' + +export default Mirage.Factory.extend({ + name(i) { return `Property ${i}`; }, + value: faker.list.random(1.23, 2.34, 3.45, 4.56), + unit: faker.list.random('A', 'kV', 'MW') +}); diff --git a/app/mirage/scenarios/default.js b/app/mirage/scenarios/default.js index e07271c..93bbb90 100644 --- a/app/mirage/scenarios/default.js +++ b/app/mirage/scenarios/default.js @@ -1,7 +1,3 @@ -export default function(/* server */) { - - // Seed your development database using your factories. This - // data will not be loaded in your tests. - - // server.createList('contact', 10); +export default function(server) { + server.createList('property', 5); } diff --git a/app/models/property.js b/app/models/property.js new file mode 100644 index 0000000..0f672b9 --- /dev/null +++ b/app/models/property.js @@ -0,0 +1,7 @@ +import DS from 'ember-data'; + +export default DS.Model.extend({ + name: DS.attr('string'), + value: DS.attr('number'), + unit: DS.attr('string') +}); diff --git a/app/routes/lab-mashup.js b/app/routes/lab-mashup.js index e5f520a..a7bf346 100644 --- a/app/routes/lab-mashup.js +++ b/app/routes/lab-mashup.js @@ -2,21 +2,7 @@ import Ember from 'ember'; export default Ember.Route.extend({ model() { - //return this.store.findAll('property'); - let properties = [ - { - name: "voltage", - value: 2.3, - type: "kV" - }, - { - name: "current", - value: 1.6, - type: "A" - } - ]; - - return properties; + return this.store.findAll('property'); } }); diff --git a/app/templates/lab-mashup.hbs b/app/templates/lab-mashup.hbs index 5a6dfe2..f3c85a6 100644 --- a/app/templates/lab-mashup.hbs +++ b/app/templates/lab-mashup.hbs @@ -7,7 +7,7 @@ {{#each model as |property|}}