Commit 4499deba authored by Bertrand PINEL's avatar Bertrand PINEL

Add Bottle in relationship with rack

parent 4bf7ae7a
import Ember from 'ember';
// app/controllers/rack.js
export default Ember.Controller.extend({
rackTableColumns: Ember.computed(function() {
var col = Ember.A([
Ember.Object.create({
propertyName: "name",
title: "Name"
title: "Name",
}),
Ember.Object.create({
propertyName: 'nbColumns',
......@@ -15,6 +17,10 @@ rackTableColumns: Ember.computed(function() {
propertyName: 'nbRows',
title: 'Nombre de lignes',
}),
Ember.Object.create({
propertyName: 'capacity',
title: 'Capacité total',
}),
Ember.Object.create({
"template": "customcell/imagecell",
title: 'Image',
......
import Ember from 'ember';
import DS from 'ember-data';
export default DS.Model.extend({
name: DS.attr('string'),
createdAt: DS.attr('date', {defaultValue() { return new Date(); }}),
yrow: DS.attr('number'),
xcolumn: DS.attr('number'),
flipped: DS.attr('boolean', {defaultValue: false}),
rack: DS.belongsTo('rack')
});
......@@ -10,4 +10,5 @@ export default DS.Model.extend({
capacity: Ember.computed('nbColumns', 'nbRows', function() {
return this.get('nbColumns')*this.get('nbRows'); }),
bottles : DS.hasMany('bottle')
});
......@@ -2,6 +2,5 @@ import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.findAll('rack');
}
return this.store.findAll('rack', {include: 'bottles'}); }
});
export default function() {
// 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
/*
Shorthand cheatsheet:
this.get('/posts');
this.post('/posts');
this.get('/posts/:id');
this.put('/posts/:id'); // or this.patch
this.del('/posts/:id');
http://www.ember-cli-mirage.com/docs/v0.2.x/shorthands/
*/
this.namespace = 'api';
this.get('/racks', function(schema) {
return schema.racks.all();
this.get('/racks', function(schema) {
return schema.racks.all();
});
this.get('/racks/:id', (schema, request) => {
return schema.racks.find(request.params.id);
});
this.get('/bottles', function(schema) {
return schema.bottles.all();
});
this.get('/bottles/:id', (schema, request) => {
return schema.bottles.find(request.params.id);
});
}
import { Factory, faker } from 'ember-cli-mirage';
export default Factory.extend({
name: faker.list.cycle('Château Beychevelle',
'Ribera del Duero',
'Clos Fourtet St.-Emilion',
'Romanée Conti',
'Chambolle Musigny Guillon',
'Tenet Syrah Columbia Valley',
'Oddero Barolo',
'Gigondas Lavau',
'Duorum Douro',
'Philippe Alliet Chinon',
'Orin Swift Machete',
'Château Lagrezette',
'Château Puech Haut',
'Château Haut Bellevue'),
createdAt() { return new Date(); },
yrow() { return faker.random.number({min:1, max:3}); },
xcolumn() { return faker.random.number({min:3, max:20}); },
flipped() { return faker.random.boolean; }
});
import { Model, belongsTo } from 'ember-cli-mirage';
export default Model.extend({
rack: belongsTo()
});
import { Model } from 'ember-cli-mirage';
import { Model, hasMany } from 'ember-cli-mirage';
export default Model.extend({
bottles: hasMany()
});
export default function(server) {
/*
Seed your development database using your factories.
This data will not be loaded in your tests.
Make sure to define a factory for each model you want to create.
*/
let numberOfRacks = 4;
let numberOfBottles = 0;
// server.createList('post', 10);
server.createList('rack', 32);
let racks = server.createList('rack', numberOfRacks);
for (let i=0; i<numberOfRacks; i++) {
for (let col=0; col < racks[i].nbColumns; col++) {
for (let lig=0; lig < racks[i].nbRows; lig++) {
if (random(0,10)<5) {
server.create('bottle', { yrow: lig, xcolumn: col, rack: racks[i] });
numberOfBottles++;
}
}
}
}
console.log(numberOfBottles+" bottles created in "+numberOfRacks+" racks");
function random(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
}
import { moduleForModel, test } from 'ember-qunit';
moduleForModel('bottle', 'Unit | Model | bottle', {
// Specify the other units that are required for this test.
needs: []
});
test('it exists', function(assert) {
let model = this.subject();
// let store = this.store();
assert.ok(!!model);
});
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