|
|
|
@@ -3,9 +3,9 @@ import {MatSort, Sort} from "@angular/material/sort"; |
|
|
|
import {PagingComponent} from "@app/_components/paging/paging.component"; |
|
|
|
import {Subscription} from "rxjs"; |
|
|
|
import { |
|
|
|
ContactJsonld, ContactPartnerProductJsonld, ContactPartnerProductService, |
|
|
|
ContactJsonld, ContactPartnerProductJsonld, ContactPartnerProductService, PartnerFollowJsonld, |
|
|
|
PartnerJsonld, PartnerProductJsonld, |
|
|
|
PartnerProductService, PostJsonld, |
|
|
|
PartnerProductService, |
|
|
|
ProductJsonld, |
|
|
|
ProductService, |
|
|
|
UserJsonld, |
|
|
|
@@ -18,6 +18,7 @@ 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"; |
|
|
|
import {TranslateService} from "@ngx-translate/core"; |
|
|
|
type GeneralDataSource = MatTableDataSource<any>; |
|
|
|
|
|
|
|
@Component({ |
|
|
|
selector: 'app-product-list', |
|
|
|
@@ -36,7 +37,14 @@ export class ProductListComponent implements OnInit, AfterViewInit { |
|
|
|
|
|
|
|
protected productsSub: Subscription; |
|
|
|
protected products: Array<ProductJsonld>; |
|
|
|
protected dataSource; |
|
|
|
protected userProducts: Array<PartnerFollowJsonld>; |
|
|
|
protected partnerProducts: Array<PartnerProductJsonld>; |
|
|
|
protected contactPartnerProducts: Array<ContactPartnerProductJsonld>; |
|
|
|
|
|
|
|
protected dataSourceProducts; |
|
|
|
protected dataSourceUserProducts; |
|
|
|
protected dataSourcePartnerProducts; |
|
|
|
protected dataSourceContactPartnerProducts; |
|
|
|
protected bShowNewProductButton: boolean; |
|
|
|
protected nameOrderAsc: OrderFilter; |
|
|
|
|
|
|
|
@@ -50,11 +58,17 @@ export class ProductListComponent implements OnInit, AfterViewInit { |
|
|
|
protected appHelperService: AppHelperService, |
|
|
|
) { |
|
|
|
this.sort = new MatSort(); |
|
|
|
this.displayedColumns = ['details', 'pos', 'image', 'name', 'storage', 'number']; |
|
|
|
this.displayedColumns = ['details', 'pos', 'image', 'name']; |
|
|
|
|
|
|
|
this.productsSub = new Subscription(); |
|
|
|
this.products = []; |
|
|
|
this.dataSource = new MatTableDataSource<ProductJsonld>(this.products); |
|
|
|
this.userProducts = []; |
|
|
|
this.partnerProducts = []; |
|
|
|
this.contactPartnerProducts = []; |
|
|
|
this.dataSourceProducts = new MatTableDataSource<ProductJsonld>(this.products); |
|
|
|
this.dataSourceUserProducts = new MatTableDataSource<PartnerFollowJsonld>(this.userProducts); |
|
|
|
this.dataSourcePartnerProducts = new MatTableDataSource<PartnerProductJsonld>(this.partnerProducts); |
|
|
|
this.dataSourceContactPartnerProducts = new MatTableDataSource<ContactPartnerProductJsonld>(this.contactPartnerProducts); |
|
|
|
this.bShowNewProductButton = true; |
|
|
|
this.nameOrderAsc = OrderFilter.Asc; |
|
|
|
} |
|
|
|
@@ -68,13 +82,24 @@ export class ProductListComponent implements OnInit, AfterViewInit { |
|
|
|
} |
|
|
|
|
|
|
|
ngAfterViewInit() { |
|
|
|
this.dataSource.sort = this.sort; |
|
|
|
this.dataSource.paginator = this.pagingComponent.paginator; |
|
|
|
this.dataSourceProducts.sort = this.sort; |
|
|
|
this.dataSourceProducts.paginator = this.pagingComponent.paginator; |
|
|
|
this.pagingComponent.getData(); |
|
|
|
} |
|
|
|
|
|
|
|
getData = (searchValue = undefined) => { |
|
|
|
getDataSource(): GeneralDataSource { |
|
|
|
if (this.user !== undefined) { |
|
|
|
return this.dataSourceUserProducts; |
|
|
|
} else if (this.partner !== undefined) { |
|
|
|
return this.dataSourcePartnerProducts; |
|
|
|
} else if (this.contact !== undefined) { |
|
|
|
return this.dataSourceContactPartnerProducts; |
|
|
|
} else { |
|
|
|
return this.dataSourceProducts; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
getData = (searchValue = undefined) => { |
|
|
|
if (this.user !== undefined) { |
|
|
|
this.getUserProducts(searchValue); |
|
|
|
} else if (this.partner !== undefined) { |
|
|
|
@@ -97,7 +122,7 @@ export class ProductListComponent implements OnInit, AfterViewInit { |
|
|
|
data => { |
|
|
|
this.products = data["hydra:member"]; |
|
|
|
this.pagingComponent.setDataLength(Number(data["hydra:totalItems"])); |
|
|
|
this.dataSource = new MatTableDataSource<ProductJsonld>(this.products); |
|
|
|
this.dataSourceProducts = new MatTableDataSource<ProductJsonld>(this.products); |
|
|
|
} |
|
|
|
); |
|
|
|
} |
|
|
|
@@ -122,7 +147,7 @@ export class ProductListComponent implements OnInit, AfterViewInit { |
|
|
|
|
|
|
|
}) |
|
|
|
this.pagingComponent.setDataLength(Number(data["hydra:totalItems"])); |
|
|
|
this.dataSource = new MatTableDataSource<ProductJsonld>(this.products); |
|
|
|
this.dataSourceProducts = new MatTableDataSource<ProductJsonld>(this.products); |
|
|
|
} |
|
|
|
); |
|
|
|
} |
|
|
|
@@ -139,15 +164,9 @@ export class ProductListComponent implements OnInit, AfterViewInit { |
|
|
|
searchValue, |
|
|
|
).subscribe( |
|
|
|
data => { |
|
|
|
let partnerProducts = data["hydra:member"]; |
|
|
|
this.products = []; |
|
|
|
partnerProducts.forEach(item => { |
|
|
|
if (item.product) { |
|
|
|
this.products.push(item.product); |
|
|
|
} |
|
|
|
}) |
|
|
|
this.partnerProducts = data["hydra:member"]; |
|
|
|
this.pagingComponent.setDataLength(Number(data["hydra:totalItems"])); |
|
|
|
this.dataSource = new MatTableDataSource<ProductJsonld>(this.products); |
|
|
|
this.dataSourcePartnerProducts = new MatTableDataSource<PartnerProductJsonld>(this.partnerProducts); |
|
|
|
} |
|
|
|
); |
|
|
|
} |
|
|
|
@@ -161,19 +180,38 @@ export class ProductListComponent implements OnInit, AfterViewInit { |
|
|
|
searchValue |
|
|
|
).subscribe( |
|
|
|
data => { |
|
|
|
let contactProduct = data["hydra:member"]; |
|
|
|
this.products = []; |
|
|
|
contactProduct.forEach(item => { |
|
|
|
if (item.product) { |
|
|
|
this.products.push(item.product); |
|
|
|
} |
|
|
|
}) |
|
|
|
this.contactPartnerProducts = data["hydra:member"]; |
|
|
|
this.pagingComponent.setDataLength(Number(data["hydra:totalItems"])); |
|
|
|
this.dataSource = new MatTableDataSource<ProductJsonld>(this.products); |
|
|
|
this.dataSourceContactPartnerProducts = new MatTableDataSource<ContactPartnerProductJsonld>(this.contactPartnerProducts); |
|
|
|
} |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
getElementValue(element: any, field: any): any { |
|
|
|
if (this.user !== undefined) { |
|
|
|
return element['partner'][field]; |
|
|
|
} else if (this.partner !== undefined) { |
|
|
|
return element['partner'][field]; |
|
|
|
} else if (this.contact !== undefined) { |
|
|
|
return element[field]; |
|
|
|
} else { |
|
|
|
return element[field]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
getProductFromElement(element: any): ProductJsonld { |
|
|
|
console.log(element['product']); |
|
|
|
if (this.user !== undefined) { |
|
|
|
return element['product']; |
|
|
|
} else if (this.partner !== undefined) { |
|
|
|
return element['product']; |
|
|
|
} else if (this.contact !== undefined) { |
|
|
|
return element['product']; |
|
|
|
} else { |
|
|
|
return element; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
onSortChange = (sortState: Sort) => { |
|
|
|
this.pagingComponent.resetPageIndex() |
|
|
|
|
|
|
|
@@ -188,7 +226,16 @@ export class ProductListComponent implements OnInit, AfterViewInit { |
|
|
|
} |
|
|
|
|
|
|
|
navigateToProductDetails(element: any) { |
|
|
|
const product: ProductJsonld = element as ProductJsonld; |
|
|
|
let product: ProductJsonld; |
|
|
|
if (this.user !== undefined) { |
|
|
|
product = element['partner']; |
|
|
|
} else if (this.partner !== undefined) { |
|
|
|
product = element['partner']; |
|
|
|
} else if (this.contact !== undefined) { |
|
|
|
product = element['partnerProduct']['partner']; |
|
|
|
} else { |
|
|
|
product = element; |
|
|
|
} |
|
|
|
this.router.navigate(['/product', this.appHelperService.extractId(product.id)]); |
|
|
|
} |
|
|
|
|
|
|
|
@@ -232,15 +279,21 @@ export class ProductListComponent implements OnInit, AfterViewInit { |
|
|
|
this.translateService.get('system.confirm-unassign').subscribe((translation: string) => { |
|
|
|
confirmMessage = translation; |
|
|
|
}); |
|
|
|
const userConfirmed = window.confirm(confirmMessage); |
|
|
|
const userConfirmed = confirm(confirmMessage); |
|
|
|
if (userConfirmed) { |
|
|
|
console.log(element); |
|
|
|
console.log(this.partner); |
|
|
|
console.log(this.contact); |
|
|
|
if (this.partner) { |
|
|
|
//this.contactPartnerProductService.contactPartnerProductsIdDelete(element.id) |
|
|
|
this.partnerProductService.partnerProductsIdDelete(this.appHelperService.extractId(element.id)).subscribe( |
|
|
|
data => { |
|
|
|
this.getData(this.pagingComponent.getSearchValue()); |
|
|
|
} |
|
|
|
); |
|
|
|
} else if (this.contact) { |
|
|
|
//this.partnerProductService.partnerProductsIdDelete(element.id) |
|
|
|
this.contactPartnerProductService.contactPartnerProductsIdDelete(this.appHelperService.extractId(element.id)).subscribe( |
|
|
|
data => { |
|
|
|
this.getData(this.pagingComponent.getSearchValue()); |
|
|
|
} |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|