|
|
|
@@ -3,6 +3,7 @@ import {MatSort, Sort} from "@angular/material/sort"; |
|
|
|
import {PagingComponent} from "@app/_components/paging/paging.component"; |
|
|
|
import {Subscription} from "rxjs"; |
|
|
|
import { |
|
|
|
ContactJsonld, ContactPartnerProductService, |
|
|
|
PartnerJsonld, |
|
|
|
PartnerProductService, |
|
|
|
ProductJsonld, |
|
|
|
@@ -15,6 +16,7 @@ import {AppHelperService} from "@app/_helpers/app-helper.service"; |
|
|
|
import {MatTableDataSource} from "@angular/material/table"; |
|
|
|
import {OrderFilter} from "@app/_models/orderFilter"; |
|
|
|
import {NewProductComponent} from "@app/_views/products/new-product/new-product.component"; |
|
|
|
import {AssignProductComponent} from "@app/_views/products/assign-product/assign-product.component"; |
|
|
|
|
|
|
|
@Component({ |
|
|
|
selector: 'app-product-list', |
|
|
|
@@ -25,6 +27,7 @@ export class ProductListComponent implements OnInit, AfterViewInit { |
|
|
|
|
|
|
|
@Input() public user!: UserJsonld; |
|
|
|
@Input() public partner!: PartnerJsonld; |
|
|
|
@Input() public contact!: ContactJsonld; |
|
|
|
@ViewChild(MatSort) sort; |
|
|
|
@ViewChild("pagingComponent", { static: false }) pagingComponent!: PagingComponent; |
|
|
|
|
|
|
|
@@ -33,12 +36,14 @@ export class ProductListComponent implements OnInit, AfterViewInit { |
|
|
|
protected productsSub: Subscription; |
|
|
|
protected products: Array<ProductJsonld>; |
|
|
|
protected dataSource; |
|
|
|
protected bShowNewProductButton: boolean; |
|
|
|
|
|
|
|
constructor( |
|
|
|
private router: Router, |
|
|
|
private productService: ProductService, |
|
|
|
private userProductService: UserProductService, |
|
|
|
private partnerProductService: PartnerProductService, |
|
|
|
private contactPartnerProductService: ContactPartnerProductService, |
|
|
|
protected appHelperService: AppHelperService, |
|
|
|
) { |
|
|
|
this.sort = new MatSort(); |
|
|
|
@@ -47,14 +52,18 @@ export class ProductListComponent implements OnInit, AfterViewInit { |
|
|
|
this.productsSub = new Subscription(); |
|
|
|
this.products = []; |
|
|
|
this.dataSource = new MatTableDataSource<ProductJsonld>(this.products); |
|
|
|
this.bShowNewProductButton = true; |
|
|
|
} |
|
|
|
|
|
|
|
ngOnInit(){ |
|
|
|
this.bShowNewProductButton = |
|
|
|
this.user === undefined && this.partner === undefined && this.contact === undefined; |
|
|
|
} |
|
|
|
|
|
|
|
ngAfterViewInit() { |
|
|
|
this.dataSource.sort = this.sort; |
|
|
|
this.dataSource.paginator = this.pagingComponent.paginator; |
|
|
|
//this.bShowNewProductButton = this.user === undefined && this.partner === undefined; |
|
|
|
this.pagingComponent.getData(); |
|
|
|
} |
|
|
|
|
|
|
|
@@ -63,6 +72,8 @@ export class ProductListComponent implements OnInit, AfterViewInit { |
|
|
|
this.getUserProducts(); |
|
|
|
} else if (this.partner !== undefined) { |
|
|
|
this.getPartnerProducts(); |
|
|
|
} else if (this.contact !== undefined) { |
|
|
|
this.getContactPartnerProduct(); |
|
|
|
} else { |
|
|
|
this.getProducts(); |
|
|
|
} |
|
|
|
@@ -93,12 +104,29 @@ export class ProductListComponent implements OnInit, AfterViewInit { |
|
|
|
this.partner.id, |
|
|
|
).subscribe( |
|
|
|
data => { |
|
|
|
console.log(data); |
|
|
|
let partnerProducts = data["hydra:member"]; |
|
|
|
this.products = []; |
|
|
|
partnerProducts.forEach(item => { |
|
|
|
this.products.push(item.product); |
|
|
|
}) |
|
|
|
this.pagingComponent.dataLength = Number(data["hydra:totalItems"]); |
|
|
|
this.dataSource = new MatTableDataSource<ProductJsonld>(this.products); |
|
|
|
} |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
getContactPartnerProduct = () => { |
|
|
|
this.productsSub = this.contactPartnerProductService.contactPartnerProductsGetCollection( |
|
|
|
this.pagingComponent.getPageIndex(), |
|
|
|
this.pagingComponent.getPageSize(), |
|
|
|
this.contact.id, |
|
|
|
).subscribe( |
|
|
|
data => { |
|
|
|
let contactProduct = data["hydra:member"]; |
|
|
|
this.products = []; |
|
|
|
contactProduct.forEach(item => { |
|
|
|
this.products.push(item.product); |
|
|
|
}) |
|
|
|
console.log(this.products); |
|
|
|
this.pagingComponent.dataLength = Number(data["hydra:totalItems"]); |
|
|
|
this.dataSource = new MatTableDataSource<ProductJsonld>(this.products); |
|
|
|
@@ -142,4 +170,18 @@ export class ProductListComponent implements OnInit, AfterViewInit { |
|
|
|
product.name = ""; |
|
|
|
this.appHelperService.openModal(NewProductComponent, { 'product': product }, this.getData); |
|
|
|
} |
|
|
|
|
|
|
|
openModalAssignProduct() { |
|
|
|
let data = {}; |
|
|
|
if (this.user !== undefined) { |
|
|
|
this.appHelperService.openModal(AssignProductComponent, { 'user' : this.user }, this.getUserProducts); |
|
|
|
} else if (this.partner !== undefined) { |
|
|
|
data = { 'partner' : this.partner }; |
|
|
|
this.appHelperService.openModal(AssignProductComponent, { 'partner' : this.partner }, this.getPartnerProducts); |
|
|
|
} else if (this.contact !== undefined) { |
|
|
|
this.appHelperService.openModal(AssignProductComponent, { 'contact' : this.contact }, this.getContactPartnerProduct); |
|
|
|
} else { |
|
|
|
throw new Error('data not found') |
|
|
|
} |
|
|
|
} |
|
|
|
} |