Skip to content

Commit 45f49b0

Browse files
committed
feat(request): request content component and viewchildren visibility control
1 parent 5100547 commit 45f49b0

1 file changed

Lines changed: 36 additions & 3 deletions

File tree

src/components/request.ts

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ContentChild, Directive, EventEmitter, Input, Output } from '@angular/core';
22
import { Http } from '@mbamobi/http';
3-
import { StateEmpty, StateError, StateLoading } from './states';
3+
import { StateEmpty, StateError, StateLoading, StateContent } from './states';
44

55
@Directive({
66
selector: '[request]'
@@ -19,6 +19,8 @@ export class Request {
1919

2020
@ContentChild(StateError) error: any;
2121

22+
@ContentChild(StateContent) content: any;
23+
2224
constructor(
2325
private http: Http
2426
) {}
@@ -47,13 +49,20 @@ export class Request {
4749
}
4850

4951
request() {
52+
if (this.loading) {
53+
this.loading.present();
54+
}
55+
56+
this.dismissError();
57+
this.dismissNoRecords();
58+
this.dismissContent();
59+
5060
this.http.request(
5161
this.url,
5262
this.params,
5363
this.requestOptions,
5464
this.options
5565
).subscribe((result: any) => {
56-
5766
this.dismissLoading();
5867

5968
if (this.noRecords) {
@@ -62,10 +71,11 @@ export class Request {
6271

6372
if (!isPresent) {
6473
this.loaded.emit(result);
74+
this.presentContent();
6575
}
66-
6776
} else {
6877
this.loaded.emit(result);
78+
this.presentContent();
6979
}
7080
}, (error) => {
7181
this.dismissLoading();
@@ -86,4 +96,27 @@ export class Request {
8696
this.loading.dismiss();
8797
}
8898
}
99+
100+
private dismissError() {
101+
if (this.error) {
102+
this.error.dismiss();
103+
}
104+
}
105+
106+
private dismissNoRecords() {
107+
if (this.noRecords) {
108+
this.noRecords.dismiss();
109+
}
110+
}
111+
112+
private dismissContent() {
113+
if (this.content) {
114+
this.content.dismiss();
115+
}
116+
}
117+
private presentContent() {
118+
if (this.content) {
119+
this.content.present();
120+
}
121+
}
89122
}

0 commit comments

Comments
 (0)