added loading indicator for tables

urls
FlayInAHook 4 years ago
parent 658b79402b
commit 0983ec85ed

@ -15,7 +15,7 @@
<button <button
mat-raised-button mat-raised-button
class="table-control-button" class="table-control-button"
(click)="addEmptyRow()"
[disabled]="reloadingTable" [disabled]="reloadingTable"
> >
<mat-icon class="spin">add</mat-icon> <mat-icon class="spin">add</mat-icon>
@ -35,6 +35,7 @@
></mat-paginator> ></mat-paginator>
</div> </div>
<div class="table-container"> <div class="table-container">
<table <table
mat-table mat-table
class="mat-elevation-z8" class="mat-elevation-z8"
@ -146,9 +147,19 @@
</td> </td>
</ng-container> </ng-container>
<mat-spinner
[diameter]="32"
*ngIf="!isLoaded"
></mat-spinner>
<!-- Table Definition --> <!-- Table Definition -->
<tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr> <tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns"></tr> <tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>
</table> </table>
<mat-card *ngIf="!isLoaded" style="display: flex; justify-content: center; align-items: center">
<mat-spinner [diameter]="320"></mat-spinner>
</mat-card>
</div> </div>
</div> </div>

@ -16,6 +16,7 @@ import { logArrayInColumnInfoForm } from 'src/app/helperFunctions/logArrayInColu
import { MatTableDataSource } from '@angular/material/table'; import { MatTableDataSource } from '@angular/material/table';
import { MatPaginator } from '@angular/material/paginator'; import { MatPaginator } from '@angular/material/paginator';
import { MatSort } from '@angular/material/sort'; import { MatSort } from '@angular/material/sort';
import { BehaviorSubject } from 'rxjs';
@Component({ @Component({
selector: 'app-bikes', selector: 'app-bikes',
@ -109,6 +110,7 @@ export class BikesComponent {
relockingInterval = null; relockingInterval = null;
relockingDuration = 1000 * 60 * 1; relockingDuration = 1000 * 60 * 1;
isLoaded = false;
constructor( constructor(
private bikesService: BikesService, private bikesService: BikesService,
@ -135,6 +137,7 @@ export class BikesComponent {
this.reloadingTable = false; this.reloadingTable = false;
const tempDataSource = []; const tempDataSource = [];
for (const row of newTableDataSource) { for (const row of newTableDataSource) {
this.isLoaded = true;
const oldRow = this.getRowById(row.id); const oldRow = this.getRowById(row.id);
/** make sure to not overwrite a row that is being edited */ /** make sure to not overwrite a row that is being edited */
if (!oldRow) { if (!oldRow) {
@ -149,6 +152,7 @@ export class BikesComponent {
}); });
this.bikesService.loadBikes(); this.bikesService.loadBikes();
this.relockingInterval = setInterval(() => { this.relockingInterval = setInterval(() => {
for (const row of this.data.data) { for (const row of this.data.data) {
if (row.isLockedByMe) { if (row.isLockedByMe) {
@ -212,6 +216,8 @@ export class BikesComponent {
reloadTable() { reloadTable() {
this.reloadingTable = true; this.reloadingTable = true;
this.isLoaded = false;
this.data.data = [];
this.bikesService.loadBikes(); this.bikesService.loadBikes();
} }

Loading…
Cancel
Save