|
|
@@ -2,7 +2,7 @@ import {AfterViewInit, ChangeDetectorRef, Component, OnInit, ViewChild} from '@a |
|
|
import {MatSort, MatSortModule, Sort} from "@angular/material/sort"; |
|
|
import {MatSort, MatSortModule, Sort} from "@angular/material/sort"; |
|
|
import {MatPaginator, MatPaginatorIntl, MatPaginatorModule, PageEvent} from "@angular/material/paginator"; |
|
|
import {MatPaginator, MatPaginatorIntl, MatPaginatorModule, PageEvent} from "@angular/material/paginator"; |
|
|
import {MatTableDataSource, MatTableModule} from "@angular/material/table"; |
|
|
import {MatTableDataSource, MatTableModule} from "@angular/material/table"; |
|
|
import {PartnerJsonld} from "@app/core/api/v1"; |
|
|
|
|
|
|
|
|
import {PartnerJsonld, ProductJsonld, ProductService} from "@app/core/api/v1"; |
|
|
import {OrderFilter} from "@app/_models/orderFilter"; |
|
|
import {OrderFilter} from "@app/_models/orderFilter"; |
|
|
import {ApiConverter} from "@app/_helpers/api.converter"; |
|
|
import {ApiConverter} from "@app/_helpers/api.converter"; |
|
|
import {Router, RouterLink, RouterLinkActive} from "@angular/router"; |
|
|
import {Router, RouterLink, RouterLinkActive} from "@angular/router"; |
|
|
@@ -21,71 +21,64 @@ import {NewProductComponent} from "@app/products/new-product/new-product.compone |
|
|
}) |
|
|
}) |
|
|
export class ProductsComponent implements OnInit, AfterViewInit { |
|
|
export class ProductsComponent implements OnInit, AfterViewInit { |
|
|
@ViewChild(MatSort) sort; |
|
|
@ViewChild(MatSort) sort; |
|
|
@ViewChild(MatPaginator) paginator: MatPaginator; |
|
|
|
|
|
|
|
|
@ViewChild(MatPaginator) productsPaginator: MatPaginator; |
|
|
|
|
|
|
|
|
protected productsSub: Subscription; |
|
|
|
|
|
protected products: Array<PartnerJsonld>; //TODO: ProductJsonld |
|
|
|
|
|
protected dataType!: string; |
|
|
|
|
|
|
|
|
|
|
|
protected dataSource; |
|
|
|
|
|
protected displayedColumns: string[]; |
|
|
protected displayedColumns: string[]; |
|
|
|
|
|
|
|
|
protected length: number; |
|
|
|
|
|
protected pageEvent: PageEvent; |
|
|
|
|
|
protected pageSize: number; |
|
|
|
|
|
protected pageIndex: number; |
|
|
|
|
|
|
|
|
protected productsSub: Subscription; |
|
|
|
|
|
protected products: Array<ProductJsonld>; |
|
|
|
|
|
protected productsDataSource; |
|
|
|
|
|
protected productsLength: number; |
|
|
|
|
|
protected productsPageEvent: PageEvent; |
|
|
|
|
|
protected productsPageSize: number; |
|
|
|
|
|
protected productPageIndex: number; |
|
|
|
|
|
|
|
|
constructor( |
|
|
constructor( |
|
|
private router: Router, |
|
|
private router: Router, |
|
|
private modalService: NgbModal |
|
|
|
|
|
|
|
|
private modalService: NgbModal, |
|
|
|
|
|
private productService: ProductService |
|
|
) { |
|
|
) { |
|
|
this.sort = new MatSort(); |
|
|
this.sort = new MatSort(); |
|
|
this.paginator = new MatPaginator(new MatPaginatorIntl(), ChangeDetectorRef.prototype); |
|
|
|
|
|
this.dataSource = new MatTableDataSource; //<ProductJsonld>(this.products) |
|
|
|
|
|
this.displayedColumns = ['pos', 'name', 'storage', 'number']; |
|
|
|
|
|
|
|
|
this.displayedColumns = ['pos', 'image', 'name', 'storage', 'number']; |
|
|
|
|
|
|
|
|
this.productsSub = new Subscription(); |
|
|
this.productsSub = new Subscription(); |
|
|
this.products = []; |
|
|
this.products = []; |
|
|
|
|
|
|
|
|
this.length = 0; |
|
|
|
|
|
this.pageEvent = new PageEvent(); |
|
|
|
|
|
this.pageSize = 10; |
|
|
|
|
|
this.pageIndex = 0; |
|
|
|
|
|
|
|
|
this.productsPaginator = new MatPaginator(new MatPaginatorIntl(), ChangeDetectorRef.prototype); |
|
|
|
|
|
this.productsDataSource = new MatTableDataSource<ProductJsonld>(this.products); |
|
|
|
|
|
this.productsLength = 0; |
|
|
|
|
|
this.productsPageEvent = new PageEvent(); |
|
|
|
|
|
this.productsPageSize = 10; |
|
|
|
|
|
this.productPageIndex = 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ngOnInit() { |
|
|
ngOnInit() { |
|
|
this.getData(); |
|
|
|
|
|
|
|
|
this.getProductData(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ngAfterViewInit() { |
|
|
ngAfterViewInit() { |
|
|
this.dataSource.sort = this.sort; |
|
|
|
|
|
this.dataSource.paginator = this.paginator; |
|
|
|
|
|
|
|
|
this.productsDataSource.sort = this.sort; |
|
|
|
|
|
this.productsDataSource.paginator = this.productsPaginator; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getData() { |
|
|
|
|
|
// this.productsSub = this.productService.productsGetCollection( |
|
|
|
|
|
// this.pageIndex + 1, |
|
|
|
|
|
// this.pageSize, |
|
|
|
|
|
// this.dataType, |
|
|
|
|
|
// undefined, |
|
|
|
|
|
// this.nameOrderAsc, |
|
|
|
|
|
// this.storageOrderAsc, |
|
|
|
|
|
// this.numberOrderAsc |
|
|
|
|
|
// ).subscribe( |
|
|
|
|
|
// data => { |
|
|
|
|
|
// this.products = data["hydra:member"]; |
|
|
|
|
|
// this.dataSource = new MatTableDataSource<ProductJsonld>(this.products); |
|
|
|
|
|
// console.log(data); |
|
|
|
|
|
// this.length = Number(data["hydra:totalItems"]); |
|
|
|
|
|
// this.paginator.length = this.length; |
|
|
|
|
|
// } |
|
|
|
|
|
// ); |
|
|
|
|
|
|
|
|
getProductData() { |
|
|
|
|
|
this.productsSub = this.productService.productsGetCollection( |
|
|
|
|
|
this.productPageIndex + 1, |
|
|
|
|
|
this.productsPageSize |
|
|
|
|
|
).subscribe( |
|
|
|
|
|
data => { |
|
|
|
|
|
this.products = data["hydra:member"]; |
|
|
|
|
|
this.productsDataSource = new MatTableDataSource<ProductJsonld>(this.products); |
|
|
|
|
|
this.productsLength = Number(data["hydra:totalItems"]); |
|
|
|
|
|
this.productsPaginator.length = this.productsLength; |
|
|
|
|
|
console.log(this.products); |
|
|
|
|
|
} |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** Announce the change in sort state for assistive technology. */ |
|
|
/** Announce the change in sort state for assistive technology. */ |
|
|
onSortChange(sortState: Sort) { |
|
|
onSortChange(sortState: Sort) { |
|
|
// Reset page index to first page |
|
|
// Reset page index to first page |
|
|
this.pageIndex = 0; |
|
|
|
|
|
|
|
|
this.productPageIndex = 0; |
|
|
|
|
|
|
|
|
let order: OrderFilter; |
|
|
let order: OrderFilter; |
|
|
if (sortState.direction === "") { |
|
|
if (sortState.direction === "") { |
|
|
@@ -108,23 +101,22 @@ export class ProductsComponent implements OnInit, AfterViewInit { |
|
|
// this.websiteOrderAsc = order; |
|
|
// this.websiteOrderAsc = order; |
|
|
// break; |
|
|
// break; |
|
|
// } |
|
|
// } |
|
|
this.getData(); |
|
|
|
|
|
|
|
|
this.getProductData(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
handlePageEvent(e: PageEvent) { |
|
|
handlePageEvent(e: PageEvent) { |
|
|
this.pageEvent = e; |
|
|
|
|
|
this.length = e.length; |
|
|
|
|
|
this.pageIndex = e.pageIndex.valueOf(); |
|
|
|
|
|
this.pageSize = e.pageSize.valueOf(); |
|
|
|
|
|
this.getData(); |
|
|
|
|
|
|
|
|
this.productsPageEvent = e; |
|
|
|
|
|
this.productsLength = e.length; |
|
|
|
|
|
this.productPageIndex = e.pageIndex.valueOf(); |
|
|
|
|
|
this.productsPageSize = e.pageSize.valueOf(); |
|
|
|
|
|
this.getProductData(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
navigateToProductDetails(element: any) { |
|
|
navigateToProductDetails(element: any) { |
|
|
const product: PartnerJsonld = element as PartnerJsonld; //Todo: ProductJsonld |
|
|
|
|
|
|
|
|
const product: ProductJsonld = element as ProductJsonld; |
|
|
console.log(product.type); |
|
|
console.log(product.type); |
|
|
console.log(ApiConverter.extractId(product.id)); |
|
|
console.log(ApiConverter.extractId(product.id)); |
|
|
// this.router.navigate(['/products', ApiConverter.extractId(product.id)]); |
|
|
|
|
|
this.router.navigate(['/products', '1']); |
|
|
|
|
|
|
|
|
this.router.navigate(['/products', ApiConverter.extractId(product.id)]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
openModalNewProduct() { |
|
|
openModalNewProduct() { |
|
|
|