juice-shop

Форк
0
/
restfulXssChallenge_2.ts 
61 строка · 2.1 Кб
1
ngAfterViewInit () {
2
    const products = this.productService.search('')
3
    const quantities = this.quantityService.getAll()
4
    forkJoin([quantities, products]).subscribe(([quantities, products]) => {
5
      const dataTable: TableEntry[] = []
6
      this.tableData = products
7
      this.encodeProductDescription(products)
8
      for (const product of products) {
9
        dataTable.push({
10
          name: product.name,
11
          price: product.price,
12
          deluxePrice: product.deluxePrice,
13
          id: product.id,
14
          image: product.image,
15
          description: product.description
16
        })
17
      }
18
      for (const quantity of quantities) {
19
        const entry = dataTable.find((dataTableEntry) => {
20
          return dataTableEntry.id === quantity.ProductId
21
        })
22
        if (entry === undefined) {
23
          continue
24
        }
25
        entry.quantity = quantity.quantity
26
      }
27
      this.dataSource = new MatTableDataSource<TableEntry>(dataTable)
28
      for (let i = 1; i <= Math.ceil(this.dataSource.data.length / 12); i++) {
29
        this.pageSizeOptions.push(i * 12)
30
      }
31
      this.paginator.pageSizeOptions = this.pageSizeOptions
32
      this.dataSource.paginator = this.paginator
33
      this.gridDataSource = this.dataSource.connect()
34
      this.resultsLength = this.dataSource.data.length
35
      this.filterTable()
36
      this.routerSubscription = this.router.events.subscribe(() => {
37
        this.filterTable()
38
      })
39
      if (window.innerWidth < 2600) {
40
        this.breakpoint = 4
41
        if (window.innerWidth < 1740) {
42
          this.breakpoint = 3
43
          if (window.innerWidth < 1280) {
44
            this.breakpoint = 2
45
            if (window.innerWidth < 850) {
46
              this.breakpoint = 1
47
            }
48
          }
49
        }
50
      } else {
51
        this.breakpoint = 6
52
      }
53
      this.cdRef.detectChanges()
54
    }, (err) => { console.log(err) })
55
  }
56

57
  encodeProductDescription (tableData: any[]) {
58
    for (let i = 0; i < tableData.length; i++) {
59
      tableData[i].description = tableData[i].description.replaceAll('<', '&lt;').replaceAll('>', '&gt;')
60
    }
61
  }

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.