diff --git a/README.md b/README.md index e53160d9..8edaa01f 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Put the dp-date-picker component wherever you need it. | Name | Type | Default | Applies To | Description | |----------------------|:-----------------------------------:|:------------------:|:-------------------------:|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | mode | `"day"\|"month"\|"time"\|"daytime"` | `"day"` | All | The mode of the calender which will be displayed in the picker | -| displayDate | `Moment\|String` | current date | `day\|month\|daytime` | Indicates on what date to open the calendar on | +| displayDate | `Moment\|String` | current date | `day\|month\|daytime` | Indicates on what date to open the calendar on | | disabled | `Boolean` | `false` | All | If set to true the input would be disabled | | placeholder | `String` | `""` | All | The date-picker input placeholder | | required | `Boolean` | `undefined` | All | This is a validation rule, if there won't be any selected date then the containing form will be invalid. | @@ -66,58 +66,60 @@ Put the dp-date-picker component wherever you need it. Here are the available configurations: -| Name | Type | Default | Applies To | Description | -|-----------------------------|:---------------------:|:-------------------------------------------------------------------------:|:-------------------------:|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| appendTo | `String\|HTMLElement` | `undefined` | All | The selector/element to which the calendar popup will append to (this is useful for `overflow: hidden` container issues). Please note that the `appendTo` element will be set with position `absolute` if it has position `static` (the default position). | -| locale | `String` | [`moment.locale()`](https://momentjs.com/docs/#/i18n/getting-locale/) | All | Localisation of language (see in the demo all supported locales) | -| disableKeypress | `Boolean` | `false` | All | Disables the possibility to change the date value by typing it - changing the date would be possible only from the picker | -| format | `String` | `"DD-MM-YYYY"` | All | If ngModel provided as `String` the format is required, this format also will be used as the input format style. | -| onOpenDelay | `Number` | `0` | All | The delay (in ms) between the date picker focusing and the date-picker popup apparel | -| drops | `'up'\|'down'` | `undefined` down if possible | All | Whether the picker appears below or above the input element. | -| opens | `'right'\|'left'` | `undefined` right if possible | All | Whether the picker appears aligned to the left or to the right the input element. | -| closeOnSelect | `Boolean` | `true` | `day\|month` | If set to `true` will close the date-picker after choosing a date from the calender, otherwise, won't. | -| openOnClick | `Boolean` | `true` | `day\|month\|daytime` | If set to `false` will not open the date-picker when input gets clicked, otherwise, will. | -| openOnFocus | `Boolean` | `true` | `day\|month\|daytime` | If set to `false` will not open the date-picker when input gets focused, otherwise, will. | -| closeOnSelectDelay | `Number` | `100` | `day\|month` | The delay (in ms) between the date selection and the date-picker collapse | -| allowMultiSelect | `Boolean` | `undefined` | `day\|month` | If set to `true` will allow for choosing multiple dates. `false` will force a single selection. If `undefined`, the picker will attempt to guess based on the type of the input value. | -| dayBtnFormat | `String` | `DD` | `day\|daytime` | The day format of the day button in the calendar. | -| dayBtnFormatter | `(Moment) => String` | `undefined` | `day\|daytime` | The formatter (callback function) of the day button in the calendar. | -| dayBtnCssClassCallback | `(Moment) => String` | `undefined` | `day\|daytime` | Callback for adding custom CSS classes to the day button in the calendar. Can contain multiple classes, just seperate with a space. | -| enableMonthSelector | `Boolean` | `true` | `day\|daytime` | Whether to enable/disable the selection of a moth granularity picker. | -| firstDayOfWeek | `String` | `"su"` | `day\|daytime` | The first day of the calendar's week. Should be one of: `"su", "mo", "tu", "we", "th", "fr", "sa"` | -| isDayDisabledCallback | `(Moment) => boolean` | `undefined` | `day\|daytime` | Callback which should indicate if specific day is disabled. | -| monthFormat | `String` | `"MMM-YYYY"` | `day\|daytime` | The date format of the day calendar, the one that seen above the calendar days. Will be overwritten if `monthFormatter` provided. | -| monthFormatter | `(Moment) => String` | `undefined` | `day\|daytime` | The date formatter (callback function) of the day calendar, the one that seen above the calendar days. | -| showNearMonthDays | `Boolean` | `true` | `day\|daytime` | Whether to show/hide next and previous month days. | -| showWeekNumbers | `Boolean` | `false` | `day\|daytime` | Whether to show/hide the week number of each week (iso week number). | -| isMonthDisabledCallback | `(Moment) => boolean` | `undefined` | `day\|month\|daytime` | Callback which should indicate if specific month is disabled (month selector). | -| max | `Moment\|String` | `undefined` | `day\|month\|daytime` | Disables all dates (on the date-picker) that are set to after the `max`, note that if invalid date would be set by the input then the date picker value would be the max date but the input will show the user typed date. | -| min | `Moment\|String` | `undefined` | `day\|month\|daytime` | Disables all dates (on the date-picker) that are set to before the `min`, note that if invalid date would be set by the input then the date picker value would be the min date but the input will show the user typed date. | -| monthBtnFormat | `String` | `DD` | `day\|month\|daytime` | The month format of the month button in the calendar. | -| monthBtnFormatter | `(Moment) => String` | `undefined` | `day\|month\|daytime` | The formatter (callback function) of the month button in the calendar. | -| monthBtnCssClassCallback | `(Moment) => String` | `undefined` | `day\|month\|daytime` | Callback for adding custom CSS classes to the month button in the calendar. Can contain multiple classes, just seperate with a space. | -| yearFormat | `String` | `"YYYY"` | `day\|month\|daytime` | The date format of the month calendar, the one that seen above the calendar months. Will be overwritten if `yearFormatter` provided. (available when `enableMonthSelector` is set to `true`). | -| yearFormatter | `(Moment) => String` | `undefined` | `day\|month\|daytime` | The date formatter (callback function) of the month calendar, the one that seen above the calendar months. (available when `enableMonthSelector` is set to `true`). | -| hours12Format | `String` | `"hh"` | `daytime\|time` | The hours format of the time select when `showTwentyFourHours` is `false`. | -| hours24Format | `String` | `"HH"` | `daytime\|time` | The hours format of the time select when `showTwentyFourHours` is `true`. | -| maxTime | `Moment\|String` | `undefined` | `daytime\|time` | Disables arrow buttons on the time select that would make the time after the `maxTime`. | -| meridiemFormat | `String` | `"A"` | `daytime\|time` | The AM/PM format of the time select when `showTwentyFourHours` is `false`. | -| minTime | `Moment\|String` | `undefined` | `daytime\|time` | Disables arrow buttons on the time select that would make the time before the `minTime`. | -| minutesFormat | `String` | `"mm"` | `daytime\|time` | The minutes format of the time select. | -| minutesInterval | `number` | `1` | `daytime\|time` | The number of minutes that will be added/subtracted when clicking up/down arrows on the time select. | -| secondsFormat | `String` | `"ss"` | `daytime\|time` | The seconds format of the time select. | -| secondsInterval | `number` | `1` | `daytime\|time` | The number of seconds that will be added/subtracted when clicking up/down arrows on the time select. | -| showSeconds | `boolean` | `false` | `daytime\|time` | If set to `true` will show seconds in the time select, otherwise, won't. | -| showTwentyFourHours | `boolean` | `false` | `daytime\|time` | If set to `true` will show hours in 24 hour format. `false` will show hours in 12 hours format and append AM/PM to the end of the time select. | -| timeSeparator | `String` | `":"` | `daytime\|time` | The separator that will be placed between hours and minutes and between minutes and seconds on the time select. | -| showMultipleYearsNavigation | `boolean` | `false` | `day\|month\|daytime` | If set to `true` will show buttons to navigate by multiple years (10 by default) | -| multipleYearsNavigateBy | `number` | `10` | `day\|month\|daytime` | Number of years to navigate when showMultipleYearsNavigation is `true` | -| returnedValueType | `ECalendarValue` | `Moment` | All | The returned value type (`Moment`, `Moment[]`, `string`, `string[]` | -| unSelectOnClick | `boolean` | `true` | `day\|month` | Will allow disallow/unselect to selected date by clicking on the selected date | -| inputElementContainer | `string\|HTMLElement` | `undefined` | All | Will place picker popup relative to the provided elemenr (if string provided will used as a selector) | -| showGoToCurrent | `boolean` | `true` | All | Show/Hides the go to current button on the calendars navigation | -| hideOnOutsideClick | `boolean` | `true` | All | Show/Hides the picker popup after click outside of the component | -| closeOnEnter | `boolean` | `true` | All | Hides the picker popup after enter button keypress | +| Name | Type | Default | Applies To | Description | +|----------------------------------|:---------------------:|:-------------------------------------------------------------------------:|:-------------------------:|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| appendTo | `String\|HTMLElement` | `undefined` | All | The selector/element to which the calendar popup will append to (this is useful for `overflow: hidden` container issues). Please note that the `appendTo` element will be set with position `absolute` if it has position `static` (the default position). | +| locale | `String` | [`moment.locale()`](https://momentjs.com/docs/#/i18n/getting-locale/) | All | Localisation of language (see in the demo all supported locales) | +| disableKeypress | `Boolean` | `false` | All | Disables the possibility to change the date value by typing it - changing the date would be possible only from the picker | +| format | `String` | `"DD-MM-YYYY"` | All | If ngModel provided as `String` the format is required, this format also will be used as the input format style. | +| onOpenDelay | `Number` | `0` | All | The delay (in ms) between the date picker focusing and the date-picker popup apparel | +| drops | `'up'\|'down'` | `undefined` down if possible | All | Whether the picker appears below or above the input element. | +| opens | `'right'\|'left'` | `undefined` right if possible | All | Whether the picker appears aligned to the left or to the right the input element. | +| closeOnSelect | `Boolean` | `true` | `day\|month` | If set to `true` will close the date-picker after choosing a date from the calender, otherwise, won't. | +| openOnClick | `Boolean` | `true` | `day\|month\|daytime` | If set to `false` will not open the date-picker when input gets clicked, otherwise, will. | +| openOnFocus | `Boolean` | `true` | `day\|month\|daytime` | If set to `false` will not open the date-picker when input gets focused, otherwise, will. | +| closeOnSelectDelay | `Number` | `100` | `day\|month` | The delay (in ms) between the date selection and the date-picker collapse | +| allowMultiSelect | `Boolean` | `undefined` | `day\|month` | If set to `true` will allow for choosing multiple dates. `false` will force a single selection. If `undefined`, the picker will attempt to guess based on the type of the input value. | +| dayBtnFormat | `String` | `DD` | `day\|daytime` | The day format of the day button in the calendar. | +| dayBtnFormatter | `(Moment) => String` | `undefined` | `day\|daytime` | The formatter (callback function) of the day button in the calendar. | +| dayBtnCssClassCallback | `(Moment) => String` | `undefined` | `day\|daytime` | Callback for adding custom CSS classes to the day button in the calendar. Can contain multiple classes, just seperate with a space. | +| enableMonthSelector | `Boolean` | `true` | `day\|daytime` | Whether to enable/disable the selection of a moth granularity picker. | +| firstDayOfWeek | `String` | `"su"` | `day\|daytime` | The first day of the calendar's week. Should be one of: `"su", "mo", "tu", "we", "th", "fr", "sa"` | +| isDayDisabledCallback | `(Moment) => boolean` | `undefined` | `day\|daytime` | Callback which should indicate if specific day is disabled. | +| monthFormat | `String` | `"MMM-YYYY"` | `day\|daytime` | The date format of the day calendar, the one that seen above the calendar days. Will be overwritten if `monthFormatter` provided. | +| monthFormatter | `(Moment) => String` | `undefined` | `day\|daytime` | The date formatter (callback function) of the day calendar, the one that seen above the calendar days. | +| showNearMonthDays | `Boolean` | `true` | `day\|daytime` | Whether to show/hide next and previous month days. | +| showWeekNumbers | `Boolean` | `false` | `day\|daytime` | Whether to show/hide the week number of each week (iso week number). | +| isMonthDisabledCallback | `(Moment) => boolean` | `undefined` | `day\|month\|daytime` | Callback which should indicate if specific month is disabled (month selector). | +| max | `Moment\|String` | `undefined` | `day\|month\|daytime` | Disables all dates (on the date-picker) that are set to after the `max`, note that if invalid date would be set by the input then the date picker value would be the max date but the input will show the user typed date. | +| min | `Moment\|String` | `undefined` | `day\|month\|daytime` | Disables all dates (on the date-picker) that are set to before the `min`, note that if invalid date would be set by the input then the date picker value would be the min date but the input will show the user typed date. | +| monthBtnFormat | `String` | `DD` | `day\|month\|daytime` | The month format of the month button in the calendar. | +| monthBtnFormatter | `(Moment) => String` | `undefined` | `day\|month\|daytime` | The formatter (callback function) of the month button in the calendar. | +| monthBtnCssClassCallback | `(Moment) => String` | `undefined` | `day\|month\|daytime` | Callback for adding custom CSS classes to the month button in the calendar. Can contain multiple classes, just seperate with a space. | +| yearFormat | `String` | `"YYYY"` | `day\|month\|daytime` | The date format of the month calendar, the one that seen above the calendar months. Will be overwritten if `yearFormatter` provided. (available when `enableMonthSelector` is set to `true`). | +| yearFormatter | `(Moment) => String` | `undefined` | `day\|month\|daytime` | The date formatter (callback function) of the month calendar, the one that seen above the calendar months. (available when `enableMonthSelector` is set to `true`). | +| hours12Format | `String` | `"hh"` | `daytime\|time` | The hours format of the time select when `showTwentyFourHours` is `false`. | +| hours24Format | `String` | `"HH"` | `daytime\|time` | The hours format of the time select when `showTwentyFourHours` is `true`. | +| maxTime | `Moment\|String` | `undefined` | `daytime\|time` | Disables arrow buttons on the time select that would make the time after the `maxTime`. | +| meridiemFormat | `String` | `"A"` | `daytime\|time` | The AM/PM format of the time select when `showTwentyFourHours` is `false`. | +| minTime | `Moment\|String` | `undefined` | `daytime\|time` | Disables arrow buttons on the time select that would make the time before the `minTime`. | +| minutesFormat | `String` | `"mm"` | `daytime\|time` | The minutes format of the time select. | +| minutesInterval | `number` | `1` | `daytime\|time` | The number of minutes that will be added/subtracted when clicking up/down arrows on the time select. | +| secondsFormat | `String` | `"ss"` | `daytime\|time` | The seconds format of the time select. | +| secondsInterval | `number` | `1` | `daytime\|time` | The number of seconds that will be added/subtracted when clicking up/down arrows on the time select. | +| showSeconds | `boolean` | `false` | `daytime\|time` | If set to `true` will show seconds in the time select, otherwise, won't. | +| showTwentyFourHours | `boolean` | `false` | `daytime\|time` | If set to `true` will show hours in 24 hour format. `false` will show hours in 12 hours format and append AM/PM to the end of the time select. | +| timeSeparator | `String` | `":"` | `daytime\|time` | The separator that will be placed between hours and minutes and between minutes and seconds on the time select. | +| showSecondaryNavigationMonthView | `boolean` | `false` | `day\|month\|daytime` | If set to `true` will show buttons to navigate by multiple years (10 years by default) when in month view. Notice that clicking on the header of the day calendar switches to month view, so would also uses this parameter | +| secondaryNavigationStepMonthView | `number` | `10` | `day\|month\|daytime` | Number of years to navigate using the secondary navigate button on month view, when `showSecondaryNavigationMonthView` is `true`. | +| showSecondaryNavigationDayView | `boolean` | `false` | `day\|daytime` | If set to `true` will show buttons to navigate by multiple months (12 months by default) when in day view. Notice that clicking on the header of the day calendar switches to month view, so will use MonthView parameters instead. | +| secondaryNavigationStepDayView | `number` | `12` | `day\|daytime` | Number of months to navigate using the secondary navigate button on day view, when `showSecondaryNavigationDayView` is `true`. | +| returnedValueType | `ECalendarValue` | `Moment` | All | The returned value type (`Moment`, `Moment[]`, `string`, `string[]` | +| unSelectOnClick | `boolean` | `true` | `day\|month` | Will allow disallow/unselect to selected date by clicking on the selected date | +| inputElementContainer | `string\|HTMLElement` | `undefined` | All | Will place picker popup relative to the provided elemenr (if string provided will used as a selector) | +| showGoToCurrent | `boolean` | `true` | All | Show/Hides the go to current button on the calendars navigation | +| hideOnOutsideClick | `boolean` | `true` | All | Show/Hides the picker popup after click outside of the component | +| closeOnEnter | `boolean` | `true` | All | Hides the picker popup after enter button keypress | ### API: In order to use the date-picker api user the `@ViewChild` annotation in the date-picker containing component class, take at the example below: @@ -172,13 +174,13 @@ i.e. ### Attributes: -| Name | Type | Default | Description | -|----------------------|:-------------------:|:------------------------------------------------------------------------:|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| required | `Boolean` | `undefined` | This is a validation rule, if there won't be any selected date then the containing form will be invalid. | -| minDate | `Moment\|String` | `undefined` | This is a validation rule, if the selected date will be before `minDate` the containing form will be invalid. Note: if provided as string format configuration should be provided in the config object. | -| maxDate | `Moment\|String` | `undefined` | This is a validation rule, if the selected date will be after `maxDate` the containing form will be invalid. Note: if provided as string format configuration should be provided in the config object. | -| theme | `String` | `''` | Theme is a class added to the popup container (and inner components) - this will allow styling of the calendar when it's appended to outer element (for example - body). There is a built in theme named dp-material, you can find it in the demo. | -| config | `IDayCalendarConfig` | See Below | Configuration object - see description below. | +| Name | Type | Default | Description | +|----------------------|:--------------------:|:------------------------------------------------------------------------:|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| required | `Boolean` | `undefined` | This is a validation rule, if there won't be any selected date then the containing form will be invalid. | +| minDate | `Moment\|String` | `undefined` | This is a validation rule, if the selected date will be before `minDate` the containing form will be invalid. Note: if provided as string format configuration should be provided in the config object. | +| maxDate | `Moment\|String` | `undefined` | This is a validation rule, if the selected date will be after `maxDate` the containing form will be invalid. Note: if provided as string format configuration should be provided in the config object. | +| theme | `String` | `''` | Theme is a class added to the popup container (and inner components) - this will allow styling of the calendar when it's appended to outer element (for example - body). There is a built in theme named dp-material, you can find it in the demo. | +| config | `IDayCalendarConfig` | See Below | Configuration object - see description below. | ### Attributes (Output): | Name | Event Arguments | Description | @@ -196,31 +198,33 @@ i.e. ``` Here are the available configurations: -| Name | Type | Default | Description | -|-----------------------------|:--------------------:|:-------------------------------------------------------------------------:|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| format | `String` | `"DD-MM-YYYY"` | If ngModel provided as `String` the format is required, this format also will be used as the input format style. | -| firstDayOfWeek | `String` | `"su"` | The first day of the calendar's week. Should be one of: `"su", "mo", "tu", "we", "th", "fr", "sa"` | -| monthFormat | `String` | `"MMM-YYYY"` | The date format of the day calendar, the one that seen above the calendar days. Will be overwritten if `monthFormatter` provided. | -| monthFormatter | `(Moment) => String` | `undefined` | The date formatter (callback function) of the day calendar, the one that seen above the calendar days. | -| yearFormat | `String` | `"YYYY"` | The date format of the month calendar, the one that seen above the calendar months. Will be overwritten if `yearFormatter` provided. (available when `enableMonthSelector` is set to `true`). | -| yearFormatter | `(Moment) => String` | `undefined` | The date formatter (callback function) of the month calendar, the one that seen above the calendar months. (available when `enableMonthSelector` is set to `true`). | -| allowMultiSelect | `Boolean` | `undefined` | If set to `true` will allow for choosing multiple dates. `false` will force a single selection. If `undefined`, the picker will attempt to guess based on the type of the input value. | -| min | `Moment\|String` | `undefined` | Disables all dates (on the date-picker) that are set to before the `min`, note that if invalid date would be set by the input then the date picker value would be the min date but the input will show the user typed date. | -| max | `Moment\|String` | `undefined` | Disables all dates (on the date-picker) that are set to after the `max`, note that if invalid date would be set by the input then the date picker value would be the max date but the input will show the user typed date. | -| showNearMonthDays | `Boolean` | `true` | Whether to show/hide next and previous month days. | -| showWeekNumbers | `Boolean` | `false` | Whether to show/hide the week number of each week (iso week number). | -| enableMonthSelector | `Boolean` | `true` | Whether to enable/disable the selection of a moth granularity picker. | -| isDayDisabledCallback | `(Moment) => boolean`| `undefined` | Callback which should indicate if specific day is disabled. | -| isMonthDisabledCallback | `(Moment) => boolean`| `undefined` | Callback which should indicate if specific month is disabled (month selector). | -| dayBtnFormat | `String` | `DD` | The day format of the day button in the calendar. | -| dayBtnFormatter | `(Moment) => String` | `undefined` | The formatter (callback function) of the day button in the calendar. | -| dayBtnCssClassCallback | `(Moment) => String` | `undefined` | Callback which can add custom CSS classes to the day button in the calendar. Multiple classes can be returned with a space between them. | -| monthBtnFormat | `String` | `DD` | The month format of the month button in the calendar. | -| monthBtnFormatter | `(Moment) => String` | `undefined` | The formatter (callback function) of the month button in the calendar. | -| monthBtnCssClassCallback | `(Moment) => String` | `undefined` | Callback which can add custom CSS classes to the month button in the calendar. Multiple classes can be returned with a space between them. | -| showMultipleYearsNavigation | `boolean` | `false` | If set to `true` will show buttons to navigate by multiple years (10 by default) | -| multipleYearsNavigateBy | `number` | `10` | Number of years to navigate when showMultipleYearsNavigation is `true` | -| numOfMonthRows | `1, 2, 3, 4, 6, 12` | `4` | Number of rows to be shown on month calendar | +| Name | Type | Default | Description | +|----------------------------------|:--------------------:|:-------------------------------------------------------------------------:|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| format | `String` | `"DD-MM-YYYY"` | If ngModel provided as `String` the format is required, this format also will be used as the input format style. | +| firstDayOfWeek | `String` | `"su"` | The first day of the calendar's week. Should be one of: `"su", "mo", "tu", "we", "th", "fr", "sa"` | +| monthFormat | `String` | `"MMM-YYYY"` | The date format of the day calendar, the one that seen above the calendar days. Will be overwritten if `monthFormatter` provided. | +| monthFormatter | `(Moment) => String` | `undefined` | The date formatter (callback function) of the day calendar, the one that seen above the calendar days. | +| yearFormat | `String` | `"YYYY"` | The date format of the month calendar, the one that seen above the calendar months. Will be overwritten if `yearFormatter` provided. (available when `enableMonthSelector` is set to `true`). | +| yearFormatter | `(Moment) => String` | `undefined` | The date formatter (callback function) of the month calendar, the one that seen above the calendar months. (available when `enableMonthSelector` is set to `true`). | +| allowMultiSelect | `Boolean` | `undefined` | If set to `true` will allow for choosing multiple dates. `false` will force a single selection. If `undefined`, the picker will attempt to guess based on the type of the input value. | +| min | `Moment\|String` | `undefined` | Disables all dates (on the date-picker) that are set to before the `min`, note that if invalid date would be set by the input then the date picker value would be the min date but the input will show the user typed date. | +| max | `Moment\|String` | `undefined` | Disables all dates (on the date-picker) that are set to after the `max`, note that if invalid date would be set by the input then the date picker value would be the max date but the input will show the user typed date. | +| showNearMonthDays | `Boolean` | `true` | Whether to show/hide next and previous month days. | +| showWeekNumbers | `Boolean` | `false` | Whether to show/hide the week number of each week (iso week number). | +| enableMonthSelector | `Boolean` | `true` | Whether to enable/disable the selection of a moth granularity picker. | +| isDayDisabledCallback | `(Moment) => boolean`| `undefined` | Callback which should indicate if specific day is disabled. | +| isMonthDisabledCallback | `(Moment) => boolean`| `undefined` | Callback which should indicate if specific month is disabled (month selector). | +| dayBtnFormat | `String` | `DD` | The day format of the day button in the calendar. | +| dayBtnFormatter | `(Moment) => String` | `undefined` | The formatter (callback function) of the day button in the calendar. | +| dayBtnCssClassCallback | `(Moment) => String` | `undefined` | Callback which can add custom CSS classes to the day button in the calendar. Multiple classes can be returned with a space between them. | +| monthBtnFormat | `String` | `DD` | The month format of the month button in the calendar. | +| monthBtnFormatter | `(Moment) => String` | `undefined` | The formatter (callback function) of the month button in the calendar. | +| monthBtnCssClassCallback | `(Moment) => String` | `undefined` | Callback which can add custom CSS classes to the month button in the calendar. Multiple classes can be returned with a space between them. | +| showSecondaryNavigationMonthView | `boolean` | `false` | If set to `true` will show buttons to navigate by multiple years (10 years by default) when in month view. Notice that clicking on the header of the day calendar switches to month view | +| secondaryNavigationStepMonthView | `number` | `10` | Number of years to navigate using the secondary navigate button on month view, when `showSecondaryNavigationMonthView` is `true`. | +| showSecondaryNavigationDayView | `boolean` | `false` | If set to `true` will show buttons to navigate by multiple months (12 months by default) when in day view. Notice that clicking on the header of the day calendar switches to month view, so will use MonthView parameters instead. | +| secondaryNavigationStepDayView | `number` | `12` | Number of months to navigate using the secondary navigate button on day view, when `showSecondaryNavigationDayView` is `true`. | +| numOfMonthRows | `1, 2, 3, 4, 6, 12` | `4` | Number of rows to be shown on month calendar | ## Inline - Month Calendar @@ -256,21 +260,21 @@ i.e. ``` Here are the available configurations: -| Name | Type | Default | Description | -|-----------------------------|:--------------------:|:-------------------------------------------------------------------------:|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| format | `String` | `"DD-MM-YYYY"` | If ngModel provided as `String` the format is required, this format also will be used as the input format style. | -| yearFormat | `String` | `"YYYY"` | The date format of the month calendar, the one that seen above the calendar months. Will be overwritten if `yearFormatter` provided. (available when `enableMonthSelector` is set to `true`). | -| yearFormatter | `(Moment) => String` | `undefined` | The date formatter (callback function) of the month calendar, the one that seen above the calendar months. (available when `enableMonthSelector` is set to `true`). | -| allowMultiSelect | `Boolean` | `undefined` | If set to `true` will allow for choosing multiple dates. `false` will force a single selection. If `undefined`, the picker will attempt to guess based on the type of the input value. | -| min | `Moment\|String` | `undefined` | Disables all dates (on the date-picker) that are set to before the `min`, note that if invalid date would be set by the input then the date picker value would be the min date but the input will show the user typed date. | -| max | `Moment\|String` | `undefined` | Disables all dates (on the date-picker) that are set to after the `max`, note that if invalid date would be set by the input then the date picker value would be the max date but the input will show the user typed date. | -| isMonthDisabledCallback | `(Moment) => boolean`| `undefined` | Callback which should indicate if specific month is disabled (month selector). | -| monthBtnFormat | `String` | `DD` | The month format of the month button in the calendar. | -| monthBtnFormatter | `(Moment) => String` | `undefined` | The formatter (callback function) of the month button in the calendar. | -| monthBtnCssClassCallback | `(Moment) => String` | `undefined` | Callback which can add custom CSS classes to the month button in the calendar. Multiple classes can be returned with a space between them. | -| showMultipleYearsNavigation | `boolean` | `false` | If set to `true` will show buttons to navigate by multiple years (10 by default) | -| multipleYearsNavigateBy | `number` | `10` | Number of years to navigate when showMultipleYearsNavigation is `true` | -| numOfMonthRows | `1, 2, 3, 4, 6, 12` | `4` | Number of rows to be shown on month calendar | +| Name | Type | Default | Description | +|----------------------------------|:--------------------:|:-------------------------------------------------------------------------:|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| format | `String` | `"DD-MM-YYYY"` | If ngModel provided as `String` the format is required, this format also will be used as the input format style. | +| yearFormat | `String` | `"YYYY"` | The date format of the month calendar, the one that seen above the calendar months. Will be overwritten if `yearFormatter` provided. (available when `enableMonthSelector` is set to `true`). | +| yearFormatter | `(Moment) => String` | `undefined` | The date formatter (callback function) of the month calendar, the one that seen above the calendar months. (available when `enableMonthSelector` is set to `true`). | +| allowMultiSelect | `Boolean` | `undefined` | If set to `true` will allow for choosing multiple dates. `false` will force a single selection. If `undefined`, the picker will attempt to guess based on the type of the input value. | +| min | `Moment\|String` | `undefined` | Disables all dates (on the date-picker) that are set to before the `min`, note that if invalid date would be set by the input then the date picker value would be the min date but the input will show the user typed date. | +| max | `Moment\|String` | `undefined` | Disables all dates (on the date-picker) that are set to after the `max`, note that if invalid date would be set by the input then the date picker value would be the max date but the input will show the user typed date. | +| isMonthDisabledCallback | `(Moment) => boolean`| `undefined` | Callback which should indicate if specific month is disabled (month selector). | +| monthBtnFormat | `String` | `DD` | The month format of the month button in the calendar. | +| monthBtnFormatter | `(Moment) => String` | `undefined` | The formatter (callback function) of the month button in the calendar. | +| monthBtnCssClassCallback | `(Moment) => String` | `undefined` | Callback which can add custom CSS classes to the month button in the calendar. Multiple classes can be returned with a space between them. | +| showSecondaryNavigationMonthView | `boolean` | `false` | If set to `true` will show buttons to navigate by multiple years (10 years by default) when in month view. | +| secondaryNavigationStepMonthView | `number` | `10` | Number of years to navigate using the secondary navigate button on month view, when `showSecondaryNavigationMonthView` is `true`. | +| numOfMonthRows | `1, 2, 3, 4, 6, 12` | `4` | Number of rows to be shown on month calendar | Here is the list of APIs: @@ -361,44 +365,46 @@ i.e. ``` Here are the available configurations: -| Name | Type | Default | Description | -|-----------------------------|:--------------------:|:-------------------------------------------------------------------------:|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| format | `String` | `"DD-MM-YYYY"` | If ngModel provided as `String` the format is required, this format also will be used as the input format style. | -| firstDayOfWeek | `String` | `"su"` | The first day of the calendar's week. Should be one of: `"su", "mo", "tu", "we", "th", "fr", "sa"` | -| monthFormat | `String` | `"MMM-YYYY"` | The date format of the day calendar, the one that seen above the calendar days. Will be overwritten if `monthFormatter` provided. | -| monthFormatter | `(Moment) => String` | `undefined` | The date formatter (callback function) of the day calendar, the one that seen above the calendar days. | -| yearFormat | `String` | `"YYYY"` | The date format of the month calendar, the one that seen above the calendar months. Will be overwritten if `yearFormatter` provided. (available when `enableMonthSelector` is set to `true`). | -| yearFormatter | `(Moment) => String` | `undefined` | The date formatter (callback function) of the month calendar, the one that seen above the calendar months. (available when `enableMonthSelector` is set to `true`). | -| allowMultiSelect | `Boolean` | `undefined` | If set to `true` will allow for choosing multiple dates. `false` will force a single selection. If `undefined`, the picker will attempt to guess based on the type of the input value. | -| min | `Moment\|String` | `undefined` | Disables all dates (on the date-picker) that are set to before the `min`, note that if invalid date would be set by the input then the date picker value would be the min date but the input will show the user typed date. | -| max | `Moment\|String` | `undefined` | Disables all dates (on the date-picker) that are set to after the `max`, note that if invalid date would be set by the input then the date picker value would be the max date but the input will show the user typed date. | -| showNearMonthDays | `Boolean` | `true` | Whether to show/hide next and previous month days. | -| showWeekNumbers | `Boolean` | `false` | Whether to show/hide the week number of each week (iso week number). | -| enableMonthSelector | `Boolean` | `true` | Whether to enable/disable the selection of a moth granularity picker. | -| isDayDisabledCallback | `(Moment) => boolean`| `undefined` | Callback which should indicate if specific day is disabled. | -| isMonthDisabledCallback | `(Moment) => boolean`| `undefined` | Callback which should indicate if specific month is disabled (month selector). | -| dayBtnFormat | `String` | `DD` | The day format of the day button in the calendar. | -| dayBtnFormatter | `(Moment) => String` | `undefined` | The formatter (callback function) of the day button in the calendar. | -| dayBtnCssClassCallback | `(Moment) => String` | `undefined` | Callback which can add custom CSS classes to the day button in the calendar. Multiple classes can be returned with a space between them. | -| monthBtnFormat | `String` | `DD` | The month format of the month button in the calendar. | -| monthBtnFormatter | `(Moment) => String` | `undefined` | The formatter (callback function) of the month button in the calendar. | -| monthBtnCssClassCallback | `(Moment) => String` | `undefined` | Callback which can add custom CSS classes to the month button in the calendar. Multiple classes can be returned with a space between them. | -| hours12Format | `String` | `"hh"` | The hours format of the time select when `showTwentyFourHours` is `false`. | -| hours24Format | `String` | `"HH"` | The hours format of the time select when `showTwentyFourHours` is `true`. | -| meridiemFormat | `String` | `"A"` | The AM/PM format of the time select when `showTwentyFourHours` is `false`. | -| minutesFormat | `String` | `"mm"` | The minutes format of the time select. | -| minutesInterval | `Number` | `1` | The number of minutes that will be added/subtracted when clicking up/down arrows on the time select. | -| secondsFormat | `String` | `"ss"` | The seconds format of the time select. | -| secondsInterval | `Number` | `1` | The number of seconds that will be added/subtracted when clicking up/down arrows on the time select. | -| showSeconds | `boolean` | `false` | If set to `true` will show seconds in the time select, otherwise, won't. | -| showTwentyFourHours | `boolean` | `false` | If set to `true` will show hours in 24 hour format. `false` will show hours in 12 hours format and append AM/PM to the end of the time select. | -| timeSeparator | `String` | `":"` | The separator that will be placed between hours and minutes and between minutes and seconds on the time select. | -| showMultipleYearsNavigation | `boolean` | `false` | If set to `true` will show buttons to navigate by multiple years (10 by default). | -| multipleYearsNavigateBy | `Number` | `10` | Number of years to navigate when showMultipleYearsNavigation is `true`. | -| hideInputContainer | `Boolean` | `false` | Will hide the input element of any picker if set to `true`. | -| weekDayFormat | `String` | `ddd` | The format of the weekday name. | -| weekDayFormatter | `(Number) => String` | `undefined` | You can customize the value of any weekday with this configuration. The parameter of the callback will start with 0 as Sunday and so on. | -| numOfMonthRows | `1, 2, 3, 4, 6, 12` | `4` | Number of rows to be shown on month calendar | +| Name | Type | Default | Description | +|----------------------------------|:--------------------:|:-------------------------------------------------------------------------:|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| format | `String` | `"DD-MM-YYYY"` | If ngModel provided as `String` the format is required, this format also will be used as the input format style. | +| firstDayOfWeek | `String` | `"su"` | The first day of the calendar's week. Should be one of: `"su", "mo", "tu", "we", "th", "fr", "sa"` | +| monthFormat | `String` | `"MMM-YYYY"` | The date format of the day calendar, the one that seen above the calendar days. Will be overwritten if `monthFormatter` provided. | +| monthFormatter | `(Moment) => String` | `undefined` | The date formatter (callback function) of the day calendar, the one that seen above the calendar days. | +| yearFormat | `String` | `"YYYY"` | The date format of the month calendar, the one that seen above the calendar months. Will be overwritten if `yearFormatter` provided. (available when `enableMonthSelector` is set to `true`). | +| yearFormatter | `(Moment) => String` | `undefined` | The date formatter (callback function) of the month calendar, the one that seen above the calendar months. (available when `enableMonthSelector` is set to `true`). | +| allowMultiSelect | `Boolean` | `undefined` | If set to `true` will allow for choosing multiple dates. `false` will force a single selection. If `undefined`, the picker will attempt to guess based on the type of the input value. | +| min | `Moment\|String` | `undefined` | Disables all dates (on the date-picker) that are set to before the `min`, note that if invalid date would be set by the input then the date picker value would be the min date but the input will show the user typed date. | +| max | `Moment\|String` | `undefined` | Disables all dates (on the date-picker) that are set to after the `max`, note that if invalid date would be set by the input then the date picker value would be the max date but the input will show the user typed date. | +| showNearMonthDays | `Boolean` | `true` | Whether to show/hide next and previous month days. | +| showWeekNumbers | `Boolean` | `false` | Whether to show/hide the week number of each week (iso week number). | +| enableMonthSelector | `Boolean` | `true` | Whether to enable/disable the selection of a moth granularity picker. | +| isDayDisabledCallback | `(Moment) => boolean`| `undefined` | Callback which should indicate if specific day is disabled. | +| isMonthDisabledCallback | `(Moment) => boolean`| `undefined` | Callback which should indicate if specific month is disabled (month selector). | +| dayBtnFormat | `String` | `DD` | The day format of the day button in the calendar. | +| dayBtnFormatter | `(Moment) => String` | `undefined` | The formatter (callback function) of the day button in the calendar. | +| dayBtnCssClassCallback | `(Moment) => String` | `undefined` | Callback which can add custom CSS classes to the day button in the calendar. Multiple classes can be returned with a space between them. | +| monthBtnFormat | `String` | `DD` | The month format of the month button in the calendar. | +| monthBtnFormatter | `(Moment) => String` | `undefined` | The formatter (callback function) of the month button in the calendar. | +| monthBtnCssClassCallback | `(Moment) => String` | `undefined` | Callback which can add custom CSS classes to the month button in the calendar. Multiple classes can be returned with a space between them. | +| hours12Format | `String` | `"hh"` | The hours format of the time select when `showTwentyFourHours` is `false`. | +| hours24Format | `String` | `"HH"` | The hours format of the time select when `showTwentyFourHours` is `true`. | +| meridiemFormat | `String` | `"A"` | The AM/PM format of the time select when `showTwentyFourHours` is `false`. | +| minutesFormat | `String` | `"mm"` | The minutes format of the time select. | +| minutesInterval | `Number` | `1` | The number of minutes that will be added/subtracted when clicking up/down arrows on the time select. | +| secondsFormat | `String` | `"ss"` | The seconds format of the time select. | +| secondsInterval | `Number` | `1` | The number of seconds that will be added/subtracted when clicking up/down arrows on the time select. | +| showSeconds | `boolean` | `false` | If set to `true` will show seconds in the time select, otherwise, won't. | +| showTwentyFourHours | `boolean` | `false` | If set to `true` will show hours in 24 hour format. `false` will show hours in 12 hours format and append AM/PM to the end of the time select. | +| timeSeparator | `String` | `":"` | The separator that will be placed between hours and minutes and between minutes and seconds on the time select. | +| showSecondaryNavigationMonthView | `boolean` | `false` | If set to `true` will show buttons to navigate by multiple years (10 years by default) when in month view. Notice that clicking on the header of the day calendar switches to month view | +| secondaryNavigationStepMonthView | `number` | `10` | Number of years to navigate using the secondary navigate button on month view, when `showSecondaryNavigationMonthView` is `true`. | +| showSecondaryNavigationDayView | `boolean` | `false` | If set to `true` will show buttons to navigate by multiple months (12 months by default) when in day view. Notice that clicking on the header of the day calendar switches to month view, so will use MonthView parameters instead. | +| secondaryNavigationStepDayView | `number` | `12` | Number of months to navigate using the secondary navigate button on day view, when `showSecondaryNavigationDayView` is `true`. | +| hideInputContainer | `Boolean` | `false` | Will hide the input element of any picker if set to `true`. | +| weekDayFormat | `String` | `ddd` | The format of the weekday name. | +| weekDayFormatter | `(Number) => String` | `undefined` | You can customize the value of any weekday with this configuration. The parameter of the callback will start with 0 as Sunday and so on. | +| numOfMonthRows | `1, 2, 3, 4, 6, 12` | `4` | Number of rows to be shown on month calendar | ## Directive diff --git a/e2e/app.po.ts b/e2e/app.po.ts index 6c040985..6bdd3a80 100644 --- a/e2e/app.po.ts +++ b/e2e/app.po.ts @@ -38,11 +38,13 @@ export class DemoPage { weekNumbers = $$(`${this.popupSelector} .dp-week-number`); dayCalendarNavHeaderBtn = $(`${this.popupSelector} .dp-nav-header-btn`); deyCalendarMonthNavHeader = $(`${this.popupSelector} dp-month-calendar .dp-nav-header`); - dayTimeCalendarNavHeaderBtnInline = $(`dp-day-time-calendar .dp-nav-header-btn`); - dayCalendarNavHeaderBtnInline = $(`dp-day-calendar .dp-nav-header-btn`); - monthCalendarNavHeaderInline = $(`dp-month-calendar .dp-nav-header`); + dayTimeCalendarNavHeaderBtnInline = $(`dp-day-time-calendar#picker .dp-nav-header-btn`); + dayCalendarNavHeaderBtnInline = $(`dp-day-calendar#picker .dp-nav-header-btn`); + monthCalendarNavHeaderInline = $(`dp-month-calendar#picker .dp-nav-header`); navHeader = $(`${this.popupSelector} .dp-nav-header`); + dayCalendarNavMonthHeaderSpan = $(`${this.popupSelector} dp-month-calendar .dp-nav-header span`); dayCalendarNavMonthHeaderBtn = $(`${this.popupSelector} dp-month-calendar .dp-nav-header-btn`); + dayCalendarNavDayHeaderBtn = $(`${this.popupSelector} dp-day-calendar .dp-nav-header-btn`); calendarDisabledDays = $$(`${this.popupSelector} .dp-calendar-day[disabled]`); calendarFirstDayOfMonth = $$(`${this.popupSelector} .dp-current-month`).get(0); calendarFirstMonthOfYear = $$(`${this.popupSelector} dp-month-calendar .dp-calendar-month`).get(0); @@ -93,8 +95,11 @@ export class DemoPage { showSeconds = $('#showSeconds'); showTwentyFourHours = $('#showTwentyFourHours'); timeSeparatorInput = $('#timeSeparator'); - showMultipleYearsNavigation = $('#showMultipleYearsNavigation'); - multipleYearsNavigateBy = $('#multipleYearsNavigateBy'); + showSecondaryNavigationMonthView = $('#showSecondaryNavigationMonthView'); + secondaryNavigationStepMonthView = $('#secondaryNavigationStepMonthView'); + showSecondaryNavigationDayView = $('#showSecondaryNavigationDayView'); + hideSecondaryNavigationDayView = $('#hideSecondaryNavigationDayView'); + secondaryNavigationStepDayView = $('#secondaryNavigationStepDayView'); hideInputRadio = $('#hideInputRadio'); showOnOutsideClick = $('#showOnOutsideClick'); @@ -147,11 +152,11 @@ export class DemoPage { } clickOnDayButton(text: string) { - return element(by.cssContainingText(`${this.popupSelector} .dp-calendar-day`, text)).click(); + return element(by.cssContainingText(`${this.popupSelector} .dp-calendar-day.dp-current-month`, text)).click(); } clickOnDayButtonInline(text: string) { - return element(by.cssContainingText(`.dp-calendar-day`, text)).click(); + return element(by.cssContainingText(`#picker .dp-calendar-day.dp-current-month`, text)).click(); } clickOnMonthButton(text: string) { @@ -159,7 +164,7 @@ export class DemoPage { } clickOnMonthButtonInline(text: string) { - return element(by.cssContainingText(`.dp-calendar-month`, text)).click(); + return element(by.cssContainingText(`#picker .dp-calendar-month`, text)).click(); } waitUntilPresent(elem: ElementFinder) { diff --git a/e2e/datepicker-e2e.spec.ts b/e2e/datepicker-e2e.spec.ts index 0732e062..b5c3f8b3 100644 --- a/e2e/datepicker-e2e.spec.ts +++ b/e2e/datepicker-e2e.spec.ts @@ -291,23 +291,24 @@ describe('dpDayPicker dayPicker', () => { expect(await page.calendarFirstMonthOfYear.getText()).toEqual('1'); }); - it('should check showMultipleYearsNavigation is working', async () => { - await page.dayPickerMenu.click(); + it('should check showSecondaryNavigationMonthView is working', async () => { + const currentTime = moment(); + await page.monthPickerMenu.click(); await page.dayPickerInput.click(); - await page.dayCalendarNavHeaderBtn.click(); + expect(await page.dayCalendarLeftSecondaryNavBtn.isPresent()).toBe(false); expect(await page.dayCalendarRightSecondaryNavBtn.isPresent()).toBe(false); - await page.showMultipleYearsNavigation.click(); - await page.multipleYearsNavigateBy.clear(); - await page.multipleYearsNavigateBy.sendKeys('20'); + await page.showSecondaryNavigationMonthView.click(); + await page.secondaryNavigationStepMonthView.clear(); + await page.secondaryNavigationStepMonthView.sendKeys('20'); await page.dayPickerInput.click(); - await page.dayCalendarNavHeaderBtn.click(); await page.dayCalendarLeftSecondaryNavBtn.click(); - expect(await page.dayCalendarNavMonthHeaderBtn.getText()).toEqual(moment().subtract(20, 'year').format('YYYY')); + + expect(await page.dayCalendarNavMonthHeaderSpan.getText()).toEqual(currentTime.clone().subtract(20, 'year').format('YYYY')); await page.dayCalendarRightSecondaryNavBtn.click(); await page.dayCalendarRightSecondaryNavBtn.click(); - expect(await page.dayCalendarNavMonthHeaderBtn.getText()).toEqual(moment().add(20, 'year').format('YYYY')); + expect(await page.dayCalendarNavMonthHeaderSpan.getText()).toEqual(currentTime.clone().add(20, 'year').format('YYYY')); }); }); diff --git a/e2e/daypicker-e2e.spec.ts b/e2e/daypicker-e2e.spec.ts index c430167d..fd2fae3b 100644 --- a/e2e/daypicker-e2e.spec.ts +++ b/e2e/daypicker-e2e.spec.ts @@ -1,4 +1,5 @@ import {DemoPage} from './app.po'; +import * as moment from 'moment'; describe('dpDayPicker dayPicker', () => { let page: DemoPage; @@ -55,4 +56,66 @@ describe('dpDayPicker dayPicker', () => { expect(await page.meridiemUpBtn.getAttribute('disabled')).toBe('true'); expect(await page.meridiemDownBtn.getAttribute('disabled')).toBe('true'); }); + + it('should check showSecondaryNavigationDayView and showSecondaryNavigationMonthView are working together', async () => { + const currentTime = moment(); + await page.dayPickerMenu.click(); + await page.dayPickerInput.click(); + + expect(await page.dayCalendarLeftSecondaryNavBtn.isPresent()).toBe(false); + expect(await page.dayCalendarRightSecondaryNavBtn.isPresent()).toBe(false); + await page.dayCalendarNavHeaderBtn.click(); + expect(await page.dayCalendarLeftSecondaryNavBtn.isPresent()).toBe(false); + expect(await page.dayCalendarRightSecondaryNavBtn.isPresent()).toBe(false); + await page.dayCalendarNavHeaderBtn.click(); + + await page.scrollIntoView(await page.showSecondaryNavigationDayView); + await page.showSecondaryNavigationDayView.click(); + await page.secondaryNavigationStepDayView.clear(); + await page.secondaryNavigationStepDayView.sendKeys('20'); + await page.dayPickerInput.click(); + expect(await page.dayCalendarLeftSecondaryNavBtn.isPresent()).toBe(true); + expect(await page.dayCalendarRightSecondaryNavBtn.isPresent()).toBe(true); + await page.dayCalendarLeftSecondaryNavBtn.click(); + expect(await page.dayCalendarNavDayHeaderBtn.getText()).toEqual(currentTime.clone().subtract(20, 'month').format('MMM, YYYY')); + await page.dayCalendarRightSecondaryNavBtn.click(); + await page.dayCalendarRightSecondaryNavBtn.click(); + expect(await page.dayCalendarNavDayHeaderBtn.getText()).toEqual(currentTime.clone().add(20, 'month').format('MMM, YYYY')); + + await page.dayCalendarNavHeaderBtn.click(); + expect(await page.dayCalendarLeftSecondaryNavBtn.isPresent()).toBe(false); + expect(await page.dayCalendarRightSecondaryNavBtn.isPresent()).toBe(false); + await page.dayCalendarNavHeaderBtn.click(); + await page.clickOnBody(); + + + await page.scrollIntoView(await page.showSecondaryNavigationMonthView); + await page.showSecondaryNavigationMonthView.click(); + await page.dayPickerInput.click(); + expect(await page.dayCalendarLeftSecondaryNavBtn.isPresent()).toBe(true); + expect(await page.dayCalendarRightSecondaryNavBtn.isPresent()).toBe(true); + await page.dayCalendarNavHeaderBtn.click(); + expect(await page.dayCalendarLeftSecondaryNavBtn.isPresent()).toBe(true); + expect(await page.dayCalendarRightSecondaryNavBtn.isPresent()).toBe(true); + await page.dayCalendarNavHeaderBtn.click(); + await page.clickOnBody(); + + await page.setInputValue(page.daytimePickerInput, currentTime.format('DD-MM-YYYY')); + await page.scrollIntoView(await page.hideSecondaryNavigationDayView); + await page.hideSecondaryNavigationDayView.click(); + await page.secondaryNavigationStepMonthView.clear(); + await page.secondaryNavigationStepMonthView.sendKeys('25'); + await page.dayPickerInput.click(); + expect(await page.dayCalendarLeftSecondaryNavBtn.isPresent()).toBe(false); + expect(await page.dayCalendarRightSecondaryNavBtn.isPresent()).toBe(false); + await page.dayCalendarNavHeaderBtn.click(); + expect(await page.dayCalendarLeftSecondaryNavBtn.isPresent()).toBe(true); + expect(await page.dayCalendarRightSecondaryNavBtn.isPresent()).toBe(true); + await page.dayCalendarLeftSecondaryNavBtn.click(); + expect(await page.dayCalendarNavDayHeaderBtn.getText()).toEqual(currentTime.clone().subtract(25, 'year').format('YYYY')); + await page.dayCalendarRightSecondaryNavBtn.click(); + await page.dayCalendarRightSecondaryNavBtn.click(); + expect(await page.dayCalendarNavDayHeaderBtn.getText()).toEqual(currentTime.clone().add(25, 'year').format('YYYY')); + await page.dayCalendarNavHeaderBtn.click(); + }); }); diff --git a/e2e/daytimepicker-e2e.spec.ts b/e2e/daytimepicker-e2e.spec.ts index 61f08e71..47a3b887 100644 --- a/e2e/daytimepicker-e2e.spec.ts +++ b/e2e/daytimepicker-e2e.spec.ts @@ -1,4 +1,5 @@ import {DemoPage} from './app.po'; +import * as moment from 'moment'; describe('dpDayPicker daytimePicker', () => { let page: DemoPage; @@ -63,4 +64,32 @@ describe('dpDayPicker daytimePicker', () => { expect(await page.selectedDays.count()).toEqual(0); }); + + it('should check showSecondaryNavigationDayView is working', async () => { + const currentTime = moment(); + await page.daytimePickerInput.click(); + + expect(await page.dayCalendarLeftSecondaryNavBtn.isPresent()).toBe(false); + expect(await page.dayCalendarRightSecondaryNavBtn.isPresent()).toBe(false); + await page.dayCalendarNavHeaderBtn.click(); + expect(await page.dayCalendarLeftSecondaryNavBtn.isPresent()).toBe(false); + expect(await page.dayCalendarRightSecondaryNavBtn.isPresent()).toBe(false); + await page.dayCalendarNavHeaderBtn.click(); + + await page.showSecondaryNavigationDayView.click(); + await page.secondaryNavigationStepDayView.clear(); + await page.secondaryNavigationStepDayView.sendKeys('20'); + await page.daytimePickerInput.click(); + await page.dayCalendarLeftSecondaryNavBtn.click(); + expect(await page.dayCalendarNavDayHeaderBtn.getText()).toEqual(currentTime.clone().subtract(20, 'month').format('MMM, YYYY')); + + await page.dayCalendarRightSecondaryNavBtn.click(); + await page.dayCalendarRightSecondaryNavBtn.click(); + expect(await page.dayCalendarNavDayHeaderBtn.getText()).toEqual(currentTime.clone().add(20, 'month').format('MMM, YYYY')); + + await page.dayCalendarNavHeaderBtn.click(); + + expect(await page.dayCalendarLeftSecondaryNavBtn.isPresent()).toBe(false); + expect(await page.dayCalendarRightSecondaryNavBtn.isPresent()).toBe(false); + }); }); diff --git a/package.json b/package.json index a667c6c8..8a9a1cf5 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "e2e": "ng e2e --port 3200", "e2e:quick": "ng e2e --dev-server-target --webdriverUpdate=false", "e2e:headless": "HEADLESS=true ng e2e", + "e2e:headless-win": "set HEADLESS=true&& ng e2e --port 3200", "build:index": "cd build-helpers && node index-maker.js", "build:demo": "rm -rf dist/ && ng build --prod --base-href /angular-datepicker/ && npm run build:index", "build:prod": "ng-packagr -p package.json", diff --git a/src/demo/demo/common/conts/consts.ts b/src/demo/demo/common/conts/consts.ts index a07b65fd..d8a600ab 100644 --- a/src/demo/demo/common/conts/consts.ts +++ b/src/demo/demo/common/conts/consts.ts @@ -31,8 +31,10 @@ export const DEF_CONF: IDatePickerConfig = { showSeconds: false, showTwentyFourHours: false, timeSeparator: ':', - multipleYearsNavigateBy: 10, - showMultipleYearsNavigation: false, + secondaryNavigationStepMonthView: 10, + showSecondaryNavigationMonthView: false, + secondaryNavigationStepDayView: 12, + showSecondaryNavigationDayView: false, locale: moment.locale(), hideInputContainer: false, returnedValueType: ECalendarValue.String, diff --git a/src/demo/demo/config-form/config-form.component.html b/src/demo/demo/config-form/config-form.component.html index a5235dbc..fd03044b 100644 --- a/src/demo/demo/config-form/config-form.component.html +++ b/src/demo/demo/config-form/config-form.component.html @@ -753,35 +753,67 @@

Config options

-
+
- Show multiple years navigation buttons (showMultipleYearsNavigation): + Show multiple years navigation buttons in the month view (showSecondaryNavigationMonthView):
-
+
- Multiple years navigate by (multipleYearsNavigateBy): + Number of years to navigate using the secondary navigation button (secondaryNavigationStepMonthView):
- + +
+
+ +
+ + Show multiple months navigation buttons in the day view (showSecondaryNavigationDayView): + +
+ + +
+
+ +
+ + Number of month to navigate using the secondary navigation button (secondaryNavigationStepDayView): + +
+
diff --git a/src/demo/demo/config-form/config-form.component.ts b/src/demo/demo/config-form/config-form.component.ts index d0ec64cd..917d52c5 100644 --- a/src/demo/demo/config-form/config-form.component.ts +++ b/src/demo/demo/config-form/config-form.component.ts @@ -53,8 +53,8 @@ const MONTH_CALENDAR_OPTION_KEYS = [ 'max', 'min', 'monthBtnFormat', - 'multipleYearsNavigateBy', - 'showMultipleYearsNavigation', + 'secondaryNavigationStepMonthView', + 'showSecondaryNavigationMonthView', 'yearFormat', 'showGoToCurrent', 'unSelectOnClick', @@ -78,6 +78,8 @@ const DAY_CALENDAR_OPTION_KEYS = [ 'showGoToCurrent', 'unSelectOnClick', 'moveCalendarTo', + 'secondaryNavigationStepDayView', + 'showSecondaryNavigationDayView', ...MONTH_CALENDAR_OPTION_KEYS ]; const TIME_SELECT_SHARED_OPTION_KEYS = [ @@ -218,8 +220,10 @@ export class ConfigFormComponent implements OnInit { showSeconds: FormControl; showTwentyFourHours: FormControl; timeSeparator: FormControl; - showMultipleYearsNavigation: FormControl; - multipleYearsNavigateBy: FormControl; + showSecondaryNavigationMonthView: FormControl; + secondaryNavigationStepMonthView: FormControl; + showSecondaryNavigationDayView: FormControl; + secondaryNavigationStepDayView: FormControl; returnedValueType: FormControl; closeOnEnter: FormControl; numOfMonthRows: FormControl; @@ -265,8 +269,10 @@ export class ConfigFormComponent implements OnInit { this.showSeconds = new FormControl(this.config.showSeconds); this.showTwentyFourHours = new FormControl(this.config.showTwentyFourHours); this.timeSeparator = new FormControl(this.config.timeSeparator); - this.showMultipleYearsNavigation = new FormControl(this.config.showMultipleYearsNavigation); - this.multipleYearsNavigateBy = new FormControl(this.config.multipleYearsNavigateBy); + this.showSecondaryNavigationMonthView = new FormControl(this.config.showSecondaryNavigationMonthView); + this.secondaryNavigationStepMonthView = new FormControl(this.config.secondaryNavigationStepMonthView); + this.showSecondaryNavigationDayView = new FormControl(this.config.showSecondaryNavigationDayView); + this.secondaryNavigationStepDayView = new FormControl(this.config.secondaryNavigationStepDayView); this.returnedValueType = new FormControl(this.config.returnedValueType); this.closeOnEnter = new FormControl(this.config.closeOnEnter); this.numOfMonthRows = new FormControl(this.config.numOfMonthRows); @@ -598,15 +604,27 @@ export class ConfigFormComponent implements OnInit { }); }); - this.showMultipleYearsNavigation.valueChanges.subscribe((val) => { + this.showSecondaryNavigationMonthView.valueChanges.subscribe((val) => { this.onConfigChange.emit({ - showMultipleYearsNavigation: val + showSecondaryNavigationMonthView: val }); }); - this.multipleYearsNavigateBy.valueChanges.subscribe((val) => { + this.secondaryNavigationStepMonthView.valueChanges.subscribe((val) => { this.onConfigChange.emit({ - multipleYearsNavigateBy: val + secondaryNavigationStepMonthView: val + }); + }); + + this.showSecondaryNavigationDayView.valueChanges.subscribe((val) => { + this.onConfigChange.emit({ + showSecondaryNavigationDayView: val + }); + }); + + this.secondaryNavigationStepDayView.valueChanges.subscribe((val) => { + this.onConfigChange.emit({ + secondaryNavigationStepDayView: val }); }); diff --git a/src/demo/demo/date-pickers/day-time/day-time-demo/day-time-demo.component.ts b/src/demo/demo/date-pickers/day-time/day-time-demo/day-time-demo.component.ts index 48f91f9c..73778fe4 100644 --- a/src/demo/demo/date-pickers/day-time/day-time-demo/day-time-demo.component.ts +++ b/src/demo/demo/date-pickers/day-time/day-time-demo/day-time-demo.component.ts @@ -13,7 +13,9 @@ export class DayTimeDemoComponent extends DateComponent implements OnInit { control: FormControl; config: IDatePickerConfig = { ...DEF_CONF, - format: 'DD-MM-YYYY HH:mm:ss' + format: 'DD-MM-YYYY HH:mm:ss', + secondaryNavigationStepDayView: 12, + secondaryNavigationStepMonthView: 10 }; ngOnInit(): void { diff --git a/src/demo/demo/date-pickers/day-time/day-time-directive-demo/day-time-directive-demo.component.ts b/src/demo/demo/date-pickers/day-time/day-time-directive-demo/day-time-directive-demo.component.ts index 4fa98855..e278530f 100644 --- a/src/demo/demo/date-pickers/day-time/day-time-directive-demo/day-time-directive-demo.component.ts +++ b/src/demo/demo/date-pickers/day-time/day-time-directive-demo/day-time-directive-demo.component.ts @@ -13,7 +13,9 @@ export class DayTimeDirectiveDemoComponent extends DateComponent implements OnIn control: FormControl; config: IDatePickerConfig = { ...DEF_CONF, - format: 'DD-MM-YYYY HH:mm:ss' + format: 'DD-MM-YYYY HH:mm:ss', + secondaryNavigationStepDayView: 12, + secondaryNavigationStepMonthView: 10 }; ngOnInit(): void { diff --git a/src/demo/demo/date-pickers/day-time/day-time-inline-demo/day-time-inline-demo.component.ts b/src/demo/demo/date-pickers/day-time/day-time-inline-demo/day-time-inline-demo.component.ts index b9d1163c..ddce4abe 100644 --- a/src/demo/demo/date-pickers/day-time/day-time-inline-demo/day-time-inline-demo.component.ts +++ b/src/demo/demo/date-pickers/day-time/day-time-inline-demo/day-time-inline-demo.component.ts @@ -13,7 +13,9 @@ export class DayTimeInlineDemoComponent extends DateComponent implements OnInit control: FormControl; config: IDatePickerConfig = { ...DEF_CONF, - format: 'DD-MM-YYYY HH:mm:ss' + format: 'DD-MM-YYYY HH:mm:ss', + secondaryNavigationStepDayView: 12, + secondaryNavigationStepMonthView: 10 }; ngOnInit(): void { diff --git a/src/demo/demo/date-pickers/day/day-demo/day-demo.component.ts b/src/demo/demo/date-pickers/day/day-demo/day-demo.component.ts index ca4fd32f..5282d644 100644 --- a/src/demo/demo/date-pickers/day/day-demo/day-demo.component.ts +++ b/src/demo/demo/date-pickers/day/day-demo/day-demo.component.ts @@ -13,7 +13,9 @@ export class DayDemoComponent extends DateComponent implements OnInit { control: FormControl; config: IDatePickerConfig = { ...DEF_CONF, - format: 'DD-MM-YYYY' + format: 'DD-MM-YYYY', + secondaryNavigationStepDayView: 12, + secondaryNavigationStepMonthView: 10 }; ngOnInit(): void { diff --git a/src/demo/demo/date-pickers/day/day-directive-demo/day-directive-demo.component.ts b/src/demo/demo/date-pickers/day/day-directive-demo/day-directive-demo.component.ts index 3e8b22de..ddf03834 100644 --- a/src/demo/demo/date-pickers/day/day-directive-demo/day-directive-demo.component.ts +++ b/src/demo/demo/date-pickers/day/day-directive-demo/day-directive-demo.component.ts @@ -14,7 +14,9 @@ export class DayDirectiveDemoComponent extends DateComponent implements OnInit { config: IDatePickerConfig = { ...DEF_CONF, - format: 'DD-MM-YYYY' + format: 'DD-MM-YYYY', + secondaryNavigationStepDayView: 12, + secondaryNavigationStepMonthView: 10 }; ngOnInit(): void { diff --git a/src/demo/demo/date-pickers/day/day-inline-demo/day-inline-demo.component.ts b/src/demo/demo/date-pickers/day/day-inline-demo/day-inline-demo.component.ts index d4d89883..570a3e0c 100644 --- a/src/demo/demo/date-pickers/day/day-inline-demo/day-inline-demo.component.ts +++ b/src/demo/demo/date-pickers/day/day-inline-demo/day-inline-demo.component.ts @@ -13,7 +13,9 @@ export class DayInlineDemoComponent extends DateComponent implements OnInit { control: FormControl; config: IDatePickerConfig = { ...DEF_CONF, - format: 'DD-MM-YYYY' + format: 'DD-MM-YYYY', + secondaryNavigationStepDayView: 12, + secondaryNavigationStepMonthView: 10 }; ngOnInit(): void { diff --git a/src/demo/demo/date-pickers/month/month-demo/month-demo.component.ts b/src/demo/demo/date-pickers/month/month-demo/month-demo.component.ts index 1897b28f..5af1465e 100644 --- a/src/demo/demo/date-pickers/month/month-demo/month-demo.component.ts +++ b/src/demo/demo/date-pickers/month/month-demo/month-demo.component.ts @@ -13,7 +13,8 @@ export class MonthDemoComponent extends DateComponent implements OnInit { control: FormControl; config: IDatePickerConfig = { ...DEF_CONF, - format: 'MMM, YYYY' + format: 'MMM, YYYY', + secondaryNavigationStepMonthView: 10 }; ngOnInit(): void { diff --git a/src/demo/demo/date-pickers/month/month-directive-demo/month-directive-demo.component.ts b/src/demo/demo/date-pickers/month/month-directive-demo/month-directive-demo.component.ts index 004927ed..6ae7234c 100644 --- a/src/demo/demo/date-pickers/month/month-directive-demo/month-directive-demo.component.ts +++ b/src/demo/demo/date-pickers/month/month-directive-demo/month-directive-demo.component.ts @@ -13,7 +13,8 @@ export class MonthDirectiveDemoComponent extends DateComponent implements OnInit control: FormControl; config: IDatePickerConfig = { ...DEF_CONF, - format: 'MMM, YYYY' + format: 'MMM, YYYY', + secondaryNavigationStepMonthView: 10 }; ngOnInit(): void { diff --git a/src/demo/demo/date-pickers/month/month-inline/month-inline-demo.component.ts b/src/demo/demo/date-pickers/month/month-inline/month-inline-demo.component.ts index 5787845c..dda6702c 100644 --- a/src/demo/demo/date-pickers/month/month-inline/month-inline-demo.component.ts +++ b/src/demo/demo/date-pickers/month/month-inline/month-inline-demo.component.ts @@ -13,7 +13,8 @@ export class MonthInlineDemoComponent extends DateComponent implements OnInit { control: FormControl; config: IDatePickerConfig = { ...DEF_CONF, - format: 'MMM, YYYY' + format: 'MMM, YYYY', + secondaryNavigationStepMonthView: 10 }; ngOnInit(): void { diff --git a/src/demo/demo/demo.component.ts b/src/demo/demo/demo.component.ts index 5ec758b1..ad28291b 100644 --- a/src/demo/demo/demo.component.ts +++ b/src/demo/demo/demo.component.ts @@ -61,8 +61,8 @@ const MONTH_CALENDAR_OPTION_KEYS = [ 'max', 'min', 'monthBtnFormat', - 'multipleYearsNavigateBy', - 'showMultipleYearsNavigation', + 'secondaryNavigationStepMonthView', + 'showSecondaryNavigationMonthView', 'yearFormat', 'showGoToCurrent', 'unSelectOnClick', @@ -85,6 +85,8 @@ const DAY_CALENDAR_OPTION_KEYS = [ 'showGoToCurrent', 'unSelectOnClick', 'moveCalendarTo', + 'secondaryNavigationStepDayView', + 'showSecondaryNavigationDayView', ...MONTH_CALENDAR_OPTION_KEYS ]; const TIME_SELECT_SHARED_OPTION_KEYS = [ @@ -203,8 +205,10 @@ export class DemoComponent implements OnInit { showSeconds: false, showTwentyFourHours: false, timeSeparator: ':', - multipleYearsNavigateBy: 10, - showMultipleYearsNavigation: false, + secondaryNavigationStepMonthView: 10, + showSecondaryNavigationMonthView: false, + secondaryNavigationStepDayView: 12, + showSecondaryNavigationDayView: false, locale: moment.locale(), hideInputContainer: false, returnedValueType: ECalendarValue.String, diff --git a/src/lib/calendar-nav/calendar-nav.component.less b/src/lib/calendar-nav/calendar-nav.component.less index 4c59ae78..b1b34d0e 100644 --- a/src/lib/calendar-nav/calendar-nav.component.less +++ b/src/lib/calendar-nav/calendar-nav.component.less @@ -53,7 +53,7 @@ .dp-calendar-secondary-nav-right { left: initial; - right: 5px; + //right: 5px; } .dp-calendar-nav-left { diff --git a/src/lib/common/services/utils/utils.service.ts b/src/lib/common/services/utils/utils.service.ts index 2fef24d6..586811b8 100644 --- a/src/lib/common/services/utils/utils.service.ts +++ b/src/lib/common/services/utils/utils.service.ts @@ -323,6 +323,21 @@ export class UtilsService { }); } + handleDeprecatedParameters(config: {[key: string]: any}) { + if (config.showMultipleYearsNavigation !== null && config.showMultipleYearsNavigation !== undefined) { + console.warn('ng2-date-picker: Warning, showMultipleYearsNavigation parameter is deprecated' + + ' and will be removed in a further release. Please use showSecondaryNavigationMonthView parameter instead'); + config.showSecondaryNavigationMonthView = config.showMultipleYearsNavigation; + delete config.showMultipleYearsNavigation; + } + if (config.multipleYearsNavigateBy !== null && config.multipleYearsNavigateBy !== undefined) { + console.warn('ng2-date-picker: Warning, multipleYearsNavigateBy parameter is deprecated' + + ' and will be removed in a further release. Please use secondaryNavigationStepMonthView parameter instead'); + config.secondaryNavigationStepMonthView = config.multipleYearsNavigateBy; + delete config.multipleYearsNavigateBy; + } + } + shouldResetCurrentView(prevConf: T, currentConf: T): boolean { if (prevConf && currentConf) { if (!prevConf.min && currentConf.min) { diff --git a/src/lib/common/styles/variables.less b/src/lib/common/styles/variables.less index 49162f8a..816b777f 100644 --- a/src/lib/common/styles/variables.less +++ b/src/lib/common/styles/variables.less @@ -33,6 +33,6 @@ } &::before { - right: -10px; + right: -3px; } } diff --git a/src/lib/date-picker/date-picker.service.ts b/src/lib/date-picker/date-picker.service.ts index b996ce93..d9947866 100644 --- a/src/lib/date-picker/date-picker.service.ts +++ b/src/lib/date-picker/date-picker.service.ts @@ -45,6 +45,7 @@ export class DatePickerService { }; this.utilsService.convertPropsToMoment(_config, _config.format, ['min', 'max']); + this.utilsService.handleDeprecatedParameters(_config); if (config && config.allowMultiSelect && config.closeOnSelect === undefined) { _config.closeOnSelect = false; @@ -78,8 +79,10 @@ export class DatePickerService { monthBtnFormat: pickerConfig.monthBtnFormat, monthBtnFormatter: pickerConfig.monthBtnFormatter, monthBtnCssClassCallback: pickerConfig.monthBtnCssClassCallback, - multipleYearsNavigateBy: pickerConfig.multipleYearsNavigateBy, - showMultipleYearsNavigation: pickerConfig.showMultipleYearsNavigation, + secondaryNavigationStepMonthView: pickerConfig.secondaryNavigationStepMonthView, + showSecondaryNavigationMonthView: pickerConfig.showSecondaryNavigationMonthView, + secondaryNavigationStepDayView: pickerConfig.secondaryNavigationStepDayView, + showSecondaryNavigationDayView: pickerConfig.showSecondaryNavigationDayView, locale: pickerConfig.locale, returnedValueType: pickerConfig.returnedValueType, showGoToCurrent: pickerConfig.showGoToCurrent, diff --git a/src/lib/day-calendar/day-calendar-config.model.ts b/src/lib/day-calendar/day-calendar-config.model.ts index 9874cd43..25800542 100644 --- a/src/lib/day-calendar/day-calendar-config.model.ts +++ b/src/lib/day-calendar/day-calendar-config.model.ts @@ -24,8 +24,12 @@ export interface IConfig { monthBtnFormat?: string; monthBtnFormatter?: (day: Moment) => string; monthBtnCssClassCallback?: (day: Moment) => string; - multipleYearsNavigateBy?: number; - showMultipleYearsNavigation?: boolean; + multipleYearsNavigateBy?: number; // deprecated warning + showMultipleYearsNavigation?: boolean; // deprecated warning + secondaryNavigationStepDayView?: number; + showSecondaryNavigationDayView?: boolean; + secondaryNavigationStepMonthView?: number; + showSecondaryNavigationMonthView?: boolean; returnedValueType?: ECalendarValue; showGoToCurrent?: boolean; unSelectOnClick?: boolean; diff --git a/src/lib/day-calendar/day-calendar.component.html b/src/lib/day-calendar/day-calendar.component.html index c98926b5..9643c551 100644 --- a/src/lib/day-calendar/day-calendar.component.html +++ b/src/lib/day-calendar/day-calendar.component.html @@ -3,12 +3,16 @@ (onGoToCurrent)="goToCurrent()" (onLabelClick)="toggleCalendarMode(CalendarMode.Month)" (onLeftNav)="onLeftNavClick()" + (onLeftSecondaryNav)="onLeftSecondaryNavClick()" (onRightNav)="onRightNavClick()" + (onRightSecondaryNav)="onRightSecondaryNavClick()" [isLabelClickable]="componentConfig.enableMonthSelector" [label]="navLabel" [showGoToCurrent]="_shouldShowCurrent" [showLeftNav]="showLeftNav" + [showLeftSecondaryNav]="showSecondaryLeftNav" [showRightNav]="showRightNav" + [showRightSecondaryNav]="showSecondaryRightNav" [theme]="theme"> diff --git a/src/lib/day-calendar/day-calendar.component.spec.ts b/src/lib/day-calendar/day-calendar.component.spec.ts index 55d5bd90..99ab1eff 100644 --- a/src/lib/day-calendar/day-calendar.component.spec.ts +++ b/src/lib/day-calendar/day-calendar.component.spec.ts @@ -138,4 +138,33 @@ describe('Component: DayCalendarComponent', () => { component.goToCurrent(); expect(component.onGoToCurrent.emit).toHaveBeenCalled(); }); + + describe('should display secondary nav buttons if necessary', () => { + it('should not display secondary navigation button when not asked to', () => { + const currentDate = moment(); + // updates showLeftNav && showLeftSecondaryNav + component.currentDateView = currentDate; + expect(component.showSecondaryLeftNav).toBeFalsy(); + }) + + it('should display secondary navigation button when true in config', () => { + const currentDate = moment(); + component.componentConfig.showSecondaryNavigationDayView = true; + + // updates showLeftNav && showLeftSecondaryNav + component.currentDateView = currentDate; + expect(component.showSecondaryLeftNav).toBeTruthy(); + }) + + it('should not display secondary navigation button when primary button is not displayed', () => { + const currentDate = moment(); + component.componentConfig.min = currentDate.clone(); + component.componentConfig.showSecondaryNavigationDayView = true; + + // updates showLeftNav && showLeftSecondaryNav + component.currentDateView = currentDate; + + expect(component.showSecondaryLeftNav).toBeFalsy(); + }) + }); }); diff --git a/src/lib/day-calendar/day-calendar.component.ts b/src/lib/day-calendar/day-calendar.component.ts index 7ec681ba..ab19ad66 100644 --- a/src/lib/day-calendar/day-calendar.component.ts +++ b/src/lib/day-calendar/day-calendar.component.ts @@ -80,6 +80,8 @@ export class DayCalendarComponent implements OnInit, OnChanges, ControlValueAcce this.navLabel = this.dayCalendarService.getHeaderLabel(this.componentConfig, this._currentDateView); this.showLeftNav = this.dayCalendarService.shouldShowLeft(this.componentConfig.min, this.currentDateView); this.showRightNav = this.dayCalendarService.shouldShowRight(this.componentConfig.max, this.currentDateView); + this.showSecondaryLeftNav = this.componentConfig.showSecondaryNavigationDayView && this.showLeftNav; + this.showSecondaryRightNav = this.componentConfig.showSecondaryNavigationDayView && this.showRightNav; } ; @@ -108,6 +110,8 @@ export class DayCalendarComponent implements OnInit, OnChanges, ControlValueAcce navLabel: string; showLeftNav: boolean; showRightNav: boolean; + showSecondaryLeftNav: boolean; + showSecondaryRightNav: boolean; api = { moveCalendarsBy: this.moveCalendarsBy.bind(this), moveCalendarTo: this.moveCalendarTo.bind(this), @@ -253,6 +257,15 @@ export class DayCalendarComponent implements OnInit, OnChanges, ControlValueAcce this.onLeftNav.emit({from, to}); } + onLeftSecondaryNavClick(): void { + const targetDate = this.dayCalendarService.computeDateAfterLeftSecondaryNav(this.componentConfig, this.currentDateView); + + const from = this.currentDateView.clone(); + this.currentDateView = targetDate; + const to = this.currentDateView.clone(); + this.onLeftNav.emit({from, to}); + } + onRightNavClick() { const from = this.currentDateView.clone(); this.moveCalendarsBy(this.currentDateView, 1, 'month'); @@ -260,6 +273,15 @@ export class DayCalendarComponent implements OnInit, OnChanges, ControlValueAcce this.onRightNav.emit({from, to}); } + onRightSecondaryNavClick(): void { + const targetDate = this.dayCalendarService.computeDateAfterRightSecondaryNav(this.componentConfig, this.currentDateView); + + const from = this.currentDateView.clone(); + this.currentDateView = targetDate; + const to = this.currentDateView.clone(); + this.onRightNav.emit({from, to}); + } + onMonthCalendarLeftClick(change: INavEvent) { this.onLeftNav.emit(change); } diff --git a/src/lib/day-calendar/day-calendar.service.spec.ts b/src/lib/day-calendar/day-calendar.service.spec.ts index 6f7b6544..93019b56 100644 --- a/src/lib/day-calendar/day-calendar.service.spec.ts +++ b/src/lib/day-calendar/day-calendar.service.spec.ts @@ -176,4 +176,21 @@ describe('Service: Calendar', () => { expect(service.getDayBtnCssClass({dayBtnCssClassCallback: (m => 'class1 class2')}, date)) .toEqual('class1 class2'); })); + + it('should navigate to min date if secondaryStep is too big', + inject([DayCalendarService], + (service: DayCalendarService) => { + const currentDate = moment(); + const minDate = currentDate.clone().subtract('4', 'month'); + + const config: IDayCalendarConfigInternal = { + min: minDate, + showSecondaryNavigationDayView: true, + secondaryNavigationStepDayView: 10 + }; + + const targetDate = service.computeDateAfterLeftSecondaryNav(config, currentDate); + + expect(targetDate.format('YYYY-MM-DD')).toEqual(minDate.format('YYYY-MM-DD')); + })); }); diff --git a/src/lib/day-calendar/day-calendar.service.ts b/src/lib/day-calendar/day-calendar.service.ts index 3f84e456..9364d398 100644 --- a/src/lib/day-calendar/day-calendar.service.ts +++ b/src/lib/day-calendar/day-calendar.service.ts @@ -11,6 +11,8 @@ const moment = momentNs; @Injectable() export class DayCalendarService { + + readonly DEFAULT_CONFIG: IDayCalendarConfig = { showNearMonthDays: true, showWeekNumbers: false, @@ -22,7 +24,9 @@ export class DayCalendarService { enableMonthSelector: true, locale: moment.locale(), dayBtnFormat: 'DD', - unSelectOnClick: true + unSelectOnClick: true, + secondaryNavigationStepDayView: 12, + secondaryNavigationStepMonthView: 10 }; private readonly DAYS = ['su', 'mo', 'tu', 'we', 'th', 'fr', 'sa']; @@ -36,6 +40,7 @@ export class DayCalendarService { }; this.utilsService.convertPropsToMoment(_config, _config.format, ['min', 'max']); + this.utilsService.handleDeprecatedParameters(_config); moment.locale(_config.locale); @@ -175,8 +180,8 @@ export class DayCalendarService { monthBtnFormat: componentConfig.monthBtnFormat, monthBtnFormatter: componentConfig.monthBtnFormatter, monthBtnCssClassCallback: componentConfig.monthBtnCssClassCallback, - multipleYearsNavigateBy: componentConfig.multipleYearsNavigateBy, - showMultipleYearsNavigation: componentConfig.showMultipleYearsNavigation, + showSecondaryNavigationMonthView: componentConfig.showSecondaryNavigationMonthView, + secondaryNavigationStepMonthView: componentConfig.secondaryNavigationStepMonthView, showGoToCurrent: componentConfig.showGoToCurrent, numOfMonthRows: componentConfig.numOfMonthRows }); @@ -198,6 +203,42 @@ export class DayCalendarService { return ''; } + computeDateAfterLeftSecondaryNav(componentConfig: IDayCalendarConfigInternal, currentDateView: momentNs.Moment) { + let navigateBy = componentConfig.secondaryNavigationStepDayView; + let targetDate = currentDateView.clone().subtract(navigateBy, 'month'); + + if (componentConfig.min) { + const yearsDiff = targetDate.year() - componentConfig.min.year(); + const monthsDiff = targetDate.month() - componentConfig.min.month(); + const isOutsideRange = (yearsDiff * 12) + monthsDiff < 0; + + if (isOutsideRange) { + navigateBy = (currentDateView.year() - componentConfig.min.year()) * 12 + + (currentDateView.month() - componentConfig.min.month()); + targetDate = currentDateView.clone().subtract(navigateBy, 'month'); + } + } + return targetDate; + } + + computeDateAfterRightSecondaryNav(componentConfig: IDayCalendarConfigInternal, currentDateView: momentNs.Moment) { + let navigateBy = componentConfig.secondaryNavigationStepDayView; + let targetDate = currentDateView.clone().add(navigateBy, 'month'); + + if (componentConfig.max) { + const yearsDiff = targetDate.year() - componentConfig.max.year(); + const monthsDiff = targetDate.month() - componentConfig.max.month(); + const isOutsideRange = (yearsDiff * 12) + monthsDiff > 0; + + if (isOutsideRange) { + navigateBy = (componentConfig.max.year() - currentDateView.year()) * 12 + + (componentConfig.max.month() - currentDateView.month()); + targetDate = currentDateView.clone().add(navigateBy, 'month'); + } + } + return targetDate; + } + private removeNearMonthWeeks(currentMonth: Moment, monthArray: IDay[][]): IDay[][] { if (monthArray[monthArray.length - 1].find((day) => day.date.isSame(currentMonth, 'month'))) { return monthArray; diff --git a/src/lib/day-time-calendar/day-time-calendar.service.ts b/src/lib/day-time-calendar/day-time-calendar.service.ts index e05b80ae..14e5c59b 100644 --- a/src/lib/day-time-calendar/day-time-calendar.service.ts +++ b/src/lib/day-time-calendar/day-time-calendar.service.ts @@ -31,6 +31,7 @@ export class DayTimeCalendarService { ...this.dayCalendarService.getConfig(config) }; + this.utilsService.handleDeprecatedParameters(_config); moment.locale(config.locale); return _config; diff --git a/src/lib/month-calendar/month-calendar-config.ts b/src/lib/month-calendar/month-calendar-config.ts index a5d39d10..21773531 100644 --- a/src/lib/month-calendar/month-calendar-config.ts +++ b/src/lib/month-calendar/month-calendar-config.ts @@ -13,8 +13,10 @@ export interface IConfig { monthBtnFormatter?: (day: Moment) => string; numOfMonthRows?: number; monthBtnCssClassCallback?: (day: Moment) => string; - multipleYearsNavigateBy?: number; - showMultipleYearsNavigation?: boolean; + secondaryNavigationStepDayView?: number; + showSecondaryNavigationDayView?: boolean; + secondaryNavigationStepMonthView?: number; + showSecondaryNavigationMonthView?: boolean; returnedValueType?: ECalendarValue; showGoToCurrent?: boolean; unSelectOnClick?: boolean; diff --git a/src/lib/month-calendar/month-calendar.component.ts b/src/lib/month-calendar/month-calendar.component.ts index d1286a46..c93b025a 100644 --- a/src/lib/month-calendar/month-calendar.component.ts +++ b/src/lib/month-calendar/month-calendar.component.ts @@ -77,8 +77,8 @@ export class MonthCalendarComponent implements OnInit, OnChanges, ControlValueAc this.navLabel = this.monthCalendarService.getHeaderLabel(this.componentConfig, this.currentDateView); this.showLeftNav = this.monthCalendarService.shouldShowLeft(this.componentConfig.min, this._currentDateView); this.showRightNav = this.monthCalendarService.shouldShowRight(this.componentConfig.max, this.currentDateView); - this.showSecondaryLeftNav = this.componentConfig.showMultipleYearsNavigation && this.showLeftNav; - this.showSecondaryRightNav = this.componentConfig.showMultipleYearsNavigation && this.showRightNav; + this.showSecondaryLeftNav = this.componentConfig.showSecondaryNavigationMonthView && this.showLeftNav; + this.showSecondaryRightNav = this.componentConfig.showSecondaryNavigationMonthView && this.showRightNav; } @Input() config: IMonthCalendarConfig; @@ -91,8 +91,6 @@ export class MonthCalendarComponent implements OnInit, OnChanges, ControlValueAc @Output() onGoToCurrent: EventEmitter = new EventEmitter(); @Output() onLeftNav: EventEmitter = new EventEmitter(); @Output() onRightNav: EventEmitter = new EventEmitter(); - @Output() onLeftSecondaryNav: EventEmitter = new EventEmitter(); - @Output() onRightSecondaryNav: EventEmitter = new EventEmitter(); isInited: boolean = false; componentConfig: IMonthCalendarConfigInternal; yearMonths: IMonth[][]; @@ -228,7 +226,7 @@ export class MonthCalendarComponent implements OnInit, OnChanges, ControlValueAc } onLeftSecondaryNavClick(): void { - let navigateBy = this.componentConfig.multipleYearsNavigateBy; + let navigateBy = this.componentConfig.secondaryNavigationStepMonthView; const isOutsideRange = this.componentConfig.min && this.currentDateView.year() - this.componentConfig.min.year() < navigateBy; @@ -239,7 +237,7 @@ export class MonthCalendarComponent implements OnInit, OnChanges, ControlValueAc const from = this.currentDateView.clone(); this.currentDateView = this.currentDateView.clone().subtract(navigateBy, 'year'); const to = this.currentDateView.clone(); - this.onLeftSecondaryNav.emit({from, to}); + this.onLeftNav.emit({from, to}); } onRightNavClick(): void { @@ -250,7 +248,7 @@ export class MonthCalendarComponent implements OnInit, OnChanges, ControlValueAc } onRightSecondaryNavClick(): void { - let navigateBy = this.componentConfig.multipleYearsNavigateBy; + let navigateBy = this.componentConfig.secondaryNavigationStepMonthView; const isOutsideRange = this.componentConfig.max && this.componentConfig.max.year() - this.currentDateView.year() < navigateBy; @@ -261,7 +259,7 @@ export class MonthCalendarComponent implements OnInit, OnChanges, ControlValueAc const from = this.currentDateView.clone(); this.currentDateView = this.currentDateView.clone().add(navigateBy, 'year'); const to = this.currentDateView.clone(); - this.onRightSecondaryNav.emit({from, to}); + this.onRightNav.emit({from, to}); } toggleCalendarMode(): void { diff --git a/src/lib/month-calendar/month-calendar.service.ts b/src/lib/month-calendar/month-calendar.service.ts index ecf15fc9..04b07fbe 100644 --- a/src/lib/month-calendar/month-calendar.service.ts +++ b/src/lib/month-calendar/month-calendar.service.ts @@ -16,8 +16,8 @@ export class MonthCalendarService { isNavHeaderBtnClickable: false, monthBtnFormat: 'MMM', locale: moment.locale(), - multipleYearsNavigateBy: 10, - showMultipleYearsNavigation: false, + showSecondaryNavigationMonthView: false, + secondaryNavigationStepMonthView: 10, unSelectOnClick: true, numOfMonthRows: 3 }; @@ -34,6 +34,7 @@ export class MonthCalendarService { this.validateConfig(_config); this.utilsService.convertPropsToMoment(_config, _config.format, ['min', 'max']); + this.utilsService.handleDeprecatedParameters(_config); moment.locale(_config.locale); return _config;