diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-05-26 02:01:59 +0200 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-05-26 02:01:59 +0200 |
commit | 6dc363a14a1d2b09d72a3f0d3e7bdfd362bad41c (patch) | |
tree | 24f789d1357b15fe5d68ec6452eaa682995204ef /js | |
parent | 0b22611a929fc317c6ad073d2ddf5f198ee836f3 (diff) |
render items
Diffstat (limited to 'js')
-rw-r--r-- | js/build/app.js | 11 | ||||
-rw-r--r-- | js/controller/ContentController.js | 11 | ||||
-rw-r--r-- | js/tests/unit/controller/ContentControllerSpec.js | 29 |
3 files changed, 45 insertions, 6 deletions
diff --git a/js/build/app.js b/js/build/app.js index fe71d10fb..52c6d8d29 100644 --- a/js/build/app.js +++ b/js/build/app.js @@ -176,12 +176,15 @@ var $__build_47_app__ = function () { } ]); app.controller('ContentController', [ + '$scope', 'Publisher', 'FeedResource', 'ItemResource', + 'SettingsResource', 'data', - function (Publisher, FeedResource, ItemResource, data) { + function ($scope, Publisher, FeedResource, ItemResource, SettingsResource, data) { 'use strict'; + $scope.Content = this; ItemResource.clear(); Publisher.publishAll(data); this.getItems = function () { @@ -203,7 +206,11 @@ var $__build_47_app__ = function () { console.log('tbd'); }; this.orderBy = function () { - console.log('tbd'); + if (SettingsResource.get('oldestFirst')) { + return '-id'; + } else { + return 'id'; + } }; this.getRelativeDate = function (timestamp) { console.log(timestamp); diff --git a/js/controller/ContentController.js b/js/controller/ContentController.js index 9258b3f11..b4f2f6498 100644 --- a/js/controller/ContentController.js +++ b/js/controller/ContentController.js @@ -8,9 +8,12 @@ * @copyright Bernhard Posselt 2014 */ app.controller('ContentController', -function (Publisher, FeedResource, ItemResource, data) { +function ($scope, Publisher, FeedResource, ItemResource, SettingsResource, + data) { 'use strict'; + $scope.Content = this; + ItemResource.clear(); // distribute data to models based on key @@ -42,7 +45,11 @@ function (Publisher, FeedResource, ItemResource, data) { }; this.orderBy = () => { - console.log('tbd'); + if (SettingsResource.get('oldestFirst')) { + return '-id'; + } else { + return 'id'; + } }; this.getRelativeDate = (timestamp) => { diff --git a/js/tests/unit/controller/ContentControllerSpec.js b/js/tests/unit/controller/ContentControllerSpec.js index dc062474a..94cb09f21 100644 --- a/js/tests/unit/controller/ContentControllerSpec.js +++ b/js/tests/unit/controller/ContentControllerSpec.js @@ -10,10 +10,16 @@ describe('ContentController', () => { 'use strict'; + let scope; + beforeEach(module('News', ($provide) => { $provide.value('BASE_URL', 'base'); })); + beforeEach(inject(($rootScope) => { + scope = $rootScope.$new(); + })); + it('should publish data to models', inject(($controller, Publisher, FeedResource, ItemResource) => { @@ -27,7 +33,8 @@ describe('ContentController', () => { {id: 3}, {id: 4} ] - } + }, + $scope: scope }); expect(controller.getItems().length).toBe(2); @@ -40,10 +47,28 @@ describe('ContentController', () => { ItemResource.clear = jasmine.createSpy('clear'); $controller('ContentController', { - data: {} + data: {}, + $scope: scope }); expect(ItemResource.clear).toHaveBeenCalled(); })); + + it('should return order by', inject(($controller, + SettingsResource) => { + + $controller('ContentController', { + SettingsResource: SettingsResource, + $scope: scope, + data: {}, + }); + + expect(scope.Content.orderBy()).toBe('id'); + + SettingsResource.set('oldestFirst', true); + + expect(scope.Content.orderBy()).toBe('-id'); + })); + }); |