|
@ -1,91 +1,26 @@ |
|
|
import { Component, OnInit } from '@angular/core'; |
|
|
import { Component, OnInit } from '@angular/core'; |
|
|
import { OrdersService } from './orders.service'; |
|
|
|
|
|
import { ICatalog } from '../shared/models/catalog.model'; |
|
|
|
|
|
import { ICatalogItem } from '../shared/models/catalogItem.model'; |
|
|
|
|
|
import { ICatalogType } from '../shared/models/catalogType.model'; |
|
|
|
|
|
import { ICatalogBrand } from '../shared/models/catalogBrand.model'; |
|
|
|
|
|
import { IPager } from '../shared/models/pager.model'; |
|
|
|
|
|
import { BasketWrapperService} from '../shared/services/basket.wrapper.service'; |
|
|
|
|
|
|
|
|
import { OrdersService } from './orders.service'; |
|
|
|
|
|
import { IOrder } from '../shared/models/order.model'; |
|
|
|
|
|
|
|
|
@Component({ |
|
|
@Component({ |
|
|
selector: 'esh-orders .orders', |
|
|
selector: 'esh-orders .orders', |
|
|
styleUrls: ['./orders.component.scss'], |
|
|
styleUrls: ['./orders.component.scss'], |
|
|
templateUrl: './orders.component.html' |
|
|
templateUrl: './orders.component.html' |
|
|
}) |
|
|
}) |
|
|
export class CatalogComponent implements OnInit { |
|
|
|
|
|
brands: ICatalogBrand[]; |
|
|
|
|
|
types: ICatalogType[]; |
|
|
|
|
|
catalog: ICatalog; |
|
|
|
|
|
brandSelected: number; |
|
|
|
|
|
typeSelected: number; |
|
|
|
|
|
paginationInfo: IPager; |
|
|
|
|
|
|
|
|
export class OrdersComponent implements OnInit { |
|
|
|
|
|
orders: IOrder[]; |
|
|
|
|
|
|
|
|
constructor(private service: OrdersService, private basketService: BasketWrapperService) { } |
|
|
|
|
|
|
|
|
constructor(private service: OrdersService) { } |
|
|
|
|
|
|
|
|
ngOnInit() { |
|
|
ngOnInit() { |
|
|
this.getBrands(); |
|
|
|
|
|
this.getCatalog(10, 0); |
|
|
|
|
|
this.getTypes(); |
|
|
|
|
|
|
|
|
this.getOrders(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
onFilterApplied(event: any) { |
|
|
|
|
|
event.preventDefault(); |
|
|
|
|
|
this.getCatalog(this.paginationInfo.itemsPage, this.paginationInfo.actualPage, this.brandSelected, this.typeSelected); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
onBrandFilterChanged(event: any, value: number) { |
|
|
|
|
|
event.preventDefault(); |
|
|
|
|
|
this.brandSelected = value; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
onTypeFilterChanged(event: any, value: number) { |
|
|
|
|
|
event.preventDefault(); |
|
|
|
|
|
this.typeSelected = value; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
onPageChanged(value: any) { |
|
|
|
|
|
console.log('catalog pager event fired' + value); |
|
|
|
|
|
event.preventDefault(); |
|
|
|
|
|
this.paginationInfo.actualPage = value; |
|
|
|
|
|
this.getCatalog(this.paginationInfo.itemsPage, value); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
addToCart(item: ICatalogItem) { |
|
|
|
|
|
this.basketService.addItemToBasket(item); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getCatalog(pageSize:number, pageIndex: number, brand?: number, type?: number) { |
|
|
|
|
|
this.service.getCatalog(pageIndex, pageSize, brand, type).subscribe(catalog => { |
|
|
|
|
|
this.catalog = catalog; |
|
|
|
|
|
console.log('catalog items retrieved: ' + catalog.count); |
|
|
|
|
|
|
|
|
|
|
|
this.paginationInfo = { |
|
|
|
|
|
actualPage : catalog.pageIndex, |
|
|
|
|
|
itemsPage : catalog.pageSize, |
|
|
|
|
|
totalItems : catalog.count, |
|
|
|
|
|
totalPages: Math.ceil(catalog.count / catalog.pageSize), |
|
|
|
|
|
items: catalog.pageSize |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
console.log(this.paginationInfo); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getTypes() { |
|
|
|
|
|
this.service.getTypes().subscribe(types => { |
|
|
|
|
|
this.types = types; |
|
|
|
|
|
let alltypes = { id: null, type: 'All' }; |
|
|
|
|
|
this.types.unshift(alltypes); |
|
|
|
|
|
console.log('types retrieved: ' + types.length); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getBrands() { |
|
|
|
|
|
this.service.getBrands().subscribe(brands => { |
|
|
|
|
|
this.brands = brands; |
|
|
|
|
|
let allBrands = { id: null, brand: 'All' }; |
|
|
|
|
|
this.brands.unshift(allBrands); |
|
|
|
|
|
console.log('brands retrieved: ' + brands.length); |
|
|
|
|
|
|
|
|
getOrders() { |
|
|
|
|
|
this.service.getOrders().subscribe(orders => { |
|
|
|
|
|
this.orders = orders; |
|
|
|
|
|
console.log('orders items retrieved: ' + orders.length); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|