2017-09-06 16:05:35 +01:00
import { Component , OnInit , Input , Output , EventEmitter } from '@angular/core' ;
import { ApiService } from '../providers/api-service' ;
2017-09-06 17:51:56 +01:00
// import { PaginatePipe } from 'ngx-pagination';
import { PaginationInstance } from 'ngx-pagination' ;
// import { PaginationControlsComponent } from 'ngx-pagination';
// import { PaginationControlsDirective } from 'ngx-pagination';
// import { TransactionResultComponent } from '../shared/transaction-result.component';
2017-09-06 16:05:35 +01:00
import * as moment from 'moment' ;
import 'rxjs/add/operator/map' ;
@Component ( {
templateUrl : 'transaction-log.component.html' ,
} )
2017-09-19 15:02:48 +01:00
export class TransactionLogComponent implements OnInit {
2017-09-06 16:05:35 +01:00
transactionList ;
noTransactionList = true ;
myDate : any ;
minDate : any ;
2017-09-19 15:02:48 +01:00
public p : any ;
2017-09-06 17:51:56 +01:00
public paginateConfig : PaginationInstance = {
id : 'transpaginate' ,
itemsPerPage : 10 ,
currentPage : 1 ,
totalItems : 0
} ;
2017-09-06 16:05:35 +01:00
constructor (
2017-09-19 15:02:48 +01:00
private api : ApiService ,
) {
2017-09-06 16:05:35 +01:00
this . myDate = moment ( ) . format ( 'YYYY-MM-DD[T]HH:mm' ) ;
// this.myDate = new Date().toISOString().slice(0, 16);
}
ngOnInit ( ) : void {
this . getMinDate ( ) ;
2017-09-06 17:51:56 +01:00
this . loadTransactions ( 1 ) ;
2017-09-06 16:05:35 +01:00
}
2017-09-19 15:02:48 +01:00
getMinDate() {
2017-09-06 16:05:35 +01:00
// gets the April 1st date of the current year
2017-09-19 15:02:48 +01:00
const aprilDate = moment ( ) . month ( 3 ) . date ( 1 ) ;
const now = moment ( ) ;
2017-09-06 16:05:35 +01:00
// Checks if current time is before April 1st, if so returns true
2017-09-19 15:02:48 +01:00
const beforeApril = now . isBefore ( aprilDate ) ;
if ( beforeApril === true ) {
2017-09-06 16:05:35 +01:00
this . minDate = aprilDate . subtract ( 2 , 'years' ) . format ( 'YYYY-MM-DD' ) ;
} else {
this . minDate = aprilDate . subtract ( 1 , 'years' ) . format ( 'YYYY-MM-DD' ) ;
}
}
2017-09-06 17:51:56 +01:00
loadTransactions ( logPage : number ) {
console . log ( logPage ) ;
this . api . transList ( logPage ) . subscribe (
2017-09-06 16:05:35 +01:00
result = > {
2017-09-19 15:02:48 +01:00
if ( result . transactions . length > 0 ) {
2017-09-06 16:05:35 +01:00
this . transactionList = result . transactions ;
2017-09-19 15:02:48 +01:00
// TODO Rename in server
2017-09-06 17:51:56 +01:00
this . paginateConfig . totalItems = result . page_no ;
this . paginateConfig . currentPage = logPage ;
2017-09-06 16:05:35 +01:00
this . noTransactionList = false ;
} else {
// handle the case when the transactionList is empty
this . transactionList = null ;
this . noTransactionList = true ;
}
} ,
error = > {
console . log ( error ) ;
}
) ;
}
}