summaryrefslogtreecommitdiffstats
path: root/usecaseui-portal/src/app/views/services/services-list/create-model/create-model.component.ts
blob: 9d0dd6106497ed65214873e43a25db719d876b78 (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import { Component, OnInit, Input, Output, EventEmitter  } from '@angular/core';
import { ServiceListService } from '../../../../core/services/serviceList.service';
import { NzMessageService } from 'ng-zorro-antd';

@Component({
  selector: 'app-create-model',
  templateUrl: './create-model.component.html',
  styleUrls: ['./create-model.component.less'],
})
export class CreateModelComponent implements OnInit { 
  @Input()isVisible: boolean;
  @Input()customerList;
  @Input()serviceTypeList;
  @Input()customerSelected;
  @Input()serviceTypeSelected;
  
  @Output() cancel = new EventEmitter<boolean>();
  @Output() createdModalShow = new EventEmitter<any>();

  serviceTypes: any[];
  currentCustomer: any;
  currentServiceType: any; 
  templateTypeSelected:string = "CCVPN";
  templates: any[] = [];
  currentTemplate: object = { name: null };
  orchestratorList: any[] = [];
  orchestratorSelected: object = { name: null, id: null };
  isSol005Interface: boolean = false;
  temParametersTips: boolean = false;
  createData: Object = {};
  loadingAnimateShow: boolean = false;

  constructor(
      private http: ServiceListService,
      private msg: NzMessageService
  ) {}

  ngOnInit() {
    this.serviceTypes = this.serviceTypeList;
    this.currentCustomer = JSON.parse(JSON.stringify(this.customerSelected));
    this.currentServiceType = JSON.parse(JSON.stringify(this.serviceTypeSelected));
    this.getAlltemplates();
  }

  getServiceType() {
    this.http.getServiceTypes(this.currentCustomer)
    .subscribe((data) => {
      this.serviceTypes = data.map((item) => {
        return { name: item["service-type"] }
      });
      this.currentServiceType = this.serviceTypes[0]
    })
  } 
  
  getAlltemplates() {
    this.http.getAllServiceTemplates(this.templateTypeSelected)
      .subscribe((data) => {
        if(data.length!==0){
            this.templates = data;
            if (this.templateTypeSelected == "Network Service") {
                this.templates = data.filter((d) => {
                    return typeof d.packageInfo.csarName == "string";
                }).map((item) => {
                    let cName = item.packageInfo.csarName.split("/").reverse()[0];
                    return { name: cName, id: item.csarId, packageInfo: item.packageInfo }
                });
            }
            this.currentTemplate = this.templates[0];
        }
      }, (err) => {
        this.msg.error(err);
      })
  }

  getallOrchestrators() {
    this.http.getAllOrchestrators()
      .subscribe((data) => {
        if(data.length > 0){
            this.orchestratorList = data.map((item) => {
                return { name: item["name"], id: item["name"] }
            });
            this.orchestratorSelected = this.orchestratorList[0];
        }
    })
  }

  handleCancel(): void {
    this.isVisible = false;
    this.cancel.emit(false);
    this.loadingAnimateShow = false;
  }

  customerChange(id): void {
    this.currentCustomer = this.customerList.find(item=>{
        return item.id === id
    });
    this.getServiceType();
  }

  choseTemplateType() {
    if(this.templateTypeSelected === 'E2E Service'){
      this.getallOrchestrators();
    }
    this.getAlltemplates();
  }

  handleOk(): void {
      if(this.templates.length === 0){
          this.msg.warning('Template is required.');
          return
      }
    if (this.templateTypeSelected === "SOTN" || this.templateTypeSelected === "CCVPN" || this.templateTypeSelected === "MDONS") {
        this.createData = {
            commonParams: {
              customer: this.currentCustomer,
              serviceType: this.currentServiceType,
              templateType: this.templateTypeSelected
            },
            template: this.currentTemplate
        };
    } else if (this.templateTypeSelected === "E2E Service" || this.templateTypeSelected === "Network Service") {
        this.createData = {
            commonParams: {
                customer: this.currentCustomer,
                serviceType: this.currentServiceType,
                templateType: this.templateTypeSelected
            },
            template: this.currentTemplate,
            orchestrator: this.orchestratorSelected,
            isSol005Interface: this.isSol005Interface
        };
    }
    this.getTemParameters();
  }
  
  getTemParameters() {
    let chosedtemplates = this.createData["template"];
    let types = this.createData["commonParams"].templateType;
    if (types == "E2E Service") {
      types = "e2e";
    } else if (types == "Network Service") {
      types = "ns";
    }
    this.loadingAnimateShow = true;
    this.http.getTemplateParameters(types, chosedtemplates)
        .subscribe((data) => {
          this.loadingAnimateShow = false;
          if (!data || !data.status) {
            this.temParametersTips = true;
            this.isVisible = true;
            this.msg.error('Back end data format error')
          }
          else if (data.status == "FAILED") {
            this.temParametersTips = true;
            this.isVisible = true;
          } else {
            this.cancel.emit(false);
            this.temParametersTips = false;
            this.createdModalShow.emit({templateType: this.templateTypeSelected, data, createData: this.createData})
          }
        })
  }
}