Skip to content

Commit

Permalink
Min date as default when calendar opens - resolves #256 (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
vlio20 authored Oct 22, 2017
1 parent 4588f6f commit 5663b7a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
11 changes: 8 additions & 3 deletions src/app/common/services/utils/utils.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,14 @@ export class UtilsService {
}

// todo:: add unit test
getDefaultDisplayDate(def: Moment, selected: Moment[], allowMultiSelect: boolean): Moment {
if (def) {
return def.clone();
getDefaultDisplayDate(current: Moment,
selected: Moment[],
allowMultiSelect: boolean,
minDate: Moment): Moment {
if (current) {
return current.clone();
} else if (minDate && minDate.isAfter(moment())) {
return minDate.clone();
} else if (allowMultiSelect) {
if (selected && selected[selected.length]) {
return selected[selected.length].clone();
Expand Down
14 changes: 12 additions & 2 deletions src/app/date-picker/date-picker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,12 @@ export class DatePickerComponent implements OnChanges,
this.currentDateView = this.displayDate
? this.utilsService.convertToMoment(this.displayDate, this.componentConfig.format).clone()
: this.utilsService
.getDefaultDisplayDate(this.currentDateView, this.selected, this.componentConfig.allowMultiSelect);
.getDefaultDisplayDate(
this.currentDateView,
this.selected,
this.componentConfig.allowMultiSelect,
this.componentConfig.min
);
this.inputValueType = this.utilsService.getInputType(this.inputValue, this.componentConfig.allowMultiSelect);
this.dayCalendarConfig = this.dayPickerService.getDayConfigService(this.componentConfig);
this.dayTimeCalendarConfig = this.dayPickerService.getDayTimeConfigService(this.componentConfig);
Expand Down Expand Up @@ -371,7 +376,12 @@ export class DatePickerComponent implements OnChanges,
if (this.dayPickerService.isValidInputDateValue(value, this.componentConfig)) {
this.selected = this.dayPickerService.convertInputValueToMomentArray(value, this.componentConfig);
this.currentDateView = this.selected.length
? this.utilsService.getDefaultDisplayDate(null, this.selected, this.componentConfig.allowMultiSelect)
? this.utilsService.getDefaultDisplayDate(
null,
this.selected,
this.componentConfig.allowMultiSelect,
this.componentConfig.min
)
: this.currentDateView;
} else {
this._selected = this.utilsService
Expand Down
2 changes: 1 addition & 1 deletion src/app/day-calendar/day-calendar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class DayCalendarComponent implements OnInit, OnChanges, ControlValueAcce
this.currentDateView = this.displayDate
? this.utilsService.convertToMoment(this.displayDate, this.componentConfig.format).clone()
: this.utilsService
.getDefaultDisplayDate(this.currentDateView, this.selected, this.componentConfig.allowMultiSelect);
.getDefaultDisplayDate(this.currentDateView, this.selected, this.componentConfig.allowMultiSelect, this.componentConfig.min);
this.weekdays = this.dayCalendarService
.generateWeekdays(this.componentConfig.firstDayOfWeek);
this.inputValueType = this.utilsService.getInputType(this.inputValue, this.componentConfig.allowMultiSelect);
Expand Down
7 changes: 6 additions & 1 deletion src/app/month-calendar/month-calendar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,12 @@ export class MonthCalendarComponent implements OnInit, OnChanges, ControlValueAc
this.currentDateView = this.displayDate
? this.displayDate
: this.utilsService
.getDefaultDisplayDate(this.currentDateView, this.selected, this.componentConfig.allowMultiSelect);
.getDefaultDisplayDate(
this.currentDateView,
this.selected,
this.componentConfig.allowMultiSelect,
this.componentConfig.min
);
this.inputValueType = this.utilsService.getInputType(this.inputValue, this.componentConfig.allowMultiSelect);
this._shouldShowCurrent = this.shouldShowCurrent();
}
Expand Down

0 comments on commit 5663b7a

Please sign in to comment.