summaryrefslogtreecommitdiffstats
path: root/public/src/app/sdc-notify-dialog/sdc-notify-dialog.component.ts
blob: 7572012925d38d2ca3e26a4995ab36736dd8c908 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { Component, ElementRef, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { RestApiService } from '../api/rest-api.service';
import { MainComponent } from '../main/main.component';
import { Store } from '../store/store';

@Component({
  selector: 'app-sdc-notify-dialog',
  templateUrl: './sdc-notify-dialog.component.html',
  styleUrls: ['./sdc-notify-dialog.component.scss']
})
export class SdcNotifyDialogComponent {
  @ViewChild(MainComponent) mainComponent: ElementRef;

  constructor(
    public store: Store,
    private router: Router,
    private _restApi: RestApiService
  ) {}

  closeDialog() {
    const currentUrl = this.router.url;
    if (currentUrl.includes('main')) {
      if (this.store.cdumpIsDirty) {
        this.saveCDUMP();
      } else {
        this.completeAndClose();
      }
    } else {
      this.completeAndClose();
    }
  }

  saveCDUMP() {
    this.store.loader = true;
    this._restApi
      .saveMonitoringComponent({
        contextType: this.store.sdcParmas.contextType,
        serviceUuid: this.store.sdcParmas.uuid,
        vfiName: this.store.vfiName,
        vfcmtUuid: this.store.mcUuid,
        flowType: this.store.flowType,
        cdump: this.store.cdump
      })
      .subscribe(
        success => {
          this.store.loader = false;
          this.store.mcUuid = success.uuid;
          this.store.ifrmaeMessenger.notify('ACTION_COMPLETED');
        },
        error => {
          this.store.loader = false;
          console.log(error.notes);
          this.store.ifrmaeMessenger.notify('ACTION_COMPLETED');
          this.store.ErrorContent = Object.values(error.requestError);
          this.store.displayErrorDialog = true;
        },
        () => {
          this.store.ifrmaeMessenger.notify('ACTION_COMPLETED');
        }
      );
  }

  private completeAndClose() {
    this.store.ifrmaeMessenger.notify('ACTION_COMPLETED');
    this.store.displaySDCDialog = false;
  }

  closeforChange() {
    this.completeAndClose();
  }
}