From 9ba333fe2eb2e5586862039daa5259b86b60f9dd Mon Sep 17 00:00:00 2001 From: Chris LoPresto Date: Thu, 12 Mar 2015 01:20:30 -0400 Subject: [PATCH] Transition to show only incomplete todos http://guides.emberjs.com/v1.10.0/getting-started/show-only-incomplete-todos/ ``` ember g route todos/active rm app/templates/todos/active.hbs ``` --- app/router.js | 4 +++- app/routes/todos/active.js | 12 ++++++++++++ app/templates/todos.hbs | 2 +- tests/unit/routes/todos/active-test.js | 14 ++++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 app/routes/todos/active.js create mode 100644 tests/unit/routes/todos/active-test.js diff --git a/app/router.js b/app/router.js index 2f657c6..c0eb2fa 100644 --- a/app/router.js +++ b/app/router.js @@ -8,7 +8,9 @@ var Router = Ember.Router.extend({ Router.map(function() { this.resource('todos', { path: '/' - }, function() {}); + }, function() { + this.route('active'); + }); }); export default Router; diff --git a/app/routes/todos/active.js b/app/routes/todos/active.js new file mode 100644 index 0000000..ba881e9 --- /dev/null +++ b/app/routes/todos/active.js @@ -0,0 +1,12 @@ +import Ember from 'ember'; + +export default Ember.Route.extend({ + model: function(){ + return this.store.filter('todo', function(todo) { + return !todo.get('isCompleted'); + }); + }, + renderTemplate: function(controller) { + this.render('todos/index', {controller: controller}); + } +}); diff --git a/app/templates/todos.hbs b/app/templates/todos.hbs index c5a0007..57ac818 100644 --- a/app/templates/todos.hbs +++ b/app/templates/todos.hbs @@ -24,7 +24,7 @@ All
  • - Active + {{#link-to "todos.active" activeClass="selected"}}Active{{/link-to}}
  • Completed diff --git a/tests/unit/routes/todos/active-test.js b/tests/unit/routes/todos/active-test.js new file mode 100644 index 0000000..3c16ef2 --- /dev/null +++ b/tests/unit/routes/todos/active-test.js @@ -0,0 +1,14 @@ +import { + moduleFor, + test +} from 'ember-qunit'; + +moduleFor('route:todos/active', { + // Specify the other units that are required for this test. + // needs: ['controller:foo'] +}); + +test('it exists', function(assert) { + var route = this.subject(); + assert.ok(route); +});