Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Bertrand PINEL
EmberCellar
Commits
4499deba
Commit
4499deba
authored
Apr 18, 2017
by
Bertrand PINEL
Browse files
Add Bottle in relationship with rack
parent
4bf7ae7a
Changes
10
Hide whitespace changes
Inline
Side-by-side
app/controllers/racks.js
View file @
4499deba
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
'
,
...
...
app/models/bottle.js
0 → 100644
View file @
4499deba
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
'
)
});
app/models/rack.js
View file @
4499deba
...
...
@@ -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
'
)
});
app/routes/racks.js
View file @
4499deba
...
...
@@ -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
'
});
}
});
mirage/config.js
View file @
4499deba
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
);
});
}
mirage/factories/bottle.js
0 → 100644
View file @
4499deba
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
;
}
});
mirage/models/bottle.js
0 → 100644
View file @
4499deba
import
{
Model
,
belongsTo
}
from
'
ember-cli-mirage
'
;
export
default
Model
.
extend
({
rack
:
belongsTo
()
});
mirage/models/rack.js
View file @
4499deba
import
{
Model
}
from
'
ember-cli-mirage
'
;
import
{
Model
,
hasMany
}
from
'
ember-cli-mirage
'
;
export
default
Model
.
extend
({
bottles
:
hasMany
()
});
mirage/scenarios/default.js
View file @
4499deba
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
;
}
}
tests/unit/models/bottle-test.js
0 → 100644
View file @
4499deba
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
);
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment