Skip to content

Commit a5683ee

Browse files
committed
added null filter in control base
BUG: not working with aot turned off? added callback observable for notify and toast
1 parent e68f180 commit a5683ee

File tree

12 files changed

+224
-214
lines changed

12 files changed

+224
-214
lines changed

.idea/runConfigurations/Angular_CLI_Server.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 117 additions & 196 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
"@angular/platform-browser-dynamic": "~8.1.0",
2121
"@angular/router": "~8.1.0",
2222
"core-js": "^2.5.4",
23+
"highlight.js": "^9.15.9",
2324
"jquery.hotkeys": "^0.1.0",
2425
"linq4js": "^2.2.2",
2526
"metro4": "^4.2.47",
2627
"moment": "^2.24.0",
28+
"ngx-highlightjs": "^3.0.3",
2729
"rxjs": "~6.5.2",
2830
"zone.js": "~0.9.1"
2931
},

projects/ng-metro4/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ng-metro4",
33
"description": "ng-metro4 is an implementation of the beautiful metro4 components",
4-
"version": "0.0.10",
4+
"version": "0.0.11",
55
"peerDependencies": {
66
"@angular/common": "~8.1.0",
77
"@angular/core": "~8.1.0",

projects/ng-metro4/src/lib/form/control-base.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export abstract class ControlBase<T> implements ControlValueAccessor, AfterViewI
2323
public touchCallback: () => void = () => {};
2424
public changeCallback: (currentValue: T) => void = (_) => {};
2525

26-
constructor(@Optional() public mainElement: ElementRef, protected cdRef: ChangeDetectorRef) {}
26+
constructor(@Optional() public mainElement: ElementRef, private cdRef: ChangeDetectorRef) {}
2727

2828
private observeClassValue() {
2929
this.classObserver = AttributeHelper.createObserver(this.mainElement, (newClasses, oldClasses) => {
@@ -79,6 +79,8 @@ export abstract class ControlBase<T> implements ControlValueAccessor, AfterViewI
7979
public abstract createControl(): Promise<void>;
8080

8181
ngAfterViewInit() {
82+
console.log(this.mainElement);
83+
8284
this.createControl().then(() => {
8385
this.callNewValue();
8486
this.observeClassValue();
@@ -104,7 +106,11 @@ export abstract class ControlBase<T> implements ControlValueAccessor, AfterViewI
104106

105107
if (oldValue !== newValue) {
106108
this[key] = newValue;
107-
this.cdRef.detectChanges();
109+
110+
if (this.cdRef) {
111+
this.cdRef.detectChanges();
112+
}
113+
108114
const changes: SimpleChanges = {};
109115
changes[key as string] = { previousValue: oldValue, currentValue: newValue, firstChange: false } as SimpleChange;
110116
this.ngOnChanges(changes);

projects/ng-metro4/src/lib/helper/attribute-helper.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export class AttributeHelper {
1212

1313
public static createObserver(element: ElementRef,
1414
newClassValues: (newClassValues: string[], oldClassValues: string[]) => void): MutationObserver {
15+
if (!element || !element.nativeElement) {
16+
return null;
17+
}
18+
1519
let previousClassValue: string[] = [];
1620
const classValueCallback = () => {
1721
const classValue: string = element.nativeElement.getAttribute('class') || '';

projects/ng-metro4/src/lib/helper/lists.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,40 @@ export const thinDictionary = {
845845
'ultra-thin': 'ultra-thin'
846846
};
847847

848+
export const easingDictionary = {
849+
'swing': 'swing',
850+
'easeInQuad': 'easeInQuad',
851+
'easeOutQuad': 'easeOutQuad',
852+
'easeInOutQuad': 'easeInOutQuad',
853+
'easeInCubic': 'easeInCubic',
854+
'easeOutCubic': 'easeOutCubic',
855+
'easeInOutCubic': 'easeInOutCubic',
856+
'easeInQuart': 'easeInQuart',
857+
'easeOutQuart': 'easeOutQuart',
858+
'easeInOutQuart': 'easeInOutQuart',
859+
'easeInQuint': 'easeInQuint',
860+
'easeOutQuint': 'easeOutQuint',
861+
'easeInOutQuint': 'easeInOutQuint',
862+
'easeInSine': 'easeInSine',
863+
'easeOutSine': 'easeOutSine',
864+
'easeInOutSine': 'easeInOutSine',
865+
'easeInExpo': 'easeInExpo',
866+
'easeOutExpo': 'easeOutExpo',
867+
'easeInOutExpo': 'easeInOutExpo',
868+
'easeInCirc': 'easeInCirc',
869+
'easeOutCirc': 'easeOutCirc',
870+
'easeInOutCirc': 'easeInOutCirc',
871+
'easeInElastic': 'easeInElastic',
872+
'easeOutElastic': 'easeOutElastic',
873+
'easeInOutElastic': 'easeInOutElastic',
874+
'easeInBack': 'easeInBack',
875+
'easeOutBack': 'easeOutBack',
876+
'easeInOutBack': 'easeInOutBack',
877+
'easeInBounce': 'easeInBounce',
878+
'easeOutBounce': 'easeOutBounce',
879+
'easeInOutBounce': 'easeInOutBounce'
880+
};
881+
848882
export class Lists {
849883
public static icons() {
850884
return Object.values(iconDictionary);
@@ -913,4 +947,8 @@ export class Lists {
913947
public static thins() {
914948
return Object.values(thinDictionary);
915949
}
950+
951+
public static easings() {
952+
return Object.values(easingDictionary);
953+
}
916954
}

projects/ng-metro4/src/lib/helper/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
animationDictionary,
66
buttonShapeDictionary,
77
buttonSpecialDictionary,
8-
colorDictionary,
8+
colorDictionary, easingDictionary,
99
gravatarDictionary,
1010
iconCategoryDictionary,
1111
iconDictionary,
@@ -54,3 +54,5 @@ export type ProgressTypeType = keyof typeof progressTypeDictionary;
5454
export type RoundTypeType = keyof typeof roundTypeDictionary;
5555

5656
export type ThinType = keyof typeof thinDictionary;
57+
58+
export type EasingType = keyof typeof easingDictionary;

projects/ng-metro4/src/lib/information/dialog/dialog.service.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ export class DialogService {
5151
return (<any>window).Metro.dialog.create(options);
5252
}
5353

54-
public alert(title: string, message: string, cls?: string, okBtnText?: string, okBtnCls?: string) {
54+
public alert(title: string, message: string, cls?: string, okBtnText?: string, okBtnCls?: string): Observable<void> {
55+
const subject$ = new Subject<void>();
56+
5557
const options: DialogOptions = {
5658
title: title,
5759
content: message,
@@ -63,11 +65,16 @@ export class DialogService {
6365
options.actions = [{
6466
caption: okBtnText,
6567
cls: (okBtnCls ? okBtnCls : '') + ' js-dialog-close',
66-
onclick: () => {}
68+
onclick: () => {
69+
subject$.next();
70+
subject$.complete();
71+
}
6772
}];
6873
}
6974

7075
this.create(options);
76+
77+
return subject$.asObservable();
7178
}
7279

7380
public confirm(title: string, message: string, yesBtnText?: string, noBtnText?: string,

projects/ng-metro4/src/lib/information/notify/notify.service.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import { Injectable } from '@angular/core';
2+
import {Observable, Subject} from 'rxjs';
3+
import {EasingType} from '../../helper/types';
24

3-
interface NotifySetupOptions {
5+
export interface NotifySetupOptions {
46
container?: string;
57
width?: string;
68
timeout?: number;
79
duration?: number;
810
distance?: string;
9-
animation?: string;
11+
animation?: EasingType;
1012
}
1113

12-
interface NotifyOptions {
14+
export interface NotifyOptions {
1315
keepOpen?: boolean;
1416
cls?: string;
15-
width: string;
16-
onShow?: () => void;
17-
onClose?: () => void;
17+
width?: string;
1818
}
1919

2020
@Injectable({
@@ -32,7 +32,17 @@ export class NotifyService {
3232
(<any>window).Metro.notify.reset();
3333
}
3434

35-
public create(message: string, title?: string, options?: NotifyOptions) {
36-
(<any>window).Metro.notify.create(message, title, options);
35+
public create(message: string, title?: string, options?: NotifyOptions): Observable<void> {
36+
const closeSubject$ = new Subject<any>();
37+
38+
(<any>window).Metro.notify.create(message, title, {
39+
onClose: () => {
40+
closeSubject$.next();
41+
closeSubject$.complete();
42+
},
43+
...options
44+
});
45+
46+
return closeSubject$.asObservable();
3747
}
3848
}

projects/ng-metro4/src/lib/information/toast/toast.service.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Injectable } from '@angular/core';
22
import {AccentType} from '../../helper/types';
3+
import {Observable, Subject} from 'rxjs';
34

45
interface ToastOptions {
56
timeout?: number;
67
cls?: string|AccentType;
7-
callback?: () => void;
88
additional?: {
99
distance?: number;
1010
showTop?: boolean;
@@ -18,7 +18,14 @@ export class ToastService {
1818

1919
constructor() { }
2020

21-
public create(message: string, options: ToastOptions = {}) {
22-
(<any>window).Metro.toast.create(message, options.callback, options.timeout, options.cls, options.additional);
21+
public create(message: string, options: ToastOptions = {}): Observable<any> {
22+
const closeSubject$ = new Subject<any>();
23+
24+
(<any>window).Metro.toast.create(message, () => {
25+
closeSubject$.next();
26+
closeSubject$.complete();
27+
}, options.timeout, options.cls, options.additional);
28+
29+
return closeSubject$.asObservable();
2330
}
2431
}

0 commit comments

Comments
 (0)