Skip to content

Instantly share code, notes, and snippets.

Created December 2, 2015 11:04
Show Gist options
  • Save anonymous/d50636ef39fb0b3d0ca4 to your computer and use it in GitHub Desktop.
Save anonymous/d50636ef39fb0b3d0ca4 to your computer and use it in GitHub Desktop.
Ember Starter Kit // source http://emberjs.jsbin.com/loxawirefa
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Ember Starter Kit</title>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.1/normalize.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://builds.emberjs.com/tags/v2.2.0/ember-template-compiler.js"></script>
<script src="http://builds.emberjs.com/tags/v2.2.0/ember.debug.js"></script>
<script src="http://builds.emberjs.com/tags/v2.2.1/ember-data.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery-mockjax/1.5.3/jquery.mockjax.js"></script>
<style id="jsbin-css">
/* Put your CSS here */
html, body {
margin: 20px;
}
</style>
</head>
<body>
<script type="text/x-handlebars">
<h2>Welcome to Ember.js</h2>
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="index">
<ul>
{{model.username}}
{{#each successfulEvaluations as |item|}}
<li>{{item.subject}} - {{item.grade}}/20</li>
{{/each}}
</ul>
</script>
<script id="jsbin-javascript">
App = Ember.Application.create();
App.Router.map(function() {
// put your routes here
});
App.IndexRoute = Ember.Route.extend({
model: function() {
//return ['red', 'yellow', 'blue'];
return this.store.find('student', 1);
}
});
App.IndexController = Ember.Controller.extend({
successfulEvaluations: Ember.computed.filter('model.evaluations.@each.grade', function(evaluation, index, array){
console.log("trigggerd");
return evaluation.get('grade') >= 10;
}),
});
App.Student = DS.Model.extend({
username: DS.attr('string'),
evaluations: DS.hasMany('evaluation')
});
App.Evaluation = DS.Model.extend({
subject: DS.attr('string'),
grade: DS.attr('number'),
student: DS.belongsTo('student')
});
$.mockjax({
url: '/students/1',
responseText: {
"data": {
"type": "students",
"id": "1",
"attributes":{ "username": "frederic" },
"relationships": {
"evaluations": {
"links": {
"related": "/students/1/evaluations"
},
}
}
},
}
});
$.mockjax({
url: '/students/1/evaluations',
responseText: {
"data": [{
"id": "1",
"type": "evaluations",
"attributes":{ "subject": "english", "grade": "15"},
"relationships": {
"student": {
"links": { "related" : "/evaluations/1/student" }
}
}
},
{
"id": "2",
"type": "evaluations",
"attributes":{ "subject": "french", "grade": "16"},
"relationships": {
"student": {
"links": { "related" : "/evaluations/1/student" }
}
}
}],
}
});
$.mockjax({
url: '/evaluations/1',
responseText: {
"data": {
"type": "evaluations",
"id": "1",
"attributes":{ "subject": "english", "grade": "15"},
"relationships": {
"student": {
"data": { "type": "student", "id": "1" }
}
}
},
}
});
$.mockjax({
url: '/evaluations/2',
responseText: {
"data": {
"type": "evaluations",
"id": "2",
"attributes":{ "subject": "french", "grade": "8" },
"relationships": {
"student": {
"data": { "type": "student", "id": "1" }
}
}
},
}
});
</script>
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Ember Starter Kit</title>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.1/normalize.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"><\/script>
<script src="http://builds.emberjs.com/tags/v2.2.0/ember-template-compiler.js"><\/script>
<script src="http://builds.emberjs.com/tags/v2.2.0/ember.debug.js"><\/script>
<script src="http://builds.emberjs.com/tags/v2.2.1/ember-data.js"><\/script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery-mockjax/1.5.3/jquery.mockjax.js"><\/script>
</head>
<body>
<script type="text/x-handlebars">
<h2>Welcome to Ember.js</h2>
{{outlet}}
<\/script>
<script type="text/x-handlebars" data-template-name="index">
<ul>
{{model.username}}
{{#each successfulEvaluations as |item|}}
<li>{{item.subject}} - {{item.grade}}/20</li>
{{/each}}
</ul>
<\/script>
</body>
</html>
</script>
<script id="jsbin-source-css" type="text/css">/* Put your CSS here */
html, body {
margin: 20px;
}
</script>
<script id="jsbin-source-javascript" type="text/javascript">App = Ember.Application.create();
App.Router.map(function() {
// put your routes here
});
App.IndexRoute = Ember.Route.extend({
model: function() {
//return ['red', 'yellow', 'blue'];
return this.store.find('student', 1);
}
});
App.IndexController = Ember.Controller.extend({
successfulEvaluations: Ember.computed.filter('model.evaluations.@each.grade', function(evaluation, index, array){
console.log("trigggerd");
return evaluation.get('grade') >= 10;
}),
});
App.Student = DS.Model.extend({
username: DS.attr('string'),
evaluations: DS.hasMany('evaluation')
});
App.Evaluation = DS.Model.extend({
subject: DS.attr('string'),
grade: DS.attr('number'),
student: DS.belongsTo('student')
});
$.mockjax({
url: '/students/1',
responseText: {
"data": {
"type": "students",
"id": "1",
"attributes":{ "username": "frederic" },
"relationships": {
"evaluations": {
"links": {
"related": "/students/1/evaluations"
},
}
}
},
}
});
$.mockjax({
url: '/students/1/evaluations',
responseText: {
"data": [{
"id": "1",
"type": "evaluations",
"attributes":{ "subject": "english", "grade": "15"},
"relationships": {
"student": {
"links": { "related" : "/evaluations/1/student" }
}
}
},
{
"id": "2",
"type": "evaluations",
"attributes":{ "subject": "french", "grade": "16"},
"relationships": {
"student": {
"links": { "related" : "/evaluations/1/student" }
}
}
}],
}
});
$.mockjax({
url: '/evaluations/1',
responseText: {
"data": {
"type": "evaluations",
"id": "1",
"attributes":{ "subject": "english", "grade": "15"},
"relationships": {
"student": {
"data": { "type": "student", "id": "1" }
}
}
},
}
});
$.mockjax({
url: '/evaluations/2',
responseText: {
"data": {
"type": "evaluations",
"id": "2",
"attributes":{ "subject": "french", "grade": "8" },
"relationships": {
"student": {
"data": { "type": "student", "id": "1" }
}
}
},
}
});</script></body>
</html>
/* Put your CSS here */
html, body {
margin: 20px;
}
App = Ember.Application.create();
App.Router.map(function() {
// put your routes here
});
App.IndexRoute = Ember.Route.extend({
model: function() {
//return ['red', 'yellow', 'blue'];
return this.store.find('student', 1);
}
});
App.IndexController = Ember.Controller.extend({
successfulEvaluations: Ember.computed.filter('model.evaluations.@each.grade', function(evaluation, index, array){
console.log("trigggerd");
return evaluation.get('grade') >= 10;
}),
});
App.Student = DS.Model.extend({
username: DS.attr('string'),
evaluations: DS.hasMany('evaluation')
});
App.Evaluation = DS.Model.extend({
subject: DS.attr('string'),
grade: DS.attr('number'),
student: DS.belongsTo('student')
});
$.mockjax({
url: '/students/1',
responseText: {
"data": {
"type": "students",
"id": "1",
"attributes":{ "username": "frederic" },
"relationships": {
"evaluations": {
"links": {
"related": "/students/1/evaluations"
},
}
}
},
}
});
$.mockjax({
url: '/students/1/evaluations',
responseText: {
"data": [{
"id": "1",
"type": "evaluations",
"attributes":{ "subject": "english", "grade": "15"},
"relationships": {
"student": {
"links": { "related" : "/evaluations/1/student" }
}
}
},
{
"id": "2",
"type": "evaluations",
"attributes":{ "subject": "french", "grade": "16"},
"relationships": {
"student": {
"links": { "related" : "/evaluations/1/student" }
}
}
}],
}
});
$.mockjax({
url: '/evaluations/1',
responseText: {
"data": {
"type": "evaluations",
"id": "1",
"attributes":{ "subject": "english", "grade": "15"},
"relationships": {
"student": {
"data": { "type": "student", "id": "1" }
}
}
},
}
});
$.mockjax({
url: '/evaluations/2',
responseText: {
"data": {
"type": "evaluations",
"id": "2",
"attributes":{ "subject": "french", "grade": "8" },
"relationships": {
"student": {
"data": { "type": "student", "id": "1" }
}
}
},
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment