juice-shop
61 строка · 2.1 Кб
1ngAfterViewInit () {2const products = this.productService.search('')3const quantities = this.quantityService.getAll()4forkJoin([quantities, products]).subscribe(([quantities, products]) => {5const dataTable: TableEntry[] = []6this.tableData = products7this.encodeProductDescription(products)8for (const product of products) {9dataTable.push({10name: product.name,11price: product.price,12deluxePrice: product.deluxePrice,13id: product.id,14image: product.image,15description: product.description16})17}18for (const quantity of quantities) {19const entry = dataTable.find((dataTableEntry) => {20return dataTableEntry.id === quantity.ProductId21})22if (entry === undefined) {23continue24}25entry.quantity = quantity.quantity26}27this.dataSource = new MatTableDataSource<TableEntry>(dataTable)28for (let i = 1; i <= Math.ceil(this.dataSource.data.length / 12); i++) {29this.pageSizeOptions.push(i * 12)30}31this.paginator.pageSizeOptions = this.pageSizeOptions32this.dataSource.paginator = this.paginator33this.gridDataSource = this.dataSource.connect()34this.resultsLength = this.dataSource.data.length35this.filterTable()36this.routerSubscription = this.router.events.subscribe(() => {37this.filterTable()38})39if (window.innerWidth < 2600) {40this.breakpoint = 441if (window.innerWidth < 1740) {42this.breakpoint = 343if (window.innerWidth < 1280) {44this.breakpoint = 245if (window.innerWidth < 850) {46this.breakpoint = 147}48}49}50} else {51this.breakpoint = 652}53this.cdRef.detectChanges()54}, (err) => { console.log(err) })55}56
57encodeProductDescription (tableData: any[]) {58for (let i = 0; i < tableData.length; i++) {59tableData[i].description = tableData[i].description.replaceAll('<', '<').replaceAll('>', '>')60}61}