Skip to content

Instantly share code, notes, and snippets.

@polotek
Last active December 11, 2015 11:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save polotek/4592503 to your computer and use it in GitHub Desktop.
Save polotek/4592503 to your computer and use it in GitHub Desktop.
var App = Ember.Application.create();
App.Store = DS.Store.extend({
revision: 11
, adapter: YamAdapter.create()
});
App.YamModel = DS.Model.extend({
type: DS.attr('string')
, url: DS.attr('string')
, webUrl: DS.attr('string')
});
App.User = App.YamModel.extend({
name: DS.attr('string')
, fullName: DS.attr('string')
, mugshotUrl: DS.attr('string')
});
App.Message = App.YamModel.extend({
type: DS.attr('string')
, privacy: DS.attr('string')
, createdAt: DS.attr('date')
, body: DS.attr('object')
, thread: DS.belongsTo('App.Thread')
, sender: DS.belongsTo('App.User')
});
App.Thread = App.YamModel.extend({
privacy: DS.attr('string')
, stats: DS.attr('object')
, olderReplyCount: function() {
return this.get('stats.updates') - this.get('messages.length');
}.property('stats.updates', 'messages')
, messages: DS.hasMany('App.Message')
, replies: function() {
return this.get('messages').without(this.get('threadStarter'));
}.property('messages')
, sortIndex: function() {
return Number(this.get('messages.lastObject.id')) || 0;
}.property('messages')
, threadStarter: DS.belongsTo('App.Message')
})
.reopenClass({
url: 'messages/in_thread'
});
App.Feed = App.YamModel.extend({
threads: DS.hasMany('App.Thread')
})
.reopenClass({
url: 'messages'
});
App.ThreadsController = Ember.ArrayController.extend({
sortProperties: ['sortIndex']
, sortAscending: false
});
App.ReplyView = Ember.View.extend({
templateName: 'reply'
, tagName: 'li'
, classNames: ['yj-reply']
});
App.ThreadView = Ember.View.extend({
templateName: 'thread'
, tagName: 'li'
, classNames: ['yj-thread']
});
App.FeedRoute = Ember.Route.extend({
model: function() {
return App.Feed.find('algo');
}
, setupController: function(controller, model) {
var threads = model.get('threads')
, threadsController = this.controllerFor('threads');
threadsController.set('content', threads);
controller.set('threadsController', threadsController);
}
});
App.Router.map(function() {
this.route('feed', { path: '/' });
});
<script type="text/x-handlebars" data-template-name="feed">
<div class="yj-feed">
<button class="yj-redraw-feed" {{action "redraw"}}>Redraw Feed</button>
<ul class="yj-threads">
<!-- Loop over the threads and display them.
I would like the threads to be sorted by
the "sortIndex" property. -->
{{#each threadsController}}
{{view App.ThreadView class="yj-clearfix"}}
{{/each}}
</ul>
</div>
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment