Skip to content

Commit d3f4b8d

Browse files
author
Vitor Durante
committed
Implement busy and block directives
1 parent a1f2c95 commit d3f4b8d

File tree

5 files changed

+82
-10
lines changed

5 files changed

+82
-10
lines changed

angular/src/app/roles/roles.component.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ <h2>
66
{{ 'Roles' | localize }}
77
</h2>
88
<ul class="header-dropdown m-r--5">
9-
<li>
9+
<li>
1010
<button mat-icon-button [matMenuTriggerFor]="headerMenu" style="bottom: 10px;">
1111
<mat-icon>more_vert</mat-icon>
1212
</button>
@@ -20,15 +20,15 @@ <h2>
2020
</ul>
2121
</div>
2222
<div id="roles-table" class="body table-responsive">
23-
<table class="table table-hover table-striped">
23+
<table class="table table-hover table-striped" [busy]="isTableLoading">
2424
<thead>
2525
<tr>
2626
<th>{{ 'Actions' | localize }}</th>
2727
<th>{{ 'RoleName' | localize }}</th>
28-
<th>{{ 'DisplayName' | localize }}</th>
28+
<th>{{ 'DisplayName' | localize }}</th>
2929
</tr>
3030
</thead>
31-
<tbody>
31+
<tbody>
3232
<tr *ngFor="let role of roles | paginate: { id: 'server', itemsPerPage: pageSize, currentPage: pageNumber, totalItems: totalItems }">
3333
<td>
3434
<button mat-icon-button [matMenuTriggerFor]="actionsMenu">
@@ -59,4 +59,4 @@ <h2>
5959
</div>
6060
</div>
6161
</div>
62-
</div>
62+
</div>

angular/src/app/roles/roles.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class RolesComponent extends PagedListingComponentBase<RoleDto> {
3434
pageNumber: number,
3535
finishedCallback: Function
3636
): void {
37-
abp.ui.setBusy($("#roles-table"));
37+
//abp.ui.setBusy($("#roles-table"));
3838

3939
this._rolesService
4040
.getAll(request.skipCount, request.maxResultCount)
@@ -46,8 +46,8 @@ export class RolesComponent extends PagedListingComponentBase<RoleDto> {
4646
.subscribe((result: PagedResultDtoOfRoleDto) => {
4747
this.roles = result.items;
4848
this.showPaging(result, pageNumber);
49-
50-
abp.ui.clearBusy($("#roles-table"));
49+
50+
//abp.ui.clearBusy($("#roles-table"));
5151
});
5252
}
5353

@@ -64,7 +64,7 @@ export class RolesComponent extends PagedListingComponentBase<RoleDto> {
6464
this.refresh();
6565
})
6666
)
67-
.subscribe(() => {});
67+
.subscribe(() => { });
6868
}
6969
}
7070
);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import {
2+
AfterViewInit,
3+
Directive,
4+
ElementRef,
5+
Injectable,
6+
HostListener,
7+
Input,
8+
SimpleChanges
9+
} from '@angular/core';
10+
11+
@Directive({
12+
selector: '[block]'
13+
})
14+
@Injectable()
15+
export class BlockDirective implements AfterViewInit {
16+
@Input('block') loading: boolean;
17+
private $element: JQuery;
18+
19+
constructor(private _element: ElementRef) { }
20+
21+
ngAfterViewInit(): void {
22+
this.$element = $(this._element.nativeElement);
23+
}
24+
25+
ngOnChanges(changes: SimpleChanges): void {
26+
$.blockUI.defaults.overlayCSS.cursor = 'not-allowed';
27+
if (changes['loading'].currentValue) {
28+
abp.ui.block(this._element.nativeElement);
29+
} else {
30+
abp.ui.unblock(this._element.nativeElement);
31+
}
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import {
2+
AfterViewInit,
3+
Directive,
4+
ElementRef,
5+
Injectable,
6+
HostListener,
7+
Input,
8+
SimpleChanges
9+
} from '@angular/core';
10+
11+
@Directive({
12+
selector: '[busy]'
13+
})
14+
@Injectable()
15+
export class BusyDirective implements AfterViewInit {
16+
@Input('busy') loading: boolean;
17+
private $element: JQuery;
18+
19+
constructor(private _element: ElementRef) { }
20+
21+
ngAfterViewInit(): void {
22+
this.$element = $(this._element.nativeElement);
23+
}
24+
25+
ngOnChanges(changes: SimpleChanges): void {
26+
27+
if (changes['loading'].currentValue) {
28+
abp.ui.setBusy(this._element.nativeElement);
29+
} else {
30+
abp.ui.clearBusy(this._element.nativeElement);
31+
}
32+
}
33+
}

angular/src/shared/shared.module.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ import {
5252
MatTooltipModule,
5353
MatTreeModule,
5454
} from '@angular/material';
55+
import { BlockDirective } from './directives/block.directive';
56+
import { BusyDirective } from './directives/busy.directive';
5557
@NgModule({
5658
imports: [
5759
CommonModule,
@@ -97,12 +99,16 @@ import {
9799
declarations: [
98100
MaterialInput,
99101
AbpPaginationControlsComponent,
100-
LocalizePipe
102+
LocalizePipe,
103+
BlockDirective,
104+
BusyDirective
101105
],
102106
exports: [
103107
MaterialInput,
104108
AbpPaginationControlsComponent,
105109
LocalizePipe,
110+
BlockDirective,
111+
BusyDirective,
106112
CdkTableModule,
107113
CdkTreeModule,
108114
DragDropModule,

0 commit comments

Comments
 (0)