Skip to content
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

Implemented beforePickerOpen event #187

Merged
merged 2 commits into from
Nov 27, 2023
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
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,16 @@ Properties for `owl-date-time`

Events for `owl-date-time`
-------
|Events|Parameter|Description|
|:--- |:--- |:--- |
|`afterPickerOpen`|null|Callback to invoke when the picker is opened|
|`afterPickerClosed`|null|Callback to invoke when the picker is closed.|
|`yearSelected`|T|Callback to invoke when the year is selected.This doesn't imply a change on the selected date.|
|`monthSelected`|T|Callback to invoke when the month is selected.This doesn't imply a change on the selected date.|
|`dateClicked`|T|Callback when the selected data changes.|
|`selectedChanged`|T|Callback when the currently selected data changes.|
|`userSelection`|null|Callback when any date is selected.|
| Events |Parameter| Description |
|:--------------------|:--- |:------------------------------------------------------------------------------------------------|
| `beforePickerOpen` |null| Callback to invoke before the picker is opened |
| `afterPickerOpen` |null| Callback to invoke when the picker is opened |
| `afterPickerClosed` |null| Callback to invoke when the picker is closed. |
| `yearSelected` |T| Callback to invoke when the year is selected.This doesn't imply a change on the selected date. |
| `monthSelected` |T| Callback to invoke when the month is selected.This doesn't imply a change on the selected date. |
| `dateClicked` |T| Callback when the selected data changes. |
| `selectedChanged` |T| Callback when the currently selected data changes. |
| `userSelection` |null| Callback when any date is selected. |

Properties for `input[owlDateTime]`
-------
Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@danielmoncada/angular-datetime-picker",
"version": "16.0.1",
"version": "16.1.0",
"description": "Angular Date Time Picker",
"keywords": [
"Angular",
Expand All @@ -23,12 +23,13 @@
"test-with-coverage": "ng test --watch=false --no-progress --browsers=ChromeHeadlessNoSandbox --code-coverage=true picker",
"lint": "ng lint",
"e2e": "ng e2e",
"build_lib": "ng build picker --configuration production && cp README.md dist/picker",
"build_lib_onWindows": "ng build picker --configuration production && copy \"README.md\" \"dist/picker\"",
"build_lib_onLinux": "ng build picker --configuration production && cp README.md dist/picker",
"build_css_onWindows": "mkdir \"dist/picker/assets/style\" && node-sass --output-style=compressed projects/picker/src/sass/picker.scss > dist/picker/assets/style/picker.min.css",
"build_css_onLinux": "mkdir -p dist/picker/assets/style && node-sass --output-style=compressed projects/picker/src/sass/picker.scss > dist/picker/assets/style/picker.min.css",
"npm_pack": "cd dist/picker && npm pack",
"package_windows": "npm run build_lib && npm run build_css_onWindows && npm run npm_pack",
"package_linux": "npm run build_lib && npm run build_css_onLinux && npm run npm_pack"
"package_windows": "npm run build_lib_onWindows && npm run build_css_onWindows && npm run npm_pack",
"package_linux": "npm run build_lib_onLinux && npm run build_css_onLinux && npm run npm_pack"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion projects/picker/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@danielmoncada/angular-datetime-picker",
"version": "16.0.1",
"version": "16.1.0",
"description": "Angular Date Time Picker",
"keywords": [
"Angular",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
owlDateTimePickerAnimations.fadeInPicker
],
host: {
'(@transformPicker.start)': 'handleContainerAnimationStart($event)',
'(@transformPicker.done)': 'handleContainerAnimationDone($event)',
'[class.owl-dt-container]': 'owlDTContainerClass',
'[class.owl-dt-popup-container]': 'owlDTPopupContainerClass',
Expand All @@ -64,7 +65,7 @@ export class OwlDateTimeContainerComponent<T>
// retain start and end time
private retainStartTime: T;
private retainEndTime: T;

/**
* Stream emits when try to hide picker
* */
Expand All @@ -83,6 +84,12 @@ export class OwlDateTimeContainerComponent<T>
return this.confirmSelected$.asObservable();
}

private beforePickerOpened$ = new Subject<any>();

get beforePickerOpenedStream(): Observable<any> {
return this.beforePickerOpened$.asObservable();
}

private pickerOpened$ = new Subject<any>();

get pickerOpenedStream(): Observable<any> {
Expand Down Expand Up @@ -226,6 +233,12 @@ export class OwlDateTimeContainerComponent<T>
this.focusPicker();
}

public handleContainerAnimationStart(event: AnimationEvent): void {
const toState = event.toState;
if (toState === 'enter') {
this.beforePickerOpened$.next();
}
}
public handleContainerAnimationDone(event: AnimationEvent): void {
const toState = event.toState;
if (toState === 'enter') {
Expand Down
21 changes: 21 additions & 0 deletions projects/picker/src/lib/date-time/date-time-picker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ export class OwlDateTimeComponent<T> extends OwlDateTime<T>
@Output()
afterPickerClosed = new EventEmitter<any>();

/**
* Callback before the picker is open
* */
@Output()
beforePickerOpen = new EventEmitter<any>();

/**
* Callback when the picker is open
* */
Expand Down Expand Up @@ -271,6 +277,7 @@ export class OwlDateTimeComponent<T> extends OwlDateTime<T>
private hidePickerStreamSub = Subscription.EMPTY;
private confirmSelectedStreamSub = Subscription.EMPTY;
private pickerOpenedStreamSub = Subscription.EMPTY;
private pickerBeforeOpenedStreamSub = Subscription.EMPTY;

/** The element that was focused before the date time picker was opened. */
private focusedElementBeforeOpen: HTMLElement | null = null;
Expand Down Expand Up @@ -515,6 +522,11 @@ export class OwlDateTimeComponent<T> extends OwlDateTime<T>
this.confirmSelectedStreamSub = null;
}

if (this.pickerBeforeOpenedStreamSub) {
this.pickerBeforeOpenedStreamSub.unsubscribe();
this.pickerBeforeOpenedStreamSub = null;
}

if (this.pickerOpenedStreamSub) {
this.pickerOpenedStreamSub.unsubscribe();
this.pickerOpenedStreamSub = null;
Expand Down Expand Up @@ -586,6 +598,9 @@ export class OwlDateTimeComponent<T> extends OwlDateTime<T>
);
this.pickerContainer = this.dialogRef.componentInstance;

this.dialogRef.beforeOpen().subscribe(() => {
this.beforePickerOpen.emit(null);
});
this.dialogRef.afterOpen().subscribe(() => {
this.afterPickerOpen.emit(null);
this._opened = true;
Expand Down Expand Up @@ -621,6 +636,12 @@ export class OwlDateTimeComponent<T> extends OwlDateTime<T>
this.popupRef.updatePosition();
});

this.pickerBeforeOpenedStreamSub = this.pickerContainer.beforePickerOpenedStream
.pipe(take(1))
.subscribe(() => {
this.beforePickerOpen.emit(null);
});

// emit open stream
this.pickerOpenedStreamSub = this.pickerContainer.pickerOpenedStream
.pipe(take(1))
Expand Down
16 changes: 16 additions & 0 deletions projects/picker/src/lib/dialog/dialog-ref.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export class OwlDialogRef<T> {

private _beforeClose$ = new Subject<any>();

private _beforeOpen$ = new Subject<any>();

private _afterOpen$ = new Subject<any>();

private _afterClosed$ = new Subject<any>();
Expand All @@ -36,6 +38,16 @@ export class OwlDialogRef<T> {
public readonly id: string,
location?: Location ) {

this.container.animationStateChanged
.pipe(
filter(( event: AnimationEvent ) => event.phaseName === 'start' && event.toState === 'enter'),
take(1)
)
.subscribe(() => {
this._beforeOpen$.next();
this._beforeOpen$.complete();
});

this.container.animationStateChanged
.pipe(
filter(( event: AnimationEvent ) => event.phaseName === 'done' && event.toState === 'enter'),
Expand Down Expand Up @@ -142,6 +154,10 @@ export class OwlDialogRef<T> {
return this.container.isAnimating;
}

public beforeOpen(): Observable<any> {
return this._beforeOpen$.asObservable();
}

public afterOpen(): Observable<any> {
return this._afterOpen$.asObservable();
}
Expand Down
9 changes: 9 additions & 0 deletions projects/picker/src/lib/dialog/dialog.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class OwlDialogService {
private ariaHiddenElements = new Map<Element, string | null>();

private _openDialogsAtThisLevel: OwlDialogRef<any>[] = [];
private _beforeOpenAtThisLevel = new Subject<OwlDialogRef<any>>();
private _afterOpenAtThisLevel = new Subject<OwlDialogRef<any>>();
private _afterAllClosedAtThisLevel = new Subject<void>();

Expand All @@ -77,6 +78,13 @@ export class OwlDialogService {
: this._openDialogsAtThisLevel;
}

/** Stream that emits when a dialog has been opened. */
get beforeOpen(): Subject<OwlDialogRef<any>> {
return this.parentDialog
? this.parentDialog.beforeOpen
: this._beforeOpenAtThisLevel;
}

/** Stream that emits when a dialog has been opened. */
get afterOpen(): Subject<OwlDialogRef<any>> {
return this.parentDialog
Expand Down Expand Up @@ -155,6 +163,7 @@ export class OwlDialogService {
dialogRef
.afterClosed()
.subscribe(() => this.removeOpenDialog(dialogRef));
this.beforeOpen.next(dialogRef);
this.afterOpen.next(dialogRef);
return dialogRef;
}
Expand Down
Loading