This repository has been archived on 2023-08-16. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
FoodLoop-Web/src/app/dashboard/suppliers.component.ts

71 lines
1.8 KiB
TypeScript
Raw Normal View History

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';
import { PaginationInstance } from 'ngx-pagination';
@Component({
templateUrl: 'suppliers.component.html',
})
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
};
public recurClick(event: any): void {
this.onClick.emit( event );
}
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;
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-12 20:05:06 +01:00
sortName() { this.sortByColumn('name'); }
sortPostcode() { this.sortByColumn('postcode'); }
sortSpend() { this.sortByColumn('spend'); }
2019-07-12 20:05:06 +01:00
sortByColumn(name) {
this.sortBy = name;
this.sortDir = this.sortDir === 'asc' ? 'desc' : 'asc';
this.loadSuppliers(1);
}
ngAfterViewInit() {
}
}