Skip to content

Commit 0437871

Browse files
author
Ihor Khomiak
committed
implement loading indicator to list component
1 parent bc355ec commit 0437871

File tree

4 files changed

+62
-37
lines changed

4 files changed

+62
-37
lines changed

app/components/cost/costs.component.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ export class CostsComponent implements OnInit {
2323

2424
ngOnInit(): void {
2525
const that = this;
26-
this.costService.getCosts().then(result => that.list.refresh());
26+
27+
that.list.reloadList();
28+
this.costService.getCosts().then(result => {
29+
that.list.stopReloadList();
30+
that.list.refresh();
31+
});
2732
}
2833

2934
add() {
@@ -60,7 +65,7 @@ export class CostsComponent implements OnInit {
6065
private pullToRefresh() {
6166
const that = this;
6267
this.costService.getCosts().then(result => {
63-
that.list.stopReloadTree();
68+
that.list.stopReloadList();
6469
that.list.refresh();
6570
});
6671
}

app/components/list/list.component.css

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,11 @@
1010
}
1111

1212
.main-container {
13-
width: 100%; height: 100%;
13+
width: 100%;
14+
height: 100%;
15+
}
16+
17+
.indicator-container {
18+
width: 100%;
19+
height: 100%;
1420
}
Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,37 @@
1-
<PullToRefresh (refresh)="refreshList($event)"
2-
class="main-container">
3-
<ListView [items]="items"
4-
#list
5-
class="list-group">
6-
<ng-template let-item="item">
7-
<GridLayout row="0"
8-
columns="*, 80, 100, 80">
9-
<Label [nsRouterLink]="['/cost', item.id]"
10-
[text]="item.quantity"
11-
class="list-group-item"
12-
col="0"></Label>
13-
<Label [nsRouterLink]="['/cost', item.id]"
14-
[text]="getDateValue(item)"
15-
class="list-group-item-date"
16-
col="1"></Label>
17-
<Label [nsRouterLink]="['/cost', item.id]"
18-
[text]="item.type"
19-
class="tag-item"
20-
col="2"></Label>
21-
<Label [nsRouterLink]="['/cost', item.id]"
22-
[text]="item.isFavorite === true ? 'Favorite' : 'Not Favorite'"
23-
class="list-group-item-favorite"
24-
col="3"></Label>
25-
</GridLayout>
26-
</ng-template>
27-
</ListView>
28-
</PullToRefresh>
1+
<AbsoluteLayout class="main-container">
2+
<PullToRefresh (refresh)="reloadList($event)"
3+
class="main-container">
4+
<ListView [items]="items"
5+
#list
6+
class="list-group">
7+
<ng-template let-item="item">
8+
<GridLayout row="0"
9+
columns="*, 80, 100, 80">
10+
<Label [nsRouterLink]="['/cost', item.id]"
11+
[text]="item.quantity"
12+
class="list-group-item"
13+
col="0"></Label>
14+
<Label [nsRouterLink]="['/cost', item.id]"
15+
[text]="getDateValue(item)"
16+
class="list-group-item-date"
17+
col="1"></Label>
18+
<Label [nsRouterLink]="['/cost', item.id]"
19+
[text]="item.type"
20+
class="tag-item"
21+
col="2"></Label>
22+
<Label [nsRouterLink]="['/cost', item.id]"
23+
[text]="item.isFavorite === true ? 'Favorite' : 'Not Favorite'"
24+
class="list-group-item-favorite"
25+
col="3"></Label>
26+
</GridLayout>
27+
</ng-template>
28+
</ListView>
29+
</PullToRefresh>
30+
<StackLayout verticalAlignment="center"
31+
class="indicator-container">
32+
<ActivityIndicator [busy]="isLoading"
33+
[visibility]="isLoading ? 'visible' : 'collapse'"
34+
horizontalAlignment="center"
35+
verticalAlignment="center"></ActivityIndicator>
36+
</StackLayout>
37+
</AbsoluteLayout>

app/components/list/list.component.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,23 @@ export class ListComponent {
1313
@ViewChild("list") list: ElementRef;
1414

1515
private pullRefresh = {};
16+
private isLoading: boolean = false;
1617

1718
refresh() {
1819
this.list.nativeElement.refresh();
1920
}
2021

21-
stopReloadTree() {
22+
reloadList(pullToRefreshArgs: any = null) {
23+
if (pullToRefreshArgs) {
24+
this.pullRefresh = pullToRefreshArgs.object;
25+
this.pullToRefreshEvent.emit();
26+
}
27+
this.isLoading = true;
28+
}
29+
30+
stopReloadList() {
2231
this.pullRefresh['refreshing'] = false;
32+
this.isLoading = false;
2333
}
2434

2535
private getDateValue(item) {
@@ -30,9 +40,4 @@ export class ListComponent {
3040
}
3141
return Utils.dateToYMD(itemDate);
3242
}
33-
34-
private refreshList(args: any) {
35-
this.pullRefresh = args.object;
36-
this.pullToRefreshEvent.emit();
37-
}
3843
}

0 commit comments

Comments
 (0)