juice-shop

Форк
0
/
code-fixes.component.ts 
59 строк · 1.8 Кб
1
import { Component, Input, type OnInit, ViewChild, type DoCheck, KeyValueDiffers, type KeyValueDiffer } from '@angular/core'
2
import { NgxTextDiffComponent } from 'ngx-text-diff'
3
import { CookieService } from 'ngx-cookie'
4
import { type DiffTableFormat } from 'ngx-text-diff/lib/ngx-text-diff.model'
5
import { type RandomFixes } from '../code-snippet/code-snippet.component'
6

7
@Component({
8
  selector: 'app-code-fixes',
9
  templateUrl: './code-fixes.component.html',
10
  styleUrls: ['./code-fixes.component.scss']
11
})
12
export class CodeFixesComponent implements OnInit, DoCheck {
13
  differ: KeyValueDiffer<string, DiffTableFormat>
14

15
  constructor (private readonly cookieService: CookieService, private readonly differs: KeyValueDiffers) {
16
    this.cookieService = cookieService
17
    this.differ = this.differs.find({}).create()
18
  }
19

20
  @Input('snippet')
21
  public snippet: string = ''
22

23
  @Input('fixes')
24
  public fixes: string[] = []
25

26
  @Input('selectedFix')
27
  public selectedFix: number = 0
28

29
  @Input('randomFixes')
30
  public randomFixes: RandomFixes[] = []
31

32
  @Input('format')
33
  public format: string = 'SideBySide'
34

35
  @ViewChild('codeComponent', { static: false }) codeComponent: NgxTextDiffComponent
36

37
  ngOnInit (): void {
38
    if (this.cookieService.hasKey('code-fixes-component-format')) {
39
      this.format = this.cookieService.get('code-fixes-component-format')
40
    } else {
41
      this.format = 'LineByLine'
42
      this.cookieService.put('code-fixes-component-format', 'LineByLine')
43
    }
44
  }
45

46
  ngDoCheck () {
47
    try {
48
      const change = this.differ.diff({ 'diff-format': this.codeComponent.format })
49
      if (change) {
50
        change.forEachChangedItem(item => {
51
          this.format = item.currentValue
52
          this.cookieService.put('code-fixes-component-format', this.format)
53
        }
54
        )
55
      }
56
    } catch {
57
    }
58
  }
59
}
60

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

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

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

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