79 lines
2.5 KiB
TypeScript
79 lines
2.5 KiB
TypeScript
|
import {AfterViewInit, Component, OnInit, ViewChild} from '@angular/core';
|
||
|
import {MatTableDataSource} from '@angular/material/table';
|
||
|
import {Transaction} from '../../../_models';
|
||
|
import {SelectionModel} from '@angular/cdk/collections';
|
||
|
import {MatPaginator} from '@angular/material/paginator';
|
||
|
import {MatSort} from '@angular/material/sort';
|
||
|
import {TransactionService, UserService} from '../../../_services';
|
||
|
import {ActivatedRoute, Params} from '@angular/router';
|
||
|
|
||
|
@Component({
|
||
|
selector: 'app-account-details',
|
||
|
templateUrl: './account-details.component.html',
|
||
|
styleUrls: ['./account-details.component.scss']
|
||
|
})
|
||
|
export class AccountDetailsComponent implements OnInit, AfterViewInit {
|
||
|
dataSource: MatTableDataSource<Transaction>;
|
||
|
displayedColumns = ['sender', 'recipient', 'token', 'value', 'view', 'select'];
|
||
|
initialSelection = [];
|
||
|
allowMultiSelect = true;
|
||
|
selection: SelectionModel<any>;
|
||
|
date: string;
|
||
|
time: number;
|
||
|
isDisbursing = false;
|
||
|
transaction: Transaction;
|
||
|
account: any;
|
||
|
|
||
|
@ViewChild(MatPaginator) paginator: MatPaginator;
|
||
|
@ViewChild(MatSort) sort: MatSort;
|
||
|
|
||
|
constructor(
|
||
|
private transactionService: TransactionService,
|
||
|
private userService: UserService,
|
||
|
private route: ActivatedRoute
|
||
|
) {
|
||
|
this.route.paramMap.subscribe((params: Params) => {
|
||
|
this.account = this.userService.getUserById(params.get('id'));
|
||
|
});
|
||
|
}
|
||
|
|
||
|
ngOnInit(): void {
|
||
|
this.transactionService.transactionsSubject.subscribe(transactions => {
|
||
|
this.dataSource = new MatTableDataSource<Transaction>(transactions);
|
||
|
this.dataSource.paginator = this.paginator;
|
||
|
this.dataSource.sort = this.sort;
|
||
|
});
|
||
|
this.selection = new SelectionModel<any>(this.allowMultiSelect, this.initialSelection);
|
||
|
|
||
|
const d = new Date();
|
||
|
this.date = `${d.getDate()}/${d.getMonth()}/${d.getFullYear()}`;
|
||
|
}
|
||
|
|
||
|
ngAfterViewInit(): void {
|
||
|
this.dataSource.paginator = this.paginator;
|
||
|
this.dataSource.sort = this.sort;
|
||
|
}
|
||
|
|
||
|
addTransfer(): void {
|
||
|
this.isDisbursing = !this.isDisbursing;
|
||
|
}
|
||
|
|
||
|
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();
|
||
|
}
|
||
|
|
||
|
viewTransaction(transaction): void {
|
||
|
this.transaction = transaction;
|
||
|
}
|
||
|
}
|