60 lines
1.8 KiB
TypeScript
60 lines
1.8 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 {UserService} from '@app/_services';
|
|
import {Router} from '@angular/router';
|
|
|
|
@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 router: Router
|
|
) {
|
|
this.userService.loadAccounts(100).then();
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
viewAccount(account): void {
|
|
this.router.navigateByUrl(`/accounts/${account.identities.evm['bloxberg:8996']}`).then();
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|