Skip to content

Commit

Permalink
feat(ui): Add loader to sorted table
Browse files Browse the repository at this point in the history
  • Loading branch information
richardlt committed Sep 12, 2018
1 parent 729ffcf commit e363ffd
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 28 deletions.
1 change: 1 addition & 0 deletions ui/src/app/shared/table/sorted-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class SortedTableComponent {
@Input() columns: Array<Column>;
@Input() data: any;
@Output() sortChange = new EventEmitter<any>();
@Input() loading: boolean;

sortedColumn: Column;
sortedColumnDirection: direction;
Expand Down
10 changes: 9 additions & 1 deletion ui/src/app/shared/table/sorted-table.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@
</th>
</tr>
</thead>
<tbody>
<tbody *ngIf="loading">
<tr>
<td class="center" [colSpan]="columns.length">
<div class="ui active small inline loader"></div>
<div>{{ 'common_loading' | translate }}</div>
</td>
</tr>
</tbody>
<tbody *ngIf="!loading">
<tr *ngFor="let d of data">
<td *ngFor="let c of columns" class="border">{{ c.selector(d) }}</td>
</tr>
Expand Down
3 changes: 3 additions & 0 deletions ui/src/app/shared/table/sorted-table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ th.descending:after {
font-family: Icons;
content: '\f0dd';
}
td.center {
text-align: center;
}
35 changes: 15 additions & 20 deletions ui/src/app/views/admin/hooks-tasks/hooks-tasks.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ export class HooksTasksComponent {
private _hookService: HookService,
private _translate: TranslateService
) {
this.loading = true;
this.columns = [
{
<Column>{
name: this._translate.instant('hook_task_cron'),
selector: d => d.config['cron'] && d.config['cron'].value,
},
Expand All @@ -36,47 +35,43 @@ export class HooksTasksComponent {
sortable: true,
sortKey: 'nb_executions_total'
},
{
<Column>{
name: this._translate.instant('common_project'),
selector: d => d.config['project'] && d.config['project'].value,
},
{
<Column>{
name: this._translate.instant('hook_task_repo_fullname'),
selector: d => d.config['repoFullName'] && d.config['repoFullName'].value,
},
{
<Column>{
name: this._translate.instant('common_stopped'),
selector: d => d.stopped,
},
{
<Column>{
name: this._translate.instant('common_type'),
selector: d => d.type,
},
{
<Column>{
name: 'UUID',
selector: d => d.uuid,
},
{
<Column>{
name: this._translate.instant('vcs_server'),
selector: d => d.config['vcsServer'] && d.config['vcsServer'].value,
},
{
<Column>{
name: this._translate.instant('common_workflow'),
selector: d => d.config['workflow'] && d.config['workflow'].value,
}
];
this._hookService.getAdminTasks('')
.subscribe(ts => {
this.tasks = ts;
this.loading = false;
});
this.getAdminTasks('');
}

sortChange(event: string) {
this._hookService.getAdminTasks(event)
.subscribe(ts => {
this.tasks = ts;
this.loading = false;
});
getAdminTasks(sort: string) {
this.loading = true;
this._hookService.getAdminTasks(sort).subscribe(ts => {
this.tasks = ts;
this.loading = false;
});
}
}
8 changes: 1 addition & 7 deletions ui/src/app/views/admin/hooks-tasks/hooks-tasks.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
<h2>{{ 'hook_tasks_summary' | translate }}</h2>

<div *ngIf="!loading && tasks;then showTasks;else loadTasks"></div>
<ng-template #showTasks>
<app-sorted-table [columns]="columns" [data]="tasks" (sortChange)="sortChange($event)"></app-sorted-table>
</ng-template>
<ng-template #loadTasks>
<div class="ui text active loader">{{ 'common_loading' | translate }}</div>
</ng-template>
<app-sorted-table [columns]="columns" [data]="tasks" (sortChange)="getAdminTasks($event)" [loading]="loading"></app-sorted-table>

0 comments on commit e363ffd

Please sign in to comment.