80 lines
2.4 KiB
TypeScript
80 lines
2.4 KiB
TypeScript
import {ChangeDetectionStrategy, Component, OnInit, ViewChild} from '@angular/core';
|
|
import {MatTableDataSource} from '@angular/material/table';
|
|
import {MatPaginator} from '@angular/material/paginator';
|
|
import {MatSort} from '@angular/material/sort';
|
|
import {LoggingService, UserService} from '@app/_services';
|
|
import {Router} from '@angular/router';
|
|
import {exportCsv} from '@app/_helpers';
|
|
|
|
@Component({
|
|
selector: 'app-accounts',
|
|
templateUrl: './accounts.component.html',
|
|
styleUrls: ['./accounts.component.scss'],
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
|
})
|
|
export class AccountsComponent implements OnInit {
|
|
dataSource: MatTableDataSource<any>;
|
|
accounts: any[] = [];
|
|
displayedColumns = ['name', 'phone', 'created', 'balance', 'location'];
|
|
defaultPageSize = 10;
|
|
pageSizeOptions = [10, 20, 50, 100];
|
|
accountsType = 'all';
|
|
|
|
@ViewChild(MatPaginator) paginator: MatPaginator;
|
|
@ViewChild(MatSort) sort: MatSort;
|
|
|
|
constructor(
|
|
private userService: UserService,
|
|
private loggingService: LoggingService,
|
|
private router: Router
|
|
) {
|
|
(async () => {
|
|
try {
|
|
await this.userService.loadAccounts(100);
|
|
} catch (error) {
|
|
this.loggingService.sendErrorLevelMessage('Failed to load accounts', this, {error});
|
|
}
|
|
})();
|
|
}
|
|
|
|
ngOnInit(): void {
|
|
this.userService.accountsSubject.subscribe(accounts => {
|
|
this.dataSource = new MatTableDataSource<any>(accounts);
|
|
this.dataSource.paginator = this.paginator;
|
|
this.dataSource.sort = this.sort;
|
|
this.accounts = accounts;
|
|
});
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
refreshPaginator(): void {
|
|
if (!this.dataSource.paginator) {
|
|
this.dataSource.paginator = this.paginator;
|
|
}
|
|
|
|
this.paginator._changePageSize(this.paginator.pageSize);
|
|
}
|
|
|
|
downloadCsv(): void {
|
|
exportCsv(this.accounts, 'accounts');
|
|
}
|
|
}
|