1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/web/ synced 2025-03-09 00:00:01 +01:00

Add dynamic data generate by mirage

This commit is contained in:
Markus Grigull 2015-09-28 13:45:09 +02:00
parent 0711372904
commit abb65735c5
6 changed files with 23 additions and 95 deletions

View file

@ -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 }))
}
});
}
/*

View file

@ -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')
});

View file

@ -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);
}

7
app/models/property.js Normal file
View file

@ -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')
});

View file

@ -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');
}
});

View file

@ -7,7 +7,7 @@
{{#each model as |property|}}
<tr>
<td>{{property.name}}</td>
<td>{{property.value}} {{property.type}}</td>
<td>{{property.value}} {{property.unit}}</td>
</tr>
{{/each}}
</table>