Project

General

Profile

1
import { NotificationsHandlingService } from './../../../../shared/services/notifications-handling/notifications-handling.service';
2
import { environment } from 'src/environments/environment';
3
import {
4
  Component,
5
  ComponentRef,
6
  ElementRef,
7
  Input,
8
  OnInit,
9
  Output,
10
  Pipe,
11
  PipeTransform,
12
  ViewChild,
13
  EventEmitter,
14
  HostListener,
15
  OnChanges
16
} from '@angular/core';
17
import {InvoiceProcessesService} from '../../../../shared/services/invoice-processes.service';
18
import {FullInvoiceProcess} from '../../../../shared/models/full-invoice-process.interface';
19
import {DomSanitizer, SafeResourceUrl} from '@angular/platform-browser';
20

    
21

    
22
@Component({
23
  selector: 'app-data-capturing-and-verification',
24
  templateUrl: './data-capturing-and-verification.component.html',
25
  styleUrls: ['./data-capturing-and-verification.component.scss']
26
})
27
export class DataCapturingAndVerificationComponent implements OnInit {
28

    
29
  private _process: FullInvoiceProcess;
30

    
31
  get process(): FullInvoiceProcess {
32
    return this._process;
33
  }
34

    
35
  @Input()
36
  set process(value: FullInvoiceProcess) {
37
    this._process = value;
38
    if (value && value.processStatus.name == "Process Needs Capturing Verification") {
39
      this.initializer();
40
    }
41
  }
42

    
43
  @Output() processCompleted = new EventEmitter();
44

    
45
  @ViewChild('iframe', {static: false})
46
  iframe: HTMLIFrameElement;
47

    
48
  sanitizeUrl: SafeResourceUrl;
49

    
50
  constructor(private processService: InvoiceProcessesService, public sanitizer: DomSanitizer, public notifications: NotificationsHandlingService) {
51
  }
52

    
53
  ngOnInit(): void {
54

    
55
  }
56

    
57
  refreshIFrame(): void {
58
    this.sanitizeUrl = this.sanitizer.bypassSecurityTrustResourceUrl((document.getElementById('theIFrame') as HTMLIFrameElement).src);
59
  }
60

    
61
  initializer(): void {
62
    this.processService.getIframe(String(this._process.id)).subscribe(url => {
63
      this.sanitizeUrl = this.sanitizer.bypassSecurityTrustResourceUrl(url);
64
    });
65
  }
66

    
67
  @HostListener('window:message', ['$event'])
68
  onMessage(event): void {
69
    const result = event && event.data ? JSON.parse(event.data) : null;
70
    if (result && result.eventName === 'FC_Verification_TaskClosed'){
71
      this.updateVerificationCompleted();
72
      this.sanitizeUrl = null;
73
    }
74
  }
75

    
76
  private updateVerificationCompleted(): void {
77
    this.processService.updateVerificationCompletedForProcess(this.process.id).subscribe(() => {
78
      this.notifications.showVerificationCompletedSuccess();
79
      this.processCompleted.emit(this.process.id);
80
    });
81
  }
82
}
(4-4/4)