2019-07-04 15:34:42 +01:00
import { Component , OnInit , AfterViewInit , Input , Output , EventEmitter , ViewChild , TemplateRef } from '@angular/core' ;
import { ApiService } from '../providers/api-service' ;
import { AgmCoreModule } from '@agm/core' ;
import { BsModalService , ModalDirective } from 'ngx-bootstrap/modal' ;
import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service' ;
2019-07-12 20:18:28 +01:00
import { PaginationInstance } from 'ngx-pagination' ;
2019-07-04 15:34:42 +01:00
@Component ( {
2019-07-04 16:36:06 +01:00
templateUrl : 'suppliers.component.html' ,
2019-07-04 15:34:42 +01:00
} )
2019-07-04 16:36:06 +01:00
export class SuppliersComponent implements OnInit , AfterViewInit {
@Output ( ) public onClick = new EventEmitter ( ) ;
@Input ( ) public categories : any ;
2019-07-12 18:50:59 +01:00
supplierList : any ;
supplierListAvailable = false ;
2019-07-12 20:05:06 +01:00
sortBy = 'name' ;
sortDir = 'asc' ;
2019-07-12 18:50:59 +01:00
public paginateConfig : PaginationInstance = {
id : 'transpaginate' ,
itemsPerPage : 10 ,
currentPage : 1 ,
totalItems : 0
} ;
2019-07-04 16:36:06 +01:00
public recurClick ( event : any ) : void {
this . onClick . emit ( event ) ;
}
2019-07-04 15:34:42 +01:00
constructor (
private api : ApiService ,
) { }
ngOnInit ( ) : void {
2019-07-12 18:50:59 +01:00
this . loadSuppliers ( 1 ) ;
}
2019-07-12 17:45:43 +01:00
2019-07-12 18:50:59 +01:00
loadSuppliers ( logPage : number ) {
2019-07-12 20:05:06 +01:00
this . api . externalSuppliers ( logPage , this . sortBy , this . sortDir ) . subscribe (
2019-07-12 18:50:59 +01:00
result = > {
this . supplierList = result . suppliers ;
2019-07-12 20:18:28 +01:00
if ( this . supplierList ) {
this . supplierListAvailable = true ;
}
2019-07-12 18:50:59 +01:00
this . paginateConfig . totalItems = result . page_no ;
this . paginateConfig . currentPage = logPage ;
} ,
error = > {
console . log ( 'Retrieval Error' ) ;
console . log ( error . _body ) ;
}
) ;
2019-07-04 15:34:42 +01:00
}
2019-07-12 20:05:06 +01:00
sortName() { this . sortByColumn ( 'name' ) ; }
sortPostcode() { this . sortByColumn ( 'postcode' ) ; }
sortSpend() { this . sortByColumn ( 'spend' ) ; }
2019-07-12 20:18:28 +01:00
2019-07-12 20:05:06 +01:00
sortByColumn ( name ) {
this . sortBy = name ;
this . sortDir = this . sortDir === 'asc' ? 'desc' : 'asc' ;
this . loadSuppliers ( 1 ) ;
}
2019-07-04 15:34:42 +01:00
ngAfterViewInit() {
}
}