Skip to content

Commit

Permalink
Changed, that indices are displayed sorted by name
Browse files Browse the repository at this point in the history
Added `App.indices.sorted` computed property, reference:

--> http://andymatthews.net/read/2012/03/20/Reversing-the-output-of-an-Ember.js-content-array
  • Loading branch information
karmi committed May 29, 2012
1 parent 666daf0 commit 2194f02
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ <h3><span {{bindAttr class="master:icon-star"}}></span> {{name}}</h3>
<h2 class="label">Indices</h2>
<script type="text/x-handlebars">
<div id="indices">
{{#each index in App.indices}}
{{#each index in App.indices.sorted}}
{{#with index}}
<div {{bindAttr class=":index :clearfix state show_detail:expanded"}}>
<div class="basic-info clearfix">
Expand Down
10 changes: 7 additions & 3 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ App.nodes = Ember.ArrayController.create({
}

// Remove missing nodes from the collection
// TODO: Use model instance identity for this
// TODO: Use model instance identity, contains(), etc
//
self.forEach(function(item) {
var loc = self.content.length || 0
Expand Down Expand Up @@ -155,6 +155,12 @@ App.indices = Ember.ArrayController.create({
App.indices.poller = setTimeout( function() { App.indices.__perform_refresh() }, App.refresh_interval.value )
},

sorted: function() {
return this.get("content")
.toArray()
.sort(function(a,b) { if (a.name < b.name) return -1; if (a.name > b.name) return 1; return 0; })
}.property("content.@each").cacheable(),

showDetail: function(event) {
// l(event.context.name)
// l(this)
Expand Down Expand Up @@ -302,8 +308,6 @@ App.indices = Ember.ArrayController.create({
}
})

// TODO: Sort indices by name
// self.set( "content", self.content.sort(function(a,b) { return a.name > b.name }) )
}
};

Expand Down

0 comments on commit 2194f02

Please sign in to comment.