juice-shop

Форк
0
/
order-completion.component.ts 
82 строки · 3.8 Кб
1
/*
2
 * Copyright (c) 2014-2024 Bjoern Kimminich & the OWASP Juice Shop contributors.
3
 * SPDX-License-Identifier: MIT
4
 */
5

6
import { Component, type OnInit } from '@angular/core'
7
import { TrackOrderService } from '../Services/track-order.service'
8
import { ActivatedRoute, type ParamMap } from '@angular/router'
9
import { MatTableDataSource } from '@angular/material/table'
10
import { BasketService } from '../Services/basket.service'
11
import { AddressService } from '../Services/address.service'
12
import { ConfigurationService } from '../Services/configuration.service'
13
import { library } from '@fortawesome/fontawesome-svg-core'
14
import { faTwitter } from '@fortawesome/free-brands-svg-icons'
15

16
library.add(faTwitter)
17

18
@Component({
19
  selector: 'app-order-completion',
20
  templateUrl: './order-completion.component.html',
21
  styleUrls: ['./order-completion.component.scss']
22
})
23
export class OrderCompletionComponent implements OnInit {
24
  public tableColumns = ['product', 'price', 'quantity', 'total price']
25
  public dataSource
26
  public orderId: string
27
  public orderDetails: any = { totalPrice: 0 }
28
  public deliveryPrice = 0
29
  public promotionalDiscount = 0
30
  public address: any
31
  public tweetText: string = 'I just purchased'
32

33
  constructor (private readonly configurationService: ConfigurationService, private readonly addressService: AddressService, private readonly trackOrderService: TrackOrderService, public activatedRoute: ActivatedRoute, private readonly basketService: BasketService) { }
34

35
  ngOnInit () {
36
    this.activatedRoute.paramMap.subscribe((paramMap: ParamMap) => {
37
      this.orderId = paramMap.get('id')
38
      this.trackOrderService.find(this.orderId).subscribe((results) => {
39
        this.promotionalDiscount = results.data[0].promotionalAmount ? parseFloat(results.data[0].promotionalAmount) : 0
40
        this.deliveryPrice = results.data[0].deliveryPrice ? parseFloat(results.data[0].deliveryPrice) : 0
41
        this.orderDetails.addressId = results.data[0].addressId
42
        this.orderDetails.paymentId = results.data[0].paymentId
43
        this.orderDetails.totalPrice = results.data[0].totalPrice
44
        // eslint-disable-next-line @typescript-eslint/restrict-plus-operands
45
        this.orderDetails.itemTotal = results.data[0].totalPrice + this.promotionalDiscount - this.deliveryPrice
46
        this.orderDetails.eta = results.data[0].eta || '?'
47
        this.orderDetails.products = results.data[0].products
48
        this.orderDetails.bonus = results.data[0].bonus
49
        this.dataSource = new MatTableDataSource<Element>(this.orderDetails.products)
50
        for (const product of this.orderDetails.products) {
51
          // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
52
          this.tweetText += `%0a- ${product.name}`
53
        }
54
        this.tweetText = this.truncateTweet(this.tweetText)
55
        this.configurationService.getApplicationConfiguration().subscribe((config) => {
56
          if (config?.application?.social) {
57
            this.tweetText += '%0afrom '
58
            if (config.application.social.twitterUrl) {
59
              this.tweetText += config.application.social.twitterUrl.replace('https://twitter.com/', '@')
60
            } else {
61
              this.tweetText += config.application.name
62
            }
63
          }
64
        }, (err) => { console.log(err) })
65
        this.addressService.getById(this.orderDetails.addressId).subscribe((address) => {
66
          this.address = address
67
        }, (error) => { console.log(error) })
68
      }, (err) => { console.log(err) })
69
    }, (err) => { console.log(err) })
70
  }
71

72
  openConfirmationPDF () {
73
    const redirectUrl = `${this.basketService.hostServer}/ftp/order_${this.orderId}.pdf`
74
    window.open(redirectUrl, '_blank')
75
  }
76

77
  truncateTweet = (tweet: string, maxLength = 140) => {
78
    if (!tweet) return null
79
    const showDots = tweet.length > maxLength
80
    return `${tweet.substring(0, maxLength)}${showDots ? '...' : ''}`
81
  }
82
}
83

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

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

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

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