62 lines
1.9 KiB
TypeScript
62 lines
1.9 KiB
TypeScript
|
import {AfterViewInit, Component, OnInit, ViewChild} from '@angular/core';
|
||
|
import {MatTableDataSource} from '@angular/material/table';
|
||
|
import {SelectionModel} from '@angular/cdk/collections';
|
||
|
import {MatPaginator} from '@angular/material/paginator';
|
||
|
import {MatSort} from '@angular/material/sort';
|
||
|
import {UserService} from '../../_services';
|
||
|
import {Router} from '@angular/router';
|
||
|
|
||
|
@Component({
|
||
|
selector: 'app-accounts',
|
||
|
templateUrl: './accounts.component.html',
|
||
|
styleUrls: ['./accounts.component.scss']
|
||
|
})
|
||
|
export class AccountsComponent implements OnInit, AfterViewInit{
|
||
|
dataSource: MatTableDataSource<any>;
|
||
|
displayedColumns = ['name', 'phone', 'created', 'balance', 'status', 'failedPinAttempts', 'select'];
|
||
|
initialSelection = [];
|
||
|
allowMultiSelect = true;
|
||
|
selection: SelectionModel<any>;
|
||
|
isDisbursing = false;
|
||
|
|
||
|
@ViewChild(MatPaginator) paginator: MatPaginator;
|
||
|
@ViewChild(MatSort) sort: MatSort;
|
||
|
|
||
|
constructor(
|
||
|
private userService: UserService,
|
||
|
private router: Router
|
||
|
) { }
|
||
|
|
||
|
ngOnInit(): void {
|
||
|
this.dataSource = new MatTableDataSource<any>(this.userService.users);
|
||
|
this.selection = new SelectionModel<any>(this.allowMultiSelect, this.initialSelection);
|
||
|
}
|
||
|
|
||
|
addTransfer(): void {
|
||
|
this.isDisbursing = true;
|
||
|
}
|
||
|
|
||
|
ngAfterViewInit(): void {
|
||
|
this.dataSource.paginator = this.paginator;
|
||
|
this.dataSource.sort = this.sort;
|
||
|
}
|
||
|
|
||
|
isAllSelected(): boolean {
|
||
|
const numSelected = this.selection.selected.length;
|
||
|
const numRows = this.dataSource.data.length;
|
||
|
return numSelected === numRows;
|
||
|
}
|
||
|
|
||
|
masterToggle(): void {
|
||
|
this.isAllSelected() ? this.selection.clear() : this.dataSource.data.forEach(row => this.selection.select(row));
|
||
|
}
|
||
|
|
||
|
doFilter(value: string): void {
|
||
|
this.dataSource.filter = value.trim().toLocaleLowerCase();
|
||
|
}
|
||
|
|
||
|
viewAccount(account): void {
|
||
|
this.router.navigateByUrl(`/accounts/${account.id}`);
|
||
|
}
|
||
|
}
|