54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
import { Component, OnInit, OnDestroy } from '@angular/core';
|
|
import { Observable } from 'rxjs';
|
|
import { Order } from '../order/order.model';
|
|
import { FullnodeService } from '../fullnode.service';
|
|
import { UserService } from '../user.service';
|
|
import {Owner} from '../owner.model';
|
|
import { OrderService } from '../order/order.service';
|
|
|
|
@Component({
|
|
selector: 'app-list-orders',
|
|
templateUrl: './listorders.component.html',
|
|
styleUrls: ['./listorders.component.css']
|
|
})
|
|
|
|
export class ListOrdersComponent implements OnInit, OnDestroy{
|
|
public todayTotal: number = 0;
|
|
public total: number = 0;
|
|
public orders: Order[] = [];
|
|
public ownerUpdate: Observable<Owner>;
|
|
public ordersUpdate: Observable<Order[]>;
|
|
|
|
constructor(
|
|
public orderService: OrderService,
|
|
public userService: UserService
|
|
){
|
|
this.ownerUpdate = userService.ownerUpdate;
|
|
this.orderService.getAllOrders();
|
|
this.ordersUpdate = orderService.allOrdersUpdate;
|
|
}
|
|
|
|
ngOnInit(){
|
|
this.ordersUpdate.subscribe((orders) => {
|
|
this.total = 0;
|
|
this.todayTotal = 0;
|
|
var today = new Date();
|
|
this.orders = orders;
|
|
console.log('lisord', this.orders.length);
|
|
for (let i=0; i < this.orders.length; i++){
|
|
this.total += this.orders[i].totalZec;
|
|
var date = new Date(this.orders[i]!.timestamp!);
|
|
var diff = (today.getTime() / 1000) - (date.getTime()/1000);
|
|
if (diff < (24*3600)){
|
|
this.todayTotal += this.orders[i].totalZec;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
ngOnDestroy(){
|
|
this.total = 0;
|
|
this.todayTotal = 0;
|
|
}
|
|
}
|