Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bsylvain/b136f90c0f9469404f52fa3f7cfb0281 to your computer and use it in GitHub Desktop.
Save bsylvain/b136f90c0f9469404f52fa3f7cfb0281 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Component.extend({
totalCosts:Ember.computed('pricing',
function(){
var costs = {};
costs["price"]=this.get('pricing').get('buy_price');
costs["subscription"]=this.get('pricing').buy_subscription;
costs["perRoom"]=this.get('pricing').buy_per_room;
return costs;
}),
margins:Ember.computed('totalCosts', function(){
var totals={};
// totals['costs']=this.get('totalCosts');
// margin={};
// seller={};
// for(var index in totals["costs"]){
// margin[index]=pricing.get(index)-totals['costs'][index]
// seller[index]=pricing.get(index+'_reseller')*margin[index]/100
// }
// totals['margin']=margin;
// totals['seller']=seller;
return totals;
})
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
totalCosts:Ember.computed('',
function(){
var costs = {};
costs["price"]=this.get('model').get('price');
return costs;
//return JSON.stringify(costs);
})
});
import DS from 'ember-data';
export default DS.Model.extend({
currency:DS.attr('string'),
buy_price_cents:DS.attr('number'),
price_cents:DS.attr('number'),
buy_price:Ember.computed('buy_price_cents',{
get(key){return (this.get('buy_price_cents')/100)},
set(key,value){this.set('buy_price_cents', (value*100));return value}
}),
price:Ember.computed('price_cents',{
get(key){return (this.get('price_cents')/100)},
set(key,value){this.set('price_cents', (value*100));return value}
})
});
import Ember from 'ember';
export default Ember.Route.extend({
model(){
return this.get('store').createRecord('pricing',{buy_price_cents: 20.0,price_cents: 20.0});
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{get totalCosts 'price'}}
{{pricing-editor pricing=model}}
<br>
<br>
{{input value= (get pricing buy_price) }}
{{get totalCosts 'price'}}
{
"version": "0.15.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "2.14.1",
"ember-template-compiler": "2.14.1",
"ember-testing": "2.14.1"
},
"addons": {
"ember-data": "2.14.10"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment