cic-staff-client/src/app/pages/accounts/accounts.component.ts

68 lines
2.1 KiB
TypeScript
Raw Normal View History

import {ChangeDetectionStrategy, Component, OnInit, ViewChild} from '@angular/core';
2020-11-25 08:57:17 +01:00
import {MatTableDataSource} from '@angular/material/table';
import {MatPaginator} from '@angular/material/paginator';
import {MatSort} from '@angular/material/sort';
import {LoggingService, UserService} from '@app/_services';
2020-11-25 08:57:17 +01:00
import {Router} from '@angular/router';
@Component({
selector: 'app-accounts',
templateUrl: './accounts.component.html',
styleUrls: ['./accounts.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
2020-11-25 08:57:17 +01:00
})
export class AccountsComponent implements OnInit {
2020-11-25 08:57:17 +01:00
dataSource: MatTableDataSource<any>;
accounts: any[] = [];
2021-03-15 12:58:18 +01:00
displayedColumns = ['name', 'phone', 'created', 'balance', 'location'];
defaultPageSize = 10;
pageSizeOptions = [10, 20, 50, 100];
accountsType = 'all';
2020-11-25 08:57:17 +01:00
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
constructor(
private userService: UserService,
private loggingService: LoggingService,
2020-11-25 08:57:17 +01:00
private router: Router
) {
(async () => {
try {
await this.userService.loadAccounts(100);
} catch (error) {
this.loggingService.sendErrorLevelMessage('Failed to load accounts', this, {error});
}
})();
}
2020-11-25 08:57:17 +01:00
ngOnInit(): void {
this.userService.accountsSubject.subscribe(accounts => {
this.dataSource = new MatTableDataSource<any>(accounts);
this.dataSource.paginator = this.paginator;
2021-03-21 12:02:18 +01:00
this.paginator._changePageSize(this.paginator.pageSize);
this.dataSource.sort = this.sort;
this.accounts = accounts;
});
2020-11-25 08:57:17 +01:00
}
doFilter(value: string): void {
this.dataSource.filter = value.trim().toLocaleLowerCase();
}
async viewAccount(account): Promise<void> {
await this.router.navigateByUrl(`/accounts/${account.identities.evm['bloxberg:8996']}`);
}
filterAccounts(): void {
if (this.accountsType === 'all') {
this.userService.accountsSubject.subscribe(accounts => {
this.dataSource.data = accounts;
this.accounts = accounts;
});
} else {
this.dataSource.data = this.accounts.filter(account => account.type === this.accountsType);
}
2020-11-25 08:57:17 +01:00
}
}