2 ============LICENSE_START==========================================
3 ===================================================================
4 Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
5 ===================================================================
6 Copyright (C) 2018 IBM.
7 ===================================================================
8 Unless otherwise specified, all software contained herein is licensed
9 under the Apache License, Version 2.0 (the License);
10 you may not use this software except in compliance with the License.
11 You may obtain a copy of the License at
13 http://www.apache.org/licenses/LICENSE-2.0
15 Unless required by applicable law or agreed to in writing, software
16 distributed under the License is distributed on an "AS IS" BASIS,
17 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 See the License for the specific language governing permissions and
19 limitations under the License.
21 ============LICENSE_END============================================
24 import { Component, OnInit, OnDestroy } from '@angular/core';
25 import { ActivatedRoute, Router } from '@angular/router';
26 import { HttpUtilService } from '../../shared/services/httpUtil/http-util.service';
27 import { Subscription } from 'rxjs/Subscription';
28 import { MappingEditorService } from '../../shared/services/mapping-editor.service';
29 import { ParamShareService } from '../../shared/services/paramShare.service';
30 import { environment } from '../../../environments/environment';
31 import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
32 import { NgProgress } from 'ngx-progressbar';
33 import { NotificationsService } from 'angular2-notifications';
34 import { appConstants } from '../../../constants/app-constants'
36 @Component({ selector: 'app-myvnfs', templateUrl: './myvnfs.component.html', styleUrls: ['./myvnfs.component.css'] })
37 export class MyvnfsComponent implements OnInit, OnDestroy {
38 vnfData: Array<Object> = [];
46 vnfcRequired: boolean = false;
51 showProgressBar: true,
56 subscription: Subscription;
58 constructor (private paramShareService: ParamShareService, private ngProgress: NgProgress, private httpUtil: HttpUtilService, private router: Router, private activeROute: ActivatedRoute,
59 private mappingEditorService: MappingEditorService, private modalService: NgbModal) {
64 sessionStorage.setItem('updateParams', undefined);
65 this.mappingEditorService.latestAction = undefined;
66 const apiToken = localStorage['apiToken'];
71 'request-id': apiToken,
72 'action': 'getDesigns',
73 'payload': '{"userID": "","filter":"reference"}'
77 const x = JSON.parse(data.input['design-request']['payload']);
78 x.userID = localStorage['userId'];
79 data.input['design-request']['payload'] = JSON.stringify(x);
80 // console.log("input to payload====", JSON.stringify(data));
81 this.getArtifacts(data);
86 if (this.subscription) { this.subscription.unsubscribe() };
91 this.ngProgress.start();
93 url: environment.getDesigns,
97 if (resp.output.data.block !== undefined && resp.output.data.block !== null && resp.output.data.block.length !== 0) {
98 tempObj = JSON.parse(resp.output.data.block);
99 this.vnfData = tempObj.designInfo;
101 if (this.vnfData === undefined || this.vnfData === null || this.vnfData.length === 0) {
103 // this.noDataMsg = resp.output.status.message;
107 this.ngProgress.done();
110 this.filter = ['vnf-type', 'vnfc-type', 'artifact-name'];
112 this.ngProgress.done();
121 buildNewDesign(response) {
123 // this.modalService.open(content).result.then(res => {
125 // sessionStorage.setItem('vnfParams', JSON.stringify({ vnfType: this.vnfType}));
126 // sessionStorage.setItem("vnfcSelectionFlag",''+this.vnfcRequired+'')
128 // sessionStorage.setItem('vnfParams',"")
131 // this.mappingEditorService.referenceNameObjects = undefined;
132 // this.mappingEditorService.identifier = '';
133 // //this.mappingEditorService.newObject = {};
134 // this.router.navigate([
135 // 'vnfs', 'design', 'references'
140 if (response == 'yes') {
141 sessionStorage.setItem('vnfParams', JSON.stringify({ vnfType: this.vnfType }));
142 sessionStorage.setItem("vnfcSelectionFlag", '' + this.vnfcRequired + '')
144 sessionStorage.setItem('vnfParams', "")
147 this.mappingEditorService.referenceNameObjects = undefined;
148 this.mappingEditorService.identifier = '';
149 //this.mappingEditorService.newObject = {};
150 this.router.navigate([
151 'vnfs', 'design', 'references'
155 validateVnfName(name) {
156 if (!name.trim() || name.length < 1) {
157 this.errorMessage = '';
159 } else if (name.startsWith(' ') || name.endsWith(' ')) {
160 this.errorMessage = 'Leading and trailing spaces are not allowed';
162 } else if (name.includes(' ')) {
163 this.errorMessage = 'More than one space is not allowed in VNF Type';
165 } else if (name.length > 150) {
166 this.errorMessage = 'VNF Type should be of minimum one character and maximum 150 character';
169 this.invalid = false;
170 this.errorMessage = '';
174 navigateToReference(item) {
175 sessionStorage.setItem('updateParams', JSON.stringify(item));
176 this.mappingEditorService.referenceNameObjects = undefined;
177 sessionStorage.setItem('vnfParams', JSON.stringify({ vnfType: item.vnfType, vnfcType: item.vnfcType }));
178 this.mappingEditorService.identifier = '';
179 if (this.mappingEditorService.newObject && this.mappingEditorService.newObject.vnfc != undefined) {
180 this.mappingEditorService.newObject.vnfc = '';
184 .navigate(['../design/references'], {
185 relativeTo: this.activeROute,
192 navigateToRefrenceUpdate() {
196 .navigate(['../design/references/update'], {
197 relativeTo: this.activeROute,
205 // get the value and save the userid and persist it.
206 sessionStorage.setItem("vnfcSelectionFlag", '' + this.vnfcRequired + '')
207 this.mappingEditorService.setTemplateMappingDataFromStore(undefined);
208 localStorage['paramsContent'] = '{}';
209 this.mappingEditorService.setParamContent(undefined);
210 this.paramShareService.setSessionParamData(undefined);
211 const appData = { reference: {}, template: { templateData: {}, nameValueData: {} }, pd: {} };
212 const downloadData = {
214 template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
215 pd: { pdData: '', pdFileName: '' }
217 this.mappingEditorService.changeNavAppData(appData);
218 this.mappingEditorService.changeNavDownloadData(downloadData);
221 let artVnfc = item['artifact-name'].substring(this.lastIndexofEnd("AllAction_", item['artifact-name']), item['artifact-name'].lastIndexOf("_"))
222 if (item['vnf-type'] == artVnfc && item['vnfc-type'] == 'null') {
224 return item['vnfc-type']
230 lastIndexofEnd(str, originlStr) {
231 var io = originlStr.lastIndexOf(str);
232 return io == -1 ? -1 : io + str.length;