select-time.js

angular.module('homepage').
directive('selectTime', function () {
	return {
		controller: 'notePanelController',
		restrict: 'E',
		replace: true,
		scope: {
            choosen: '=',
            getData: '='
        },
        transclude: true,
		templateUrl: 'components/common-components/select-time/select-time.html'
	}
}).
controller('notePanelController', function($scope, DateUtility) {
    function getDateRange(index) {
        var month, dateRange = {};
		if (index === "ALL") {
			dateRange.start = DateUtility.getYearStart(new Date());
			dateRange.end = DateUtility.getYearEnd(new Date());
		} else {
			month = new Date($scope.choosen.year, index, 1);
			dateRange = DateUtility.getMonthDateRange(month);
        }
        return dateRange;
    }

    $scope.years = [ 2018, 2017, 2016 ];
    $scope.months = DateUtility.getMonthTitles(true);
    
    $scope.isYearDdOpen = false;

	$scope.selectMonth = function(index) {
        var dateRange = getDateRange(index);
        $scope.isYearDdOpen = false;
		$scope.choosen.month = index;
		$scope.getData(dateRange);
	};

	$scope.selectYear = function(year) {
        var dateRange = getDateRange($scope.choosen.month);
		$scope.isYearDdOpen = !$scope.isYearDdOpen;
		$scope.choosen.year = year;
        $scope.getData(dateRange);
	};
});