Skip to content

adding support for custom amount of rows for month calendar - resolve… #487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.
# [8.1.0] (???)

### Features
- Add number of rows to month calendar ([???](https://github.com/vlio20/angular-datepicker/commit/???)) closes [#387](https://github.com/vlio20/angular-datepicker/issues/387)
- Close popup on enter ([???](https://github.com/vlio20/angular-datepicker/commit/???)) closes [#438](https://github.com/vlio20/angular-datepicker/issues/438)

### Bug Fixes
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ Here are the available configurations:
| 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 |

## Inline - Month Calendar

Expand Down Expand Up @@ -266,7 +267,8 @@ Here are the available configurations:
| 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` |
| 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 |

Here is the list of APIs:

Expand Down Expand Up @@ -393,7 +395,8 @@ Here are the available configurations:
| 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. |
| 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
Expand Down
2 changes: 2 additions & 0 deletions e2e/app.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ export class DemoPage {
meridiemDisplay = $(`${this.popupSelector} .dp-time-select-display-meridiem`);
meridiemDisplayInline = $(`.dp-inline .dp-time-select-display-meridiem`);
timeSeparatorDisplay = $(`${this.popupSelector} .dp-time-select-separator:nth-child(2)`);
monthRows = $$('.dp-months-row');
numOfMonthRowsToggle2 = $('#numOfMonthRows2');

daytimePickerMenu = $('#daytimePickerMenu');
daytimeInlineMenu = $('#daytimeInlineMenu');
Expand Down
40 changes: 40 additions & 0 deletions e2e/fetures/number-of-month-rows-e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {DemoPage} from '../app.po';

describe('number of month rows', () => {

let page: DemoPage;

beforeEach(async () => {
page = new DemoPage();
await page.navigateTo();
});

it('should make sure number of rows are changing on date-picker', async () => {
await page.daytimePickerMenu.click();
await page.dayPickerInput.click();
await page.dayCalendarNavHeaderBtn.click();
expect(await page.monthRows.count()).toEqual(3);

await page.numOfMonthRowsToggle2.click();
await page.dayPickerInput.click();
expect(await page.monthRows.count()).toEqual(2);
});

it('should make sure number of rows are changing on month-picker', async () => {
await page.monthPickerMenu.click();
await page.monthPickerInput.click();
expect(await page.monthRows.count()).toEqual(3);

await page.numOfMonthRowsToggle2.click();
await page.dayPickerInput.click();
expect(await page.monthRows.count()).toEqual(2);
});

it('should make sure number of rows are changing on month inline', async () => {
await page.monthInlineMenu.click();
expect(await page.monthRows.count()).toEqual(3);

await page.numOfMonthRowsToggle2.click();
expect(await page.monthRows.count()).toEqual(2);
});
});
3 changes: 2 additions & 1 deletion src/demo/demo/common/conts/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ export const DEF_CONF: IDatePickerConfig = {
hideInputContainer: false,
returnedValueType: ECalendarValue.String,
unSelectOnClick: true,
hideOnOutsideClick: true
hideOnOutsideClick: true,
numOfMonthRows: 3
};
50 changes: 50 additions & 0 deletions src/demo/demo/config-form/config-form.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,56 @@ <h3 class="dp-options-section">Config options</h3>
</label>
</div>
</div>

<div *ngIf="isValidConfig('numOfMonthRows')" class="dp-option">
<span class="dp-option-header">
Number of Month rows (numOfMonthRows):
</span>
<div class="dp-option-playground">
<label>1
<input id="numOfMonthRows1"
[formControl]="numOfMonthRows"
[value]="1"
name="numOfMonthRows"
type="radio">
</label>
<label>2
<input id="numOfMonthRows2"
[formControl]="numOfMonthRows"
[value]="2"
name="numOfMonthRows"
type="radio">
</label>
<label>3
<input id="numOfMonthRows3"
[formControl]="numOfMonthRows"
[value]="3"
name="numOfMonthRows"
type="radio">
</label>
<label>4
<input id="numOfMonthRows4"
[formControl]="numOfMonthRows"
[value]="4"
name="numOfMonthRows"
type="radio">
</label>
<label>6
<input id="numOfMonthRows6"
[formControl]="numOfMonthRows"
[value]="6"
name="numOfMonthRows"
type="radio">
</label>
<label>12
<input id="numOfMonthRows12"
[formControl]="numOfMonthRows"
[value]="12"
name="numOfMonthRows"
type="radio">
</label>
</div>
</div>
</div>

<div class="dp-api">
Expand Down
9 changes: 9 additions & 0 deletions src/demo/demo/config-form/config-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const MONTH_CALENDAR_OPTION_KEYS = [
'showGoToCurrent',
'unSelectOnClick',
'moveCalendarTo',
'numOfMonthRows',
...GLOBAL_OPTION_KEYS
];
const DAY_CALENDAR_OPTION_KEYS = [
Expand Down Expand Up @@ -221,6 +222,7 @@ export class ConfigFormComponent implements OnInit {
multipleYearsNavigateBy: FormControl;
returnedValueType: FormControl;
closeOnEnter: FormControl;
numOfMonthRows: FormControl;

ngOnInit() {
this.localFormat = this.getDefaultFormatByMode(this.pickerMode);
Expand Down Expand Up @@ -267,6 +269,7 @@ export class ConfigFormComponent implements OnInit {
this.multipleYearsNavigateBy = new FormControl(this.config.multipleYearsNavigateBy);
this.returnedValueType = new FormControl(this.config.returnedValueType);
this.closeOnEnter = new FormControl(this.config.closeOnEnter);
this.numOfMonthRows = new FormControl(this.config.numOfMonthRows);
this.initListeners();
}

Expand Down Expand Up @@ -618,6 +621,12 @@ export class ConfigFormComponent implements OnInit {
closeOnEnter: val
});
});

this.numOfMonthRows.valueChanges.subscribe((val) => {
this.onConfigChange.emit({
numOfMonthRows: val
});
});
}

private getDefaultFormatByMode(mode: string): string {
Expand Down
4 changes: 1 addition & 3 deletions src/lib/date-picker/date-picker.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ import {
ViewContainerRef
} from '@angular/core';
import {NgControl} from '@angular/forms';
import {CalendarValue} from '../common/types/calendar-value';
import {SingleCalendarValue} from '../common/types/single-calendar-value';
import {CalendarValue, ISelectionEvent, SingleCalendarValue} from '..';
import {INavEvent} from '../common/models/navigation-event.model';
import {UtilsService} from '../common/services/utils/utils.service'
import {ISelectionEvent} from '../common/types/selection-evet.model';

@Directive({
exportAs: 'dpDayPicker',
Expand Down
3 changes: 2 additions & 1 deletion src/lib/date-picker/date-picker.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ export class DatePickerService {
locale: pickerConfig.locale,
returnedValueType: pickerConfig.returnedValueType,
showGoToCurrent: pickerConfig.showGoToCurrent,
unSelectOnClick: pickerConfig.unSelectOnClick
unSelectOnClick: pickerConfig.unSelectOnClick,
numOfMonthRows: pickerConfig.numOfMonthRows
};
}

Expand Down
1 change: 1 addition & 0 deletions src/lib/day-calendar/day-calendar-config.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface IConfig {
returnedValueType?: ECalendarValue;
showGoToCurrent?: boolean;
unSelectOnClick?: boolean;
numOfMonthRows?: number;
}

export interface IDayCalendarConfig extends IConfig,
Expand Down
3 changes: 2 additions & 1 deletion src/lib/day-calendar/day-calendar.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ export class DayCalendarService {
monthBtnCssClassCallback: componentConfig.monthBtnCssClassCallback,
multipleYearsNavigateBy: componentConfig.multipleYearsNavigateBy,
showMultipleYearsNavigation: componentConfig.showMultipleYearsNavigation,
showGoToCurrent: componentConfig.showGoToCurrent
showGoToCurrent: componentConfig.showGoToCurrent,
numOfMonthRows: componentConfig.numOfMonthRows
});
}

Expand Down
3 changes: 2 additions & 1 deletion src/lib/month-calendar/month-calendar-config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Moment} from 'moment';
import {ICalendar, ICalendarInternal} from '../common/models/calendar.model';
import {ECalendarValue} from '../common/types/calendar-value-enum';
import {ECalendarValue} from '..';

export interface IConfig {
isMonthDisabledCallback?: (date: Moment) => boolean;
Expand All @@ -11,6 +11,7 @@ export interface IConfig {
isNavHeaderBtnClickable?: boolean;
monthBtnFormat?: string;
monthBtnFormatter?: (day: Moment) => string;
numOfMonthRows?: number;
monthBtnCssClassCallback?: (day: Moment) => string;
multipleYearsNavigateBy?: number;
showMultipleYearsNavigation?: boolean;
Expand Down
Loading