{ "version": 3, "sources": ["src/@omnial/shared/product-collections/product-collections.component.ts", "src/app/shared/product-collections/product-collections.component.html", "src/@omnial/shared/product-collections/product-collections.module.ts"], "sourcesContent": ["import { Component, Input, AfterViewInit, OnInit, OnDestroy, ViewChild } from '@angular/core';\r\nimport { MatDialog } from '@angular/material/dialog';\r\nimport { Router } from '@angular/router';\r\nimport { NgxSpinnerService } from 'ngx-spinner';\r\nimport { Subscription } from 'rxjs';\r\nimport { ProductCollection, ProductCollectionTab } from 'src/@omnial/_models/catalog/product.collection.model';\r\nimport { Product, ProductDetail } from 'src/@omnial/_models/catalog/product.model';\r\nimport { CatalogService } from 'src/@omnial/_services/catalog/catalog.service';\r\nimport { SevenSpikesService } from 'src/@omnial/_services/catalog/seven.spikes.service';\r\nimport { AppSettings } from 'src/app/app.settings';\r\nimport { ProductDialogComponent } from '../product-dialog/product-dialog.component';\r\n\r\n@Component({\n selector: 'app-product-collections',\n templateUrl: './../../../app/shared/product-collections/product-collections.component.html',\n styleUrls: ['./../../../app/shared/product-collections/product-collections.component.scss'],\n standalone: false\n})\r\nexport class ProductCollectionsComponent implements OnInit, OnDestroy {\r\n @Input() widgetZone: string;\r\n @Input() collectionId: number;\r\n @Input() count1700 = 4;\r\n @Input() count1280 = 4;\r\n @Input() count960 = 4;\r\n @Input() count740 = 3;\r\n @Input() count480 = 2;\r\n public collectionTitle: string;\r\n public collections: ProductCollection[] = [];\r\n private subscriptions: Subscription[] = [];\r\n\r\n constructor(\r\n public dialog: MatDialog,\r\n public router: Router,\r\n public sevenSpikesService: SevenSpikesService,\r\n public catalogService: CatalogService,\r\n public settings: AppSettings,\r\n public spinner: NgxSpinnerService) { }\r\n\r\n ngOnDestroy(): void {\r\n if (this.subscriptions && this.subscriptions.length > 0) {\r\n this.subscriptions.forEach((sub) => { sub.unsubscribe(); });\r\n }\r\n }\r\n\r\n ngOnInit(): void {\r\n if (this.widgetZone) {\r\n this.subscriptions.push(this.sevenSpikesService.getProductCollections(this.widgetZone).subscribe(\r\n res => {\r\n this.collections = this.filterCollection(res);\r\n this.initialiseTabs();\r\n }\r\n ));\r\n } else if (this.collectionId) {\r\n this.subscriptions.push(this.sevenSpikesService.getProductCollectionById(this.collectionId).subscribe(\r\n res => {\r\n this.collections = this.filterCollection(res);\r\n this.initialiseTabs();\r\n }\r\n ));\r\n }\r\n }\r\n\r\n public filterCollection(collections: ProductCollection[]): ProductCollection[] {\r\n collections.forEach((collection) => {\r\n // Only show active tabs and published products\r\n const tabs: ProductCollectionTab[] = []\r\n collection.tabs?.forEach((collectionTab) => {\r\n const products: Product[] = []\r\n const productIds: number[] = []\r\n let noProducts = 0;\r\n collectionTab.products.forEach((product) => {\r\n if (product.published) {\r\n products.push(product);\r\n productIds.push(product.id);\r\n noProducts++;\r\n }\r\n });\r\n collectionTab.products = products;\r\n collectionTab.productIds = productIds;\r\n collectionTab.noProducts = noProducts;\r\n if (collectionTab.active) {\r\n tabs.push(collectionTab);\r\n }\r\n collection.tabs = tabs;\r\n });\r\n });\r\n return collections;\r\n }\r\n\r\n public initialiseTabs() {\r\n if (this.collections[0]?.tabs[0]?.products) {\r\n this.collectionTitle = this.collections[0].title;\r\n }\r\n }\r\n\r\n public openProductDialog(productSimple: Product): void {\r\n this.spinner.show();\r\n this.subscriptions.push(this.catalogService.getProductDetail(productSimple.id).subscribe(\r\n res => {\r\n this.spinner.hide();\r\n const product = res as ProductDetail;\r\n const dialogRef = this.dialog.open(ProductDialogComponent, {\r\n data: { product, category: null, listId: this.widgetZone },\r\n panelClass: 'product-dialog',\r\n direction: (this.settings.rtl) ? 'rtl' : 'ltr'\r\n });\r\n dialogRef.afterClosed().subscribe(productDialog => {\r\n if (productDialog) {\r\n this.router.navigate([productSimple.canonical, product.seName]);\r\n }\r\n });\r\n }));\r\n }\r\n}\r\n", "