Created
July 18, 2013 03:34
-
-
Save hashg/6026528 to your computer and use it in GitHub Desktop.
Ember Model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var App = window.App = Ember.Application.create(); | |
App.Router.map(function () { | |
this.resource('projects', {path: '/projects'}, function(){ | |
this.route('new'); | |
this.resource('project', {path: '/:project_id'}, function(){ | |
this.route('edit'); | |
this.resource('members', {path: '/members'},function(){ | |
this.route('add'); | |
this.route('edit',{path: '/:member_id/edit'}); | |
}); | |
this.resource('sprints', {path: '/sprints'}, function(){ | |
this.route('new'); | |
this.resource('sprint', {path: '/:sprint_id'}, function(){ | |
this.route('edit'); | |
this.resource('stories', {path: '/stories'}, function(){ | |
this.route('new'); | |
this.resource('story', {path: '/:story_id'}, function(){ | |
this.route('edit'); | |
this.resource('tasks', {path: '/tasks'}, function(){ | |
this.route('new'); | |
this.resource('task', {path: '/:task_id'}, function(){ | |
this.route('edit'); | |
this.resource('timeEntries', {path: '/timeEntries'}, function(){ | |
this.route('new'); | |
this.resource('timeEntry', {path: '/:timeEntry_id'}, function(){ | |
this.route('edit'); | |
}); | |
}); | |
}); | |
}); | |
}); | |
}); | |
}); | |
}); | |
}); | |
}); | |
}); | |
App.IndexRoute = Em.Route.extend({ | |
redirect: function(){ | |
this.transitionTo('projects'); | |
} | |
}); | |
App.ProjectsRoute = Em.Route.extend({ | |
model: function () { | |
return App.Project.find(); | |
} | |
}); | |
App.SprintsRoute = Em.Route.extend({ | |
model: function () { | |
return App.Sprint.find(); | |
} | |
}); | |
App.PersonsRoute = Em.Route.extend({ | |
model: function () { | |
return App.Person.find(); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/x-handlebars"> | |
<h2>Scrums</h2> | |
{{outlet main}} | |
</script> | |
<script type="text/x-handlebars" data-template-name="projects"> | |
<h4>{{#linkTo projects}}Projects{{/linkTo}}</h4> | |
<ul> | |
{{#each item in model}} | |
<li>{{#linkTo sprints item}}{{item.name}}{{/linkTo}}</li> | |
{{/each}} | |
</ul> | |
<hr> | |
{{outlet}} | |
</script> | |
<script type="text/x-handlebars" data-template-name="project"> | |
<h4>{{name}}</h4> | |
<ul> | |
{{#each item in sprints}} | |
<li>{{#linkTo sprint item }}{{item.name}}{{/linkTo}}</li> | |
{{/each}} | |
</ul> | |
{{outlet}} | |
</script> | |
<script type="text/x-handlebars" data-template-name="sprints"> | |
<hr> | |
{{outlet}} | |
</script> | |
<script type="text/x-handlebars" data-template-name="sprint"> | |
<h4>{{name}}</h4> | |
<ul> | |
{{#each item in stories}} | |
<li>{{#linkTo story item }}{{item.name}}{{/linkTo}}</li> | |
{{/each}} | |
</ul> | |
{{outlet}} | |
</script> | |
<script type="text/x-handlebars" data-template-name="stories"> | |
<hr> | |
{{outlet}} | |
</script> | |
<script type="text/x-handlebars" data-template-name="story"> | |
<h4>{{name}} | |
<ul> | |
{{#each item in tasks}} | |
<li>{{#linkTo task item }}{{item.name}}{{/linkTo}}</li> | |
{{/each}} | |
</ul> | |
{{outlet}} | |
</script> | |
<script type="text/x-handlebars" data-template-name="tasks"> | |
<hr> | |
{{outlet}} | |
</script> | |
<script type="text/x-handlebars" data-template-name="task"> | |
{{#linkTo projects}}projects{{/linkTo}}/ | |
{{#linkTo project}}{{story.sprint.project.name}}{{/linkTo}}/ | |
{{#linkTo sprints}}sprints{{/linkTo}}/ | |
{{#linkTo sprint}}{{story.sprint.name}}{{/linkTo}}/ | |
{{#linkTo stories}}stories{{/linkTo}}/ | |
{{#linkTo story story}}{{story.name}}{{/linkTo}}/ | |
{{#linkTo tasks}}Tasks{{/linkTo}} | |
<ul> | |
<li>{{name}}</li> | |
</ul> | |
{{outlet}} | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var attr = Ember.attr, hasMany = Ember.hasMany, belongsTo = Ember.belongsTo; | |
var apiPrefix = '/api'; | |
App.Person = Ember.Model.extend({ | |
id: attr(), | |
name: attr(), | |
members: hasMany('App.Member', {key: 'members', embedded: true}) | |
}); | |
App.Person.url = apiPrefix + "/persons"; | |
App.Person.adapter = Ember.RESTAdapter.create(); | |
App.Project = Ember.Model.extend({ | |
id: attr(), | |
name: attr(), | |
updates: attr(), | |
members: hasMany('App.Member', {key: 'members', embedded: true}), | |
sprints: hasMany('App.Member', {key: 'sprints', embedded: true}) | |
}); | |
App.Project.url = apiPrefix + "/projects"; | |
App.Project.collectionKey = 'objects'; | |
// App.Project.rootKey = 'story'; | |
App.Project.camelizeKeys = true; | |
App.Project.adapter = Ember.RESTAdapter.create(); | |
App.Sprint = Ember.Model.extend({ | |
id: attr(), | |
name: attr(), | |
project: belongsTo('App.Project', {key: 'project_id'}), | |
stories: hasMany('App.Story', {key: 'stories', embedded: true}) | |
}); | |
App.Sprint.url = apiPrefix + "/sprints"; | |
App.Sprint.collectionKey = 'objects'; | |
App.Sprint.adapter = Ember.RESTAdapter.create(); | |
App.Story = Ember.Model.extend({ | |
id: attr(), | |
name: attr(), | |
sprint: belongsTo('App.Sprint', {key: 'sprint_id'}), | |
tasks: hasMany('App.Task', {key: 'tasks', embedded: true}) | |
}); | |
App.Story.url = apiPrefix + "/stories"; | |
App.Story.rootKey = 'story'; | |
App.Story.collectionKey = 'objects'; | |
App.Story.adapter = Ember.RESTAdapter.create(); | |
App.Task = Ember.Model.extend({ | |
id: attr(), | |
name: attr(), | |
Story: belongsTo('App.Story', {key: 'story_id'}) | |
}); | |
App.Task.url = apiPrefix + "/tasks"; | |
App.Task.collectionKey = 'objects'; | |
App.Task.adapter = Ember.RESTAdapter.create(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"updated": null, | |
"created": null, | |
"is_active": null, | |
"person_id": "1", | |
"project_id": "c97eadb1", | |
"id": "kcb896f5" | |
} | |
], | |
"id": "c97eadb1", | |
"desc": null | |
} | |
], | |
"num_results": 4, | |
"page": 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment