Skip to content

Instantly share code, notes, and snippets.

@code0100fun
Created August 3, 2016 20:11
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 code0100fun/dccf5740da0070214b14a835bb696733 to your computer and use it in GitHub Desktop.
Save code0100fun/dccf5740da0070214b14a835bb696733 to your computer and use it in GitHub Desktop.
Mail
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
mail: Ember.inject.service(),
actions: {
toggleFolder(mail) {
mail.toggleProperty('trashed');
}
}
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
body: attr(),
trashed: attr('boolean'),
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return [
this.store.createRecord('mail', {
body: 'Mail 1', trashed: false
}),
this.store.createRecord('mail', {
body: 'Mail 2', trashed: true
}),
]
}
});
import Ember from 'ember';
export default Ember.Service.extend({
store: Ember.inject.service(),
items: Ember.computed(function() {
return this.get('store').peekAll('mail');
}),
trash: Ember.computed.filterBy('items', 'trashed', true),
inbox: Ember.computed.filterBy('items', 'trashed', false),
inboxCount: Ember.computed.alias('inbox.length'),
trashCount: Ember.computed.alias('trash.length'),
});
<h2>Inbox ({{mail.inboxCount}})</h2>
{{#each mail.inbox as |mail|}}
<p {{action 'toggleFolder' mail}}>{{mail.body}} - {{mail.trashed}}</p>
{{/each}}
<h2>Trash ({{mail.trashCount}})</h2>
{{#each mail.trash as |mail|}}
<p {{action 'toggleFolder' mail}}>{{mail.body}} - {{mail.trashed}}</p>
{{/each}}
{
"version": "0.10.4",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "release",
"ember-data": "release",
"ember-template-compiler": "release"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment