aboutsummaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/drawingBoard/drawing-board-header/drawing-board-header.component.ts
blob: 38284e214dbeff2329a3b3468868ccce577fa131 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import {Component, ViewChild} from '@angular/core';
import {ContextMenuComponent, ContextMenuService} from 'ngx-contextmenu';
import {DialogService} from 'ng2-bootstrap-modal';
import {ServicePopupComponent} from '../../components/service-popup/service-popup.component';
import {MsoService} from '../../services/msoService/mso.service'
import * as _ from 'lodash';
import {ActivatedRoute} from '@angular/router';
import {ServiceInstance} from "../../shared/models/serviceInstance";
import {OwningEntity} from "../../shared/models/owningEntity";
import {MessageBoxData, ModalSize, ModalType} from "../../shared/components/messageBox/messageBox.data";
import {MessageBoxService} from "../../shared/components/messageBox/messageBox.service";
import {NgRedux} from "@angular-redux/store";
import {AppState} from "../../store/reducers";
import {IframeService} from "../../shared/utils/iframe.service";

@Component({
  selector: 'drawing-board-header',
  providers: [MsoService],
  templateUrl: './drawing-board-header.component.html',
  styleUrls: ['./drawing-board-header.component.scss']
})

export class DrawingBoardHeader {
  serviceName: string;
  numServicesToDeploy: number;
  status: string = 'Designing a new service';
  serviceModelId: string;
  parentElementClassName = 'content';

  constructor(private _contextMenuService: ContextMenuService, private dialogService: DialogService,
              private _iframeService : IframeService,
              private route: ActivatedRoute, private msoService: MsoService,
              private store: NgRedux<AppState>) {
    this.route
      .queryParams
      .subscribe(params => {
        this.serviceModelId = params['serviceModelId'];
        if (_.has(this.store.getState().service.serviceHierarchy, this.serviceModelId)) {
          this.setValuesFromStore();
          this.store.subscribe(() => {
            this.setValuesFromStore();
          });
        }
      });
  }


  @ViewChild(ContextMenuComponent) public contextMenu: ContextMenuComponent;

  public onContextMenu($event: MouseEvent, item: any): void {
    this._contextMenuService.show.next({
      contextMenu: this.contextMenu,
      event: $event,
      item: item,
    });
    $event.preventDefault();
    $event.stopPropagation();
  }

  private setValuesFromStore() {
    const serviceInstance = this.store.getState().service.serviceInstance[this.serviceModelId];
    this.numServicesToDeploy = serviceInstance.bulkSize;
    this.serviceName = serviceInstance.instanceName || '<Automatically Assigned>';

  }

  public editService(): void {
    this._iframeService.addClassOpenModal(this.parentElementClassName);
    this.dialogService.addDialog(ServicePopupComponent, {})

  }


  extractOwningEntityNameAccordingtoId(id:String): string {
    let owningEntityName;
    _.forEach(this.store.getState().service.categoryParameters.owningEntityList,function(owningEntity: OwningEntity) {
      if (owningEntity.id === id) {
        owningEntityName = owningEntity.name;

      }})

    return owningEntityName;
  }

  extractServiceFields(): any {
    let instanceFields : ServiceInstance;
    instanceFields = this.store.getState().service.serviceInstance[Object.keys(this.store.getState().service.serviceInstance)[0]];
    instanceFields.subscriberName = this.store.getState().service.subscribers.find(sub => sub.id === instanceFields.globalSubscriberId).name;
    instanceFields.owningEntityName = this.extractOwningEntityNameAccordingtoId(instanceFields.owningEntityId);
    return instanceFields;
  }

  public deployMacroservice(): void {
    var instanceFields = this.extractServiceFields();
    instanceFields.rollbackOnFailure = instanceFields.rollbackOnFailure === 'true';
    this.msoService.submitMsoTask(instanceFields).subscribe((result) => {
      window.parent.postMessage("navigateToInstantiationStatus", '*');
      })
  }

  closePage() {
    let messageBoxData : MessageBoxData = new MessageBoxData(
         "Delete Instantiation",  // modal title
      "You are about to stop the instantiation process of this service. \nAll data will be lost. Are you sure you want to stop?",

              ModalType.alert,
              ModalSize.medium,
             [
      {text:"Stop Instantiation", size:"large",  callback: this.navigate.bind(this), closeModal:true},
      {text:"Cancel", size:"medium", closeModal:true}
    ]);

    MessageBoxService.openModal.next(messageBoxData);
  }

  navigate(){
    window.parent.postMessage("navigateTo", "*");
  }
}