Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit b784422

Browse files
daviouswesleycho
authored andcommitted
feat(datepicker): yearRange -> yearRows and yearColumns
BREAKING CHANGE: yearRange is replaced by yearRows and yearColumns for manually specifying the dimensions of the yearpicker. If one wants the prior behavior with yearRange with a different number of rows, just set yearRows Closes #3348 Closes #4970
1 parent d84cb65 commit b784422

File tree

4 files changed

+35
-23
lines changed

4 files changed

+35
-23
lines changed

src/datepicker/datepicker.js

+12-9
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
1414
maxMode: 'year',
1515
showWeeks: true,
1616
startingDay: 0,
17-
yearRange: 20,
17+
yearRows: 4,
18+
yearColumns: 5,
1819
minDate: null,
1920
maxDate: null,
2021
shortcutPropagation: false
@@ -33,7 +34,7 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
3334
});
3435

3536
// Evaled configuration attributes
36-
angular.forEach(['showWeeks', 'startingDay', 'yearRange', 'shortcutPropagation'], function(key) {
37+
angular.forEach(['showWeeks', 'startingDay', 'yearRows', 'yearColumns', 'shortcutPropagation'], function(key) {
3738
self[key] = angular.isDefined($attrs[key]) ? $scope.$parent.$eval($attrs[key]) : datepickerConfig[key];
3839
});
3940

@@ -396,15 +397,16 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
396397
}])
397398

398399
.controller('UibYearpickerController', ['$scope', '$element', 'dateFilter', function(scope, $element, dateFilter) {
399-
var range;
400+
var columns, range;
400401
this.element = $element;
401402

402403
function getStartingYear(year) {
403404
return parseInt((year - 1) / range, 10) * range + 1;
404405
}
405406

406407
this.yearpickerInit = function() {
407-
range = this.yearRange;
408+
columns = this.yearColumns;
409+
range = this.yearRows * columns;
408410
this.step = { years: range };
409411
};
410412

@@ -420,7 +422,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
420422
}
421423

422424
scope.title = [years[0].label, years[range - 1].label].join(' - ');
423-
scope.rows = this.split(years, 5);
425+
scope.rows = this.split(years, columns);
426+
scope.columns = columns;
424427
};
425428

426429
this.compare = function(date1, date2) {
@@ -433,13 +436,13 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
433436
if (key === 'left') {
434437
date = date - 1;
435438
} else if (key === 'up') {
436-
date = date - 5;
439+
date = date - columns;
437440
} else if (key === 'right') {
438441
date = date + 1;
439442
} else if (key === 'down') {
440-
date = date + 5;
443+
date = date + columns;
441444
} else if (key === 'pageup' || key === 'pagedown') {
442-
date += (key === 'pageup' ? - 1 : 1) * this.step.years;
445+
date += (key === 'pageup' ? - 1 : 1) * range;
443446
} else if (key === 'home') {
444447
date = getStartingYear(this.activeDate.getFullYear());
445448
} else if (key === 'end') {
@@ -651,7 +654,7 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
651654
datepickerEl.attr('date-disabled', 'dateDisabled({ date: date, mode: mode })');
652655
}
653656

654-
angular.forEach(['formatDay', 'formatMonth', 'formatYear', 'formatDayHeader', 'formatDayTitle', 'formatMonthTitle', 'showWeeks', 'startingDay', 'yearRange'], function(key) {
657+
angular.forEach(['formatDay', 'formatMonth', 'formatYear', 'formatDayHeader', 'formatDayTitle', 'formatMonthTitle', 'showWeeks', 'startingDay', 'yearRows', 'yearColumns'], function(key) {
655658
if (angular.isDefined(attrs[key])) {
656659
datepickerEl.attr(cameltoDash(key), attrs[key]);
657660
}

src/datepicker/docs/readme.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,14 @@ The datepicker has 3 modes:
9191
_(Default: `uib/template/datepicker/datepicker.html`)_ -
9292
Add the ability to override the template used on the component.
9393

94-
* `year-range`
95-
_(Default: `20`)_ -
96-
Number of years displayed in year selection.
97-
94+
* `year-rows`
95+
_(Default: `4`)_ -
96+
Number of rows displayed in year selection.
97+
98+
* `year-columns`
99+
_(Default: `5`)_ -
100+
Number of columns displayed in year selection.
101+
98102
* `ng-model-options`
99103
_(Default: {})_ -
100104
allowInvalid support. [More on ngModelOptions](https://docs.angularjs.org/api/ng/directive/ngModelOptions).

src/datepicker/test/datepicker.spec.js

+14-9
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,8 @@ describe('datepicker', function() {
11081108
'format-month="MMM"' +
11091109
'format-month-title="yy"' +
11101110
'format-year="yy"' +
1111-
'year-range="10"></uib-datepicker>')($rootScope);
1111+
'year-rows="3"' +
1112+
'year-columns="4"></uib-datepicker>')($rootScope);
11121113
$rootScope.$digest();
11131114
});
11141115

@@ -1132,10 +1133,11 @@ describe('datepicker', function() {
11321133
clickTitleButton();
11331134
clickTitleButton();
11341135

1135-
expect(getTitle()).toBe('01 - 10');
1136+
expect(getTitle()).toBe('05 - 16');
11361137
expect(getOptions()).toEqual([
1137-
['01', '02', '03', '04', '05'],
1138-
['06', '07', '08', '09', '10']
1138+
['05', '06', '07', '08'],
1139+
['09', '10', '11', '12'],
1140+
['13', '14', '15', '16']
11391141
]);
11401142
});
11411143

@@ -1166,7 +1168,8 @@ describe('datepicker', function() {
11661168
uibDatepickerConfig.formatDayTitle = 'MMM, yy';
11671169
uibDatepickerConfig.formatMonthTitle = 'yy';
11681170
uibDatepickerConfig.showWeeks = false;
1169-
uibDatepickerConfig.yearRange = 10;
1171+
uibDatepickerConfig.yearRows = 2;
1172+
uibDatepickerConfig.yearColumns = 5;
11701173
uibDatepickerConfig.startingDay = 6;
11711174

11721175
element = $compile('<uib-datepicker ng-model="date"></uib-datepicker>')($rootScope);
@@ -2435,7 +2438,8 @@ describe('datepicker', function() {
24352438
'format-month="MMM"' +
24362439
'format-month-title="yy"' +
24372440
'format-year="yy"' +
2438-
'year-range="10" /></div>')($rootScope);
2441+
'year-rows="3"' +
2442+
'year-columns="4"></uib-datepicker>')($rootScope);
24392443
$rootScope.$digest();
24402444
assignElements(wrapElement);
24412445
});
@@ -2461,10 +2465,11 @@ describe('datepicker', function() {
24612465
assignElements(wrapElement);
24622466
clickTitleButton();
24632467
assignElements(wrapElement);
2464-
expect(getTitle()).toBe('01 - 10');
2468+
expect(getTitle()).toBe('05 - 16');
24652469
expect(getOptions()).toEqual([
2466-
['01', '02', '03', '04', '05'],
2467-
['06', '07', '08', '09', '10']
2470+
['05', '06', '07', '08'],
2471+
['09', '10', '11', '12'],
2472+
['13', '14', '15', '16']
24682473
]);
24692474
});
24702475

template/datepicker/year.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<thead>
33
<tr>
44
<th><button type="button" class="btn btn-default btn-sm pull-left uib-left" ng-click="move(-1)" tabindex="-1"><i class="glyphicon glyphicon-chevron-left"></i></button></th>
5-
<th colspan="3"><button id="{{::uniqueId}}-title" role="heading" aria-live="assertive" aria-atomic="true" type="button" class="btn btn-default btn-sm uib-title" ng-click="toggleMode()" ng-disabled="datepickerMode === maxMode" tabindex="-1" style="width:100%;"><strong>{{title}}</strong></button></th>
5+
<th colspan="{{::columns - 2}}"><button id="{{::uniqueId}}-title" role="heading" aria-live="assertive" aria-atomic="true" type="button" class="btn btn-default btn-sm uib-title" ng-click="toggleMode()" ng-disabled="datepickerMode === maxMode" tabindex="-1" style="width:100%;"><strong>{{title}}</strong></button></th>
66
<th><button type="button" class="btn btn-default btn-sm pull-right uib-right" ng-click="move(1)" tabindex="-1"><i class="glyphicon glyphicon-chevron-right"></i></button></th>
77
</tr>
88
</thead>

0 commit comments

Comments
 (0)