Skip to content

Instantly share code, notes, and snippets.

@jelhan
Created October 11, 2016 09:14
Show Gist options
  • Save jelhan/87899b16e2a9c859667d92cc3a7b34b5 to your computer and use it in GitHub Desktop.
Save jelhan/87899b16e2a9c859667d92cc3a7b34b5 to your computer and use it in GitHub Desktop.
import Ember from 'ember';
import groupBy from 'ember-group-by';
const { computed } = Ember;
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
meetings: computed.readOnly('model'),
meetingsPerDay: groupBy('meetings', 'day')
});
import Ember from 'ember';
import moment from 'moment';
const { computed, get } = Ember;
const Meeting = Ember.Object.extend({
date: null,
day: computed('date', function() {
let date = get(this, 'date');
return moment(date).format('LL');
}),
topic: null
});
export default Ember.Route.extend({
model() {
return [
Meeting.create({
date: moment('2016-10-11 12:00'),
topic: 'foo'
}),
Meeting.create({
date: moment('2016-10-11 15:00'),
topic: 'bar'
}),
Meeting.create({
date: moment('2016-10-12 08:00'),
topic: 'baz'
})
];
}
});
<h1>Welcome to {{appName}}</h1>
{{#each meetingsPerDay as |meetingsForDay|}}
<h2>{{meetingsForDay.value}}</h2>
<ul>
{{#each meetingsForDay.items as |meeting|}}
<li>{{moment-format meeting.date 'LT'}}: {{meeting.topic}}</li>
{{/each}}
</ul>
{{/each}}
{
"version": "0.10.5",
"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.6.0",
"ember-data": "2.6.0",
"ember-template-compiler": "2.6.0",
"ember-testing": "2.6.0"
},
"addons": {
"ember-moment": "4.1.0",
"ember-group-by": "0.0.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment