diff --git a/controller.js b/controller.js index 9354734..1b35d08 100644 --- a/controller.js +++ b/controller.js @@ -1,4 +1,75 @@ angular.module('test', []) -.controller('testController', ['$scope', function($scope) { - -}]); \ No newline at end of file + .directive('numbers', function() { + return { + templateUrl: 'numbers.html' + }; + }) + + .factory('numbersBuilder', function() { + return { + build: function() { + return []; + }, + + getRange: function(min, max) { + var items = []; + if(min === '' && max === '') { + return items; + } + + if(max === '' && min) { + items.push(min); + return items; + } + + if(min === '' && max) { + items.push(max); + return items; + } + + for(var i = min; i <= max; i++) { + items.push(i); + } + + return items; + } + }; + }) + + .controller('testController', ['$scope', 'numbersBuilder', function($scope, numbersBuilder) { + function initController() { + $scope.items = numbersBuilder.build(); + $scope.minNumber = ''; + $scope.maxNumber = ''; + } + + $scope.displayLeft = function() { + $scope.floatRight = false; + }; + + $scope.displayRight = function() { + $scope.floatRight = true; + }; + + $scope.generateRange = function() { + $scope.items = numbersBuilder.getRange($scope.minNumber, $scope.maxNumber); + }; + + $scope.showAll = function() { + $scope.showEvens = false; + $scope.showOdds = false; + }; + + $scope.filterEvens = function() { + $scope.showEvens = true; + $scope.showOdds = false; + }; + + $scope.filterOdds = function() { + $scope.showEvens = false; + $scope.showOdds = true; + }; + + initController(); + + }]); \ No newline at end of file diff --git a/index.html b/index.html index 4079a43..f460f07 100644 --- a/index.html +++ b/index.html @@ -9,24 +9,25 @@