-
-
Save EdwardIII/bf5f307266d0a867bcef84d5666f16b4 to your computer and use it in GitHub Desktop.
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
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
'currentOrder': Ember.inject.service(), | |
model(){ | |
return Ember.Object.create({ | |
// in the template: (subclass of Ember.ArrayProxy) == :) | |
'invoices': this.get('store').findAll('invoice'), | |
// in the template: [object Object] == :( | |
'currentOrders': this.get('currentOrder').current() | |
}); | |
} | |
}); |
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
import Ember from 'ember'; | |
export default Ember.Service.extend({ | |
currentUser: Ember.inject.service(), | |
store: Ember.inject.service(), | |
orderBasket: Ember.inject.service(), | |
order: function(){ | |
return this.get('currentUser').user() | |
.then(user => user.get('orders')) | |
.then(orders => orders.get('firstObject')); | |
}, | |
past(){ | |
return this._orders_for('past'); | |
}, | |
current(){ | |
return this._orders_for('current'); | |
}, | |
addOption(option, quantity){ | |
return this.order().then((order) => this.get('orderBasket').add(order, option, quantity)); | |
}, | |
_orders_for(type){ | |
return this | |
.get('currentUser') | |
.user() | |
.then(user => this._filter(user, {type: type})); | |
}, | |
_filter(user, by){ | |
return this | |
.get('store') | |
.query('order', { | |
user_id: user.get('id'), | |
filters: by | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment