|
1 | 1 | import {Subscription} from 'rxjs'; |
2 | 2 | import {Component, TemplateRef, Type, Inject, ChangeDetectorRef} from '@angular/core'; |
| 3 | +import {InstanceConfigHolderService} from '../service/instance-config-holder.service'; |
3 | 4 |
|
4 | 5 | export class BusyConfig implements IBusyConfig { |
5 | | - template: TemplateRef<any> | Type<any>; |
6 | | - delay: number; |
7 | | - minDuration: number; |
8 | | - backdrop: boolean; |
9 | | - message: string; |
10 | | - wrapperClass: string; |
11 | | - disableAnimation: boolean; |
| 6 | + template: TemplateRef<any> | Type<any>; |
| 7 | + delay: number; |
| 8 | + minDuration: number; |
| 9 | + backdrop: boolean; |
| 10 | + message: string; |
| 11 | + wrapperClass: string; |
| 12 | + disableAnimation: boolean; |
12 | 13 |
|
13 | | - constructor(config: IBusyConfig = {}) { |
14 | | - for (const option of Object.keys(BUSY_CONFIG_DEFAULTS)) { |
15 | | - this[option] = config[option] !== undefined ? config[option] : BUSY_CONFIG_DEFAULTS[option]; |
16 | | - } |
| 14 | + constructor(config: IBusyConfig = {}) { |
| 15 | + for (const option of Object.keys(BUSY_CONFIG_DEFAULTS)) { |
| 16 | + this[option] = config[option] !== undefined ? config[option] : BUSY_CONFIG_DEFAULTS[option]; |
17 | 17 | } |
| 18 | + } |
18 | 19 | } |
19 | 20 |
|
20 | 21 | @Component({ |
21 | | - selector: 'default-busy', |
22 | | - template: ` |
23 | | - <div class="ng-busy-default-wrapper"> |
24 | | - <div class="ng-busy-default-sign"> |
25 | | - <div class="ng-busy-default-spinner"> |
26 | | - <div class="bar1"></div> |
27 | | - <div class="bar2"></div> |
28 | | - <div class="bar3"></div> |
29 | | - <div class="bar4"></div> |
30 | | - <div class="bar5"></div> |
31 | | - <div class="bar6"></div> |
32 | | - <div class="bar7"></div> |
33 | | - <div class="bar8"></div> |
34 | | - <div class="bar9"></div> |
35 | | - <div class="bar10"></div> |
36 | | - <div class="bar11"></div> |
37 | | - <div class="bar12"></div> |
38 | | - </div> |
39 | | - <div class="ng-busy-default-text">{{message}}</div> |
40 | | - </div> |
41 | | - </div> |
42 | | - `, |
| 22 | + selector: 'default-busy', |
| 23 | + template: ` |
| 24 | + <div class="ng-busy-default-wrapper"> |
| 25 | + <div class="ng-busy-default-sign"> |
| 26 | + <div class="ng-busy-default-spinner"> |
| 27 | + <div class="bar1"></div> |
| 28 | + <div class="bar2"></div> |
| 29 | + <div class="bar3"></div> |
| 30 | + <div class="bar4"></div> |
| 31 | + <div class="bar5"></div> |
| 32 | + <div class="bar6"></div> |
| 33 | + <div class="bar7"></div> |
| 34 | + <div class="bar8"></div> |
| 35 | + <div class="bar9"></div> |
| 36 | + <div class="bar10"></div> |
| 37 | + <div class="bar11"></div> |
| 38 | + <div class="bar12"></div> |
| 39 | + </div> |
| 40 | + <div class="ng-busy-default-text">{{message}}</div> |
| 41 | + </div> |
| 42 | + </div> |
| 43 | + `, |
43 | 44 | }) |
44 | 45 | export class DefaultBusyComponent { |
45 | | - private _msg: string; |
46 | 46 |
|
47 | | - constructor(@Inject('message') private msg: string, private _changeDetectionRef: ChangeDetectorRef) { |
48 | | - } |
49 | | - |
50 | | - get message() { |
51 | | - if (this._msg === undefined) { |
52 | | - this.message = this.msg; |
53 | | - } |
54 | | - return this._msg; |
55 | | - } |
| 47 | + constructor(@Inject('instanceConfigHolder') private instanceConfigHolder: InstanceConfigHolderService) { |
| 48 | + } |
56 | 49 |
|
57 | | - set message(msg: string) { |
58 | | - this._msg = msg; |
59 | | - this._changeDetectionRef.detectChanges(); |
60 | | - } |
| 50 | + get message() { |
| 51 | + return this.instanceConfigHolder.config.message; |
| 52 | + } |
61 | 53 | } |
62 | 54 |
|
63 | 55 | export interface IBusyConfig { |
64 | | - template?: TemplateRef<any> | Type<any>; |
65 | | - delay?: number; |
66 | | - minDuration?: number; |
67 | | - backdrop?: boolean; |
68 | | - message?: string; |
69 | | - wrapperClass?: string; |
70 | | - busy?: Array<Promise<any> | Subscription>; |
71 | | - disableAnimation?: boolean; |
| 56 | + template?: TemplateRef<any> | Type<any>; |
| 57 | + delay?: number; |
| 58 | + minDuration?: number; |
| 59 | + backdrop?: boolean; |
| 60 | + message?: string; |
| 61 | + wrapperClass?: string; |
| 62 | + busy?: Array<Promise<any> | Subscription>; |
| 63 | + disableAnimation?: boolean; |
72 | 64 | } |
73 | 65 |
|
74 | 66 | export const BUSY_CONFIG_DEFAULTS = { |
75 | | - template: DefaultBusyComponent, |
76 | | - delay: 0, |
77 | | - minDuration: 0, |
78 | | - backdrop: true, |
79 | | - message: 'Please wait...', |
80 | | - wrapperClass: 'ng-busy', |
81 | | - disableAnimation: false |
| 67 | + template: DefaultBusyComponent, |
| 68 | + delay: 0, |
| 69 | + minDuration: 0, |
| 70 | + backdrop: true, |
| 71 | + message: 'Please wait...', |
| 72 | + wrapperClass: 'ng-busy', |
| 73 | + disableAnimation: false |
82 | 74 | }; |
0 commit comments