Skip to content

Instantly share code, notes, and snippets.

@leondmello
Last active March 4, 2017 20:30
Show Gist options
  • Save leondmello/db2ad015ef20ef7ed3d59fe9e96c2e9f to your computer and use it in GitHub Desktop.
Save leondmello/db2ad015ef20ef7ed3d59fe9e96c2e9f to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Component.extend({
valueMap: Ember.Object.create({
3600: 'One Update Per Hour',
86400: 'One Update Per Day',
604800: 'One Update Per Week',
2629746: 'One Update Per Month'
}),
displayValue: Ember.computed('model.value', function() {
console.log(
this.get('rule.changes.firstObject'),
);
return this.get('valueMap').get(String(this.get('model.value')));
})
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
value: attr()
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.createRecord('my-model', {
value: 3600
});
}
});
{{my-component model=model}}
<div class="btn-group">
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown">
{{displayValue}}
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>
<a {{action (action (mut model.value)) 3600}}>
<span class="glyphicon glyphicon-ok {{unless (eq model.value 3600) 'invisible'}}"></span>
{{get valueMap '3600'}}
</a>
<a {{action (action (mut model.value)) 86400}}>
<span class="glyphicon glyphicon-ok {{unless (eq model.value 86400) 'invisible'}}"></span>
{{get valueMap '86400'}}
</a>
<a {{action (action (mut model.value) 604800)}}>
<span class="glyphicon glyphicon-ok {{unless (eq model.value 604800) 'invisible'}}"></span>
{{get valueMap '604800'}}
</a>
<a {{action (action (mut model.value) 2629746)}}>
<span class="glyphicon glyphicon-ok {{unless (eq model.value 2629746) 'invisible'}}"></span>
{{get valueMap '2629746'}}
</a>
</li>
</ul>
</div>
{
"version": "0.11.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.8.0",
"ember-data": "2.11.0",
"ember-template-compiler": "2.10.2",
"ember-testing": "2.10.2"
},
"addons": {
"ember-truth-helpers": "1.3.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment