/
transactions.component.ts
63 lines (56 loc) · 2.3 KB
/
transactions.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import {AfterViewInit, Component, OnInit, ViewChild} from '@angular/core';
import {MatPaginator} from '@angular/material/paginator';
import {MatSort} from '@angular/material/sort';
import {MatTableDataSource} from '@angular/material/table';
import {FormControl} from '@angular/forms';
import {ActivatedRoute} from '@angular/router';
import {Transaction, Account} from '@burstjs/core';
import {convertBurstTimeToDate, convertNQTStringToNumber} from '@burstjs/util';
@Component({
selector: 'app-transactions',
styleUrls: ['./transactions.component.scss'],
templateUrl: './transactions.component.html'
})
export class TransactionsComponent implements OnInit, AfterViewInit{
public dataSource: MatTableDataSource<Transaction>;
public convertNQTStringToNumber = convertNQTStringToNumber;
public account: Account;
pickerFromField = new FormControl();
pickerToField = new FormControl();
@ViewChild(MatPaginator, {static: false}) paginator: MatPaginator;
@ViewChild(MatSort, {static: false}) sort: MatSort;
constructor(
private route: ActivatedRoute
) {
}
public ngOnInit(): void {
this.dataSource = new MatTableDataSource<Transaction>();
this.dataSource.data = this.route.snapshot.data.transactions;
this.account = this.route.snapshot.data.account;
}
public ngAfterViewInit(): void {
const defaultFilterPredicate = this.dataSource.filterPredicate;
this.dataSource.sort = this.sort;
this.dataSource.filterPredicate = (data, filterValue: string) => {
const date = this.convertTimestamp(data.timestamp);
let withinRange = true;
if (this.pickerFromField.value && this.pickerToField.value) {
withinRange = date > this.pickerFromField.value &&
date < this.pickerToField.value;
} else if (this.pickerFromField.value) {
withinRange = date > this.pickerFromField.value;
} else if (this.pickerToField.value) {
withinRange = date < this.pickerToField.value;
}
return withinRange && defaultFilterPredicate(data, filterValue);
};
}
public applyFilter(filterValue: string): void {
filterValue = filterValue.trim();
filterValue = filterValue.toLowerCase();
this.dataSource.filter = filterValue || 'burst';
}
public convertTimestamp(timestamp: number): Date {
return convertBurstTimeToDate(timestamp);
}
}