Skip to content

Instantly share code, notes, and snippets.

@scottmessinger
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottmessinger/11187340 to your computer and use it in GitHub Desktop.
Save scottmessinger/11187340 to your computer and use it in GitHub Desktop.
Flow
<!--
template: planbook.hbs
-->
{{render 'dates'}}
<!--
template: dates.hbs
controller: see DatesController below
itemControllers: see DateController below)
-->
{{#each arrangedContent}}
{{render 'planbook/date' controller.planbookDate}}
{{/each}}
<!--
template: planbook/date.hbs
model: see PlanbookDate below
-->
{{render 'routine' routine}}
var DatesController = Ember.ArrayController.extend({
init: function(){
this._super()
this._loadDates()
},
_loadDates: function(){
var range = this._getRange(); // returns array of dates ["2014-02-02", "2014-02-03"]
var content = range.map(this._createDateController, this)
this.pushObjects(content)
},
_createDateController: function(date){
return this.container.lookupFactory('controller:date').create({date: date})
},
})
export default DatesController
var DateController = Ember.Controller.extend({
needs: ['dates', 'planbook'],
planbookDate: function(){
var id = this.get('controllers.planbook.content.id') + ":" + this.get('date')
return this.store.modelFor('planbookDate').find(id)
}.property('content.date', 'controllers.planbook')
})
export default DateController
var PlanbookDate = Ember.Model.extend({
routine: Ember.belongsTo('routine', {key: 'routineId'}),
})
export default PlanbookDate;
var Routine = Ember.Model.extend({
parts: Ember.hasMany('part', {embedded: true, key: 'parts'}),
})
export default Routine;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment