Skip to content

Commit 8932f52

Browse files
committed
changing delimitter to '|' + changing ChangeDetectionStrategy to nav and month components
1 parent 2f79b16 commit 8932f52

File tree

8 files changed

+42
-11
lines changed

8 files changed

+42
-11
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ All notable changes to this project will be documented in this file.
77
### Bug Fixes
88
- Prevent overriding of form control value from input updates ([c96f2 ](https://github.com/vlio20/angular-datepicker/commit/e4de3cb )) closes [#297](https://github.com/vlio20/angular-datepicker/issues/297) - PR by [@pklein](https://github.com/pklein)
99

10+
## Breaking Changes
11+
- Multiselect delimiter changed to `|` instead of `,`
12+
1013
<a name="2.6.2"></a>
1114
# [2.6.2] (2017-11-11)
1215

e2e/datpicker-e2e.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,14 @@ describe('dpDayPicker dayPicker', () => {
267267
expect(page.selectedDays.count()).toBe(3);
268268
expect(page.datePickerPopup.isDisplayed()).toBe(true);
269269
expect(page.dayPickerInput.getAttribute('value')).toEqual(
270-
`${moment().date(18).format('DD-MM-YYYY')}, ${moment().date(15).format('DD-MM-YYYY')}, ${moment().date(16)
270+
`${moment().date(18).format('DD-MM-YYYY')} | ${moment().date(15).format('DD-MM-YYYY')}, ${moment().date(16)
271271
.format('DD-MM-YYYY')}`
272272
);
273273

274274
page.clickOnDayButton('18');
275275
expect(page.selectedDays.count()).toBe(2);
276276
expect(page.dayPickerInput.getAttribute('value')).toEqual(
277-
`${moment().date(15).format('DD-MM-YYYY')}, ${moment().date(16).format('DD-MM-YYYY')}`
277+
`${moment().date(15).format('DD-MM-YYYY')} | ${moment().date(16).format('DD-MM-YYYY')}`
278278
);
279279
});
280280

src/app/calendar-nav/calendar-nav.component.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1-
import {Component, EventEmitter, HostBinding, Input, Output, ViewEncapsulation} from '@angular/core';
1+
import {
2+
ChangeDetectionStrategy,
3+
Component,
4+
EventEmitter,
5+
HostBinding,
6+
Input,
7+
Output,
8+
ViewEncapsulation
9+
} from '@angular/core';
210

311
@Component({
412
selector: 'dp-calendar-nav',
513
templateUrl: './calendar-nav.component.html',
614
styleUrls: ['./calendar-nav.component.less'],
7-
encapsulation: ViewEncapsulation.None
15+
encapsulation: ViewEncapsulation.None,
16+
changeDetection: ChangeDetectionStrategy.OnPush
817
})
918
export class CalendarNavComponent {
1019
@Input() label: string;

src/app/common/services/utils/utils.service.spec.ts

+14
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,18 @@ describe('Service: ObUtilsService', () => {
101101
expect(moment.isMoment(obj.min)).toBeTruthy();
102102
expect(moment.isMoment(obj.max)).toBeTruthy();
103103
}));
104+
105+
it('should test datesStringToStringArray', inject([UtilsService], (service: UtilsService) => {
106+
expect(service.datesStringToStringArray('')).toEqual([]);
107+
expect(service.datesStringToStringArray('14-01-1984')).toEqual(['14-01-1984']);
108+
expect(service.datesStringToStringArray('14-01-1984|15-01-1984'))
109+
.toEqual(['14-01-1984', '15-01-1984']);
110+
111+
expect(service.datesStringToStringArray(''))
112+
.toEqual([]);
113+
expect(service.datesStringToStringArray('14,01-1984|15,01-1984'))
114+
.toEqual(['14,01-1984', '15,01-1984']);
115+
expect(service.datesStringToStringArray('14,01-1984| asdasd'))
116+
.toEqual(['14,01-1984', 'asdasd']);
117+
}));
104118
});

src/app/common/services/utils/utils.service.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import {ECalendarValue} from '../../types/calendar-value-enum';
22
import {SingleCalendarValue} from '../../types/single-calendar-value';
3-
import {Injectable, SimpleChange} from '@angular/core';
3+
import {Injectable} from '@angular/core';
44
import * as moment from 'moment';
55
import {Moment, unitOfTime} from 'moment';
66
import {CalendarValue} from '../../types/calendar-value';
77
import {IDate} from '../../models/date.model';
88
import {CalendarMode} from '../../types/calendar-mode';
99
import {DateValidator} from '../../types/validator.type';
1010
import {ICalendarInternal} from '../../models/calendar.model';
11+
import {forEach} from '@angular/router/src/utils/collection';
1112

1213
export interface DateLimits {
1314
minDate?: SingleCalendarValue;
@@ -257,7 +258,7 @@ export class UtilsService {
257258
}
258259

259260
datesStringToStringArray(value: string): string[] {
260-
return (value || '').split(',').map(m => m.trim());
261+
return (value || '').split('|').map(m => m.trim()).filter(Boolean);
261262
}
262263

263264
getValidMomentArray(value: string, format: string): Moment[] {

src/app/common/styles/variables.less

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@
3333
}
3434

3535
&::before {
36-
right: -5px;
36+
right: -10px;
3737
}
3838
}

src/app/date-picker/date-picker.component.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import {
4343
ValidationErrors,
4444
Validator
4545
} from '@angular/forms';
46-
import * as moment from 'moment';
4746
import {Moment, unitOfTime} from 'moment';
4847
import {DateValidator} from '../common/types/validator.type';
4948
import {MonthCalendarComponent} from '../month-calendar/month-calendar.component';
@@ -127,7 +126,7 @@ export class DatePickerComponent implements OnChanges,
127126
this._selected = selected;
128127
this.inputElementValue = (<string[]>this.utilsService
129128
.convertFromMomentArray(this.componentConfig.format, selected, ECalendarValue.StringArr))
130-
.join(', ');
129+
.join(' | ');
131130
const val = this.processOnChangeCallback(selected);
132131
this.onChangeCallback(val, false);
133132
this.onChange.emit(val);

src/app/month-calendar/month-calendar.component.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {ECalendarValue} from '../common/types/calendar-value-enum';
22
import {
3+
ChangeDetectionStrategy, ChangeDetectorRef,
34
Component,
45
EventEmitter,
56
forwardRef,
@@ -35,6 +36,7 @@ import {SingleCalendarValue} from '../common/types/single-calendar-value';
3536
templateUrl: 'month-calendar.component.html',
3637
styleUrls: ['month-calendar.component.less'],
3738
encapsulation: ViewEncapsulation.None,
39+
changeDetection: ChangeDetectionStrategy.OnPush,
3840
providers: [
3941
MonthCalendarService,
4042
{
@@ -103,8 +105,9 @@ export class MonthCalendarComponent implements OnInit, OnChanges, ControlValueAc
103105
return this._currentDateView;
104106
}
105107

106-
constructor(public monthCalendarService: MonthCalendarService,
107-
public utilsService: UtilsService) {
108+
constructor(public readonly monthCalendarService: MonthCalendarService,
109+
public readonly utilsService: UtilsService,
110+
public readonly cd: ChangeDetectorRef) {
108111
}
109112

110113
ngOnInit() {
@@ -152,6 +155,8 @@ export class MonthCalendarComponent implements OnInit, OnChanges, ControlValueAc
152155
.generateYear(this.componentConfig, this.currentDateView, this.selected);
153156
this.inputValueType = this.utilsService.getInputType(this.inputValue, this.componentConfig.allowMultiSelect);
154157
}
158+
159+
this.cd.markForCheck();
155160
}
156161

157162
registerOnChange(fn: any): void {

0 commit comments

Comments
 (0)