Skip to content

Commit e194581

Browse files
committed
Merge branch 'release/1.1.2'
2 parents ec850c9 + 93c9f0c commit e194581

File tree

4 files changed

+28
-57
lines changed

4 files changed

+28
-57
lines changed

CHANGELOG.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
#### 1.1.2 (2018-06-22)
2+
3+
##### Bug Fixes
4+
5+
* **ranges:** Applied range does not have 'active' class - Fix [#17](https://github.com/fetrarij/ngx-daterangepicker-material/pull/17) ([1c0f03d4](https://github.com/fetrarij/ngx-daterangepicker-material/commit/1c0f03d4bb9e4b66780ee26d635c98249d1ca73d))
6+
* **autoApply:** autoApply showing Cancel & Apply buttons - Fix [#16](https://github.com/fetrarij/ngx-daterangepicker-material/pull/16) ([53288f50](https://github.com/fetrarij/ngx-daterangepicker-material/commit/53288f506bbfa276bf8840b34403ed6b17f1eedb))
7+
* **readme:** remove showInputs ([672ec99a](https://github.com/fetrarij/ngx-daterangepicker-material/commit/672ec99a106097c59e72923c2c480f9ba92be1c1))
8+
19
#### 1.1.1 (2018-06-12)
210

311
##### Chores
@@ -6,7 +14,7 @@
614

715
##### New Features
816

9-
* **#3:** show 2nd calendar as per maxDate if provided - As, we have provided maxDate, there is no use of showing next month as 2nd calendar as those dates will not be selectable - instead, can it be maxDate's month as second calendar and prev month as first calendar Close [#3](https://github.com/fetrarij/ngx-daterangepicker-material/pull/3) ([daf00119](https://github.com/fetrarij/ngx-daterangepicker-material/commit/daf00119cc6865cb7f3ad7d00307d0cf47b673c0))
17+
* **#3:** show 2nd calendar as per maxDate if provided - As, we have provided maxDate, there is no use of showing next month as 2nd calendar as those dates will not be selectable - instead, can it be maxDate's month as second calendar and prev month as first calendar - Fix [#3](https://github.com/fetrarij/ngx-daterangepicker-material/pull/3) ([daf00119](https://github.com/fetrarij/ngx-daterangepicker-material/commit/daf00119cc6865cb7f3ad7d00307d0cf47b673c0))
1018
* **customisation:** ability to add custom classes and custom invalid dates function - isCustomDate - isInvalidDate Close [#12](https://github.com/fetrarij/ngx-daterangepicker-material/pull/12) ([145bbf5c](https://github.com/fetrarij/ngx-daterangepicker-material/commit/145bbf5c3401c00545608e9e8286fa58e45e51c4))
1119

1220
##### Bug Fixes

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ngx-daterangepicker-material",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "Angular 2+ date range picker (with material design theme)",
55
"keywords": [
66
"angular2",

src/daterangepicker/daterangepicker.component.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
}">
1010
<div class="ranges">
1111
<ul *ngFor="let range of rangesArray">
12-
<li (click)="clickRange($event, range)" [ngClass]="{'active': range === chosenLabel}">{{range}}</li>
12+
<li (click)="clickRange($event, range)" [ngClass]="{'active': range === chosenRange}">{{range}}</li>
1313
</ul>
1414
</div>
1515
<div class="calendar" [ngClass]="{right: singleDatePicker, left: !singleDatePicker}"
@@ -138,7 +138,7 @@
138138
</table>
139139
</div>
140140
</div>
141-
<div class="buttons" *ngIf="(!autoApply && !rangesArray.length) || (showCalInRanges && !singleDatePicker)">
141+
<div class="buttons" *ngIf="!autoApply && ( !rangesArray.length || (showCalInRanges && !singleDatePicker))">
142142
<div class="buttons_input">
143143
<button *ngIf="showClearButton" class="btn btn-default clear" type="button" (click)="clear()" title="clear the date">
144144
<svg xmlns="http://www.w3.org/2000/svg" width="30" height="30" viewBox="0 -5 24 24"><path d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"/></svg>

src/daterangepicker/daterangepicker.component.ts

+16-53
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@ import { FormControl} from '@angular/forms';
33

44
import * as _moment from 'moment'; const moment = _moment;
55

6-
interface Hour {
7-
hour: string;
8-
minute: string;
9-
second: string;
10-
ampm: string;
11-
}
126
export enum SideEnum {
137
left = 'left',
148
right = 'right'
@@ -23,18 +17,11 @@ export enum SideEnum {
2317
},
2418
})
2519
export class DaterangepickerComponent implements OnInit {
26-
chosenLabel;
27-
oldStartDate;
28-
oldEndDate;
20+
private _old: {start: any, end: any} = {start: null, end: null};
21+
chosenLabel: string;
2922
calendarVariables: {left: any, right: any} = {left: {}, right: {}};
3023
daterangepicker: {start: FormControl, end: FormControl} = {start: new FormControl(), end: new FormControl()};
31-
disabled: {} = {};
32-
daterangepickerEnd: {active?: boolean, model?: any, control: FormControl, focus?: boolean} =
33-
{active: false, model: undefined, control: new FormControl(), focus: false};
34-
daterangepickerStart: {active?: boolean, model?: any, control: FormControl, focus?: boolean} =
35-
{active: false, model: undefined, control: new FormControl(), focus: false};
3624
applyBtn: {disabled: boolean} = {disabled: false};
37-
3825
startDate = moment().startOf('day');
3926
endDate = moment().endOf('day');
4027
minDate: _moment.Moment = null;
@@ -70,6 +57,7 @@ export class DaterangepickerComponent implements OnInit {
7057
rightCalendar: any = {};
7158
// custom ranges
7259
ranges: any = {};
60+
chosenRange: string;
7361
showCustomRangeLabel: boolean;
7462
rangesArray: Array<any> = [];
7563
// states
@@ -420,16 +408,8 @@ export class DaterangepickerComponent implements OnInit {
420408
}
421409

422410
updateView() {
423-
if (this.endDate) {
424-
this.daterangepickerStart.active = true;
425-
this.daterangepickerEnd.active = false;
426-
} else {
427-
this.daterangepickerStart.active = false;
428-
this.daterangepickerEnd.active = true;
429-
}
430411
this.updateMonthsInView();
431412
this.updateCalendars();
432-
this.updateFormInputs();
433413
}
434414

435415
updateMonthsInView() {
@@ -504,8 +484,8 @@ export class DaterangepickerComponent implements OnInit {
504484
}
505485

506486
clickCancel(e) {
507-
this.startDate = this.oldStartDate;
508-
this.endDate = this.oldEndDate;
487+
this.startDate = this._old.start;
488+
this.endDate = this._old.end;
509489
this.hide();
510490
}
511491
/**
@@ -613,6 +593,9 @@ export class DaterangepickerComponent implements OnInit {
613593
if (!e.target.classList.contains('available')) {
614594
return;
615595
}
596+
if (this.rangesArray.length) {
597+
this.chosenRange = this.locale.customRangeLabel;
598+
}
616599

617600
let date = side === SideEnum.left ? this.leftCalendar.calendar[row][col] : this.rightCalendar.calendar[row][col];
618601

@@ -650,7 +633,7 @@ export class DaterangepickerComponent implements OnInit {
650633
* @param label
651634
*/
652635
clickRange(e, label) {
653-
this.chosenLabel = label;
636+
this.chosenRange = label;
654637
if (label == this.locale.customRangeLabel) {
655638
this.isShown = true; // show calendars
656639
this.showCalInRanges = true;
@@ -672,33 +655,13 @@ export class DaterangepickerComponent implements OnInit {
672655
this.clickApply();
673656
}
674657
};
675-
/**
676-
* Update the input after applying
677-
*/
678-
updateFormInputs() {
679-
// ignore mouse movements while an above-calendar text input has focus
680-
if (this.daterangepickerEnd.focus || this.daterangepickerStart.focus) {
681-
return;
682-
}
683-
684-
this.daterangepickerStart.model = this.startDate.format(this.locale.format);
685-
if (this.endDate) {
686-
this.daterangepickerEnd.model = this.endDate.format(this.locale.format);
687-
}
688658

689-
if (this.singleDatePicker || (this.endDate && (this.startDate.isBefore(this.endDate) || this.startDate.isSame(this.endDate)))) {
690-
this.applyBtn.disabled = false;
691-
} else {
692-
this.applyBtn.disabled = true;
693-
}
694-
695-
}
696659

697660

698661
show(e?) {
699662
if (this.isShown) { return; }
700-
this.oldStartDate = this.startDate.clone();
701-
this.oldEndDate = this.endDate.clone();
663+
this._old.start = this.startDate.clone();
664+
this._old.end = this.endDate.clone();
702665
this.isShown = true;
703666
this.updateView();
704667
}
@@ -709,16 +672,16 @@ export class DaterangepickerComponent implements OnInit {
709672
}
710673
// incomplete date selection, revert to last values
711674
if (!this.endDate) {
712-
if (this.oldStartDate) {
713-
this.startDate = this.oldStartDate.clone();
675+
if (this._old.start) {
676+
this.startDate = this._old.start.clone();
714677
}
715-
if (this.oldEndDate) {
716-
this.endDate = this.oldEndDate.clone();
678+
if (this._old.end) {
679+
this.endDate = this._old.end.clone();
717680
}
718681
}
719682

720683
// if a new date range was selected, invoke the user callback function
721-
if (!this.startDate.isSame(this.oldStartDate) || !this.endDate.isSame(this.oldEndDate)) {
684+
if (!this.startDate.isSame(this._old.start) || !this.endDate.isSame(this._old.end)) {
722685
// this.callback(this.startDate, this.endDate, this.chosenLabel);
723686
}
724687

0 commit comments

Comments
 (0)